Skip to content

fix(gateway): run full node teardown when a node token is revoked - #124117

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-token-revoke-teardown
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-token-revoke-teardown

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

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 node work, wake state, surface caps, remote node info) plus reconcileRevokedDeviceWorker (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

  • New regression test mirrors the existing device.pair.remove teardown coverage (wake snapshot gone, wake lifecycle aborted, pending work drained to baseline, updateSurface cleared, 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.

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.
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 15, 2026 08:47
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 15, 2026, 4:53 AM ET / 08:53 UTC.

ClawSweeper review

What this changes

The PR makes node-token revocation clear node runtime state and reconcile device-backed worker placements, matching permanent pairing removal.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep 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
Reviewed head: f5977333d5a59c8bf51e8da118d577c5f0377e0c

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch identifies the correct teardown boundary but has one high-priority authorization-ordering defect.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the body provides mock-based regression evidence only.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the body provides mock-based regression evidence only.
Evidence reviewed 6 items Current-main defect: Current main handles a revoked node token by invalidating only wake state; it does not call the full node-runtime teardown or worker reconciler.
Sibling lifecycle ordering: Permanent pairing removal clears runtime state, invalidates clients, then awaits worker reconciliation; this is the established authority-fence order.
Patch delays the fence: The proposed await runs before the existing client invalidation block, unlike the sibling permanent-removal path.
Findings 1 actionable finding [P1] Fence revoked clients before awaiting worker reconciliation
Security Needs attention Revocation fence runs after asynchronous cleanup: Worker reconciliation can await environment and placement operations before invalidateClientsForDevice marks the node connection invalid, allowing requests during a token-revocation window.

How this fits together

Gateway 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]
Loading

Before merge

  • Fence revoked clients before awaiting worker reconciliation (P1) - reconcileRevokedDeviceWorker awaits environment and placement work before the later invalidation block sets client.invalidated. Existing node sessions are rejected only after that flag is set, so a revoked token retains an avoidable authority window (or indefinitely if reconciliation fails). Match device.pair.remove: clear state, invalidate clients, then await reconciliation; add an ordering regression with deferred reconciliation.
  • Resolve security concern: Revocation fence runs after asynchronous cleanup - Worker reconciliation can await environment and placement operations before invalidateClientsForDevice marks the node connection invalid, allowing requests during a token-revocation window.
  • Resolve merge risk (P1) - Merging as written places the authorization fence after awaited environment and placement work, so a revoked node can retain usable buffered or new RPC frames until cleanup returns or fails.
  • Resolve merge risk (P1) - Production is net +4 lines; after fixing the order, the added teardown calls and lifecycle comment are justified by the permanent-authority boundary.
  • Complete next step (P2) - A narrow mechanical repair can restore immediate revocation fencing and add the missing ordering assertion.

Findings

  • [P1] Fence revoked clients before awaiting worker reconciliation — src/gateway/server-methods/devices.ts:825
  • [high] Revocation fence runs after asynchronous cleanup — src/gateway/server-methods/devices.ts:825
Agent review details

Security

Needs attention: The new await delays the security fence for a revoked node token across asynchronous worker cleanup.

PR surface

Source +4, Tests +49. Total +53 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 1 +4
Tests 1 49 0 +49
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 54 1 +53

Review metrics

Metric Value Why it matters
Production versus regression coverage production +5/-1 (net +4); tests +49/-0 The runtime expansion is justified only if it preserves the immediate revocation fence while adding the missing full teardown.

Merge-risk options

Maintainer options:

  1. Fence the node before worker cleanup (recommended)
    Move client invalidation ahead of the awaited worker reconciliation and prove the order with a deferred-reconciliation test before merging.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Move device-token client invalidation before worker reconciliation and add a deferred-reconciliation ordering regression test.

Technical review

Best 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:

  • [P1] Fence revoked clients before awaiting worker reconciliation — src/gateway/server-methods/devices.ts:825
    reconcileRevokedDeviceWorker awaits environment and placement work before the later invalidation block sets client.invalidated. Existing node sessions are rejected only after that flag is set, so a revoked token retains an avoidable authority window (or indefinitely if reconciliation fails). Match device.pair.remove: clear state, invalidate clients, then await reconciliation; add an ordering regression with deferred reconciliation.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against de4104c84d71.

Labels

Label changes:

  • add P1: A revoked node can retain authenticated request authority while asynchronous worker cleanup runs.
  • add merge-risk: 🚨 security-boundary: The patch changes token-revocation ordering and can defer the session fence that blocks a revoked credential.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the body provides mock-based regression evidence only.

Label justifications:

  • P1: A revoked node can retain authenticated request authority while asynchronous worker cleanup runs.
  • merge-risk: 🚨 security-boundary: The patch changes token-revocation ordering and can defer the session fence that blocks a revoked credential.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; the body provides mock-based regression evidence only.

Evidence

Security concerns:

  • [high] Revocation fence runs after asynchronous cleanup — src/gateway/server-methods/devices.ts:825
    Worker reconciliation can await environment and placement operations before invalidateClientsForDevice marks the node connection invalid, allowing requests during a token-revocation window.
    Confidence: 0.99

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs run src/gateway/server-methods/devices.test.ts.
  • [P1] pnpm tsgo.
  • [P1] pnpm check:test-types.

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the revoke and pairing-removal lifecycle code to this contributor, who also authored the proposed repair. (role: recent area contributor; confidence: high; commits: 49e783da74f9, f5977333d5a5; files: src/gateway/server-methods/devices.ts, src/gateway/server-methods/devices.test.ts)
  • Alix-007: Introduced the device-backed node-pairing removal behavior that supplies the established full-teardown pattern. (role: feature ancestor; confidence: medium; commits: 6a27300a5ba4; files: src/gateway/server-methods/devices.ts, src/gateway/server-methods/nodes.pairing.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Move invalidation before the worker-reconciliation await.
  • Extend the regression to hold reconciliation pending and verify invalidation occurs first while the response remains after cleanup.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 160e368 into main Aug 15, 2026
246 of 255 checks passed
@steipete
steipete deleted the codex/autoqa-token-revoke-teardown branch August 15, 2026 09:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant