Repository navigation
refactor(infra): split device pairing lifecycle modules - #124734
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Land-ready proof for
|
|
Codex review: needs maintainer review before merge. Reviewed August 16, 2026, 2:29 PM ET / 18:29 UTC. ClawSweeper reviewWhat this changesThe PR splits device-pairing state, approval, and token lifecycle code into dedicated modules and updates Gateway, CLI, SDK, and test callers to use those module boundaries. Merge readinessThis PR remains necessary: current main still has the monolithic device-pairing owner, while the branch establishes a shared state/lock owner and separates approval and token lifecycle responsibilities. No blocking correctness or security finding was identified; the maintainer label requires normal maintainer handling. Priority: P3 Review scores
Verification
How this fits togetherDevice pairing records approved device roles and metadata, then supplies tokens used by Gateway and Control UI authentication. Requests enter through device connections or management commands, move through pairing approval and token handling, and produce authenticated device access. flowchart LR
A[Device or CLI request] --> B[Pairing state owner]
B --> C[Approval policy]
C --> D[Token lifecycle]
D --> E[Gateway authentication]
E --> F[Device and Control UI access]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +92, Tests +16, Other -1. Total +107 across 53 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the state module as the sole pairing mutation-lock owner, retain the stable Plugin SDK export, and land after the exact-head required checks complete. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR reorganizes existing lifecycle code and does not report a failing user behavior. Is this the best way to solve the issue? Yes: placing the shared lock and state helpers in a dedicated owner lets approval and token operations remain independently cohesive without retaining a compatibility re-export from the old monolith. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9d0c1f8f8c59. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
main split the device pairing lifecycle modules in openclaw#124734 and moved approveDevicePairing to src/infra/device-pairing-approval.ts. Nothing on either side touched this import line, so the merge stays conflict free and only the typecheck reports the missing export.
…118720) * fix(agents): node plugin tool calls report a generic client timeout Plain node-hosted plugin tool calls send no invocation budget, so the Gateway arms no deadline over pairing, wake, and policy work and the node registry falls back to its own 30s pending timer that only starts at dispatch. The agent-side wait defaults to the same 30s but starts earlier, so the caller always abandons the request first and the Gateway answer that carries nodeCommandDispatched retry-safety provenance can never arrive. Send the same 30s budget explicitly and give the caller the +5s grace the node MCP path already uses, so the Gateway answer wins the race. * test(gateway): prove the node invoke deadline answer reaches the agent Adds an end-to-end proof that runs a real Gateway, pairs a real node that accepts the forwarded command and never answers, and drives the shipped agent tool through the real gateway client. It asserts the agent receives the Gateway's structured timeout with nodeCommandDispatched provenance rather than a client-side gateway timeout. * fix(gateway): keep node invoke dispatch inside the caller budget The invocation budget only started once dispatch was reached, so pairing revalidation before it spent nothing. With the Gateway deadline now armed for plain node plugin tools, that let a send land after the deadline had already answered the caller with nodeCommandDispatched:false, advertising a command the node had in fact received as retry-safe. Anchor the budget at entry and re-derive what is left after pairing revalidation, refusing to dispatch once it is exhausted. * test(gateway): restore the Gateway URL after the invoke deadline proof The shared Gateway fixture does not snapshot OPENCLAW_GATEWAY_URL, so the proof left later tests in the same worker pointing at its stopped ephemeral server. Capture and restore the key, including its previously-unset case. * fix(gateway): read the node invoke budget after request serialization Pairing revalidation is not the only step that can spend the caller budget before the pending timer is armed: tool parameters are unbounded, so serializing them and resolving the pending system.run event can outlive the remaining budget on their own. Reading the budget once all of that work is behind the call site keeps the node timeout and the pending timer starting from what is actually left, so an exhausted budget refuses the dispatch instead of arming a timer that answers after the caller already reported a timeout. * test(gateway): pin node invoke dispatch provenance against a budget-consuming send The review asked for the final event envelope to be serialized before the deadline admission check, on the grounds that a slow serialization could let the Gateway report nodeCommandDispatched: false for a command the node did receive. Envelope build, send and onDispatchReady are one synchronous block, so nothing can settle the pending request between them. Pin that invariant with a send that spends the whole remaining budget. * test(gateway): type the node socket send mock with its call signature The budget-consuming send regression wraps the recorded socket send, and ReturnType<typeof vi.fn> resolves to a mock without a call signature, so tsgo rejected the wrapper with TS2348 while vitest ran it fine. * test(gateway): follow the node pairing helpers into device-pairing-node main folded src/infra/node-pairing.ts into src/infra/device-pairing-node.ts, so the deadline proof stopped resolving its pairing import after the merge. * fix(gateway): scope the invoke deadline to caller-supplied budgets Callers that omit timeoutMs, such as fs.listDir and the exec-approval paths, have always used the registry's 30-second fallback as a post-dispatch pending timer. Anchoring that fallback before pairing revalidation turned it into a dispatch admission check, so a slow revalidation could answer TIMEOUT without ever dispatching. Only a positive caller-supplied budget anchors the deadline now, which keeps the plain plugin-tool path covered while those callers keep their established semantics. * fix(test): import approveDevicePairing from its new module main split the device pairing lifecycle modules in #124734 and moved approveDevicePairing to src/infra/device-pairing-approval.ts. Nothing on either side touched this import line, so the merge stays conflict free and only the typecheck reports the missing export. * refactor(gateway): move node invoke deadline budget to a sibling module node-registry-private.ts sits at 693 counted lines on main against a 700-line max-lines ratchet, and the inline budget bookkeeping pushed it to 703, which is what turned check-lint-core-2 red. The budget arithmetic moves to node-registry.invoke-budget.js unchanged; the call site keeps the same two reads. * refactor(gateway): move system.run invoke helpers to their sibling module The max-lines ratchet caps src/gateway/node-registry-private.ts at 700 effective lines and main now sits at 699, so the dispatch budget guard this branch adds takes the file to 705 and check-lint-core fails. resolvePendingSystemRunEvent and normalizeSystemRunInvokeParams are module-private and both already delegate to normalizeSystemRunTimeoutMs in node-registry.system-run.ts, so that module is where they belong. Pure move: no behavior change and no new export surface. * fix(gateway): keep the moved system.run helpers within the ratchet baselines The previous commit moved resolvePendingSystemRunEvent and normalizeSystemRunInvokeParams into node-registry.system-run.ts. It changed no behavior, but it did move three per-file measurements. normalizeSystemRunTimeoutMs was exported because node-registry-private.ts consumed it; the two callers that moved were its only external consumers, so after the move the export had none and Knip reported it as an unused production export. It is module-private now. The moved code also carried two `as Record<string, unknown>` assertions that were grandfathered under the old file. The new file's baseline is 0, so both now carry the // SAFETY: invariant the ratchet asks for, and the source file's baseline entry is shrunk from 3 to 1 as the ratchet's own message requested. * test(gateway): fix typed node invoke serialization fixture Close over the typed execution payload instead of reading contextual this inside toJSON, whose surrounding invoke params contract is unknown. Keep the serialization delay and independent execution-budget assertions. The 141 registry tests and focused canonical-inherited test type graph pass. Co-authored-by: Yigtwxx <[email protected]> * docs(changelog): avoid node deadline entry merge conflict Move only this PR's credited release-note entry beside the existing Gateway client watchdog entry, away from the concurrently edited section boundary. The entry and tested runtime behavior are unchanged. Co-authored-by: Yigtwxx <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
…penclaw#118720) * fix(agents): node plugin tool calls report a generic client timeout Plain node-hosted plugin tool calls send no invocation budget, so the Gateway arms no deadline over pairing, wake, and policy work and the node registry falls back to its own 30s pending timer that only starts at dispatch. The agent-side wait defaults to the same 30s but starts earlier, so the caller always abandons the request first and the Gateway answer that carries nodeCommandDispatched retry-safety provenance can never arrive. Send the same 30s budget explicitly and give the caller the +5s grace the node MCP path already uses, so the Gateway answer wins the race. * test(gateway): prove the node invoke deadline answer reaches the agent Adds an end-to-end proof that runs a real Gateway, pairs a real node that accepts the forwarded command and never answers, and drives the shipped agent tool through the real gateway client. It asserts the agent receives the Gateway's structured timeout with nodeCommandDispatched provenance rather than a client-side gateway timeout. * fix(gateway): keep node invoke dispatch inside the caller budget The invocation budget only started once dispatch was reached, so pairing revalidation before it spent nothing. With the Gateway deadline now armed for plain node plugin tools, that let a send land after the deadline had already answered the caller with nodeCommandDispatched:false, advertising a command the node had in fact received as retry-safe. Anchor the budget at entry and re-derive what is left after pairing revalidation, refusing to dispatch once it is exhausted. * test(gateway): restore the Gateway URL after the invoke deadline proof The shared Gateway fixture does not snapshot OPENCLAW_GATEWAY_URL, so the proof left later tests in the same worker pointing at its stopped ephemeral server. Capture and restore the key, including its previously-unset case. * fix(gateway): read the node invoke budget after request serialization Pairing revalidation is not the only step that can spend the caller budget before the pending timer is armed: tool parameters are unbounded, so serializing them and resolving the pending system.run event can outlive the remaining budget on their own. Reading the budget once all of that work is behind the call site keeps the node timeout and the pending timer starting from what is actually left, so an exhausted budget refuses the dispatch instead of arming a timer that answers after the caller already reported a timeout. * test(gateway): pin node invoke dispatch provenance against a budget-consuming send The review asked for the final event envelope to be serialized before the deadline admission check, on the grounds that a slow serialization could let the Gateway report nodeCommandDispatched: false for a command the node did receive. Envelope build, send and onDispatchReady are one synchronous block, so nothing can settle the pending request between them. Pin that invariant with a send that spends the whole remaining budget. * test(gateway): type the node socket send mock with its call signature The budget-consuming send regression wraps the recorded socket send, and ReturnType<typeof vi.fn> resolves to a mock without a call signature, so tsgo rejected the wrapper with TS2348 while vitest ran it fine. * test(gateway): follow the node pairing helpers into device-pairing-node main folded src/infra/node-pairing.ts into src/infra/device-pairing-node.ts, so the deadline proof stopped resolving its pairing import after the merge. * fix(gateway): scope the invoke deadline to caller-supplied budgets Callers that omit timeoutMs, such as fs.listDir and the exec-approval paths, have always used the registry's 30-second fallback as a post-dispatch pending timer. Anchoring that fallback before pairing revalidation turned it into a dispatch admission check, so a slow revalidation could answer TIMEOUT without ever dispatching. Only a positive caller-supplied budget anchors the deadline now, which keeps the plain plugin-tool path covered while those callers keep their established semantics. * fix(test): import approveDevicePairing from its new module main split the device pairing lifecycle modules in openclaw#124734 and moved approveDevicePairing to src/infra/device-pairing-approval.ts. Nothing on either side touched this import line, so the merge stays conflict free and only the typecheck reports the missing export. * refactor(gateway): move node invoke deadline budget to a sibling module node-registry-private.ts sits at 693 counted lines on main against a 700-line max-lines ratchet, and the inline budget bookkeeping pushed it to 703, which is what turned check-lint-core-2 red. The budget arithmetic moves to node-registry.invoke-budget.js unchanged; the call site keeps the same two reads. * refactor(gateway): move system.run invoke helpers to their sibling module The max-lines ratchet caps src/gateway/node-registry-private.ts at 700 effective lines and main now sits at 699, so the dispatch budget guard this branch adds takes the file to 705 and check-lint-core fails. resolvePendingSystemRunEvent and normalizeSystemRunInvokeParams are module-private and both already delegate to normalizeSystemRunTimeoutMs in node-registry.system-run.ts, so that module is where they belong. Pure move: no behavior change and no new export surface. * fix(gateway): keep the moved system.run helpers within the ratchet baselines The previous commit moved resolvePendingSystemRunEvent and normalizeSystemRunInvokeParams into node-registry.system-run.ts. It changed no behavior, but it did move three per-file measurements. normalizeSystemRunTimeoutMs was exported because node-registry-private.ts consumed it; the two callers that moved were its only external consumers, so after the move the export had none and Knip reported it as an unused production export. It is module-private now. The moved code also carried two `as Record<string, unknown>` assertions that were grandfathered under the old file. The new file's baseline is 0, so both now carry the // SAFETY: invariant the ratchet asks for, and the source file's baseline entry is shrunk from 3 to 1 as the ratchet's own message requested. * test(gateway): fix typed node invoke serialization fixture Close over the typed execution payload instead of reading contextual this inside toJSON, whose surrounding invoke params contract is unknown. Keep the serialization delay and independent execution-budget assertions. The 141 registry tests and focused canonical-inherited test type graph pass. Co-authored-by: Yigtwxx <[email protected]> * docs(changelog): avoid node deadline entry merge conflict Move only this PR's credited release-note entry beside the existing Gateway client watchdog entry, away from the concurrently edited section boundary. The entry and tested runtime behavior are unchanged. Co-authored-by: Yigtwxx <[email protected]> --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
src/infra/device-pairing.tsmixed request/record/node pairing, approval policy, and token lifecycle in one oversized owner. It required a grandfathered max-lines suppression and made the shared write-serialization boundary harder to see.Why This Change Was Made
The refactor extracts a single state owner with the only pairing mutation lock, a dedicated approval engine, and a dedicated token lifecycle module. Every internal caller now imports the canonical owner directly;
device-pairing.tsdoes not re-export moved APIs. The old suppression and max-lines baseline entry are removed.User Impact
No user-visible behavior changes. Device pairing, approval, and token behavior remain equivalent, while the ownership and locking boundary is easier to maintain.
Evidence
node scripts/run-vitest.mjs src/infra/device-pairing.test.ts src/gateway/server/ws-connection src/gateway/server.auth.control-ui.test.ts— 22 files, 306 tests passed after rebase.node --import tsx scripts/check-max-lines-ratchet.mts— passed with 909 remaining grandfathered entries.tbx_01m05w1ga9z5qq0zjvr107pp3p:pnpm tsgo:core,pnpm tsgo:core:test,pnpm tsgo:extensions,pnpm tsgo:extensions:test,pnpm deadcode:dependencies,pnpm check:import-cycles, andpnpm buildall passed: https://github.com/openclaw/openclaw/actions/runs/31963596474