Repository navigation
fix: forget an owner server's grant when its entry can no longer use it - #39550
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The fix reuses Notes
What this change shipsInventory (7 items) — 6 justifiedIntent: 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.
[FIRST-PRINCIPLES-REVIEWED] 2a1f751 Description read[DESCRIPTION-READ] 59d2b77cc68b1edf35411160c089497672b66595aad90d171a87ee417a2d0855 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks. Every place that strands a grant now goes through the existing Notes
[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 |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
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
4c785ea to
2a1f751
Compare
|
self-added: yes
[operator: bolichen97] |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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.
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_TOKENSandCONNECTIONS_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
KIROCREW_CONNECTIONS_*environment variables.What changed (motivation → approach → change)
Root cause: nothing deletes a grant held under an owner key.
crew_oauth.disconnectalready revokes and deletes such a key, but only a Connections card's Disconnect calls it, and only for registry slugs.mcp_config_purge._forget_owner_serversmcp_custom._record_owner_serversconnections.api_connections_oauth_client_putEach 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 sameis_signable_namerule the MCP Servers row and the sign-in already apply, so a server under another name, or a letter-case variant such asSlackat the card's url, keeps its own grant. Both hand the names and urls tocrew_oauth.forget_owner_grants. It runsdisconnecton 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 withdata_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]andtest_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, theslackserver's grant and client are gone and the case variantSlackat 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 throughPOST /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 owncrew_oauth_dcr.keep_client. The table shows, after each action, whether each server's pair and client are still in the vault (T/Tboth present,F/Fboth gone). Every request answered 200 on both trees.acme-remove(/api/mcp/remove)T/Tacme-removeF/Facme-uninstall(/api/mcp/apply)T/Tacme-uninstallF/Facme-moveto/v2(PUT /api/mcp/custom/{name})T/Tacme-moveF/Facme-localinto a local command (same route)T/Tacme-localF/Facme-keepwithout changing its url (same route)T/Tacme-keepstaysT/TslackOAuth app, client id only (PUT /api/connections/oauth-clients/slack)T/TslackstaysT/T(the card still yields)T/TslackF/F;work-slack(another name at the same url) staysT/TThe gateway log of the head run has no
could not forget the grantline.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 withAttributeError: ... no attribute 'forget_owner_grants'orassert (not True)for theslackgrant 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 isF/Fright after its action;acme-keepandwork-slackkeep 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_recordmoves only Atlassian's record, whose card never yields, so no grant is ever held under an owner key for itSibling: 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)