Repository navigation
refactor(sessions): move async durable transcript reads off the Gateway thread - #163605
Conversation
…ay thread Reuse the existing history hydration stream with captured physical store identity, read fences, typed errors, and cold-restoration custody. Keep incognito and the released synchronous SDK reader with their native owners.
|
🦞👀 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. Reviewed October 2, 2026, 9:00 PM ET / October 3, 2026, 01:00 UTC (Revision 12). ClawSweeper reviewWhat this changesMoves awaited durable session transcript reads into the existing history worker, preserves synchronous and incognito readers, and synchronizes affected test fixtures. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still performs awaited transcript reads through synchronous SQLite. No introduced correctness or security defect was found; failed CI remains subject to the native landing gates. Priority: P2 Review scores
Verification
How this fits togetherSession transcript storage supplies conversation history to compaction, reset hooks, exports, and side questions. The changed accessor sends durable reads through a worker and returns ordered events to those consumers. flowchart TD
A[Transcript consumers] --> B[Session read accessor]
B --> C{Durable or incognito}
C -->|Durable| D[History worker]
C -->|Incognito| E[Process-held reader]
D --> F[SQLite snapshot and cold restoration]
F --> G[Validated ordered events]
E --> G
G --> A
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +163, Tests +210, Docs +9, Other +1. Total +383 across 22 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing history worker for durable awaited reads while preserving canonical transcript bytes, read fences, cold restoration, and the released synchronous contract. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that current main's awaited loader directly invokes synchronous SQLite reads on its caller thread; no runtime reproduction was executed in this read-only review. Is this the best way to solve the issue? Yes, reusing the existing hydration worker removes the async host-reader path while retaining the established storage and SDK contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3b3d1b09dedd. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (11 earlier review cycles; latest 8 shown)
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…ay thread (openclaw#163605) * refactor(sessions): move async durable transcript reads off the Gateway thread Reuse the existing history hydration stream with captured physical store identity, read fences, typed errors, and cold-restoration custody. Keep incognito and the released synchronous SDK reader with their native owners. * fix(tooling): include transcript budget error in PR wrapper * fix(sessions): preserve transcript read scope across worker boundaries * test(sessions): await shared-store preview settlement * test(sessions): await archive-phase writer settlement * test(sessions): avoid draining resources inside handle-loss callbacks * test(sessions): synchronize native fixture writes and cache probes
What Problem This Solves
Awaiting
loadTranscriptEventsstill ran native SQLite reads on the Gateway thread during compaction preflight, reset hooks, BTW context preparation, and other async transcript consumers.Solution
Route durable event loads through the existing history worker's full-transcript hydration reader and bounded frame transfer. Capture the physical store before target discovery yields, retain its read custody through cold restoration and cleanup, and reject changed sources before returning events. Preserve raw ordering, branch/leaf records, read fences, byte limits, and typed budget/parse errors. All existing awaited callers follow the same accessor export; the old async host-reader implementation is removed.
Only declared read-scope fields cross the worker boundary, so wider caller objects cannot leak callbacks into structured cloning. Unqualified session keys retain store-owner discovery, and an absent member of a captured store family returns an empty read. The trusted PR wrapper inventory includes the budget-error module introduced by the worker error transport.
BTW rechecks cancellation after context preparation. An adjacent unreachable auth-profile comparison was simplified without changing profile selection.
Impact
No schema, stored-byte, retention, configuration, or update changes. Incognito retains its process-held owner. Missing sessions and missing stores return empty events; durable reads do not create an absent store. There is no fallback to host SQLite after a worker failure.
Released SDK surface check:
v2026.9.7already exposesreadSessionTranscriptEvents(...): Promise<SessionTranscriptEvent[]>; its signature stays compatible. The releasedsession-store-runtimeexportloadTranscriptEventsSync(...): SessionStoreTranscriptEvent[]is unchanged. No new SDK adapter or export is introduced.This is the explicitly bounded async-loader cutover. Retained scans need later owner-level work and are not claimed as migrated:
src/config/sessions/session-accessor.sqlite-message-cut.ts:243.src/config/sessions/session-accessor.sqlite-parent-session.ts:163,311,478,506.src/config/sessions/session-accessor.sqlite-lifecycle.ts:164→src/config/sessions/session-accessor.sqlite-reset-boundary.ts:30.src/hooks/bundled/session-memory/capture.ts:109.src/infra/session-cost-usage-collection.ts:389, and the released synchronous SDK remain outside this lane.The recent-PR overlap check found no active competing production-function owner for this cutover. The history-reader factory itself is reused without modification.
Evidence
Original measurement and review base:
7555e3f88132bc5915e42141d9a09aa435ed7c2a.Production LOC: +192 / −29 / net +163 across 8 production files. Static inventory T1 1,518 → 1,518: shared native kernels remain mixed-use, so no whole-file reclassification is claimed. The new boundary regression fails on the original implementation with 3,437 caller-thread SQL observations and passes after the cutover with 0, including cold target discovery and missing reads. Real cold-archive restoration also records 0 caller-thread SQL.
All focused commands used
--maxWorkers=1; measured wall times:session-transcript-events.worker.test.tssession-transcript-runtime.read-fence.test.tssession-cold-storage.test.ts -t 'restores on async read'btw.test.tscommands-core.test.ts -t 'before_reset'The new boundary file spends about 2.8 s in tests; compilation/setup account for most wall time. The existing cold-storage test performs real archive creation and restoration to prove that transaction/lifecycle boundary. The existing BTW suite spent under 1 s in tests; its cold compiled-worker preparation dominates the run. CI seconds are not yet available at PR creation.
pnpm check:madge-import-cycles: 0 cycles.pnpm check:database-worker-ratchet --base <pinned-base>: passed.git diff --check: passed.node scripts/check-changed.mjs --base <pinned-base> --timed: conflict and line-cap guards pass; execution stops at the inherited env-name budget failure. The max-lines suppression check itself passes. All 30 remaining commands from the canonical plan ran separately and passed, including production types, all 27 affected test type graphs, formatting, lint, dead exports, and storage/import/auth boundary guards. No guard or budget was modified.Main was integrated with merge commit
51da93ca642292fadbe3cca6309c67868a9b37f3(main parent87af5763bbc0bd1febc08d78eedc7fafd9eb5225), including the owner-approved environment-budget repair1f14ba2cbe2f6. The integrated max-lines and environment-name gate passes at 477/477. This PR adds 0 new OPENCLAW_ names* and does not change the budget.Landing validation found and repaired the omitted wrapper dependency, callback-bearing worker inputs, early rejection of unqualified session keys, and missing sibling-store reads. Existing fixtures now await database teardown before reopening; the host-SQL positive control uses the synchronous reader, and maintenance-race seeding does not schedule unrelated automatic maintenance. Assertions and authority fences remain intact.
The wrapper source-closure cases pass (3 tests, 18.11 s wall time), and its eager-import inventory check passes (1 selected test, 40.91 s). The complete Gateway-method group passes 44 tests in 675.05 s. A focused command through
node scripts/run-vitest.mjs <9 files> --maxWorkers=1 -t <failing-contract selectors>passes 30 tests in 1,049.56 s wall time, including real canonical descendant forks, all reset-authorization cases, storage ownership, typed errors, missing stores, byte bounds, and zero caller SQL. Setup and source transformation dominate this loaded host. The fresh repair autoreview is clean through P2; the final type-only capture annotation correction emits identical JavaScript. Production types, affected test graphs (agents-sessions: 15.1 s;gateway-methods: 16.9 s), and focused lint pass. SDK signatures were independently compared withv2026.9.7during landing and remain compatible.Independently reproduced inherited CI failures on scheduled main run 37027847475, head
1f14ba2cbe2f6:110907288313).110907288657).These seven exact cases also fail in PR run
37030006935. Their causal source files are untouched by this PR and match between independently failing main and that run's main parent. Any final inherited-failure admin admission remains bound to the repaired head and its actual completed CI attempt; this historical evidence is not a claim that current-head CI is green.The same main integration includes fixes for the inherited cron fixture failures (
3c765df3cea998caf69634b4eff8a3574428b3db) and archive-lifecycle projection fixtures (180d8bbecb04f78a8c59ff5cfc917ad98d345e2e). The older failure evidence above is historical, not a current-head CI exception.The combined-store preview assertion was independently diagnosed as a pre-existing fixture settlement race. Its enrichment path uses
projectionLane→readRowBackfill, notloadTranscriptEvents. Temporary probes showed the one-second polling assertion expiring before the global preview read began; the preceding row then reported revoked custody after fixture disposal, after its worker reply had already arrived. The fixed fixture holds foreground work until the existing accepted-publication observer is registered, releases it, and awaits publication before preserving all title, preview, and logical/physical ownership assertions. No sleeps, timeout increases, production seam, or production reader change was added. All temporary logging was removed.The standalone fixture proof on
166bce9aplus the repair passes 26/26 tests with Node 24.19 andpnpm test src/config/sessions/combined-store-gateway.test.ts --maxWorkers=1: 1,156.37 s wall, largely cold compilation and transformation on the loaded host. The repaired preview case completes in 12.944 s. Its isolated Codex autoreview is clean through P2; focused formatting and lint pass. The two existing foreground-settlement sibling cases also pass (4 unrelated cases filtered), 536.68 s wall, and all wrappers joined successfully. Post-main validation on Node 24.21 passes 31/31 tests acrosscombined-store-gateway.test.tsandsession-transcript-events.worker.test.ts, 789.30 s wall, with--maxWorkers=1. Production types and the conflict, line-cap, environment, assertion-safety, SQLite-worker, timeout, dependency, formatting, and documentation gates pass; the canonical changed-check plan has passing evidence for all commands. The corrected fixture and final main integration received focused follow-up checks; no check was disabled.Five standalone and five exact 25-file CI-shard invocations were run per pinned head. The preview assertion failed as follows:
166bce9a87422fa2af2a44c451adb168106e3aa67555e3f88132bc5915e42141d9a09aa435ed7c2aThe different Node launchers and heavy host load limit quantitative comparisons; the identical call path and post-disposal trace establish the fixture race independently of these rates. The pre-fix campaigns also each hit one
session-accessor.reply-init-concurrency.test.tsworker deadline (PR shard 4, baseline shard 3). That separate failure was retained as observed; no longer timeout or retry was used to conceal it.A further cleanup fixture repair (
20b68ad7638fbc3f0878b265088490d602564fbc) removes its 500 ms writer race: it awaits the real write while the archive barrier remains held, then releases the archive. Test-finish cleanup releases that barrier and joins every started operation. The three existing archive/writer cases pass (152.90 s wall, 10 unrelated cases filtered), with affected test types, lint, and isolated P2 autoreview clean. This keeps the lock-release assertion independent of worker startup latency.Second main integration:
2ea2a397ce149e88e94a368bf37c82393d76aa4a, a merge commit with main parentff1c3955bdb0ac8972afd26a59a356705fde81ef. It includes the overlapping subagent-completion repair8af8744f74df1696b763b37381386f18f733a877and placement fixture synchronization inec62b500c9e6e. The final event-worker suite passes 5/5 tests, 235.48 s wall, and production types, formatting, core/script lint, import cycles, schema, storage, webhook, and auth guards pass.Historical CI run 37057673052, at
62f009a8, completed with 12 failing test jobs and the downstream CI gate. The archive-writer timing assertion is repaired above, and main supplies the browser/placement fixes. Independent main CI or one-pass pristine-main replays at87af5763bbc0bd1febc08d78eedc7fafd9eb5225reproduce the remaining observed fixture families: raw SQLite images captured before worker closure, corpus/sharing fixtures assuming a host database handle after worker writes, Doctor integrity receipt/teardown, shared-store reaping, model-catalog startup closure, trajectory mock identity getters, and placement/sharing/search observations. The sharing authorization rejection itself succeeds; its broad commit-stage spy assertion fails. Search's exact 120-second timeout reproduces, but its precise timed-out phase remains uninstrumented.The separate Doctor auth E2E maintenance-refusal cases reproduce on pristine main
87af5763bbc0bd1febc08d78eedc7fafd9eb5225on Linux: 2 failed / 1 passed, 747.65 s wall, Node 24.19.0, Testbox run 37065636879. Both report “Doctor could not enter maintenance. An agent database is in use.” The payload verified its source checkout and clean diff before execution; the lease is completed. macOS had refused artifact preparation before executing tests, so it supplies no E2E result. Current-head CI and any native inherited-failure admission will be bound to the final head and completed attempt; historical evidence is not current-head CI success.The next main advance caused one real conflict in
session-transcript-hydration.types.ts. Merge resolution preserves both transcript read and write scopes plus main's maintenance contracts; both versions emit empty JavaScript. The complete 20-file candidate against main1b4dbda4c95f14ca6cbd9739c42ca0551e59edb6received fresh isolated P2 autoreview: scoped-clean, no findings. Production types, the affected agents/sessions test type graph, focused lint, andgit diff --checkpass.CI run 37070175570, head
e4ea62676e273bd5f03a3866ce1ce49e9a9e0574, completed with 84 successful jobs, 20 skipped jobs, 10 failing test jobs, and the downstream failing CI gate; no cancelled jobs.security-fastpassed. The actual tested merge was27ef71744d8ef7feeba185bb1fd471a29b7dfd04, with main parent2d1011a9a4161ae3931acfe1dea25800e344e5eb. All failed job logs were collected once. The lifecycle fixture self-drain timeout is repaired below; remaining independent-main qualifications are tracked separately. This historical run is not current-head green proof, and it was not rerun. ClawSweeper completed this exact-head review at 2026-10-02 22:06:01 UTC with no findings.The lifecycle fixture now closes the captured cached host handle in its two handle-loss callbacks. Previously, a callback could hold writer admission while awaiting whole-owner closure; maintenance retirement then waited for work queued behind that same admission. The unchanged case passed alone, but a full-file pre-fix replay reproduced a 120-second test timeout plus 180-second teardown timeout in the async predicate case. After recording that failure, the owned stalled wrapper was interrupted and fully joined. The repair preserves closed-handle, appended-event, label, and post-operation teardown assertions. Full-file proof passes 17/17, 59.87 s wall, Node 24.21.0,
pnpm test src/config/sessions/session-accessor.sqlite-handle-lifecycle.test.ts --maxWorkers=1; affected test types, lint, formatting, and diff checks pass. Fresh isolated P2 review is scoped-clean. No production behavior or timeout changed.Merge commit
eacd84291309d5df7192b860e2231fc403fb91a5incorporates maindb24ac34b6ab0337ba37b8f57432ea601fbc621a, includinga97e007542efc(conversation-registry and public-sharing raw fixture writes) andaa906dbd5f8d2(forwarding the moved native model helper in the test mock). The merge was conflict-free; all 18 authored source/test files remain byte-identical to revieweda64841f5a8b38. Main additions in the documentation and wrapper inventory were inspected. The event-worker and handle-lifecycle files pass 22/22, 83.51 s wall, with affected test types and diff check passing. Prior raw-write and stale-mock failures are retired by those main fixes.Independent Doctor-preflight proof is now complete on pristine main
2d1011a9a4161ae3931acfe1dea25800e344e5eb, using a Linux AWS Crabbox runner and Node 24.19.0: 1 failed / 16 passed, 125.57 s wall. The exact case fails with the same retired Discordallowsetting refusal, before transcript loading. The source receiver verified the complete pinned tree and frozen installation; the payload verified its physical checkout, clean diff, and causal source hashes against the tested PR merge. The runner is released. Earlier local preparation and two Testbox admissions ran zero tests; those attempts supplied no proof and were not treated as passing. The Testbox expiry is recorded in run 37074155485. No guard or timeout was weakened.The final main-history check found the direct fixture repair
56a17f9c950321d89dedbae78e43892c65b59e82: shared-store retirement is now awaited before cold cron owner discovery. Merge commit5e1292728da80029401c152422f18387f1fdd62fincorporates main3059a884501aec497d4ffaa6560a00e8450dd404, including that fix. The merge is conflict-free, all 18 authored source/test files remain byte-identical, and the worker boundary suite passes 5/5, 58.80 s wall, with the affected test type graph and diff checks passing. Main's cron repair records 35/35 passing cases and independent review. Prior cron failure attribution is retired for the integrated head.The next CI attempt exposed two more native-fixture assumptions. The same-connection cache probe now awaits retirement of its exact seeded state root before opening its measured connection and capturing cached entries. A pristine-main full-file control passed 20/20; that control is not claimed as a fix or inherited-failure proof. The pending-input rollback and relocation tests now serialize their existing CREATE/DROP trigger statements through the foreground database writer FIFO, preserving live receipt custody. All SQL strings and rollback, consumption, identity, and no-reparse assertions are unchanged. Full-file validation passes 57/57 (37 pending-input, 20 cache), 419.12 s wall with
--maxWorkers=1; the repaired aggregate rollback takes 8.744 s and cache case 4.989 s on the loaded local host. Lint, formatting, and affected types pass. Fresh isolated P2 review of the two-file repair is scoped-clean, with no findings.Independent main
fc12c47da1a289a6c9514ab8290fa0c1604085d2reproduces all four newly observed placement discovery/registry failures. Main9f0da25a995bc7c9ee35b0dbfd80c6e4b78858c8introduces eager candidate identity checks and unconditional registry witnesses; the changed transcript reader is not reached. The two-file main placement replay has 5 failed/35 passed in 311.50 s, including one additional incognito-independence failure. Its grouped pending-input file was not executed after the gateway project failed; no pending-input main proof is claimed.The Talk confirmation failures also match scheduled main run
37077835919, job111071892660: all 30 failed cases and three unhandled rejections. Both Node on main and Bun in the PR reject workspace preparation because its worker-thread test environment has no host SQLite broker, before the migrated transcript reader runs. Their 18 causal source files match; this is not a new transcript-reader or Bun-routing change.Final exact-head CI run 37082183994, attempt 1, tested
a7be72da07b0d01b549da65cfbe411bd3ab2b0fein mergec3abc65a54c999cc656896af8f0e2f64b5d5d104against main5046ab7d684d0c45462b6e23b12054f043a39375. It completed with 93 successful jobs, 20 skipped jobs, five failed test jobs and their downstream CI gate; no cancellations.security-fastpassed. The five remaining roots are independently reproduced main failures: two Doctor maintenance-admission cases (Linux main proof above), two placement worker cases and two placement discovery cases (pristine mainfc12c47dproof above), repository publication's raw fixtureBEGIN IMMEDIATEcontention (main run37054655798, job110996434296), and Talk's 30 workspace host-broker failures/timeouts plus three unhandled rejections (main run37077835919, job111071892660). These failures occur before the migrated transcript reader and their causal files are untouched by this PR. The exact competing repository lock holder remains unidentified; newer main coordinator additions are confined to claim methods that this personal-publication test prefix never calls. Failed CI remains failed and is submitted through the explicitly owner-approved native inherited-failure exception, with exact-head source, log, checkout and complete job-accounting evidence.ClawSweeper completed its review of
a7be72daon 2026-10-03 at 00:35:50 UTC: no correctness or security findings and no before-merge requests. All authored repairs have focused passing proof and clean isolated P2 review; no CI rerun was used to conceal a failure.