Repository navigation
fix(cleanup): the orphaned-key sweep skips a just-minted agent key and names what it revokes (#4259) - #4260
Merged
Conversation
…d names what it revokes (#4259) `crud.create_agent` mints the agent's MCP key before the container exists and writes the ownership row only after it does, so for a few seconds a healthy new agent looks exactly like a ghost. A cleanup tick inside that window revoked the key one second after it was minted; the agent's first MCP call failed 401 and nothing repaired it. `deactivate_orphaned_agent_keys` now skips keys younger than ORPHANED_KEY_GRACE_SECONDS (10 minutes) by their own `created_at`, compared against a Python-computed ISO-Z cutoff (Invariant #16), never by container state; a key the create path failed to roll back is still revoked on the first tick after the window. The function returns the revoked agent names and the `[Cleanup]` log line names them. A key whose agent row is live is never orphaned at any age (pinned). Existing instances: the key table carries no deactivation timestamp, so a race victim cannot be told from a deliberate revocation — no blind reactivation; `docs/migrations/ORPHANED_KEY_SWEEP_RACE_2026-11.md` gives the candidate query and the per-key repair. Red first: all six tests in `test_4259_key_sweep_startup_grace.py` fail with the fix reverted (the minted-seconds-ago key is revoked; the log line carries no names). Fixes #4259 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ace is pinned (#4259) Mechanical, per the merge-train note on the PR: the operator note misquoted the [Cleanup] line, and no test sat inside the window, so a grace of 30 s stayed green. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Contributor
Author
|
merge-train: pushed one mechanical commit to this branch — the operator note now quotes the |
trinity-ability
approved these changes
Nov 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
crud.create_agentmints the agent's MCP key before the container exists and writes the ownership row only after it does. A cleanup tick inside that window revoked a healthy agent's key one second after it was minted; its first MCP call failed 401 and nothing repaired it. On an instance that creates agents from a hook, this is a coin flip per person.deactivate_orphaned_agent_keysskips keys younger than 10 minutes (ORPHANED_KEY_GRACE_SECONDS) by their owncreated_at, against a Python-computed ISO-Z cutoff (Invariant #16), never by container state. A key the create path failed to roll back is still revoked on the first tick after the window.[Cleanup]log line names them.docs/migrations/ORPHANED_KEY_SWEEP_RACE_2026-11.mdgives the candidate query and the per-key repair.Test plan
tests/unit/test_4259_key_sweep_startup_grace.py— 6 tests, all red with the fix reverted (the minted-seconds-ago key is revoked; the log line carries no names)test_1745_agent_key_revocation.pyadapted to the list return (its fixture wrotecreated_at="t", which would have read as "younger than the grace")1745,2845,912,cleanup_unreachable_orphan): 72 passedFixes #4259
🤖 Generated with Claude Code