Repository navigation
fix(gateway): run full node teardown when a node token is revoked - #124117
Conversation
device.token.revoke for role=node only invalidated wake state, while its sibling device.pair.remove — the other way node authority permanently ends — runs the full teardown owner: clearRemovedNodeRuntimeState (pending actions, pending work, wake state, surface caps, remote node info) plus reconcileRevokedDeviceWorker (worker environments and active placements). A revoked node therefore kept stranded pending work, stale surface caps, and live worker placements until restart. Revoke now runs the same teardown owner as pairing removal. Rotate and reapproval intentionally keep their narrower wake-state invalidation: the node stays paired there and reconnects with the new token/generation. Regression test mirrors the pair.remove teardown coverage and fails pre-fix.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs changes before merge. Reviewed August 15, 2026, 4:53 AM ET / 08:53 UTC. ClawSweeper reviewWhat this changesThe PR makes node-token revocation clear node runtime state and reconcile device-backed worker placements, matching permanent pairing removal. Merge readinessKeep open: the teardown owner is correct, but the patch delays node-session invalidation until after awaited worker reconciliation, leaving revoked clients usable during that work. Priority: P1 Review scores
Verification
How this fits togetherGateway device handlers process pairing and token lifecycle RPCs. Revoking a node token must remove node state, fence its connected sessions, and then reconcile workers that depended on that node. flowchart TD
A[Operator revokes node token] --> B[Gateway device handler]
B --> C[Clear node runtime state]
C --> D[Invalidate node client sessions]
D --> E[Reconcile worker environments]
E --> F[Reconcile active placements]
F --> G[Return revocation result]
Before merge
Findings
Agent review detailsSecurityNeeds attention: The new await delays the security fence for a revoked node token across asynchronous worker cleanup. PR surfaceSource +4, Tests +49. Total +53 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Use the canonical permanent-removal order: clear node runtime state, synchronously invalidate node clients and projections, then await worker reconciliation before responding; add a deferred-reconciliation ordering regression. Do we have a high-confidence way to reproduce the issue? Yes—current main and the PR head show a direct source reproduction: token revocation reaches an awaited worker reconciler before the client-invalidated flag is set. No tests were run because this review is read-only. Is this the best way to solve the issue? No—the full teardown owner is the right solution, but client invalidation must remain before every awaited cleanup step, as in the pairing-removal sibling. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against de4104c84d71. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
Acceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…enclaw#124117) device.token.revoke for role=node only invalidated wake state, while its sibling device.pair.remove — the other way node authority permanently ends — runs the full teardown owner: clearRemovedNodeRuntimeState (pending actions, pending work, wake state, surface caps, remote node info) plus reconcileRevokedDeviceWorker (worker environments and active placements). A revoked node therefore kept stranded pending work, stale surface caps, and live worker placements until restart. Revoke now runs the same teardown owner as pairing removal. Rotate and reapproval intentionally keep their narrower wake-state invalidation: the node stays paired there and reconnects with the new token/generation. Regression test mirrors the pair.remove teardown coverage and fails pre-fix.
What Problem This Solves
device.token.revokeforrole=nodeonly invalidated wake state, while its siblingdevice.pair.remove— the other way node authority permanently ends — runs the full teardown owner:clearRemovedNodeRuntimeState(pending actions, pending node work, wake state, surface caps, remote node info) plusreconcileRevokedDeviceWorker(worker environments + active placement reconciliation). A node whose token was revoked therefore kept stranded pending work, stale surface caps/commands in the node registry, and live worker placements until a gateway restart.Why This Change Was Made
One-sided teardown is exactly the sibling-surface asymmetry the Repair Doctrine flags: both exits end node authority permanently, so both must run the same owner. The intentionally narrower paths stay narrow — rotate and pairing-reapproval keep only wake-state invalidation because the node remains paired there and reconnects with the new token/generation.
User Impact
Operators revoking a node token (instead of removing the pairing) no longer leave ghost node state behind: pending work stops accumulating for a dead node, its registry surface clears, and device-backed worker placements reconcile immediately.
Evidence
device.pair.removeteardown coverage (wake snapshot gone, wake lifecycle aborted, pending work drained to baseline,updateSurfacecleared, worker reconciliation invoked with the device id) — fails pre-fix (stash proof), passes post-fix.node scripts/run-vitest.mjs run src/gateway/server-methods/devices.test.ts— 47/47;src/gateway/server.device-token-rotate-authz.test.ts+src/gateway/server-methods/nodes.test.ts— 30/30.pnpm tsgo,pnpm check:test-types, oxfmt/oxlint clean; autoreview clean (0.98).Production LOC +5/−1 (the teardown call + invariant comment; wake-state call absorbed into the owner); tests +49.