Skip to content

refactor(gateway): register and redeem device join codes in workers - #164759

Merged
steipete merged 1 commit into
mainfrom
dbasync/joincode
Oct 4, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/joincode

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The setup RPC (device.pair.setupCode with joinUrl: true) and public GET /j/:shortcode redemption executed native SQLite on the Gateway main thread.

Why This Change Was Made

Extend the existing devicePairing worker 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 new OPENCLAW_* 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–130 and src/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

  • Base pinned to 5fc6683924d2033f32ac5de44aeb3983da2a8a91.
  • Same-host RPC/HTTP control: original synchronous helper, 482.86 s, four functional cases passed and SQL-zero failed; corrected worker implementation, 471.79 s, all five cases passed including invalid JSON and null-payload burns. These loaded-host timings are dominated by preparation and are not a latency claim.
  • Delayed-acknowledgement expiry regressions failed for both registration and redemption before the fix; the worker now checks expiry at its transaction and before result disclosure.
  • Released-SDK check: integrity-verified npm [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:

File Passed Wall time
src/infra/device-pairing-join-code.worker.test.ts 9 24.43 s
src/infra/device-pairing-worker.test.ts 8 23.70 s
src/gateway/server-methods/device-pair-setup.test.ts 26 28.87 s
src/gateway/server-http.device-pairing-join.test.ts 5 32.68 s
src/gateway/server-http.device-pairing-ingress.test.ts 4 25.73 s

The 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 numeric toSorted() 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 Gateway beforeAll startup 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.

  • Local core typecheck: 49.96 s; full core-test typecheck: 836.94 s; final Gateway-server test graph after the null-payload regression: 12.08 s. All pass.
  • Madge: 0 cycles on the final corrected source (148.86 s local wall). The database-worker ratchet passes against the pinned base. node scripts/check-changed.mjs --base 5fc6683924d2033f32ac5de44aeb3983da2a8a91 passes on the final local diff (2,097.57 s), including final lint and zero runtime import cycles.
  • Codex autoreview through P2 on the final diff, including the test-lint correction, against the pinned base: scoped-clean, no actionable findings (exit 0).
  • Published-driver × candidate update: passed, released [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, /readyz returned 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.
  • Package build emitted a nonfatal UI startup-size warning: 374,855 B gzip versus a 373,454 B budget (+1,401 B). This patch changes no UI files; no budget, baseline, or ignore was adjusted.
  • Exact-head CI run 37176672793: 49 non-skipped jobs passed, 8,619 aggregate job-seconds; the enforced CI gate, dependency review, and security review are green. No CI rerun was requested. The PR-context check initially rejected the section heading; correcting it to the repository template produced a passing check without a source change.

Landing verification

  • The final-head source audit confirms atomic select-and-burn, one-use and post-acknowledgement expiry, malformed-payload burn, no-store HTTP, serialized throttling, unchanged opaque errors, and no replay of unknown outcomes. Existing other-owner guard reads remain the follow-up debt named above.
  • Released SDK source tracing against v2026.9.8 confirms 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 for v2026.9.8 versus 010fc862f84342b09a9163e64b14fdd75e5f46cc (digest 83e99c18). 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.
  • Final-head import/build proof: runtime-process-build-graph.test.ts, get-reply.imports.test.ts, and openclaw-state.worker.imports.test.ts: 13 passed. The focused eager-import-closure.test.ts PR-wrapper inventory check also passed (1 selected case, 20.43 s wrapper wall time). The new worker remains behind the existing lazy runtime boundary.
  • The requested single plain-main comparison at 2e76e316c286b32d14581e7ad3480e1ec49253d7 also 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.
  • ClawSweeper completed on the exact head at 2026-10-04 04:31 UTC: no actionable or security findings, ready for maintainer review. The coordinator approved landing this head, and the recorded Codex P2 autoreview is clean.
  • The lane's AWS lease is released; provider cleanup and native local cleanup are complete.

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

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 010fc862f84342b09a9163e64b14fdd75e5f46cc
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/device-pairing-join-http.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/gateway/server-methods/device-pair-setup.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-core.worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-dispatch.worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-join-code.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-join-code.worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.
  • src/infra/device-pairing-worker.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: L labels Oct 4, 2026
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 1:07 AM ET / 05:07 UTC (Revision 2).

ClawSweeper review

What this changes

Moves 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
Reviewed head: 010fc862f84342b09a9163e64b14fdd75e5f46cc

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-supported refactor with meaningful production-boundary coverage and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): Author-recorded corrected-source proof exercises authenticated setup RPC and real HTTP redemption through the production Gateway and SQLite worker, observing one-use exchange, malformed burns, expiry, throttling, and zero host join SQL. Real-worker fault cases cover refused grants and uncertain burn results. Later startup failures are explicitly separated from passing evidence; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Author-recorded corrected-source proof exercises authenticated setup RPC and real HTTP redemption through the production Gateway and SQLite worker, observing one-use exchange, malformed burns, expiry, throttling, and zero host join SQL. Real-worker fault cases cover refused grants and uncertain burn results. Later startup failures are explicitly separated from passing evidence; no stored-data contract changes.
Evidence reviewed 7 items Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduction. The raw test-merge parents are the pinned base followed by the exact PR head; its pairing-owner delta preserves the reviewed changes.
Still needed on main: Fetched main retains synchronous native transactions in both join-code helpers. Inspection of v2026.9.8 also found the synchronous implementation, so the requested worker cutover is not already supplied by main or that release.
Live authority and atomic effects: Setup retains requester and physical-store authority before preparation and passes its guard into pairing admission. The existing owner checks these guards at transaction and commit grants. Worker redemption selects and deletes synchronously; host decoding follows acknowledgement and checks expiry.
Findings None None.
Security None None.

How this fits together

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

Before merge

None.

Agent review details

Security

None.

PR surface

Source +97, Tests +391, Docs +12. Total +500 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 7 192 95 +97
Tests 3 413 22 +391
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 617 117 +500

Review metrics

Metric Value Why it matters
Production versus test growth Production +192/-95, net +97; tests +413/-22, net +391 Production growth implements worker dispatch and authority preservation; test growth covers transport, rollback, expiry, and settlement contracts.

Technical review

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

Labels

Label changes:

  • add P2: This is a bounded runtime improvement removing synchronous onboarding database work, with no demonstrated urgent user-facing regression.
  • add proof: sufficient: Contributor real behavior proof is sufficient. Author-recorded corrected-source proof exercises authenticated setup RPC and real HTTP redemption through the production Gateway and SQLite worker, observing one-use exchange, malformed burns, expiry, throttling, and zero host join SQL. Real-worker fault cases cover refused grants and uncertain burn results. Later startup failures are explicitly separated from passing evidence; no stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Author-recorded corrected-source proof exercises authenticated setup RPC and real HTTP redemption through the production Gateway and SQLite worker, observing one-use exchange, malformed burns, expiry, throttling, and zero host join SQL. Real-worker fault cases cover refused grants and uncertain burn results. Later startup failures are explicitly separated from passing evidence; no stored-data contract changes.

Label justifications:

  • P2: This is a bounded runtime improvement removing synchronous onboarding database work, with no demonstrated urgent user-facing regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Author-recorded corrected-source proof exercises authenticated setup RPC and real HTTP redemption through the production Gateway and SQLite worker, observing one-use exchange, malformed burns, expiry, throttling, and zero host join SQL. Real-worker fault cases cover refused grants and uncertain burn results. Later startup failures are explicitly separated from passing evidence; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Author-recorded corrected-source proof exercises authenticated setup RPC and real HTTP redemption through the production Gateway and SQLite worker, observing one-use exchange, malformed burns, expiry, throttling, and zero host join SQL. Real-worker fault cases cover refused grants and uncertain burn results. Later startup failures are explicitly separated from passing evidence; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduction. The raw test-merge parents are the pinned base followed by the exact PR head; its pairing-owner delta preserves the reviewed changes. (010fc862f843)
  • Still needed on main: Fetched main retains synchronous native transactions in both join-code helpers. Inspection of v2026.9.8 also found the synchronous implementation, so the requested worker cutover is not already supplied by main or that release. (src/infra/device-pairing-join-code.ts:48, 217efe0ad597)
  • Live authority and atomic effects: Setup retains requester and physical-store authority before preparation and passes its guard into pairing admission. The existing owner checks these guards at transaction and commit grants. Worker redemption selects and deletes synchronously; host decoding follows acknowledgement and checks expiry. (src/infra/device-pairing-worker.ts:207, 010fc862f843)
  • Production-boundary proof: The captured body records passing corrected-source Gateway RPC/HTTP runs, including zero caller-thread join SQL, concurrent one-use exchange, malformed/null burns, and opaque throttling. The inspected suite uses registered RPC handlers, a real Gateway, WebSocket authentication, HTTP fetch, and real SQLite. Worker cases exercise refused grants, uncertain outcomes, delayed expiry, and close settlement through the real worker owner. These results were supplied by the author; this read-only review did not rerun them. (src/gateway/server-http.device-pairing-join.test.ts:86, 010fc862f843)
  • Validation limitations and upgrade evidence: The captured body distinguishes passing Linux/corrected-runtime evidence from later fixture startup timeouts before test execution, including a plain-main startup failure. It also records a published 2026.9.8 updater-to-candidate cell with verified running identity and readyz=200. No timeout, assertion, schema, stored format, or configuration default was changed. (010fc862f843)
  • Related work and review continuity: feat(gateway): route pairing and default approvals through the live owner; routing docs (routing 4/4) #164075 merged the underlying live-owner/offline-custody routing, rather than this join-code cutover. fix: paired clients time out behind queued connection metadata #161421 overlaps the pairing owner but addresses connection metadata and other distinct work. The previous completed review covered this same head with no findings; current REST reads confirm the PR remains open and cleanly mergeable with successful aggregate CI, dependency-review, and security-sensitive statuses. (010fc862f843)

Likely related people:

  • Peter Steinberger: Raw commit ade3456 adds src/infra/device-pairing-join-code.ts:4 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ade3456dd48f; files: src/infra/device-pairing-join-code.ts)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-04T04:31:27.996Z sha 010fc86 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 4, 2026
@steipete
steipete merged commit f288016 into main Oct 4, 2026
160 of 163 checks passed
@steipete
steipete deleted the dbasync/joincode branch October 4, 2026 06:32
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant