Skip to content

feat(client): keep native credentials in a local store - #174485

Closed
steipete wants to merge 8 commits into
pgprep/r14b-pg-migration-generationsfrom
pgprep/r10-pr1b-credential-cutover
Closed

steipete wants to merge 8 commits into
pgprep/r14b-pg-migration-generationsfrom
pgprep/r10-pr1b-credential-cutover

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Reconciliation STOP after R14b landed. R14b #174360 landed as 407c309f27da. The local PR1b reconciliation is held under the coordinator's approximately 300 net production-line limit for a generic redesign; this is no longer an unmerged-prerequisite block. The published head remains f2a025f5b8dfc0411acfcbca5a1f45f25dd7c594, and this PR remains DRAFT. No new reconciliation commit was pushed.

The implemented generic source/companion/publication seam and wiring measure +212 net lines. Correct standalone Doctor authorization additionally requires an estimated 95–115 lines at the existing backup producer, scoped-snapshot verifier, and immediate version runner: total +307–327. Reused backups currently prove integrity and source inode, not equality with the current source rows. A fresh post-backup generation alone could therefore authorize retiring newer credentials that the retained backup cannot restore. That verification must not be omitted to meet the size threshold.

Need Landed R14b / reconciliation
Captured SQLite source authorization Not covered by landed R14b. Provisional same-handle exclusion and isolated-generation verification implemented locally; standalone exact-backup proof still missing.
Local companion attribution Not covered. Provisional local publication uses the existing capture receipt, ignores unknown companion paths for older drivers, and retains native custody; public-path validation fails on companion access.
Native-v0 to PostgreSQL publication Not covered; R14b covers existing PG state/agent migrations. Provisional fresh-publication hook is local and unproved; native-v0 public admission currently refuses before capture.

Rebased proof so far: PostgreSQL schema generators/checks 144+21 and Kysely4 passed; shared Swift/native113 tests passed, including receipt/wire fixtures; unchanged published native readers again accept the untouched independent source. The actual new SQLite public-admission suite finished with 1 pass and 2 failures: foreign-write refusal passes; canonical v25 candidate Doctor reports maintenance does not own the database; native-v0 createUpdateRun refuses missing global schema role before capture. Rollback assertions were not reached. Two declaration-preflight errors remain in the provisional tree. PostgreSQL public-path/conformance reruns, remaining native proof, fresh review and full CI are incomplete. No READY claim is made. Signed real-Mac proof pending (landing gate).

The prior published-head implementation and evidence are retained below; they do not validate the provisional reconciliation.


What Problem This Solves

Native and TypeScript clients currently keep private identities, cached pairing tokens, and socket secrets in shared Gateway state, preventing client bootstrap from remaining independent of the selected database.

R10 PR1b follows preparatory #174294 and recovery prerequisite #174360. Peter approved the R0 responsibility-based ownership design on 2026-10-14. The coordinator's binding follow-up requires copy-only import for uncaptured independent native sources. This draft stacks on R14b and includes PR1a until it lands.

User Impact

Client identities, token refresh, and native socket credentials use local client/credentials.sqlite, including when shared state uses PostgreSQL. Existing identities and token bytes are preserved. Migration requires captured custody; rollback loses credentials issued after upgrade, and affected clients re-pair.

This draft is not ready to land. The current R14b API does not yet provide all required migration-publication hooks described below. Signed real-Mac proof pending (landing gate), scheduled separately by the coordinator.

Why This Change Was Made

  • Cut both Swift and TypeScript client paths over to the independently versioned local owner, including pre-readiness CLI pairing, public-session decryption, profile roots, and read-existing elevation lookup. Use bounded authenticated app operations or exclusive offline custody; preserve atomic claims, expected-token comparisons, and server-first revocation.
  • Copy, verify, and receipt captured canonical credentials before retiring their three shared tables. Extract socket secrets from exec_approvals_config; keep approval policy and effect-time authority with their existing owners for PR3.
  • Leave independent native databases and retained JSON byte-identical: no chmod, checkpoint, marker, private backup, retirement, or unlink. Bind the local copy to source identity and content hash, including auth-table presence. Preserve local tokens/claims for the same source; rebuild changed sources without resurrecting consumed JSON.
  • Define destinationVersion identically in both languages as the local schema version, currently 1, separate from shared cutover version 26. Release obsolete shared credential workers and duplicate preparation/codecs/socket orchestration.

Update Behavior

PR1a enables no production reader or writer, so a published SQLite driver reaches PR1b with credentials still in shared state. Automatic rollback restores those shared tables; the old release ignores the orphaned local file. Credentials issued between upgrade and rollback are lost; affected clients re-pair. A subsequent cutover rebuilds a stale canonical local copy from restored shared state, never merges it. Published native readers continue accepting untouched independent sources and refuse the retired canonical table layout.

No published release supports PostgreSQL shared state. Those installations use an engine-aware driver containing PR1a's local-family capture/restore support. The actual updater capture/restore test passes for an already-cut-over PostgreSQL store, its retained agent, and local identity/token/socket credentials. Predecessor extraction still requires R14b's missing integration.

Current R14b head 48d0ad6d37be0f59dfc6f5cd6806b01779311fd6 covers existing PostgreSQL generation advancement, but lacks (1) captured SQLite/native-v0 source authorization, (2) local companion preimage/absence and final-generation attribution, and (3) compound native-v0 to fresh PostgreSQL publication. Production retirement deliberately refuses without that authority. The actual published-driver harness captures schema20, then candidate Doctor refuses before cutover with the original shared tables intact and no local file created. This is an unproven migration handoff, not orphan-induced rollback failure. No substitute capture callback or fabricated receipt is used to claim end-to-end proof.

Evidence

  • Final post-integration migration/backup proof: 16 passed (177.4s); the post-merge actual PostgreSQL updater capture/restore cell also passed (88.86s test, 217.86s wrapper), with completed-generation verification. Four credential suites: 49 cases passed in the combined run; the remaining test expected an exception from Doctor's warning-returning API. Corrected only that assertion and reran it successfully. These cover receipt/wire fixtures, exact preservation, revoked JSON reimport, same-inode source changes, native auth-table presence, interruption/resume, source-free recovery fencing, and Doctor identity repair.
  • Retained focused proof: 117 Gateway cases; 44 restore/pairing cases; 7 device-auth cases; actual PostgreSQL updater capture/restore passed again after integration (88.86s); SQLite archive/backup and PostgreSQL extraction contracts passed. Fixture-owned extraction is not presented as the missing production updater handoff.
  • Swift: 113 shared-kit/native tests and 40 Mac policy/handler tests passed. Shared test build, documented macOS SwiftPM app/test builds, strict lint and format passed. No app launch/install, real Gateway state, Keychain, or Docker use.
  • Final current Swift importer plus unchanged 2026.10.4 and 2026.10.10-beta.1 native readers: both accept the exact independent identity before/after import; source bytes, modes, inventory and JSON remain unchanged. Both readers separately refuse a fresh canonical schema26 produced by the real state owner without recreating tables. This proves the layout fence, not predecessor rollback.
  • Core/focused test typechecks, targeted lint/format, PostgreSQL catalog/generator checks (144 + 21), Kysely/dialect/import/line-cap guards, and wrapper closure (22 cases) passed. Worker inventory is regenerated. The six generated Mermaid Knip assets match the checked main baseline; no exceptions were added. The staged line-cap comparison against the R14b parent passed for 151 changed source files. Worker inventory contains 621 files and 2,345 call expressions. The worker ratchet passed with 222 live calls and 12 compatibility calls, both unchanged.
  • One complete independent Codex P0–P2 autoreview covered the full candidate in 11 parts. Both findings were verified and fixed: never-imported native auth JSON was prematurely marked consumed; consumed-identity repair reacquired held custody. Focused regressions pass. Additional reproduced repairs preserve offline identity after first PostgreSQL connection failure and forbid Doctor rebinding a fresh receipt to an unrelated shared file.

Scope and Schema Coordination

PR1b-only production: +5,497 / −2,971 = +2,526 net, across 104 production files (197 total), excluding both prerequisites, generated output, tests, docs, and wrapper inventory. The 8,468 changed production lines exceed the revised 4,500–6,000 changed / +1,500–2,200 net estimate. The retained growth implements both language owners, full caller cutover, exact credential preservation, and the required recovery boundaries; LOC is reported, not a stop.

This migration currently uses state26. Async #174036 also targets26: take the next free version at landing, 26 if this lands first, otherwise27; whoever lands second renumbers and regenerates PostgreSQL/schema outputs. Table-scoped backup is exactly device_identities, device_auth_tokens, gateway_origin_device_tokens, exec_approvals_config, plus sqlite_stat1/sqlite_stat4 for the removed indexes.

Do not merge. READY requires the complete R14b publication integration and its end-to-end proofs; the standalone prerequisite's READY flag alone does not establish those boundaries.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: ios App: ios app: macos App: macos gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations size: XL labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper closed this pull request because it changes 68,223 lines (62,146 added, 6,077 removed) across 216 files, above this repository's 50,000-line limit for review. Changes this large cannot be reviewed safely or scanned within limits and usually indicate a stale branch merged against an old base. Please open a fresh pull request from current main containing only the intended change, or split it into focused pull requests. A maintainer can apply size: accepted-large to exempt a deliberately large change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: ios App: ios app: macos App: macos cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant