Repository navigation
perf(sessions): read transcript anchors and readiness through the history reader - #164747
Conversation
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.
Route audited writer claims, live-model-switch bookkeeping, and pending-final preparation, settlement, and cleanup through the existing agent executor. Preserve native opaque SDK callbacks and the excluded lifecycle and cron paths. The paired isolated Gateway workload reduces native patch transactions from 8 to 2 per warmed turn and target-site SQL from 48 to 12. Overall main-thread SQL averages 648.5 to 493.4 statements per warmed turn. Lifecycle persistence remains follow-up work after #142236; cron preparation remains with #161105. Local caller, settlement, error identity, import-boundary, cycle, and database ratchet proof passes. Full build, changed checks, and released SDK diff remain explicit merge preconditions under the maintainer's validation instruction.
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.
Create and read producer-recovery sessions under the same explicit shared-state root as their delivery queue. Worker-backed pending-final settlement correctly rejects the previous fixture ownership mismatch. Preserve durable payloads and all existing assertions.
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.
Keep the accounting persistence suite within its line cap by moving fixture construction into a dedicated test-support module. Preserve suite-owned state, immediate operation registration, and every test case and assertion.
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.
…basync/schemafacts' into dbasync/transcriptfacts
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Merge current main after the schema-facts prerequisite landed, preserving the common context-engine finalizer and user-turn recorder cleanup. Retain duplicate reply identity with the normalized writer authority selected by persistence. Recheck that authority and the explicit caller guard after the awaited anchor read so a superseded attempt cannot acknowledge a duplicate. Reuse the existing database-candidate identity capture helper. Validation: both new authority regressions failed before the repair; the full mirror-identity file now passes 14 tests. Core types, focused lint, and fresh P2 review pass. Caller and import-closure validation continues before landing.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: blocked before merge. Reviewed October 4, 2026, 7:30 AM ET / 11:30 UTC (Revision 5). ClawSweeper reviewWhat this changesMoves durable transcript identity and readiness reads into the existing history worker and makes turn finalizers await preparation while preserving the synchronous Plugin SDK helper. Merge readiness⛔ Blocked before merge - 2 items remain This PR remains useful: current main still performs synchronous anchor preparation. No actionable introduced defect was found, and the completed Linux speech comparison resolves the previous review blocker. Priority: P2 Review scores
Verification
How this fits togetherSession transcripts record conversation history and identify the messages belonging to the active conversation branch. Turn finalization and chat delivery consume these identities to schedule review work and confirm replies. flowchart TD
A[Turn completion or chat reply] --> B[Capture transcript ownership]
B --> C[Existing history worker]
C --> D[Read readiness and message identities]
D --> E[Recheck current ownership]
E --> F[Schedule review or confirm delivery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +437, Tests +377, Docs +13, Other +2. Total +829 across 30 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Complete the existing history-worker cutover while preserving released SDK behavior, current authority checks, and native incognito ownership. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: this is a performance cutover, supported by source inspection and a recorded before/after Gateway SQL workload. Is this the best way to solve the issue? Yes. Extending the existing history reader preserves one ownership path, and the additive awaited SDK helper avoids breaking published synchronous callers. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e318434756f9. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
Merge current main without restoring its retired throughSeq option. Remove the argument left in the extracted reader, which broke cold reads, media rewrites, and speech supplements in the GitHub merge tree. Document the agent-end mock isolation and canonically remove its obsolete baseline entry. Register the released synchronous agent-end compatibility window and verify its void return alongside the additive awaited helpers. Core and SDK test types, focused lint, and independent P2 review pass. Focused runtime validation and the integrated released-SDK report remain landing gates.
Merge main and preserve its tool-authored source reply helper. Retain exactly one additional public, callable, and deprecated export for transcript anchor preparation, with both approved additions reflected in the shared budget. The SDK surface check, SDK test types, script lint, and independent P2 review pass. The prior candidate passed 226 focused tests and its released-SDK report; current-head CI and the refreshed released-SDK report remain landing gates.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Merge main to include the directive-tag fixture fix for the inherited async reader failure. Preserve the transcript anchor worker cutover and released SDK compatibility.
|
@clawsweeper re-review Integrated main's directive-tag worker-reader fixture repair in f8177d9. The affected 132 tests, import/build-graph checks, core types/lint, and fresh P2 review pass. The historical Linux speech comparison is complete: original merge fails 5/5 with throughSeq undefined, main parent passes 5/5, and repaired 6510a8e passes. Fresh exact-head CI and the local released-SDK comparison are running. |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…tory reader (openclaw#164747) * 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. * perf(agents): run per-turn session-entry patches through the worker Route audited writer claims, live-model-switch bookkeeping, and pending-final preparation, settlement, and cleanup through the existing agent executor. Preserve native opaque SDK callbacks and the excluded lifecycle and cron paths. The paired isolated Gateway workload reduces native patch transactions from 8 to 2 per warmed turn and target-site SQL from 48 to 12. Overall main-thread SQL averages 648.5 to 493.4 statements per warmed turn. Lifecycle persistence remains follow-up work after openclaw#142236; cron preparation remains with openclaw#161105. Local caller, settlement, error identity, import-boundary, cycle, and database ratchet proof passes. Full build, changed checks, and released SDK diff remain explicit merge preconditions under the maintainer's validation instruction. * test(outbound): align recovery fixtures with queue state Create and read producer-recovery sessions under the same explicit shared-state root as their delivery queue. Worker-backed pending-final settlement correctly rejects the previous fixture ownership mismatch. Preserve durable payloads and all existing assertions. * 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. * test(agents): extract accounting persistence fixture Keep the accounting persistence suite within its line cap by moving fixture construction into a dedicated test-support module. Preserve suite-owned state, immediate operation registration, and every test case and assertion. * 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): read transcript anchors and readiness through the history reader * refactor(sessions): group history read request types
What Problem This Solves
Turn completion and chat reply observation still read durable transcript anchors and projection readiness on the Gateway thread.
Why This Change Was Made
Extend the existing transcript/history reader with a typed anchor operation. Capture the physical database before discovery yields, read readiness, active anchors, and optional reply-tail facts in one snapshot, and refuse stale projections without rebuilding them on the host. Consume final delivery facts while the existing writer FIFO and reader custody remain retained, checking native mutation and current run authority after awaits. Incognito stays with its native owner. Duplicate acknowledgments retain the normalized writer authority selected by persistence and recheck it, together with the explicit caller guard, after the asynchronous anchor read.
Bundled Codex finalization now awaits anchor preparation through the documented SDK before releasing its turn lease. Interactive plugin hooks remain nonblocking. The shipped synchronous SDK helper stays compatible and is deprecated until the next Plugin SDK major. Its dated compatibility record lives with the session-persistence records; the SDK type test preserves its
voidresult alongside the additive awaited helpers.Context/watermark migration remains excluded: #119055 owns
SessionManager.openModelContextAsyncand transcript hydration/context validation. Integration preserves main’s shared asynchronous context-engine finalization from #158891/#164647 and its user-turn recorder cleanup. This PR changes only the awaited agent-end helper in that finalizer. #162433 remains the standing exempt umbrella draft.Incidental file overlap with unrelated cleanup/read changes (#158789, #161286, #164603, #164538, #128845, #164810) is limited to minimal hunks. Shared SDK budget edits in #155860, #154043, #104018, #119023, and #119256 concern unrelated features; this patch changes only its approved numeric allowances.
User Impact
No schema, storage bytes, retention, durability, permissions, configuration, or update-contract change. No new worker service or persistent cache. No new OPENCLAW_* names. Production: +539/-102, net +437, 641 changed lines; the budget script separately changes three numeric limits (+3/-3).
Current landing status: main's inherited directive-tag fixture defect is repaired by
6aefbb11f30aabb872e7fc379e4b97af7217903cand incorporated in the current head. The affected 132 tests, import/build-graph checks, core types/lint, and fresh P2 review pass. The current-head released-SDK comparison is complete. Exact-head CI is green, trusted ClawSweeper review is complete, and native preparation is complete. No admin exception has been submitted.The moved durable read boundary performs zero caller-thread SQL. This does not claim every runtime anchor read is off-thread. Retained contracts/debt:
src/agents/sessions/session-manager-append.ts:585: deprecated synchronous SDK append/idempotency path.src/agents/sessions/session-manager-current-turn.ts:83: shipped synchronous SDKincludeOmittedCustomMessagesopt-in.src/agents/harness/agent-end-side-effects.ts:74: deprecated synchronous SDK helper; bundled review-source callers await worker preparation.src/gateway/server-methods/chat-send-commentary-media.ts:195: current-anchor predicate inside the native rewrite transaction.src/sessions/user-turn-transcript-annotation.ts:88: native annotation writer authority, checked inside the rewrite callback and around publication; runtime writer debt.src/gateway/internal-source-reply-persistence.ts:82: synchronous committed-message acceptance before media/publication; the writer also checks its typed active-entry predicate.src/infra/heartbeat-session-publication.ts:94: accepted-result authority across preflight, committed-message acceptance, and media/publication settlement; runtime writer debt.Final delivery consumption also retains the pre-existing session-entry/source authority reads in
src/gateway/server-methods/chat-send-reply-dispatch.ts:236(loadSessionEntryand transcript target resolution). They remain separate-owner migration debt; the zero-caller-SQL boundary covers the moved anchor/readiness operations. The FIFO observation holds no worker write transaction while this callback runs.Budget change
The bundled Codex extension consumes
openclaw/plugin-sdk/agent-harness-runtime, so its awaited replacement must be a documented SDK export. Budget change: Peter’s async-SDK directive plus acceleration takeover authorize better asynchronous SDK calls with deprecated synchronous compatibility (2026-10-02, reaffirmed 2026-10-03). This patch raises only these approved limits by one:agent-harness-runtimeEvidence
Current integrated head:
f8177d96f47fde49101993b793cad89692f5a3a0. Prerequisite #164490 merged asc828f7ed1d560295f78166a98fb54687dc162b28. Merge commits integrate main without rebasing, most recentlyd47ee981f47b0cfddec29b2eaacc9c686c2f2902. The main-relative change is 30 files (+989/-160). This integration applies main's existing fixture repair without conflicts or new production edits. The prior SDK-budget conflict preserves main's #164558 source-reply export and adds exactly one allowance for this PR.pnpm test src/gateway/server-methods/chat.directive-tags.test.ts --maxWorkers=1: 132 passed, 147.80s wall. The explicit runtime-process build graph and reply/history/reconcile import-closure suites pass 14 tests, 15.03s runner wall. The mock-export baseline was canonically pruned by exactly one; no allowance was added.eb0f1675: 226 tests across six files passed,node scripts/run-vitest.mjs <files> --maxWorkers=1, 1472.22s wall on the shared macOS host: Gateway media/directive (148), lifecycle (16), cold-read (27), SDK facade (23), and compatibility registry (12). Earlier65c14e55caller/import proof passed 150 tests / 11 files (1162.13s). Duplicate-authority regressions failed before the repair (292.67s) and the full mirror-identity file passed 14 tests (481.02s) afterward, exercising explicit and inherited writer revocation after a real anchor read without changing transcript bytes.eb0f1675(1214.58s) and6510a8eb(914.77s, digest2cd4ec73d1e2a315e722dda534d2098e168a8de7ce55df925a2262c07769df18). They addrunAgentEndSideEffectsAsyncwhile preserving the synchronousvoidand existing awaited declarations. The current-head report completed locally in 369.257s, digest7bb7d7e1652fa168c976ede459d411e4d40d550ebdd324fb06b97bbd9cd882fb, with the same agent-end compatibility result. This includes cumulative main-versus-release changes outside the PR; the two existing agent-end declaration texts are unchanged. Existing signatures retain a dated readonly deprecation record and type test; approved SDK budgets change exactly +1/+1/+1. The predecessor's hosted SDK type lane passed in 35.3s (job 111409153402; 185s total job).preserveFullChecks: trueconfirmed in the check-plan log. One earlier lint command used the wrong production tsconfig; the corrected canonical core invocation passes. No timeout is counted as passing evidence.6510a8ebat 2026-10-04 09:46:57 UTC, with no actionable code findings; the current-head review completed at 2026-10-04 11:30:19.567 UTC, also with no actionable code or security findings. Its request to record the current SDK report is satisfied above; its own technical evidence confirms that the compatibility record changes no stored-data contract. Its migration flag is a path-based false positive:src/plugins/compat/session-persistence-records.tsadds readonly deprecation metadata, with no database writes, schema, backfill, or migration.Current exact-head CI: run 37198600728 completed successfully: 86 successful jobs, 21 skipped, zero failed or cancelled jobs. Build, production/test types, core/extension lint, extension declaration boundary, ratchets, Windows, all UI shards, both real-Gateway UI shards, and
openclaw/ci-gatepass. The full-check plan explicitly setspreserveFullChecks: true, satisfying the hosted alternative to the earlier localcheck-changeddeclaration timeout. The first watcher briefly observed a dependency-review failure status that the publisher subsequently replaced with success; no CI rerun was dispatched.CI failures and their repairs
Run 37189420836 failed on
65c14e55. Main's #164810 removedthroughSeqwhile this PR's extracted helper still forwarded it. The merge-tree ReferenceError broke build/types/lint, cold reads, media rewriting, and speech supplements.eb0f1675removes the stale argument/parameter and preserves main's simplified query. Its separate mock ratchet failure was repaired with an isolation explanation and shrink-only baseline regeneration.Linux attribution run 37190658411, Node 24.19.0, pnpm 12.5.1: cold-read, directive-tags, and commentary-media each fail 5/5 on exact CI merge
56d201e7189c028c623f634aa0095223e75e3be2and pass 5/5 on main parent302ce3d76565f909e779edd7e28cd5914657471f. Single-file commands usedpnpm test <file> --maxWorkers=1; wall times were 22–27s, 28–40s, and 34–41s, respectively. These are PR/main integration defects, not flakes or inherited-red exceptions.The corresponding real-Gateway speech UI comparison is complete on Linux with the same Node/pnpm versions and documented private-QA runtime build: original merge fails 5/5 with
throughSeq is not defined, main parent passes 5/5 (53–58s), repaired6510a8ebpasses 1/1 (57s). It usesui/src/e2e/chat-tts-supplement.real-gateway.e2e.test.tswith the canonical UI Vitest configuration and one worker. Both real-Gateway UI shards also passed in predecessor hosted CI. Both current integrated-head real-Gateway UI shards passed in CI run 37198600728. A Testbox queue timeout led to the approved AWS fallback; remote compute is stopped.Run 37192953378, attempt 1, tested
6510a8ebthrough mergec0ce5cfe1494f7d2b2ddc91e32b11ed59ddd4f9awith main parente95e11c679301368a2f30f09e13647597c65f730: 81 successful jobs, 21 skipped, no cancelled jobs, with one failed Node job and downstream gate. The 13 directive-tag failures came from main's #164779 fixture, whose old synchronous reader mock no longer intercepted async finalization. Its causal files are unchanged by this PR.Independent Linux comparison 37193969337: 5/5 focused runs on both the exact merge and main parent reproduce the same 13 failure names, assertions, and locations (28–41s wall, one worker). Both five-file native-plan replays match, using a one-worker ceiling rather than CI concurrency. Main subsequently repaired the fixture in
6aefbb11f30aabb872e7fc379e4b97af7217903c. The current integration includes that repair and all 132 tests pass locally. No assertion, timeout, retry, or allowance was weakened; no inherited-failure admin merge was submitted.Historical implementation proof for the original approved head 228d95d, including the SQL workload
These measurements retain their original baseline and head identities. Main now supplies the shared asynchronous context-engine flow; this is not a new benchmark of the integrated head.
228d95d9f1d10fc011e464863853b3d232091500: fullnode scripts/check-changed.mjs --base e1f9a9c53d92b826d953a4fd4237c5b9d76a1306took 2034.04s wall. Guards, six Doctor contract tests, all selected production/test/script typechecks, SDK export/surface checks, unused-export scans, formatting, and core lint passed. Extension lint again failed before execution becauseplugin-sdk boundary dtshit its 300000ms managed timeout. The full gate remains incomplete; hosted jobs covering it on the integrated head remain a merge precondition.--maxWorkers=1, 394.23s wall. Covers zero caller-thread SQL including cold discovery, missing-store noncreation, stale projection refusal/no repair, physical replacement, incognito exclusion, and close through the original alias. The alias-close test failed before the fix with SQLite still locked and passed after the fix.--maxWorkers=1, 1599.76s wall. Includesruntime-process-build-graph,get-reply.imports, history/reconcile/state/worker import closures, reply dispatch/commentary, turn lifecycle, user-turn persistence, core agent-end, and bundled Codex agent-end context. The unpublished native-append race refuses final delivery certification.check-changed: tooling timeout; merge precondition, 2931.48s wall on final head. All guards, typechecks, unused-export scans, formatting, and core lint passed. Extension lint could not start because itsplugin-sdk boundary dtspreparation hit the managed 300000ms timeout. Rerun the complete gate, including extension lint, on a host with sufficient capacity before merging. The first completed run (1234.37s) passed core and all core test type graphs, then exposed a missing declared QA Lab workspace devdependency. Installed that dependency through frozen pnpm preparation (6.68s), with no source/lockfile change, before the final rerun. A subsequent strict lint pass found a 702-line worker types file despite the shrink-only ratchet passing; the unchanged progress-card request type now lives with the existing read contracts. Targeted lint passes (59.58s).228d95d9f1d10fc011e464863853b3d232091500, canonical temporary root, 2432.58s wall.runAgentEndSideEffectsAsyncis added; the declarations of the existing synchronousrunAgentEndSideEffects(...): voidand awaited helper remain intact. The report includes cumulative main-versus-release changes outside this PR. Comparing the final report with the implementation-commit report shows no new/removed diff rows and no changed export declaration text from the type-only follow-up.Observed Gateway-thread statement executions (preparations counted separately), using the same isolated local mock-provider workload and Node 24 source-map build. All 13 chats, the child run, cron, compaction, and graceful shutdown succeeded before and after. Selected four-site T1 SQL: 28.0 → 0.0 per warmed turn. Overall: 337.2 → 321.4 per warmed turn (ten-turn totals 3372 → 3214). Each selected site fell from 7.0 to 0.0 per turn. Overall counts include unrelated background work and asynchronous phase timing; they are reported without filtering the two higher after-run turns.
Warmed main-thread totals by turn: before
[336, 336, 338, 338, 340, 336, 336, 336, 338, 338]; after[304, 410, 304, 306, 362, 308, 304, 304, 304, 308]. Selected sites are 28 → 0 on every one of the ten turns.Baseline:
e1f9a9c53d92b826d953a4fd4237c5b9d76a1306(authorized prerequisites combined). Measured behavior commit:0aef2212c385ca732eef6db8b9e5d830ac394252. Final head228d95d9f1d10fc011e464863853b3d232091500only moves an unchanged internal worker request type to meet the absolute lint cap; compiler output for both affected modules is byte-identical. The final SDK comparison and review include that follow-up. The harness code is unchanged apart from absolute import/observer paths for external scratch. The harness’s legacy hardcoded head field is not used as revision evidence.