Skip to content

fix: preserve database admission for post-restart turns - #166867

Merged
steipete merged 2 commits into
mainfrom
ci/fix3-qa-peer-verify
Oct 8, 2026
Merged

steipete merged 2 commits into
mainfrom
ci/fix3-qa-peer-verify

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes intermittent first-turn failures after a Gateway restart when concurrent opens revoke otherwise valid agent-database admission. QA Smoke's subagent-completion-direct-fallback scenario then waits for a reply that never starts.

User Impact

A healthy database remains admitted while startup readers and the checked host opener converge on the same physical store. In the captured failure, the post-restart turn failed before provider dispatch; all five earlier child replies had already been delivered. This is an availability defect, not demonstrated loss of a completed reply.

No persisted schema, stored bytes, migration, public SDK contract, retry, or timeout changes. Replacement, explicit revocation, schema drift, and failed installation still invalidate admission.

Why This Change Was Made

Two owners incorrectly treated successful local setup as revocation. Extend the checked TEMP installer from #166698 to the existing transcript-index tracking objects, then promote a live canonical-only validation entry when the full opener completes. Preserve matching live shared-schema revocation cells so delayed healthy receipts do not detach existing borrowers; reject stale required-schema receipts before mutating the cache.

The trace records a pending native receipt with valid integrity and schema bits being refused solely because a concurrent checked host open replaced the captured cache entry. The fix keeps that entry alive while retaining physical-file and lifecycle fences.

Evidence

  • The actual Linux QA scenario failed on the original baseline, on attempt 5 of the peer-only candidate, and on attempt 9 with only the TEMP repair. The complete repair passed 20/20 serial pressured runs, with unchanged scenario assertions and timeout. Command walls were 69–84 seconds, median 70 seconds, versus approximately 136 seconds for the original failing command.
  • Three profile-4 primary + Matrix replay pairs passed: 27/27 scenario executions, zero failures or skips.
  • Receipt/schema/tracker owners passed 84 tests, and real-worker recreation/creation-witness siblings passed another 56. The owner regressions fail before their corresponding repairs. The latest-main integration passes all 40 validation-cache tests in 25.89 seconds on the permitted single-file local route.
  • 22 whole configurations passed on Linux, including the agent, state, CLI/plugin, Gateway core/methods, and channel lanes. Core types, all 27 test type graphs, focused and boundary lint, source contracts, architecture, and docs checks passed. Independent P2 reviews found no actionable findings.

The broad Linux proof used base 06a1b56f5c9b plus the exact candidate. Rebase onto b27f3f32eb9d preserves the authored implementation; the additional owner-file run checks its integration with upstream schema-marker reuse. Completed predecessor proof is not represented as an exact-head whole-suite run.

Direct-push proof remains incomplete. Native Testbox timed out after 15 minutes; AWS fallback supplied the results above, but the whole infra run reached its lease cap before a terminal summary. This PR uses the authorized fallback; it has not been directly landed or armed for auto-merge.

Broader failures and remaining uncertainty
  • check-changed and full Knip report the inherited unused readRecommendedModels export. The remaining static commands passed independently.
  • Tooling's missing-Ruby prerequisites were repaired on the test host; all 46 tests in the three affected files then passed. Its remaining lint-suppression inventory failure reproduces on untouched base.
  • The incomplete infra run observed a 1,155 ms branch-summary operation against a 1,000 ms assertion. No full passing result or baseline attribution is claimed.
  • Gateway database and server configs remain red. The test host's /tmp is below the worktree reserve; focused disk-backed comparisons also found auth logout at 1,040 ms against 1,000 ms and a forced-abandonment authorization wait failure. A matched diagnostic reproduces forced abandonment on both untouched base and candidate under identical CPU pressure: the first cold read remains pending until teardown at 1,046/1,053 ms, before any drain operation runs. Both unloaded controls close authorization at approximately 611 ms. Plugin/config lease contention also reproduces on base, but the full failure mix is not conclusively attributed.
  • Whole E2E completed all 274 files: 248 passed, 15 failed, 11 skipped. Its missing embedded-auth mock export, fault-sequence error mismatch, and missing cron killed status independently reproduce on untouched base: the same 20 failures. Two files fail because the required sandbox Docker image is absent. Ten failing files remain unclassified, including runtime-artifact publication refusals, recovery authority, and timing.

No assertions, retries, timeout budgets, suppressions, inventories, dependencies, or unrelated product paths were changed to conceal these results.

Extend the checked TEMP tracking owner introduced in #166698 to the fixed
transcript-index status table, pending queue, index and enqueue triggers.
Installing these connection-local objects must not revoke the agent database's
main-schema admission receipt. Ordinary DDL, unexpected object shapes,
reentrant mutations and partial installation failures still revoke it.

Move the existing SQL into the typed builder and migrate both tracking callers
to its shared operation. Preserve local read revisions, rollback staging and
INSERT OR REPLACE behavior. No persisted schema, stored bytes, migration,
public SDK contract, retry or timeout changes.

The existing status-owner regression fails on the parent at first tracker
installation. All six owner cases pass after the repair (1.78s invocation),
including drift, rollback, foreign writes and bounded cleanup. P2 review is
clean. The broader restart investigation and Linux gates remain recorded in
the task evidence; this commit alone is not a claim that the QA race is fixed.
A startup reader can publish canonical proof before native admission starts.
A concurrent fully checked host open then registered the same database by
revoking that proof, rejecting the pending native receipt and failing the
post-restart turn before a provider request could begin.

Publish the checked opener's registration through the validation owner and
promote live proof without retiring its pending handoff. Keep physical-file
replacement and explicit lifecycle revocation strict. Reject stale required
schema receipts before they can replace newer facts, and retain the shared
schema revocation cell for matching live schemas. Accepted schema changes
and schema-optional revocation reports retire the displaced borrowers.

Regressions cover canonical and empty promotion, physical replacement,
revocation, delayed publication, and borrowed-schema retirement. All 36
receipt-owner cases pass (30.60s Vitest, 34.03s wrapper); the corresponding
negative controls failed before their repairs. P2 review is clean. Linux
pressure, owner-suite, and static gates are tracked separately before landing.
No stored data, schema version, public SDK, retry, or timeout changes.
@clawsweeper

clawsweeper Bot commented Oct 8, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 7, 2026, 9:33 PM ET / October 8, 2026, 01:33 UTC.

ClawSweeper review

What this changes

The branch preserves database admission during transcript tracker installation and concurrent successful database opens.

Example: A user starts a subagent turn after a Gateway restart

  • Before: Concurrent database opens can prevent the turn from reaching provider dispatch, leaving the user without a reply.
  • After: The reported pressured runs deliver QA-SUBAGENT-TERMINAL-RESTART-OK after restart.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/infra/sqlite-schema-facts.ts, src/infra/sqlite-temp-generation-schema.ts. Prefer a design that avoids changing persisted SQLite tables. Migration or upgrade compatibility proof is recorded, but maintainers should still confirm that the schema change is necessary.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful restart proof is present, but the new acceptance path leaves a required revocation invariant broken.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR reports the actual Linux Gateway restart scenario passing 20 pressured runs and 27 replay executions after both repairs, with exact post-restart delivery assertions. That supports the original availability fix, but does not prove revocation across independent schema cells. Source confirms that only process-local receipts and TEMP objects change, so no stored-data migration is required.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A first turn after Gateway restart can fail before contacting the provider, so the user receives no reply.
Reason: Reliable post-restart turns are established behavior, and prior area-owner work explicitly calls for this admission repair. The change adds no user configuration or permanent storage contract.

Merge readiness

⛔ Needs changes before merge - 3 items remain

This PR addresses a demonstrated restart failure, but its receipt acceptance path introduces a blocking schema-revocation gap.

Priority: P1
Reviewed head: 5b0a3c1182a4455cb93f99af1e689266b23c4927

Before merge

  • Connect the accepted worker receipt to shared schema revocation (P1) - When a worker independently validates the database while a checked host open promotes the same store, their schema markers can match while their schema.valid buffers differ. This new early return keeps only the host buffer and acknowledges the worker receipt without returning that buffer to the worker. Later worker-local DDL revokes the worker buffer, but the host buffer remains live; createAgentDatabaseNativeGeneration.run() therefore skips database.prepareWrite, and the worker continues through its cached opener without required schema readmission. Preserve revocation from both accepted connections, and add the independent-cell case to the promotion regression.
  • Complete next step (P2) - Connect independently accepted host and worker schema receipts to shared revocation, and validate readmission after DDL from either connection.
  • Improve patch quality - Repair independent host/worker schema-cell coordination and prove that DDL from either connection forces readmission before subsequent work.

Findings

  • [P1] Connect the accepted worker receipt to shared schema revocation — src/state/openclaw-agent-db-validation-cache.ts:328-332

Tests

  • Missing end-to-end proof: Missing coverage is independent host/worker admission followed by worker-local DDL, showing that host admission becomes invalid and the next production operation performs readmission; the reviewer did not run base/head tests.
Agent review details

How this fits together

OpenClaw validates each agent’s SQLite database before processing turns. Shared admission receipts let host and worker connections reuse those checks, while revocation tells them when validation must run again.

flowchart TD
  A[Post-restart turn] --> B[Host and worker database opens]
  B --> C[Database validation owner]
  C --> D[Shared admission receipts]
  D --> E[Schema change or lifecycle revocation]
  E --> F[Readmission before subsequent work]
  D --> G[Agent turn processing]
Loading

Technical review

Best possible solution:

Keep successful admission promotion, but ensure every accepted host and worker receipt participates in the same revocation lifecycle before subsequent database work.

Do we have a high-confidence way to reproduce the issue?

Yes: the supplied Linux restart scenario establishes the original failure, and source establishes the introduced independent-cell revocation failure. This read-only review executed neither scenario.

Is this the best way to solve the issue?

No: extending the existing admission owners is appropriate, but accepting equal schema markers does not establish shared revocation between independently opened connections.

Full review comments:

  • [P1] Connect the accepted worker receipt to shared schema revocation — src/state/openclaw-agent-db-validation-cache.ts:328-332
    When a worker independently validates the database while a checked host open promotes the same store, their schema markers can match while their schema.valid buffers differ. This new early return keeps only the host buffer and acknowledges the worker receipt without returning that buffer to the worker. Later worker-local DDL revokes the worker buffer, but the host buffer remains live; createAgentDatabaseNativeGeneration.run() therefore skips database.prepareWrite, and the worker continues through its cached opener without required schema readmission. Preserve revocation from both accepted connections, and add the independent-cell case to the promotion regression.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against c2827be879b9.

Provenance checked

  • src/config/sessions/session-accessor.sqlite-entry-revision.ts keeps the original intent (653294c: Install fixed generation trackers without revoking admitted main-schema facts.)
  • src/config/sessions/session-transcript-index-status.worker.ts keeps the original intent (359eb9c: Use connection-owned revision-bound projection facts and bounded maintenance instead of recurring full-store scans.)
  • src/infra/sqlite-schema-facts.ts keeps the original intent (653294c: Keep fixed TEMP installation under the existing schema observer while retaining revocation for unexpected DDL and failed installation.)
  • src/infra/sqlite-temp-generation-schema.ts keeps the original intent (653294c: Generate and verify fixed counter and trigger shapes before preserving schema admission.)
  • src/state/openclaw-agent-db-registry.ts changes intended behavior with a stated reason (72f7155: Registry transitions revoke retained validation so recreated databases cannot inherit old initialization proof.)
  • src/state/openclaw-agent-db-validation-cache.ts changes intended behavior with a stated reason (fbac0be: Classify stale schema publication separately from malformed receipts while preserving settled transfer behavior.)
  • src/state/openclaw-agent-db.ts keeps the original intent (694f9ae: Reuse successful physical database verification while retaining replacement and explicit lifecycle revocation.)
  • docs/reference/database-schemas/worker-access.md keeps the original intent (653294c: Document checked connection-local tracker installation and ordinary schema revocation.)

Testing

Proof path: shipped entry point. Added test files: 2.

Security

None.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/state/openclaw-agent-db-validation-cache.test.ts --maxWorkers=1.
  • [P1] pnpm test src/state/openclaw-agent-execution.integrity.test.ts --maxWorkers=1.
  • [P1] pnpm test src/state/openclaw-agent-execution.registration.test.ts --maxWorkers=1.
  • [P1] pnpm check:changed --base b27f3f3.
  • [P1] Prove through the production worker handoff that independent-cell publication followed by DDL from either connection forces readmission before subsequent database work.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +120, Tests +140, Docs +8. Total +268 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 7 236 116 +120
Tests 2 142 2 +140
Docs 1 12 4 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 390 122 +268

Stored data model

Persistent data-model change detected: database schema: src/config/sessions/session-transcript-index-status.worker.ts, database schema: src/state/openclaw-agent-db-validation-cache.ts, unknown-data-model-change: src/infra/sqlite-schema-facts.ts, unknown-data-model-change: src/infra/sqlite-temp-generation-schema.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Labels

Label changes:

  • add P1: The reported defect prevents post-restart agent turns from starting.
  • add merge-risk: 🚨 availability: Accepting a detached worker schema cell can skip required readmission and leave later agent operations running against an unvalidated schema.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🐚 platinum hermit and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P1: The reported defect prevents post-restart agent turns from starting.
  • merge-risk: 🚨 availability: Accepting a detached worker schema cell can skip required readmission and leave later agent operations running against an unvalidated schema.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🐚 platinum hermit and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

@steipete
steipete enabled auto-merge (squash) October 8, 2026 01:46
@steipete
steipete merged commit b5c9a25 into main Oct 8, 2026
169 of 177 checks passed
@steipete
steipete deleted the ci/fix3-qa-peer-verify branch October 8, 2026 01:47
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

Merged at the pinned head 5b0a3c1 despite one red check, because that red is inherited from main and unrelated to this change.

  • The only failing test in PR CI was src/gateway/session-utils.transcript-title.test.ts ("does not hydrate named transcript payloads for scalar title-only rows", expected 3060 to be greater than 450366). Main fails it with the identical values in the 23:30Z and 01:11Z hourlies, before this PR existed. A separate fix is in progress.
  • Five changed-scope shards were cancelled when the run stopped after that failure. The owning configs for every changed file were run whole on Linux before this PR opened: gateway-core 8,072 tests green, all 36 receipt-owner regressions, plus the infra, runtime-config, unit-src and agents-support owners. The failing QA smoke scenario passed 20/20 under pressure, and 3 profile replay pairs passed 27/27.
  • The P2 review, lint, types, boundary, source-contract and architecture checks all passed.

The change fixes a production admission race: a concurrent checked database open revoked a healthy pending receipt, and transcript TEMP setup invalidated admission. Together these could drop the first post-restart reply before model dispatch.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
)

* fix(sqlite): preserve admission during transcript tracker setup

Extend the checked TEMP tracking owner introduced in openclaw#166698 to the fixed
transcript-index status table, pending queue, index and enqueue triggers.
Installing these connection-local objects must not revoke the agent database's
main-schema admission receipt. Ordinary DDL, unexpected object shapes,
reentrant mutations and partial installation failures still revoke it.

Move the existing SQL into the typed builder and migrate both tracking callers
to its shared operation. Preserve local read revisions, rollback staging and
INSERT OR REPLACE behavior. No persisted schema, stored bytes, migration,
public SDK contract, retry or timeout changes.

The existing status-owner regression fails on the parent at first tracker
installation. All six owner cases pass after the repair (1.78s invocation),
including drift, rollback, foreign writes and bounded cleanup. P2 review is
clean. The broader restart investigation and Linux gates remain recorded in
the task evidence; this commit alone is not a claim that the QA race is fixed.

* fix(state): retain valid admission across concurrent opens

A startup reader can publish canonical proof before native admission starts.
A concurrent fully checked host open then registered the same database by
revoking that proof, rejecting the pending native receipt and failing the
post-restart turn before a provider request could begin.

Publish the checked opener's registration through the validation owner and
promote live proof without retiring its pending handoff. Keep physical-file
replacement and explicit lifecycle revocation strict. Reject stale required
schema receipts before they can replace newer facts, and retain the shared
schema revocation cell for matching live schemas. Accepted schema changes
and schema-optional revocation reports retire the displaced borrowers.

Regressions cover canonical and empty promotion, physical replacement,
revocation, delayed publication, and borrowed-schema retirement. All 36
receipt-owner cases pass (30.60s Vitest, 34.03s wrapper); the corresponding
negative controls failed before their repairs. P2 review is clean. Linux
pressure, owner-suite, and static gates are tracked separately before landing.
No stored data, schema version, public SDK, retry, or timeout changes.
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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant