Skip to content

fix: prevent session creation failures on fresh stores - #167515

Merged
steipete merged 7 commits into
mainfrom
fix/session-create-readiness
Oct 9, 2026
Merged

steipete merged 7 commits into
mainfrom
fix/session-create-readiness

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes concurrent sessions.create calls failing with schema-missing or “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 af8245b4ca4ec0 passed 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.

Test file Tests Node wall Bun wall Prior CI test seconds
session-entry-database-preparation.test.ts 5 33.08s 29.32s 4.768s
session-transcript-worker-lanes.test.ts 26 25.28s 24.06s 0.024s
session-transcript-search.worker.test.ts 5 33.91s 29.75s 5.862s
session-history.async.test.ts 14 50.38s 48.69s 2.175s (1/14 cases)
session-history-worker-errors.test.ts 46 32.36s 31.17s 0.118s
openclaw-agent-execution.creation-witness.test.ts 27 41.57s 34.56s not measured
sqlite-board-store.worker.test.ts 25 53.13s 41.59s 1.667s (2/25 cases)
session-accessor.sqlite-reclamation.test.ts 16 44.24s 36.37s 12.627s
chat-history-worker.test.ts 6 39.33s 34.20s not measured
session-canonical-key.test.ts 15 32.20s 27.90s 3.301s
session-accessor.transcript-identity.test.ts 17 43.25s 34.96s 8.975s
session-history-worker-lifecycle.test.ts 22 76.95s 64.95s 29.564s
collector.session-store-path.test.ts 7 39.54s 33.45s 8.513s
session-cold-storage.inventory.test.ts 5 30.68s 27.71s not measured

CI seconds above sum the emitted Node test-case durations from run 37865376164 at f1cecddc1f8824; 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.

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.
@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: L labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 23:18
@steipete

steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The 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

  • Before: The Bun baseline failed 32 of 320 first-batch requests with schema-missing or database-preparation errors.
  • After: The final candidate completed all 320 first-batch requests on each runtime and listed every acknowledged session.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful owner-boundary repair with convincing exact-head Gateway evidence and no remaining actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded exact-head trials exercise cold admission through the built Gateway’s sessions.create entry point on isolated fresh Node and Bun setups: zero creation failures, every acknowledgment listed, and clean shutdown. Source inspection verifies unchanged stored formats and schemas, so no data migration is required.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Concurrent session requests can fail immediately after a fresh Gateway reports ready.
Reason: The baseline demonstrates failure in established session creation. Current-main area history establishes owner direction for a bounded repair that preserves lazy storage and public contracts.

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
Reviewed head: af8245b4ca4ec082adeb9199d566eea5c52f1abc

Before merge

None.

Findings

None.

Agent review details

How this fits together

The 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]
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 5592e61 adds src/state/openclaw-agent-execution.ts:412 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5592e6169e55; files: src/state/openclaw-agent-execution.ts)

PR surface

Source +232, Tests +345, Docs +13. Total +590 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 374 142 +232
Tests 8 383 38 +345
Docs 1 13 0 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 770 180 +590

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The real-Gateway baseline demonstrates failed concurrent session creation immediately after readiness on fresh Bun stores.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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.

History

Review history (5 earlier review cycles)
  • reviewed 2026-10-08T23:24:45.967Z sha 075c247 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T23:33:18.904Z sha 075c247 :: needs changes before merge. :: [P2] Update existing reader fixtures for the cold-lane cutover
  • reviewed 2026-10-08T23:40:46.695Z sha 075c247 :: needs changes before merge. :: [P2] Update existing reader fixtures for the cold-lane cutover
  • reviewed 2026-10-09T00:46:44.584Z sha f1cecdd :: needs changes before merge. :: [P2] Move transcript-identity fault injection onto the cold reader lane
  • reviewed 2026-10-09T01:33:56.878Z sha af8245b :: needs maintainer review before merge. :: none

Reviewed October 8, 2026, 10:38 PM ET / October 9, 2026, 02:38 UTC (Revision 6).

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
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.
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Oct 9, 2026
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Oct 9, 2026
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 9, 2026
@steipete
steipete merged commit 56e0b78 into main Oct 9, 2026
121 of 178 checks passed
@steipete
steipete deleted the fix/session-create-readiness branch October 9, 2026 02:39
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
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.
steipete added a commit that referenced this pull request Oct 9, 2026
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.
steipete added a commit that referenced this pull request Oct 9, 2026
… 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.
steipete added a commit that referenced this pull request Oct 9, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
… 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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant