Repository navigation
refactor(gateway): carry authoritative read facts - #125145
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 7:55 AM ET / 11:55 UTC. ClawSweeper reviewWhat this changesThe PR removes repeated Gateway and CLI state reads by carrying validated pairing and device-auth facts forward and consolidating read-only SQLite access. Merge readinessKeep open: this active maintainer PR is not on current main, and the prior credential-rotation blocker is addressed by conditional writes and deletes at the durable auth owner. Priority: P1 Review scores
Verification
How this fits togetherGateway CLI calls select pairing and stored device credentials before constructing the shared Gateway client; authentication outcomes can then update the same durable credential record. Separate status and metadata readers use the shared read-only SQLite lifecycle without creating state. flowchart LR
A[CLI and status commands] --> B[Gateway call and pairing list]
B --> C[Validated device and node facts]
C --> D[Gateway client]
D --> E[Gateway authentication result]
E --> F[Conditional credential store]
A --> G[Read-only state consumers]
G --> H[Existing SQLite read helper]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -12, Tests +103. Total +91 across 19 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the canonical fact-carrying flow after exact-head validation, retaining conditional token mutations for both durable credential scopes. Do we have a high-confidence way to reproduce the issue? Yes: the focused A→B credential-rotation interleaving is directly represented in the client and SQLite-owner regressions, though this read-only review did not execute them. Is this the best way to solve the issue? Yes: fencing mutations at the SQLite owner is preferable to a client-side retry or cleanup guard because it preserves the credential selected for the request without allowing it to alter a newer row. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e6616fdc4c4c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
90238db to
541c8c1
Compare
541c8c1 to
cc00f76
Compare
cc00f76 to
016237e
Compare
|
P1 repaired at fc88f5f. The durable device-auth owner now treats the prepared token as a compare-and-swap fence. Prepared credentials remain immutable request input; later hello stores use conditional UPDATE and mismatch cleanup uses conditional DELETE against the original token. If local or origin-scoped durable auth has rotated or disappeared, the stale request changes zero rows and cannot upsert, clear, or overwrite the current credential. Ordinary unprepared clients retain their existing upsert/clear behavior. Regression proof reproduces the A→B interleaving at both boundaries: four Gateway client cases cover local/origin × stale clear/overwrite, and the SQLite owner test rotates A to B before stale conditional store and clear attempts, then verifies B remains byte-for-byte current. Both regressions failed on the prior head for the intended reason. Validation on the pushed head:
Current PR surface: production +455/-467 (net -12); tests +221/-118 (net +103). No protocol, config, schema-version, migration, dependency, or compatibility surface changed. Behind-main drift remains advisory while the PR is mergeable; the repo-native prepare chain will enforce the final guarded base and exact-head proof before merge. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready verification for
No proof gaps remain. No protocol, config, SQLite schema/version, migration, dependency, docs, or compatibility surface changed. |
|
Merged via squash.
|
* refactor(gateway): carry authoritative read facts * fix(gateway): fence prepared device auth rotations * fix(ci): split oversized session types
What Problem This Solves
Removes three families of read-path rediscovery that had drifted away from their authoritative producers:
devicesre-readnode.listand joined node/device records by device ID or IP even thoughdevice.pair.listalready carries approved and pending node surfaces.Why This Change Was Made
Facts now cross the boundary that produced them. Device approval notices use
nodeSurface/pendingNodeSurfacefrom the pairing record; Gateway calls pass their prepared auth entry into the client host deps; writable and read-only device-auth loaders share one Kysely query owner; and all eleven existing-state readers usewithExistingOpenClawStateDatabaseReadOnlyfor reuse, existence, forward-schema, corruption, and close handling.The migrated readers are MCP OAuth, sandbox registry, Doctor incognito repair journal, fleet registry, startup migration lease, both installed-plugin index readers, config machine state, onboarding recommendations, registered agent databases, and TUI last-session state.
No protocol, config, SQLite schema/version, migration, dependency, or compatibility surface changes.
User Impact
Device/node approval guidance no longer spends extra Gateway round trips or depends on inferred ID/IP joins. Read-only Gateway calls reuse the exact stored credential they already validated. CLI and metadata reads consistently avoid creating writable state while preserving missing-database fallbacks and non-missing filesystem failures.
Production LOC: +322/-404 (net -82) | Tests: +87/-118 (net -31).
Evidence
devices-cli.test.tsobserved 5/2 Gateway calls where the recorded-fact contract requires 3/1; 2 tests failed for the intended reason.preparedDeviceAuth, and the client connect frame had no prepared token; 2 tests failed for the intended reason.OPENCLAW_TESTBOX=1 node scripts/check-changed.mjssucceeded on Blacksmith Testbox run https://github.com/openclaw/openclaw/actions/runs/32004752402. Core/core-test typechecks, three changed-file lint stripes, dead exports, import cycles, database-first, schema, sidecar, pairing, formatting, and selected guards passed.Best-fix verdict: best. Each cleanup removes consumer inference or duplicate lifecycle/query ownership instead of adding a cache, fallback, or compatibility path. Missing-database behavior remains at the canonical helper, and stored credentials remain owned by the one-shot call that selected and validated them.