Skip to content

fix: forget an owner server's grant when its entry can no longer use it - #39550

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/35816-forget-stranded-owner-grant
Nov 19, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/35816-forget-stranded-owner-grant

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: When an owner-added remote MCP server can no longer use the sign-in Crew holds for it, Crew revokes that sign-in and removes it from the vault instead of leaving it there unused.

#35692 lets an owner-added remote MCP server sign in through Crew. The grant is stored in the vault under a key made from the server's name and url (crew_oauth.custom_key): CONNECTIONS_CUSTOM_<KEY>_OAUTH_TOKENS and CONNECTIONS_CUSTOM_<KEY>_OAUTH_CLIENT. Four owner actions leave both entries behind with nothing reading them again and nothing deleting them: removing the server, pointing it at another url, turning it into a local server, and saving the OAuth app of the card that then takes over the server's name (#34811). The tokens also stay valid upstream.

Why it matters

A user who removes a server, or moves it, expects Crew to stop holding its sign-in. Today the old grant stays live at the vendor and sits in the vault with no Disconnect that reaches it; the only way out is to spot the unused entry under Settings → Secrets and delete it by hand.

Not a goal

  • Carrying the old grant over to the card: the card signs in with a different client, so the old tokens belong to another client (rejected in owner-server grant left unused in the vault after a card takes over the entry or the server is removed #35816).
  • Sweeping grants stranded before this change: they keep showing as unused under Settings → Secrets.
  • A card that stops yielding without an OAuth app saved on this gateway, such as an app supplied through KIROCREW_CONNECTIONS_* environment variables.
  • Showing a Crew-held grant on the MCP Servers row.
  • Cancelling a Crew sign-in still waiting on its consent page when its server is removed or re-pointed: a consent finished after that stores its grant under the old key.

What changed (motivation → approach → change)

Root cause: nothing deletes a grant held under an owner key. crew_oauth.disconnect already revokes and deletes such a key, but only a Connections card's Disconnect calls it, and only for registry slugs.

Owner action Seam What it hands the cleanup
Remove the server (MCP Servers remove; an Apply uninstall, once the MCP lock is released, however the batch ends) mcp_config_purge._forget_owner_servers each removed name and the url its record held
Edit the server to another url, or to a local command mcp_custom._record_owner_servers the name and the url its record held before
Save the OAuth app of the card that then owns the name connections.api_connections_oauth_client_put each recorded server named for that slug that loses its own sign-in

Each owner record write captures, inside its locked write, the url it moves or drops (owner_servers.replaced_urls). A card save reads which recorded servers the card now claims (owner_servers.taken_by_card), with the same is_signable_name rule the MCP Servers row and the sign-in already apply, so a server under another name, or a letter-case variant such as Slack at the card's url, keeps its own grant. Both hand the names and urls to crew_oauth.forget_owner_grants. It runs disconnect on the pair, revoked upstream where the server advertises a revocation endpoint, then deletes the client. It touches only entries the vault lists, opens the vault with data_home() as async code must, runs after the config write and outside the MCP config lock, and logs a failure without failing the request. An Apply uninstall that the crash-window sweep removes (mcp_config_purge._sweep_dangling_uninstalls, which now returns the names it purged) is forgotten like one the batch reached.

The connections spec (docs/system-specs/modules/connections.md) states the cleanup in both the card and the owner-server paragraphs.

Backwards compatibility

Compatible: every request answers as before; the only difference is that the vault stops keeping a grant that nothing can read.

Reader: src/kiro_crew/connections/crew_oauth.py:_custom_slug -- chat -- reads the pair only under the key of the url the owner record names now, and a card-claimed name never reaches it; a forgotten key is neither (test_a_re_pointed_or_unrecorded_server_is_never_bridged, test_the_card_owns_an_owner_added_slack_server_once_it_has_an_app_or_a_grant)
Reader: src/kiro_crew/connections/crew_oauth_proxy.py:handle -- chat -- a live session still bridged to a forgotten key gets the same 409 "reconnect it on the MCP Servers page" a Disconnect gives, and sends nothing upstream
Reader: src/kiro_crew/connections/crew_oauth_dcr.py:revoke -- crew page -- reads the client before the cleanup deletes it (test_forgetting_an_owner_grant_revokes_it_and_deletes_its_pair_and_client)
Reader: src/kiro_crew/dashboard/handlers/secrets_usage.py:_scan_crew_oauth -- crew page -- lists an owner-server entry only while the vault holds it, so a forgotten one leaves Settings → Secrets instead of reading as used

Tests

  • test_forgetting_an_owner_grant_revokes_it_and_deletes_its_pair_and_client (test/test_crew_oauth_custom_servers.py): only the named key goes, its pair revoked once while its client is still there, then the client; a client left without a pair goes with no revoke; another key is untouched.
  • test_an_edit_off_the_recorded_url_forgets_the_old_grant[moved|local] and test_removing_an_owner_server_forgets_its_grant (test/test_mcp_custom_api.py): the add and an edit that keeps the url hand the cleanup nothing; a move, a switch to a local command and a removal hand it the old name and url.
  • test_an_uninstall_is_forgotten_after_the_lock_when_another_change_fails[reached|swept] (test/test_mcp_apply_owner_grants.py): an Apply batch with a failing change hands the cleanup the uninstall the batch reached before it and the one after it that only the crash-window sweep removed, each once the MCP lock is released.
  • test_saving_the_slack_app_forgets_the_owner_grant_the_card_takes_over (test/test_connections_oauth_client_routes.py), against a real scratch vault: a client id alone keeps both grants; once the secret makes the app configured, the slack server's grant and client are gone and the case variant Slack at the card's url keeps both.

Determinism: the seven new node ids 20/20 green at -n0; the four changed test files whole, 10/10 green at -n 4 --dist loadgroup; one shuffled order (seed 6697) over their 204 ids, all passed.

Proof: PROVEN test/test_connections_oauth_client_routes.py::test_saving_the_slack_app_forgets_the_owner_grant_the_card_takes_over, test/test_mcp_apply_owner_grants.py::test_an_uninstall_is_forgotten_after_the_lock_when_another_change_fails[reached], test/test_mcp_apply_owner_grants.py::test_an_uninstall_is_forgotten_after_the_lock_when_another_change_fails[swept] (head 2a1f751)

Manual verification

Two isolated gateways (a fresh data home each, bound to 127.0.0.1, a stub ACP backend, no OAuth app in the environment), one on the base and one on this head, driven through the same seven owner actions over the dashboard API. Seven owner servers were added through POST /api/mcp/custom; a real sign-in needs a vendor's consent page, so each got its grant (pair and client, no revocation endpoint) written into the gateway's own vault under its owner key with the tree's own crew_oauth_dcr.keep_client. The table shows, after each action, whether each server's pair and client are still in the vault (T/T both present, F/F both gone). Every request answered 200 on both trees.

action (route) base this head
remove acme-remove (/api/mcp/remove) all T/T acme-remove F/F
uninstall acme-uninstall (/api/mcp/apply) all T/T acme-uninstall F/F
re-point acme-move to /v2 (PUT /api/mcp/custom/{name}) all T/T acme-move F/F
turn acme-local into a local command (same route) all T/T acme-local F/F
edit acme-keep without changing its url (same route) all T/T acme-keep stays T/T
save the slack OAuth app, client id only (PUT /api/connections/oauth-clients/slack) all T/T slack stays T/T (the card still yields)
save the same app with its secret (same route) all T/T slack F/F; work-slack (another name at the same url) stays T/T

The gateway log of the head run has no could not forget the grant line.

Real-machine verification

Machine: EC2 m7i.2xlarge, Ubuntu 24.04.5 LTS (kernel 7.0.0-1014-aws), x86_64, 8 vCPU / 32 GiB

Before (main 48d0a9300546): the seven owner actions in Manual verification against an isolated gateway on the base -> every server still holds its pair and client after every action, including the removed, uninstalled, re-pointed, local and card-claimed ones. The new tests on the base's production code fail: five with AttributeError: ... no attribute 'forget_owner_grants' or assert (not True) for the slack grant still present, and both Apply cases ([reached]: assert [True] == [False], the base forgets inside the MCP lock; [swept]: Awaited 0 times, a swept uninstall is never forgotten).

After (head 2a1f751b6121): the same actions against an isolated gateway on this head -> each server that lost its entry is F/F right after its action; acme-keep and work-slack keep both entries to the end. The new tests pass.

Cleanup: both gateways were stopped by their own pid and exited, and both isolated data homes were deleted; each run used its own disposable instance.

Related Issues

Closes #35816

Sibling sweep

Swept: git grep -nE "owner_mcp_servers|owner_servers.(record|forget)|custom_key(" -- src/
Sibling: src/kiro_crew/connections/endpoint_migration.py:122 -- not affected -- _migrate_owner_record moves only Atlassian's record, whose card never yields, so no grant is ever held under an owner key for it
Sibling: src/kiro_crew/dashboard/handlers/connections.py:932 -- not affected -- a card's own grant is keyed on its slug and its Disconnect already revokes and deletes it

Pattern harvest

Not generalizable: the owner key is the only vault key built from a config record's values (name and url); every other grant Crew holds is keyed on a fixed registry slug, so no other writer can strand one.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 2a1f751b61214cce7e2204bf8764668def47704b touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 2a1f751b61214cce7e2204bf8764668def47704b — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. The fix reuses crew_oauth.disconnect and runs it from the three places where the owner record changes. One place that re-points a record is left out.

Notes

  • Item 3 — symptom-level: the fix covers 3 of the 4 places that write connections.owner_mcp_servers (I grepped for importers of owner_servers and found every record write). The one it misses is connections/endpoint_migration.py:_migrate_owner_record. It sets record["url"] = current without calling replaced_urls, so any grant under the old custom_key(name, url) is left in the vault and still valid upstream, the same way an owner re-point leaves it. The migration path reads no crew_oauth or vault state today.

What this change ships

Inventory (7 items) — 6 justified

Intent: when an owner-added remote MCP server can no longer use the sign-in Crew holds for it, revoke that grant and delete it from the vault. This is a FIX.

  1. Removing an owner server from MCP Servers revokes its grant and deletes it from the vault — justified
  2. An Apply uninstall, including one only the crash-window sweep removed, revokes and deletes the grant — justified
  3. Moving a server to another url, or turning it into a local command, revokes and deletes the old grant — symptom-level, the endpoint migration re-point is not covered
  4. Saving the Slack card's OAuth app deletes the grant of the slack owner server the card takes over; a Slack case variant keeps its grant — justified
  5. The Apply's owner-record cleanup now runs after the MCP lock is released, on every way out of the batch — justified
  6. _sweep_dangling_uninstalls now returns the names it purged — justified
  7. These owner actions now make an upstream revocation call where the server advertises an endpoint — justified

[FIRST-PRINCIPLES-REVIEWED] 2a1f751

Description read

[DESCRIPTION-READ] 59d2b77cc68b1edf35411160c089497672b66595aad90d171a87ee417a2d0855

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 2a1f751b61214cce7e2204bf8764668def47704b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. Every place that strands a grant now goes through the existing disconnect seam, after the config write and outside the MCP lock, and the cleanup is best-effort.

Notes

  • The cleanup deletes the grant upstream and in the vault, so it can't be undone. An owner who re-points a server by mistake and points it back has to sign in again. The description should say this, since it's the one irreversible effect.
  • taken_by_card runs on every card save, including saves where the card already owned the name. That's harmless because such a grant was already unreadable, but the name implies a change happened when it may not have.

[DESIGN-REVIEWED] 2a1f751

Description read

[DESCRIPTION-READ] a9b11af11d56840df36e54feca0aa5bb995d19a7da1c85953629dd2a44b3a79e

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 2a1f751b61214cce7e2204bf8764668def47704b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2a1f751

Verdict parsed from the review's SHA-scoped output markers for commit 2a1f751b61214cce7e2204bf8764668def47704b.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 2a1f751b61214cce7e2204bf8764668def47704b false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 2a1f751b61214cce7e2204bf8764668def47704b and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2a1f751

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 2a1f751b61214cce7e2204bf8764668def47704b false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 19, 2026
A grant Crew holds for an owner-added remote MCP server is keyed on the
server's name and url. Removing the server, pointing it at another url,
turning it local, or saving the OAuth app of the card that then takes
over its name left that grant and its client in the vault with nothing
reading them, and the grant stayed live upstream.

Each of those owner actions hands the old name and url to one cleanup
that revokes the pair where the server allows it and deletes the pair
and the client. It runs after the config change has landed and never
fails it.

Closes #35816
@bolichen97
bolichen97 force-pushed the fix/35816-forget-stranded-owner-grant branch from 4c785ea to 2a1f751 Compare November 19, 2026 22:25
@bolichen97

bolichen97 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: forget the Apply uninstalls that landed, after the MCP lock

  • span=08f2b50ccf90 Swept uninstalls skip owner-grant cleanup

fixed in 2a1f751: _sweep_dangling_uninstalls returns the names it purged, and _do_mcp_apply adds them to the set it forgets after the MCP lock on both the normal and the cancellation await, so an uninstall only the crash-window sweep removed loses its owner record and grant like one the batch reached.
Pinned by test/test_mcp_apply_owner_grants.py::test_an_uninstall_is_forgotten_after_the_lock_when_another_change_fails[swept] (red on 4c785ea, green on the fix); [reached] pins that the forget never runs under the lock.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 19, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked head 2a1f751. The grant key the cleanup deletes is computed from the recorded url, the same name and url a session uses to read that grant. Each of the four owner actions forgets a grant only after its config write lands, and only once that grant has no reader left. The Apply path now forgets outside the MCP lock, and a crash-window sweep is handled like an uninstall the batch reached. The changed test files and the neighbouring MCP, owner-record and Slack sign-in suites pass on this head, and I found no wrong behaviour or data-loss path that blocks merging.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 19, 2026 23:41
@KiroCrewCaptain
KiroCrewCaptain merged commit c4ebe9d into main Nov 19, 2026
99 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/35816-forget-stranded-owner-grant branch November 19, 2026 23:41
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

owner-server grant left unused in the vault after a card takes over the entry or the server is removed

2 participants