Repository navigation
fix: prevent session creation failures on fresh stores - #167515
Conversation
Coordinate cold metadata reads with the existing physical writer admission and retain the native first-creation witness across awaited authority. Keep writer-held reads on their independent worker lane, preserve request and host-work deadlines, and join cleanup before releasing borrowed owners.
Integrate current history search cancellation and execution custody. Preserve the original remaining request budget, and keep first-creation identity validation with the existing scope owner.
|
🦞👀 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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThe branch coordinates cold session reads with database initialization and lets delayed creators retain the original store’s matching first-creation witness. Example: Send 16 concurrent sessions.create requests immediately after a fresh Gateway reports ready
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful because current main retains the fresh-store races. The previous fixture findings are resolved, and no actionable patch defect remains; the inherited architecture-check failure is tracked separately. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe Gateway stores session metadata and transcripts in per-agent SQLite databases. Database admission coordinates initialization and worker access before session requests return results. flowchart TD
A[Concurrent session requests] --> B[Capture caller and store identity]
B --> C{Store already admitted?}
C -->|No| D[Physical writer admission queue]
D --> E[Independent cold reader worker]
C -->|Yes| F[Existing reader worker]
E --> G[Validate store and caller lifetime]
F --> G
G --> H[Return or create session]
Technical reviewBest possible solution: Keep cold reads and first creation under the existing physical admission owner while preserving lazy storage, independent reader capacity, and live caller checks. Do we have a high-confidence way to reproduce the issue? Yes: concurrent sessions.create calls after fresh Gateway readiness have a documented failing Bun baseline, and current main retains the responsible cold-reader path. This read-only review did not execute target code. Is this the best way to solve the issue? Yes: reusing physical writer admission and its matching creation witness repairs the demonstrated races without another storage owner or configuration surface. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 608134ea54c3. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +232, Tests +345, Docs +13. Total +590 across 16 files. Added test files: 0. View PR surface stats
LabelsLabel changes: No label 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 (5 earlier review cycles)
Reviewed October 8, 2026, 10:38 PM ET / October 9, 2026, 02:38 UTC (Revision 6). |
Reserve FIFO order without falsely marking a readonly Board operation as a native writer. Preserve source and consumer authority checks. Keep lifecycle test fixtures on their intended admitted lane and intercept actual hydration requests across reader lanes.
Integrate the current explicit-source validation while retaining first-creation witnesses only after an absence transition. Prepared file identities, captured aliases, physical targets and live authority remain mandatory.
Pause the owned target-discovery pool for absent-store hydration. Keep the run-owner interception and all revocation and absence assertions intact.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
Concurrent session requests on fresh Gateways could read an incompletely admitted agent database or reject a sibling's legitimate first creation. Coordinate cold readers with the existing physical admission owner and retain only matching creation witnesses, preserving lazy stores and identity, authority, cancellation, and cleanup checks. Deterministic original-code regressions and Node 24/pinned Bun suites pass. Final real-Gateway proof completed 3,200 creates per runtime plus 16 immediate-readiness creates per runtime, with every acknowledgment listed and all 42 Gateways shutting down cleanly. Database schemas, durability, public configuration, and APIs are unchanged.
Reuse the existing read-candidate owner so pending writable startup admission does not block independent recovery reads. Keep cold reads serialized with first creation and retain native custody through cleanup. Preserve the deferred-recovery contract from #165184 after #167515. Verify raw sharing fixture aftermath without recertifying foreign edits, and count initial authority reads across cold and prepared worker lanes. Restores the eight red-main cases identified by the stability campaign without changing schema, public contracts, or sharing policy.
… test #167515 moved cold history reads (no known source, prepared generation or open native database) onto the target-discovery worker lane. The quarantine hydration test closes the database first, so its read is cold, but it still spied on the history lane and failed on main ("run" called 0 times) while the rejection itself was correct. Spy on the lane the read actually uses.
After #167515, missing-store reads use the discovery worker for both target selection and conversation rows. Hold the actual worker reply before replacing the source, preserving both phases and every refusal assertion. Validation: the original conversation-rows case fails before replacement because the old observer sees no dispatch. The corrected full gateway-core configuration passes 8,082 tests with 11 pre-existing skips on Linux (766.88s). The final single-file check passes 10/10 in 18.28s wall time (16.15s Vitest). Core types, core test types, ordinary lint, boundary lint and remaining static guards pass. check-changed reports only four unchanged pre-existing dead exports. P2 review is clean.
Reuse the existing read-candidate owner so pending writable startup admission does not block independent recovery reads. Keep cold reads serialized with first creation and retain native custody through cleanup. Preserve the deferred-recovery contract from openclaw#165184 after openclaw#167515. Verify raw sharing fixture aftermath without recertifying foreign edits, and count initial authority reads across cold and prepared worker lanes. Restores the eight red-main cases identified by the stability campaign without changing schema, public contracts, or sharing policy.
… test openclaw#167515 moved cold history reads (no known source, prepared generation or open native database) onto the target-discovery worker lane. The quarantine hydration test closes the database first, so its read is cold, but it still spied on the history lane and failed on main ("run" called 0 times) while the rejection itself was correct. Spy on the lane the read actually uses.
After openclaw#167515, missing-store reads use the discovery worker for both target selection and conversation rows. Hold the actual worker reply before replacing the source, preserving both phases and every refusal assertion. Validation: the original conversation-rows case fails before replacement because the old observer sees no dispatch. The corrected full gateway-core configuration passes 8,082 tests with 11 pre-existing skips on Linux (766.88s). The final single-file check passes 10/10 in 18.28s wall time (16.15s Vitest). Core types, core test types, ordinary lint, boundary lint and remaining static guards pass. check-changed reports only four unchanged pre-existing dead exports. P2 review is clean.
What Problem This Solves
Fixes concurrent
sessions.createcalls failing withschema-missingor “Session creation database changed during preparation” immediately after a fresh Gateway reports ready.User Impact
First session requests participate in database admission and safely follow a sibling’s legitimate first creation. Stores remain lazy; schemas, durability, public configuration, and APIs are unchanged, with no migration or user action required.
Why This Change Was Made
Cold readers could open a newly created file before its schema was admitted, while a delayed creator could mistake first creation for physical replacement. Cold reads now join the existing physical writer admission queue and use independent existing worker capacity. Delayed creators retain only matching original absence witnesses. Identity, alias, shared-state, authority, cancellation, deadline, and cleanup checks remain enforced.
Board reads retain foreground admission without falsely claiming a native writer. Read-owner revocation takes precedence over a borrowed execution error, and status keeps its existing empty-summary behavior for a currently refused matching agent. Regression fixtures intercept the actual cold lane while preserving their original assertions.
Evidence
The baseline used the built Gateway entry point, isolated state, the benchmark readiness signals and warmup, then ten batches of 16 concurrent creates on each of 20 fresh Gateways per runtime. Node 24.19.0 had 0/3,200 failures. The SHA-verified shared Bun pin had 32/3,200 failures, all in the cold first batches: 32/320 (10%), affecting 16/20 Gateways. Every acknowledged session was listed, and all processes shut down cleanly.
Final source
af8245b4ca4ec0passed 0/3,200 failures on Node 24.21.0 and 0/3,200 on pinned Bun, with 20 fresh Gateways per runtime. The cold first-batch rate was 0/320 on both runtimes, down from Bun’s 32/320 baseline. A further fresh Gateway per runtime passed all 16 creates immediately after readiness without probe warmup. Every acknowledgment was listed and all 42 Gateways shut down cleanly. The build passed. An earlier refresh interrupted by its host’s lease deadline was excluded from the completed Bun cell and repeated on a retained host.Deterministic original-code controls reproduce both cold-read ordering and the delayed first-creation witness error. Fake-clock tests cover admission expiry/revocation, and bounded-worker coverage proves progress when search callbacks need the writer. The final production correction passes 118 targeted tests per runtime; the final inventory-only fixture correction passes 5 per runtime. Earlier 185-test-per-runtime proof is retained for unchanged contracts. Every implementation delta is P2 scoped-clean, and ClawSweeper completed the exact-head review with zero findings. No retries, sleeps, widened timeouts, or weakened assertions were introduced.
Production types, all 27 core test-type groups, lint, schema/owner guards, and every remaining selected check passed on the final source. Candidate Madge reports zero cycles. The full changed-check command retains an inherited unused-export failure in four untouched files; the same findings are documented on clean main in #167541 and #167542. The subsequent checks were run separately and passed; the failing scan was not skipped or relabeled.
CI run 37869827643 has one independent failure: the model-catalog fingerprint/worker Madge cycle introduced on main. Its inputs are byte-identical in the actual tested merge and its exact main parent, and the parent reproduces the failure independently. Repair is tracked by #167556. The aggregate failed downstream, and the successful fail-fast monitor cancelled 52 jobs; none contains an independent failed step. This is qualified under the native inherited-failure policy, with failed/cancelled coverage explicitly retained rather than described as green.
Measured focused test costs
Each file ran with the repository wrapper and
--maxWorkers=1, as required by the test-cost budget. Times below are wall time, including transformation and compiled-worker preparation. Unchanged contracts retain their earlier measured proof; revalidated files use their latest measurements.session-entry-database-preparation.test.tssession-transcript-worker-lanes.test.tssession-transcript-search.worker.test.tssession-history.async.test.tssession-history-worker-errors.test.tsopenclaw-agent-execution.creation-witness.test.tssqlite-board-store.worker.test.tssession-accessor.sqlite-reclamation.test.tschat-history-worker.test.tssession-canonical-key.test.tssession-accessor.transcript-identity.test.tssession-history-worker-lifecycle.test.tscollector.session-store-path.test.tssession-cold-storage.inventory.test.tsCI seconds above sum the emitted Node test-case durations from run
37865376164atf1cecddc1f8824; they exclude transformation/setup and include that run’s failing cases. Partial counts are explicit; absent measurements were cancelled. They describe cost, not current-head success.Real database execution and worker callbacks are necessary to prove physical-store ownership, status callback reentry, replacement refusal, and cleanup settlement. The fast transport tests use deterministic gates and a fake clock; new tests add no sleeps or real-time polling.