Repository navigation
Conversation
- Startup client-credential maintenance reads the canonical exec-approval row through detectLegacyExecApprovals on the Gateway main thread without engine admission. On PostgreSQL state this throws "PostgreSQL connections must run in a worker" and the Gateway exits. - The path runs only when the credential receipt no longer matches the state anchor's path/dev/ino, e.g. after copying, moving or restoring the home. The failed start has already rebound the receipt, so the next start works. - Wrap that synchronous detection in withEngineStoreAdmission, as the same file already does for the required-credential source read. - Add a Gateway-role PostgreSQL test that replaces the anchor and reruns startup credential preparation; register it in database conformance.
|
🦞👀 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. |
|
Codex review: needs maintainer review before merge. What this changesAdmit the synchronous exec-approval detection read during startup maintenance so restored PostgreSQL homes start successfully. Example: Restore a stopped PostgreSQL home whose anchor inode changes from 452684932 to 452707160.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a concrete startup failure still present on current main, with a focused patch and convincing supplied behavior proof; no actionable defects found. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway startup prepares local credentials against the selected shared-state database before serving; maintenance reconciles the credential receipt and checks legacy approvals. flowchart TD
A[Gateway startup] --> B[Credential preparation]
B --> C[Existing maintenance owner]
C --> D[Credential receipt reconciliation]
D --> E[Admitted approval detection]
E --> F[PostgreSQL shared state]
E --> G[Gateway ready]
Technical reviewBest possible solution: Land the narrow admission fix and Gateway-role regression through the normal merge gates. Do we have a high-confidence way to reproduce the issue? The source establishes the unadmitted canonical-read path, and supplied base/head Gateway traces reproduce the reported first-start failure; this read-only review ran no target code. Is this the best way to solve the issue? This is the smallest complete fix: admit the existing synchronous maintenance read through its existing owner while preserving normal worker admission and migration policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against aca9ee2199b5. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +79, Other +1. Total +84 across 3 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)Reviewed October 31, 2026, 4:45 AM ET / 08:45 UTC (Revision 4). |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
What Problem This Solves
Fixes: the Gateway exits on its first start with "PostgreSQL connections must run in a worker; only synchronous admission, migrations, and CLI one-shots may run on the main thread" after a PostgreSQL-backed OpenClaw home is copied, moved or restored. The second start works.
User Impact
User impact: a copied, moved or restored PostgreSQL home now starts on the first try. Before this, the first start always failed with a database connection error, and a plain retry worked. That pointed operators at the database, which was not the problem.
Why This Change Was Made
The local client-credential receipt records the path, device and inode of
state/openclaw.sqlite(the PostgreSQL anchor file). When the home is copied, moved or restored, those no longer match, so Gateway startup runs client-credential maintenance to rebind the receipt. Near the end of that maintenance, the legacy exec-approval detection reads the canonical exec-approval row from shared state synchronously on the Gateway main thread, without engine admission. On PostgreSQL state the main-thread guard refuses that read and startup fails. The receipt has already been rebound by then, so the next start skips maintenance and works.The fix wraps that one synchronous detection in
withEngineStoreAdmission. The same file already does this for the required-credential source read on PostgreSQL. SQLite behaviour is unchanged: admission only affects the PostgreSQL main-thread guard.Real behavior proof
Real
openclaw gateway runon PostgreSQL. Both builds came from this PR's commits, built the same way, and ran with the same script and the same synthetic home:4d2a9f8bb4c47da0daae7fd820cab33fa450ef7b, this PR's parent.bb36792e746bf0c22179e4fb2e0c66e1880503cb.Environment:
docs/gateway/postgresql.md: theopenclaw_runtimerole, plus theunaccent,pg_trgmandvectorextensions.--auth none. Channels, cron and providers are skipped.Steps for each run:
openclaw database port --to postgres.cp -Rp, delete it, and restore it from the backup. The path stays the same, but the anchor gets a new inode.After each start, the script reads three things from the home: the anchor inode, the client-credential receipt (
client/credentials.sqlite), and the device identity.[gateway] ready,/readyz200"ready":trueRuns alternated base, head, base, head. On main, step 6 (the plain retry) was ready 3/3. That matches the report: the failed start has already rebound the receipt, so the retry skips maintenance.
On the PR head, the restored home's first start rebinds the receipt to the new anchor inode and keeps the device identity. There are no device tokens in this synthetic home (0 before and after), so only the device identity is shown.
main 4d2a9f8, run 1, steps 3 to 6 (script output excerpt; paths shortened to <work>)
PR head bb36792, run 1, steps 3 to 6
Commands (per arm)
Upgrade from the latest stable release
Latest stable is
[email protected](npmlatest;extended-stableis 2026.9.36). That release has no PostgreSQL engine and no client-credential store, so a PostgreSQL home cannot be created on it. The upgrade path therefore starts on SQLite, and a single home goes through every step:mainandresearch,agents.defaults.timeoutSeconds: 900) and start the Gateway. Then, through the running Gateway, add 3 sessions with labels (sessions.create), add 9 messages (chat.inject), and add 2 exec allowlist entries (openclaw approvals allowlist add). Stop.openclaw doctor --fix --non-interactive(the migration stepopenclaw updateruns; head refuses the 2026.10.9 agent schema v25 until it has run), then the first start on SQLite.openclaw database port --to postgres, then start on PostgreSQL 17.11.cp -Rpbackup. The anchor gets a new inode. Then the first start of the restored home.After every start, the script reads
/readyzand queries the running Gateway for the seeded sessions (sessions.list), each session's messages (chat.history) and the exec approvals (approvals get). With the Gateway stopped, it reads the settings and the device identity from disk. Each later snapshot is compared field by field with the 2026.10.9 snapshot:/readyz200035bdea6, 2 agents4abb951c...client/credentials.sqliteclient/credentials.sqlite.must run in a workerappears in none of these logs.meta(migration markers),wizard(last run), andskills.entrieswith 4 bundled skills disabled. That is head's Doctor behavior, independent of this PR.Upgrade run, steps 2 to 4 (script output excerpt; paths shortened to <work>)
Evidence
cp -Rc, matched: main failed the first start 3/3, and the fix was ready 3/3. Stack from the failing start:readCanonicalRow<-hasLegacySqliteExecApprovals<-detectLegacyExecApprovals<-prepareStartupClientCredentialsmaintenance.startup-client-credentials.gateway.postgres.test.tsruns in the Gateway process role. It replaces the anchor (copy, then rename, so it gets a new inode) and reruns startup credential preparation. It fails on main with the same error and passes with the fix. The existingstartup-client-credentials.postgres.test.ts(7 tests) andstartup-client-credentials.test.ts(SQLite) pass.pnpm check:changedpasses everything except the knip production dead-export scan, which reportssrc/gateway/plugin-node-capability.ts: prepareClientPluginNodeCapabilities. That scan fails the same way on main, and the failure is unrelated to this change.Test commands