Repository navigation
refactor(gateway): register and redeem device join codes in workers - #164759
Conversation
Move setup RPC registration and public join-code redemption into the existing pairing worker, preserving physical-store custody, FIFO, live commit grants, atomic one-use burns, expiry, and serialized HTTP throttling. Keep malformed and uncertain burns unreplayed, recheck expiry after acknowledgement, and avoid unrelated paired-device scans or publications.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 1:07 AM ET / 05:07 UTC (Revision 2). ClawSweeper reviewWhat this changesMoves device join-code creation and one-use redemption into the existing pairing worker, with regression coverage and database-worker documentation. Merge readiness✅ Ready for maintainer review This PR remains useful: fetched main still performs join-code SQLite work synchronously. No actionable correctness or security defect was found in the pinned change. Priority: P2 Review scores
Verification
How this fits togetherDevice onboarding creates a short-lived join URL through an authenticated Gateway request. Public HTTP redemption exchanges that URL for a setup payload backed by shared SQLite state. flowchart TD
A[Authenticated setup request] --> C[Capture store and requester authority]
B[Public join request] --> D[Serialized rate limiting]
C --> E[Pairing worker FIFO]
D --> E
E --> F[Atomic SQLite registration or burn]
F --> G[Check acknowledged result and expiry]
G --> H[Join URL or setup response]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +97, Tests +391, Docs +12. Total +500 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep join-code persistence under the existing pairing worker while preserving atomic redemption and the current public onboarding contract. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the main-thread SQL path: main's authenticated setup handler and public HTTP redemption call synchronous SQLite helpers. This review did not execute a reproduction. Is this the best way to solve the issue? Yes, extending the existing pairing worker avoids a competing writer and preserves the established transaction, custody, and transport contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 217efe0ad597. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
…penclaw#164759) Move setup RPC registration and public join-code redemption into the existing pairing worker, preserving physical-store custody, FIFO, live commit grants, atomic one-use burns, expiry, and serialized HTTP throttling. Keep malformed and uncertain burns unreplayed, recheck expiry after acknowledgement, and avoid unrelated paired-device scans or publications.
What Problem This Solves
The setup RPC (
device.pair.setupCodewithjoinUrl: true) and publicGET /j/:shortcoderedemption executed native SQLite on the Gateway main thread.Why This Change Was Made
Extend the existing
devicePairingworker operations. Capture the physical store before setup preparation or rate-limit waits, retain the pairing FIFO and transaction/commit authority grants, and keep selection and deletion in one synchronous worker transaction. Decode only after acknowledgement, preserve malformed-payload burns, recheck expiry before disclosing results, and never replay an uncertain burn.Join-only operations acknowledge their result without scanning or republishing unrelated paired-device records. Database close still joins accepted operations through the existing worker owner. This builds on the live-owner/offline-custody routing in #164075 without adding another writer or route.
User Impact
No schema, stored format, retention, durability, SDK, configuration, or update migration changes. HTTP response shapes, one-use behavior,
Cache-Control: no-store, and serialized throttling remain intact. Adds zero newOPENCLAW_*names.Production: +192 / -95 / net +97 (287 changed lines across seven files). Inventoried main-thread sites: T1 915 → 908; all seven cited join-code sites leave the host. The existing transaction wrapper replaces the two removed native transaction entry points.
Supported generic plugin Gateway dispatch remains available. Its prepared profile assertions stay live; existing tool-origin exact session/placement authority reads remain follow-up debt at
src/gateway/node-claude-skill-runtime.ts:129–130andsrc/gateway/worker-environments/placement-store.ts:245–256. No join-code SQL remains in host grants.Overlap: #161421 also changes the pairing worker/core owner; this PR keeps its changes limited to join commands and their publication behavior.
Evidence
5fc6683924d2033f32ac5de44aeb3983da2a8a91.[email protected], 504 declarations / 510 SDK files / 354 public exports; neither join-code helper is exported or reached through an SDK entrypoint. Generic Gateway dispatch is retained.Focused Linux proof: 52 passed. The 14 directly affected worker/HTTP cases were rerun on the corrected final source; the 38 unchanged pairing-worker, setup-RPC, and ingress cases reuse their passing snapshot evidence. Each command used
pnpm test <file> --maxWorkers=1:src/infra/device-pairing-join-code.worker.test.tssrc/infra/device-pairing-worker.test.tssrc/gateway/server-methods/device-pair-setup.test.tssrc/gateway/server-http.device-pairing-join.test.tssrc/gateway/server-http.device-pairing-ingress.test.tsThe corrected source was independently verified against all 13 task file hashes on Linux (tree
5c00fa9f80e62b6711a64ae0a81df8a88288835f, parent at the pinned base). The final local delta only replaces two test assertion sorts with numerictoSorted()calls after the lint gate flagged them; production bytes are identical. A final local HTTP rerun after that assertion-only change timed out in the shared GatewaybeforeAllstartup hook (180 s; total 408.33 s), before any of the five cases ran. Its earlier corrected-runtime local run and the Linux run both passed. The timeout and subsequent fixture-cleanup refusal remain recorded as a loaded-host validation limitation; timeouts were not increased.The HTTP suite retains one real Gateway for the file; it proves registered RPC/HTTP routing, authenticated minting, and unauthenticated one-use exchange together. Worker compiler preparation accounts for most cold-start cost. No serial test configuration or worker pin was added.
node scripts/check-changed.mjs --base 5fc6683924d2033f32ac5de44aeb3983da2a8a91passes on the final local diff (2,097.57 s), including final lint and zero runtime import cycles.[email protected]driving the verified candidate. Package build/integrity: 651.93 s; update cell: 440.24 s (managed update 362.552 s). Recorded update validated,/readyzreturned 200, running version verified, and the synthetic service stopped. Tarball SHA-256:e501484e6b735ad9fcec69fb19f1943af4b8799f8df34ee9cf2d35ed87c0cf35. Used the authorized AWS fallback after Testbox stayed queued without a runner for over 15 minutes; that queued lease executed no cell and was stopped.Landing verification
v2026.9.8confirms the changed join-code functions are internal: absent from SDK exports, plugin runtime contracts, documented SDK subpaths, and package exports. The local released-SDK API diff report was generated forv2026.9.8versus010fc862f84342b09a9163e64b14fdd75e5f46cc(digest83e99c18). It records accumulated release-to-main surface changes; none of this PR's changed function names appears in its public diff. No new SDK compatibility boundary is required by this lane.runtime-process-build-graph.test.ts,get-reply.imports.test.ts, andopenclaw-state.worker.imports.test.ts: 13 passed. The focusedeager-import-closure.test.tsPR-wrapper inventory check also passed (1 selected case, 20.43 s wrapper wall time). The new worker remains behind the existing lazy runtime boundary.2e76e316c286b32d14581e7ad3480e1ec49253d7also failed during the shared HTTP fixture's startup, before all four baseline cases. It timed out waiting for the admin WebSocket handshake (connectReq/onceMessage), after 606.69 s to reach Gateway startup; total Vitest duration was 1,008.78 s. This reproduces startup failure without the PR and supports the loaded-host fixture classification. The earlier PR timeout was the encompassing 180 s startup hook, so the precise timeout site differs; neither run is counted as passing, and no timeout/assertion was weakened or rerun for green.