Skip to content

perf(sessions): run lifecycle inventory and snapshot writes through the lifecycle writer - #164755

Merged
steipete merged 14 commits into
mainfrom
dbasync/lifemaint
Oct 4, 2026
Merged

steipete merged 14 commits into
mainfrom
dbasync/lifemaint

Conversation

@steipete

@steipete steipete commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session lifecycle upserts still counted session inventory and wrote entry snapshots synchronously on the Gateway thread during reply initialization and maintenance. This completes the sess-lifecycle-maintenance inventory/snapshot lane.

Why This Change Was Made

Run projected durable lifecycle upserts through the existing agent executor and synchronous lifecycle transaction kernel. Capture physical store identity before yielding, prepare builders and maintenance protection outside the transaction, reread authoritative rows in the worker, and revalidate current host grants at transaction admission and commit. Publish acknowledged entry, identity, reset, and maintenance facts through the existing owner before releasing its FIFO. Lost replies reconcile the existing native receipt without replaying the mutation.

Reset progress-card events and projection reconciliation remain acknowledgment-driven. Accepted lifecycle persistence settles through the real Gateway close order; new scheduled work is rejected after close begins. The worker performs the lifecycle inventory and snapshot SQL, including inline maintenance and the final inventory after maintenance settles.

User Impact

No intentional user-visible behavior, schema, retention, durability, configuration, or update-contract change. Lane production delta: +265 / −31 / net +234 (296 changed lines), excluding prerequisite changes, tests, and documentation. writeSessionEntry is untouched; native-patch snapshot writes remain with their existing owner. Existing synchronous contracts remain for opaque transaction callbacks, process-held incognito, and offline maintenance.

The original measurement builds on main e25a98150544d4848f4296e79b1d5384ed8f6ab6 plus the tested #164490 foundation at 9bd9115a3287a88aba5db15912e1bb4f05373c11; #164514 is already included in main. Measurement before and after uses that identical foundation. The prerequisite landed as c828f7ed1d560295f78166a98fb54687dc162b28; merge commit d07ce205da51855c79d183d648e2a361bb965634 incorporates main d2a9f9a114c2e2570ed861a5ab0273291d56a793 without conflicts or rebasing. The PR base remains main.

Overlap is intentional and scoped: #163592 retains ownership of writeSessionEntry; #162433 is the standing umbrella design overlap; #164645 overlaps reclamation cleanup; #164512 overlaps retained-transcript semantics and will be reconciled if it lands first. Main also contains #164520’s removal of a redundant archive-runtime import cache in the same projection module; that cleanup is retained in the integrated candidate. The parallel session-initialization-read lane shares only the small commitGuard handoff in session-accessor.reset.ts.

Retained host-grant debt: src/gateway/server-worker-placement-startup.ts:376 calls the existing placement preservation provider through src/gateway/worker-environments/placement-store.ts:364 (listForReconcile) and existing environment authority. These are pre-existing reads of another shared-state owner, retained to keep revocation checks live; this change adds no SQL there. Boundary assertions cover only the moved inventory/snapshot operations.

Evidence

SQL measurement

T1 (mean main-thread statements per warmed turn): 353.1 → 332.4; median 338 → 326. The direct lane sites go from 6 → 0 per warmed turn (3 inventory + 3 projected snapshot statements). The broader projected-transaction stack goes from 25 → 0; it overlaps the direct sites and must not be added to them.

Same original observer and workload, Node 24, source maps, isolated synthetic state, and a loopback provider. Before: 367ca02825133839945ba9b1b5dbab5005ceec6b. After: 8a7c6d9c49978e52225e28ddadd0d79bc41d9f19, tree d6624eecc1a26a647e07b87330bd3c957af6b10f. Both successful runs completed all 13 chats plus child execution, cron, compaction, and graceful shutdown (exit 0). Source-map builds took 892.5s before and 1027.0s after; successful harness runs took 269.7s and 260.5s. All owned processes exited.

Phase Main before Main after Worker before Worker after Helper before Helper after
Boot 2928 2988 1009 1143 109 109
Connect 55 0 339 200 0 0
First turn 893 885 3838 4874 63 63
Ten warmed turns 3531 3324 12972 13971 216 212
Second session + child 1160 1126 4886 5076 64 60
Control plane 0 0 61 75 0 0
Cron 484 520 2369 1374 10 10
Compaction 203 203 581 585 20 20
Shutdown 408 400 2084 2055 0 0
Total 9662 9446 28139 29353 482 474
Lane main-thread operation Before total After total Before / warmed turn After / warmed turn
Inventory count 39 0 3 0
Projected lifecycle snapshot writes 33 0 3 0
Broader projected transaction stack (overlaps direct sites) 319 0 25 0
Native-patch snapshots (excluded debt) 32 32 0 0
Warmed turn Before main After main
1 392 333
2 437 331
3 338 352
4 338 358
5 338 324
6 340 326
7 336 324
8 338 324
9 336 326
10 338 326

Every warmed turn had 3 → 0 inventory statements and 3 → 0 projected snapshot statements.

Phase Main inventory before → after Main projected snapshots before → after Main broader projected stack before → after
Boot 0 → 0 0 → 0 0 → 0
Connect 0 → 0 0 → 0 0 → 0
First turn 3 → 0 0 → 0 22 → 0
Ten warmed turns 30 → 0 30 → 0 250 → 0
Second session + child 6 → 0 3 → 0 47 → 0
Control plane 0 → 0 0 → 0 0 → 0
Cron 0 → 0 0 → 0 0 → 0
Compaction 0 → 0 0 → 0 0 → 0
Shutdown 0 → 0 0 → 0 0 → 0

Raw after Gateway-main stacks contain zero readSessionEntryCount, commitProjectedSessionEntryLifecycleMutationInDatabase, or commitProjectedLifecycleMutation records. Worker traces account for the same work: inventory execution is main 39 → 0 / worker 36 → 75; all snapshot writes are main 65 → 32 / worker 92 → 125. Every residual host snapshot statement belongs to the excluded native-patch path (2 first-turn, 7 second-session/child, 23 cron in both runs). No moved write disappears.

Counts are successful top-level SQLite statement executions, excluding prepare calls and failed executions; this is not a latency benchmark. Before excluded 4 main and 5 worker lock-contention attempts; after excluded 2 main boot and 2 worker shutdown attempts, with no prepare failures. Background recovery and authority work vary across phase windows: baseline warmed turns 1–2 and candidate turns 3–4 have extra overhead. Existing other-owner authority reads remain inside worker grants (over ten warmed turns: placement +40, shared-state admission +43, ownership +41), so the overall reduction is smaller than the eliminated projected-stack count. Overall phase deltas are observations and are not attributed entirely to this lane.

Verification and landing corrections

Reviewed landing head: 494871c186eaf8edfd1fa3c84fa97d3a224847fb, incorporating main 6aefbb11f30aabb872e7fc379e4b97af7217903c. All four integrations use merge commits. The second resolves actual conflicts with #164788, preserving joined database retirement and cache eviction plus the lane's revocation coverage. Main's internal reply-init cleanup (#164810) and account-authority error leaf/compatible async methods (#164630) remain intact. The third integration resolves an import-only conflict from #164779 in the shared worker-error registry, retaining both its dependency-free canonical-key migration error and this lane's lifecycle conflict error. Main's wrapper inventory includes its new leaf. The fourth integration incorporates the independently proven main chat-fixture repair described below; it merged without conflicts. The PR base is main.

Initial CI exposed a real FIFO defect: selecting worker execution also changed preparation scheduling, allowing a later writer to overtake an awaited upsert builder. d08f737c142945d5557ec1a6320f9ebc8181a74e retains the foreground FIFO reservation while the reentrant worker owns SQL. Worker-aware fixtures distinguish eviction from retirement, use real lineage validation for transaction failure, and observe integrity in the worker. The original warm FIFO regression failed before the correction.

cddc88d79d33ce31d7e3f3859cd654f5456bbc9c repairs a reclamation fixture prerequisite: worker seeding no longer retains a host handle. The fixture now drains seeded workers and opens its host handle before invalidating validation, preventing delete preparation from legitimately republishing proof ahead of the instrumented reclaimer. Held-validation, concurrency, live-authority, integrity, and exit assertions remain unchanged. Original reclamation/prepared-admission failures reproduced 5/5 on 8a7c6d9c and passed 5/5 on each pre-lane control; they were PR-caused, not inherited exceptions.

Proof Result Command wall time
Current 494871c combined chat directive, lifecycle worker, runtime build graph and get-reply imports 149 passed / four files 377.69s
adf8394 worker error serialization, history worker errors, lifecycle worker, runtime build graph and get-reply imports 119 passed / five files 233.21s
4157962 full handle-lifecycle and prepared-admission files, Node 24, --maxWorkers=1 39 passed 762.70s
4157962 runtime-process build graph and get-reply import closure 11 passed 23.10s
4157962 session-test typing, targeted type-aware lint, formatting, diff check Passed Scoped checks
Current 494871c full-delta P2 autoreview against incorporated main Scoped-clean; reviewed tree equals committed tree Completed
Integrated d07ce205 prepared-admission / lifecycle worker / full close, isolated Linux Node 24 21 / 6 / 5 passed 70 / 33 / 72s
Integrated reclamation, five runs per revision, --maxWorkers=1 Candidate 5/5; incorporated main 5/5, two cases each Candidate 41–59s; main 37–56s
Original lifecycle/reset/reply/maintenance proof 32 cases, six files passed 1060.41s
Original changed checks / core typing / changed-test typing Passed 3921.47 / 46.03 / 210.36s
Original registry/import/build closures 24 unique cases, eight files passed 652.51s

The worker boundary regression fails on the original implementation with 11 caller-thread inventory/snapshot statements and passes after cutover with zero. It covers maintenance, archives, replacement snapshots, conflict identity, transaction/commit vetoes, preservation revocation, and lost-reply reconciliation without replay. The real close regression uses the existing Gateway fixture and proves accepted persistence settles before teardown. Worker tests need the real transaction/admission/acknowledgment protocol; helper tests cannot prove SQL placement or unknown-outcome settlement. Original final worker-file wall time was 522.68s (Vitest 431.61s, mostly transforms), and the selected close-case command was 589.72s (case 182.694s) on the loaded host. Hosted per-test CI seconds are not separately measured. No sleeps, retries, assertion weakening, or new Gateway boots were added. This lane adds zero OPENCLAW_* names.

Released SDK contract

The lifecycle API's callable shape, mutation inputs/results, conflict class, and legacy re-export remain compatible with v2026.9.8; no lane compatibility shim is needed. Main's removed commitReplySessionInitialization archive options are internal: absent from named SDK exports, api.runtime, and documented subpaths. Its appearance in generated whole-module declaration closure is not a released callable contract. Main retains all seven synchronous account-service methods alongside async siblings, with its registered compatibility record and public-route type tests.

The completed local report binds both head and workflow to 494871c186eaf8edfd1fa3c84fa97d3a224847fb, against latest stable v2026.9.8 (fc23bc864e4553c2d215e479eeec47b67a0bf943). Digest: 7afc05dd315c010ecd872993d3172d37a39bd36f6621101cd95d5f530d1fc49e. It contains one added/eight removed entrypoints and 78 signature, 1,192 reachable, 61 added, and 1,007 removed export records, including the cumulative changes on main since that release. The command exited 0 in 507.37s on Node 24; temporary checkouts were removed normally. Compared with the prior adf8394 report, direct public declarations are unchanged and 127 modeled closure hashes changed, including main #164853's internal worker-cleanup declaration. Earlier reports retain their historical head identity.

CI and investigated failures

Previous integration CI run 37192109300 completed successfully on 415796221e007174b10cc521ebb8a94b51457f90. This is prior-head proof. The current SDK report is complete. Current CI is qualified below as failed on an independently reproduced main fixture defect; it is not reported as green.

Current-head CI: 37196528783, attempt 1, tested merge 8d9fc693d02afd644d4dff54de15f68ffe674510 with main parent 715c18120e19eb23fb5ba54e97fac55efaf5fe3a and PR head 494871c. It finished with 70 successful jobs, 22 skipped, 18 collateral cancellations, one root failure and the downstream aggregate gate failure. Cancelled coverage remains unrun.

The sole root, job 111419665174, failed all 18 run.harness-auth-failover.test.ts cases with Agent admission requires its host owner. All five exact-head and five untouched-main 6aefbb11 full-file controls reproduced the same cases at that guard, before the real workspace consumer. Candidate walls: 141.16/118.75/123.56/107.83/181.36s; main walls: 210.28/132.88/91.19/145.95/110.97s. The causal test, reader, admission and project-configuration inputs are byte-identical across the main control, actual CI baseline, and tested merge.

Main #164779 added the real preflight worker read, while this fixture remained in the Unix threaded Vitest project. The existing host-owner guard correctly rejects that context before workspace consumption or this lane's host-only lifecycle worker path. The repair is one registry entry assigning the fixture to the existing forked infra owner. On main 73407386, it passes all 18 unchanged assertions in 357.57s, plus 137 existing planner/configuration tests in 279.10s, formatting and P2 review. The unchanged PR source also passes all 18 cases with explicit --pool forks in 207.44s; that diagnostic confirms the host-mode requirement without relabeling the original CI as passing. The routing repair was published directly on main after landing as ec583a242659c2a972f25d7a93520cc6f06098c0. GitHub verifies exactly one added registry line. Two Git pushes lost races to advancing main; the final atomic update used the unchanged file SHA as its precondition and preserved the exact reviewed content.

Landed as 80725e3b4f4cd37dd2fae89f8fb58e71f965b98d through the operator's explicitly approved native pre-existing-failure exception. The native landing-parent audit matched 58bcc015a37d82400359a63f2973dbb2f4c00ce4. The retained evidence binds the exact head, run/attempt, tested merge, source blobs, ten control receipts and actual passing scoped checks. Successful monitor 111419664530, step 4, caused all 18 cancellations; inspection found no hidden failed step. Aggregate 111420626895 names the sole root. Security, required reviews and live authority remain native admission gates. This exception applies only to the independently reproduced harness-admission failure and its proven collateral cancellations.

CI 37194167638, at adf8394, failed 13 cases in chat.directive-tags.test.ts and cancelled 58 sibling jobs; cancelled coverage is not counted as passing. The fixture and finalizers are byte-identical between the candidate and incorporated main. All five candidate and all five plain-main full-file controls reproduced the exact same 13 failures, with the other 119 cases passing. Candidate walls were 364.77/177.99/229.67/167.44/207.81s; main walls were 487.83/202.35/168.26/205.34/124.33s.

Main #164779 moved reply finalization to a worker reader while this fixture mocked only the previous reader. The new reader bypassed its synthetic session/key/store selection and resolved another fixture-local store, so final transcript/media outputs were absent. Main repair 6aefbb11f30aabb872e7fc379e4b97af7217903c routes both readers through the same fixture owner, preserving captured-source facts, activity checks, and every assertion. Its full file passed 132/132 in 427.97s; Gateway-method types, lint, formatting, and P2 review passed. This is a test-only main repair, now incorporated here. The combined branch passed all 149 relevant tests, including those 132 cases and the lifecycle worker. No CI rerun was used to claim the fixture repaired.

Prior-head CI run 37188279290, at d07ce205, had three failures investigated without source or deadline changes:

  • SDK transcript runtime: AgentDatabaseRegistryChangedError during two concurrent appends to a missing custom store. The test and target/lock/registry owners match incorporated main; lifecycle projection is not called. Five candidate and five main full-file runs passed all 12 cases. A cold-registration witness race remains a hypothesis. The single authorized job rerun passed on unchanged d07ce205; this is replay evidence, not a root-cause fix.
  • Mocked UI: the 390px dark question/composer case exceeded 120s. The browser stayed connected and the page open, but renderer diagnostics could not evaluate. App imports do not reach this lane. Five candidate and five main full-file runs passed all 19 cases, with the original case around 1.08s. Zero-case Chromium startup failures from a long temporary socket path were excluded; shortening the proof directory repaired only that prerequisite. The single authorized job rerun passed on unchanged d07ce205. The blocked renderer operation remains unknown.
  • Windows managed child: the Crabbox wrapper fixture exceeded its 10s completion deadline after all four synthetic child calls reached successful writes within 1.7s. The loaded wrapper graph reaches session modules through diagnostics, but this flow does not call lifecycle mutation. The evidence cannot distinguish child exit, Windows Job settlement, wrapper finalization, or pipe drainage. Five candidate and five incorporated-main native Windows full-file controls passed all 41 applicable cases each, with five source-declared POSIX skips per run. The original case took 1,895–2,026ms on the candidate and 1,955–2,066ms on main. All ten runs used pinned Node 24.21.0, pnpm 12.5.1, Vitest 5.0.1, Windows x64, one worker, and unchanged sources/deadlines. First candidate / final main control. No historical Windows CI rerun was requested after 4157962 CI passed. The non-group test runner retained its temporary namespace where descendant completion could not be attested; ephemeral Actions job teardown owns cleanup. Both failed direct-provider Windows allocations were confirmed fully released before closeout.

These failures are retained as unattributed where not reproduced. Recent main passed the same UI and Windows cases; that does not establish an inherited failure. Those older unreproduced failures are excluded from the current inherited-failure exception.

Two historical local failures also remain explicit. The original full close file timed out in its unchanged first case, then cascaded through a retained startup spy. Five original-head and five plain-main full-file runs passed; main also preloads the reload module before the fixture deadline. The initial timeout remains unproven, and passing replays do not establish a fix. Separately, a loaded Node 26 local reclamation run hit a 10s WebSocket response deadline after 423.65s Gateway startup; its sibling passed. That owned command was stopped after 1054.84s while the next file loaded. All interrupted contract coverage subsequently passed on isolated Linux, including five exact-candidate/five-main reclamation runs. The RPC timeout remains unreproduced, not attributed to load or the added ACP metadata boundary.

The independently inherited native Node duration-format import defect was fixed directly on main as 3c0f7e4c5cdade301b896970c9afbf4ab253de5e: the import failed 5/5 before and passed 5/5 after, with 23 formatter regressions, lint, and P2 review passing. The longer declaration fixture cleared that failure and consumer typing but later hit its existing cumulative 120s deadline; it is not reported as wholly passing. That main fix is incorporated here.

ClawSweeper completed its latest exact-head 494871c review at 2026-10-04 11:27:10 UTC (review), finding no introduced correctness or security defect. The latest review marks the PR ready for maintainer review with no before-merge items; the completed SDK report satisfies its prior evidence request.

The incoming #164779 sync-to-async helpers remain internal rather than released SDK/runtime exports, and its canonical-key error preserves its re-export and round-trip identity. Incoming #164694 retains its synchronous TTS functions with its registered compatibility record/type tests. The fresh report includes main #164853's conservative reachable-declaration change.

Refresh freshness at read admission and after BEGIN while reusing
handle-owned facts for runtime schema checks. Validate canonical
triggers before exposing agent readers and classify shared-state
failures only after failed admission.

Focused runtime checks execute zero SQL statements, versus 30 with
the baseline owner. Preserve foreign-commit and snapshot semantics.
Full workload measurement and remote integration checks remain merge
preconditions after remote runner and fleet-capacity admission failed.
Integrate the pinned measurement baseline and retain main-key facts through the existing connection and reader-admission owners. Preserve raw writes, foreign commits, transaction snapshots, authorizers, and continuation authority.
Use the existing worker generation claim for maintenance metadata instead of
retaining a host read handle. Keep both live ownership checks around the
required transaction-entry freshness probe.

Consolidate shared-state cache initialization, refresh, and terminal failures
in its admission sibling and update the compiled-wrapper inventory. This
keeps the cache within the existing module-size limit without changing stored
schema or quarantine semantics.

Focused maintenance, ownership, schema, worker, wrapper, and quarantine proof
passed. Independent Codex review is clean through P2. Full landing validation
remains required before merge.
Refresh canonical readiness when it consumes schema facts. Retention only
holds native lifetime, so cold restore and other worker handoffs no longer
execute host SQLite before dispatch.

Protect foreign schema invalidation at the warm readiness fast path. Tighten
retained-reader budgets to the optimized counts, and require early missing-table
diagnosis before callbacks while preserving handle-cleanup assertions.

Validation: 93 focused tests, production types, state/config test types, and
independent review clean through P2.
Integrate the released-SDK diff tooling fix and the inherited child-coordination fixture correction. The merge preserves every authored source, test, and documentation blob; the wrapper inventory combines both branches.
Include main's failed-placement publication fix after the paired-node lifecycle CI failure. Authored schemafacts source, tests, and documentation remain byte-identical to the reviewed head; the wrapper inventory includes current main dependencies.
Preserve maintenance publication and accepted settlement across Gateway close. Reuse the existing agent executor and native receipt recovery without replaying lifecycle mutations.
@clawsweeper

clawsweeper Bot commented Oct 4, 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 gateway Gateway runtime scripts Repository scripts size: XL labels Oct 4, 2026
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. labels Oct 4, 2026
@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 7:27 AM ET / 11:27 UTC (Revision 10).

ClawSweeper review

What this changes

Moves durable session inventory counts and snapshot writes into the existing database worker while preserving ordered preparation, live commit checks, and acknowledged state publication.

Merge readiness

✅ Ready for maintainer review

This remains useful work: current main still excludes lifecycle upserts from worker execution. No actionable introduced defect remains, and the completed current-head SDK report satisfies the previous review request.

Priority: P2
Reviewed head: 494871c186eaf8edfd1fa3c84fa97d3a224847fb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused worker cutover with strong production-path evidence, resolved prior feedback, and no remaining actionable patch finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The real Gateway workload exercises lifecycle inventory and snapshot persistence through the production worker, showing zero direct caller-thread statements after the cutover. Real worker-boundary and Gateway-close evidence covers revocation, rollback, lost replies, and accepted-write settlement; current-head supplemental coverage and the completed SDK comparison are recorded separately. The shared storage kernel, schemas, and serialized contracts remain unchanged.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The real Gateway workload exercises lifecycle inventory and snapshot persistence through the production worker, showing zero direct caller-thread statements after the cutover. Real worker-boundary and Gateway-close evidence covers revocation, rollback, lost replies, and accepted-write settlement; current-head supplemental coverage and the completed SDK comparison are recorded separately. The shared storage kernel, schemas, and serialized contracts remain unchanged.
Evidence reviewed 8 items Pinned introduction reviewed: Reviewed the complete introduced patch against incorporated main, including production, documentation, and test changes. The checkout matches the original PR head; the supplied test merge is stale relative to the pinned base and was not used to infer removal of current-main behavior.
Still necessary on current main: Fetched main still requires upserts.length === 0 before selecting worker execution. The merged schema-facts prerequisite and adjacent entry-read and patch work do not implement this lifecycle-upsert cutover.
Shared transaction and authority owners: The worker calls the existing lifecycle transaction kernel, checks durable subagent facts around the mutation, and transfers its exact publication candidate through the existing receipt protocol. The host adapter supplies current execution, source, commit, and maintenance-preservation checks to transaction and commit admission.
Findings None None.
Security None None.

How this fits together

Session lifecycle persistence records session creation, replacement, reset, and maintenance results. Reply initialization and maintenance feed this owner, which commits SQLite state and publishes changes to Gateway session consumers.

flowchart TD
 A[Reply initialization and maintenance] --> B[Ordered lifecycle preparation]
 B --> C[Current authority checks]
 C --> D[Existing database worker]
 D --> E[Session transaction and maintenance]
 E --> F[Confirmed commit receipt]
 F --> G[Session and reset publication]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +234, Tests +356, Docs +12. Total +602 across 25 files.

View PR surface stats
Area Files Added Removed Net
Source 15 265 31 +234
Tests 9 419 63 +356
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 25 696 94 +602

Review metrics

Metric Value Why it matters
Production versus test growth production net +234; tests net +356 Production growth implements the existing worker handoff and publication contract; tests cover SQL placement, revocation, FIFO ordering, and shutdown settlement.
Measured caller-thread SQL 6 → 0 direct statements per warmed turn The paired production-path workload demonstrates the intended inventory and snapshot cutover without claiming a latency improvement.

Technical review

Best possible solution:

Complete the lifecycle worker cutover through the existing persistence owner, retaining native callback exceptions, FIFO ordering, live authority checks, and receipt-based settlement.

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

Not applicable as a bug reproduction: source confirms the remaining caller-thread lifecycle path, and the recorded paired Gateway workload measures its SQL placement.

Is this the best way to solve the issue?

Yes. Reusing the existing worker, synchronous transaction kernel, and publication protocol is a focused solution, and the prior FIFO correction preserves preparation ordering.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded session-persistence performance improvement with no intentional user-facing contract change.
  • 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. Sufficient (live_output): The real Gateway workload exercises lifecycle inventory and snapshot persistence through the production worker, showing zero direct caller-thread statements after the cutover. Real worker-boundary and Gateway-close evidence covers revocation, rollback, lost replies, and accepted-write settlement; current-head supplemental coverage and the completed SDK comparison are recorded separately. The shared storage kernel, schemas, and serialized contracts remain unchanged.
  • proof: sufficient: Contributor real behavior proof is sufficient. The real Gateway workload exercises lifecycle inventory and snapshot persistence through the production worker, showing zero direct caller-thread statements after the cutover. Real worker-boundary and Gateway-close evidence covers revocation, rollback, lost replies, and accepted-write settlement; current-head supplemental coverage and the completed SDK comparison are recorded separately. The shared storage kernel, schemas, and serialized contracts remain unchanged.

Evidence

What I checked:

  • Pinned introduction reviewed: Reviewed the complete introduced patch against incorporated main, including production, documentation, and test changes. The checkout matches the original PR head; the supplied test merge is stale relative to the pinned base and was not used to infer removal of current-main behavior. (494871c186ea)
  • Still necessary on current main: Fetched main still requires upserts.length === 0 before selecting worker execution. The merged schema-facts prerequisite and adjacent entry-read and patch work do not implement this lifecycle-upsert cutover. (src/config/sessions/session-accessor.sqlite-projection.ts:100, e318434756f9)
  • Shared transaction and authority owners: The worker calls the existing lifecycle transaction kernel, checks durable subagent facts around the mutation, and transfers its exact publication candidate through the existing receipt protocol. The host adapter supplies current execution, source, commit, and maintenance-preservation checks to transaction and commit admission. (src/config/sessions/session-lifecycle-projection.worker.ts:16, 494871c186ea)
  • Prior FIFO finding resolved: Upsert preparation retains foreground FIFO reservation while the reentrant worker executes SQL. The existing prepared-admission test retains the awaited-builder ordering assertion; the PR records the original failing control and correction d08f737. (src/config/sessions/session-accessor.sqlite-projection.ts:312, 494871c186ea)
  • Real production-path proof: The captured body records paired Node 24 Gateway workloads with isolated synthetic state and a loopback provider: all 13 chats, child execution, cron, compaction, and graceful shutdown completed. Direct inventory and projected-snapshot statements fell from six to zero per warmed turn. Real worker-boundary coverage additionally exercises transaction and commit revocation, preservation changes, stale-row refusal, lost-reply reconciliation without replay, and accepted persistence through Gateway close. Measurements retain their original source identities rather than being restamped as current-head measurements. (src/config/sessions/session-lifecycle-projection.worker.test.ts:178, 494871c186ea)
  • Completed SDK request and complete body coverage: Read the omitted body remainder through GitHub and verified SHA-256 b01e24447490c5629c32ed0d29986162c5e3fd9161dd5b725d0aab84090e342a, matching the captured snapshot. It records the completed comparison for exact head 494871c against v2026.9.8, exit zero in 507.37 seconds, report digest 7afc05dd315c010ecd872993d3172d37a39bd36f6621101cd95d5f530d1fc49e. Cumulative main changes are distinguished from this lane, whose callable lifecycle shapes and conflict-class re-export remain compatible. (src/config/sessions/session-accessor.lifecycle-types.ts:162, 494871c186ea)

Likely related people:

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

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-04T04:22:52.114Z sha 8a7c6d9 :: blocked before merge. :: none
  • reviewed 2026-10-04T07:34:31.688Z sha 8a7c6d9 :: blocked before merge. :: [P2] Preserve FIFO admission while preparing lifecycle upserts
  • reviewed 2026-10-04T08:22:39.056Z sha d07ce20 :: blocked before merge. :: none
  • reviewed 2026-10-04T08:49:15.046Z sha d07ce20 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-04T09:18:16.226Z sha d07ce20 :: blocked before merge. :: none
  • reviewed 2026-10-04T09:35:26.425Z sha 4157962 :: needs changes before merge. :: none
  • reviewed 2026-10-04T10:11:20.941Z sha adf8394 :: needs changes before merge. :: none
  • reviewed 2026-10-04T10:53:57.110Z sha 494871c :: needs changes before merge. :: none

Retain the existing writer FIFO while preparing lifecycle upserts and awaiting
entry builders. The reentrant worker still owns inventory, snapshot, and
maintenance SQL; later writers cannot overtake the builder.

Update boundary fixtures to distinguish host-cache eviction from database
retirement, observe integrity checks in their worker owner, and inject rollback
through real lineage validation instead of a connection-local temporary trigger.
Keep real exports in maintenance mocks.

The original FIFO regression reproduced before this correction. Focused proof
now covers 59 passing tests across five files using --maxWorkers=1; the final
21-case prepared-admission run took 727.66 seconds on the loaded host. Core,
config-test, and Gateway-test typing plus targeted type-aware lint pass. Fresh
independent P2 review has no actionable findings. Hosted proof remains pending.
Lifecycle seeding now warms workers instead of a host handle. Drain the
seeded workers and explicitly retain the host handle before invalidating
integrity proof, so deletion preparation cannot reopen it and republish
proof before the cold reclaimer reaches its held native check.

Keep the held-validation, unrelated-patch, authority-revocation, integrity,
and worker-exit assertions unchanged. The original file failed 5/5 on the
PR and passed 5/5 on both its pre-lane baseline and merge base. This fixture
correction passes both cases in 5/5 isolated Linux runs (59/40/40/40/41s).
Gateway test typing, type-aware lint, formatting, and fresh P2 review pass.
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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. and removed 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. labels Oct 4, 2026
Merge main d2a9f9a after the
schema-facts prerequisite #164490 landed. Retain main's archive-runtime
cleanup and incorporate the native duration-import and preview fixes.
No conflicts or new lane signature changes were introduced.

The complete integrated delta has a clean P2 review. Eleven import/runtime
build-graph tests and the staged mock-export ratchet pass. Local Gateway
proof recorded a WebSocket response timeout in reclamation concurrency
under heavy startup load; its authority-revocation sibling passed. The
remaining local run was interrupted and is not passing coverage. Exact
candidate/main attribution, fresh released-SDK diff, and final CI follow.
@openclaw-barnacle openclaw-barnacle Bot removed scripts Repository scripts size: XL labels Oct 4, 2026
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current head: d07ce20. The schema-facts prerequisite is merged and integrated, and the FIFO and worker-fixture corrections are pushed. The PR body records completed proof and the remaining integrated-head SDK, timeout-attribution, and CI work.

@clawsweeper

clawsweeper Bot commented Oct 4, 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Oct 4, 2026
Merge main bced158 after its
shutdown-owner changes caused two test conflicts. Preserve main's awaited
cold cleanup and cache eviction, retain lifecycle retirement refusal,
and join retirement before reopening the fixture for readback.

Keep main's internal reply-init option cleanup and account-authority leaf
error registration. Existing released account methods remain compatible.

All 39 conflict-focused tests pass (762.70s on the loaded local host), as
do 11 runtime-process/import tests (23.10s), session-test typing, targeted
type-aware lint, formatting, and fresh P2 review. A fresh released-SDK
report and current-head CI remain required after this integration.
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Current head: 4157962. Main's database-shutdown changes are integrated with both fixture conflicts resolved. All 39 affected storage tests and 11 shared-registry/import checks pass, with fresh P2 review, typing, and lint. The PR body distinguishes prior-head CI attribution from the current-head SDK report and CI now running.

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

Merge current main without rebasing. Preserve both canonical-key migration and lifecycle-upsert conflict error identities at the shared registry boundary.

Validation: 119 focused tests across five files passed; formatting, diff check, and full-delta P2 review passed.
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

steipete added a commit that referenced this pull request Oct 4, 2026
Reply finalization moved to worker-backed session reads in #164779, while this fixture still mocked only the earlier reader. Route both readers through the existing synthetic session-selection owner, preserving current-activity checks and every transcript and media assertion.

Found during #164755 validation and independently reproduced on main. Validation: all 132 full-file cases, Gateway-method types, lint, formatting, and P2 review pass.
Merge main after repairing its worker-reader chat fixture in 6aefbb1. Preserve the lifecycle worker cutover and current maintenance, cleanup, and SDK owners.

Validation: all 149 combined chat, lifecycle-worker, import-closure and runtime-build tests passed; full-delta P2 review is clean.
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete
steipete merged commit 80725e3 into main Oct 4, 2026
160 of 181 checks passed
@steipete
steipete deleted the dbasync/lifemaint branch October 4, 2026 11:34
@steipete

steipete commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

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

steipete added a commit that referenced this pull request Oct 4, 2026
The real harness admission reader requires the host-owned SQLite execution path. Register this fixture in the existing forked core project so its authentication and workspace assertions execute instead of failing in a thread without a host owner.

The failure reproduced in all five main and five PR controls for #164755. The unchanged cases pass 18/18 with the correct host mode; 137 existing planner checks and P2 review also pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
Reply finalization moved to worker-backed session reads in openclaw#164779, while this fixture still mocked only the earlier reader. Route both readers through the existing synthetic session-selection owner, preserving current-activity checks and every transcript and media assertion.

Found during openclaw#164755 validation and independently reproduced on main. Validation: all 132 full-file cases, Gateway-method types, lint, formatting, and P2 review pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
…he lifecycle writer (openclaw#164755)

* perf(state): carry admitted schema facts with database handles

Refresh freshness at read admission and after BEGIN while reusing
handle-owned facts for runtime schema checks. Validate canonical
triggers before exposing agent readers and classify shared-state
failures only after failed admission.

Focused runtime checks execute zero SQL statements, versus 30 with
the baseline owner. Preserve foreign-commit and snapshot semantics.
Full workload measurement and remote integration checks remain merge
preconditions after remote runner and fleet-capacity admission failed.

* fix(state): preserve worker handoffs during schema admission

Use the existing worker generation claim for maintenance metadata instead of
retaining a host read handle. Keep both live ownership checks around the
required transaction-entry freshness probe.

Consolidate shared-state cache initialization, refresh, and terminal failures
in its admission sibling and update the compiled-wrapper inventory. This
keeps the cache within the existing module-size limit without changing stored
schema or quarantine semantics.

Focused maintenance, ownership, schema, worker, wrapper, and quarantine proof
passed. Independent Codex review is clean through P2. Full landing validation
remains required before merge.

* fix(state): keep retained handles free of schema probes

Refresh canonical readiness when it consumes schema facts. Retention only
holds native lifetime, so cold restore and other worker handoffs no longer
execute host SQLite before dispatch.

Protect foreign schema invalidation at the warm readiness fast path. Tighten
retained-reader budgets to the optimized counts, and require early missing-table
diagnosis before callbacks while preserving handle-cleanup assertions.

Validation: 93 focused tests, production types, state/config test types, and
independent review clean through P2.

* perf(sessions): run lifecycle inventory and snapshots through the writer

Preserve maintenance publication and accepted settlement across Gateway close. Reuse the existing agent executor and native receipt recovery without replaying lifecycle mutations.

* fix(sessions): preserve lifecycle builder admission ordering

Retain the existing writer FIFO while preparing lifecycle upserts and awaiting
entry builders. The reentrant worker still owns inventory, snapshot, and
maintenance SQL; later writers cannot overtake the builder.

Update boundary fixtures to distinguish host-cache eviction from database
retirement, observe integrity checks in their worker owner, and inject rollback
through real lineage validation instead of a connection-local temporary trigger.
Keep real exports in maintenance mocks.

The original FIFO regression reproduced before this correction. Focused proof
now covers 59 passing tests across five files using --maxWorkers=1; the final
21-case prepared-admission run took 727.66 seconds on the loaded host. Core,
config-test, and Gateway-test typing plus targeted type-aware lint pass. Fresh
independent P2 review has no actionable findings. Hosted proof remains pending.

* test(gateway): retain the host handle for reclamation validation

Lifecycle seeding now warms workers instead of a host handle. Drain the
seeded workers and explicitly retain the host handle before invalidating
integrity proof, so deletion preparation cannot reopen it and republish
proof before the cold reclaimer reaches its held native check.

Keep the held-validation, unrelated-patch, authority-revocation, integrity,
and worker-exit assertions unchanged. The original file failed 5/5 on the
PR and passed 5/5 on both its pre-lane baseline and merge base. This fixture
correction passes both cases in 5/5 isolated Linux runs (59/40/40/40/41s).
Gateway test typing, type-aware lint, formatting, and fresh P2 review pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 5, 2026
The real harness admission reader requires the host-owned SQLite execution path. Register this fixture in the existing forked core project so its authentication and workspace assertions execute instead of failing in a thread without a host owner.

The failure reproduced in all five main and five PR controls for openclaw#164755. The unchanged cases pass 18/18 with the correct host mode; 137 existing planner checks and P2 review also pass.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. 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