Repository navigation
perf(sessions): read model context and watermarks through the history reader - #164989
Conversation
|
🦞👀 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: blocked before merge. Reviewed October 4, 2026, 1:57 PM ET / 17:57 UTC (Revision 5). ClawSweeper reviewWhat this changesMoves transcript context validation, watermark reads, and message-presence checks into history workers and carries prepared transcript boundaries through reply callbacks. Merge readiness⛔ Blocked before merge - 1 item remains This remains a distinct optimization absent from current main. No actionable introduced defect was found, and the previous migration-proof blocker does not apply because this cutover preserves the stored-data contract. Priority: P2 Review scores
Verification
How this fits togetherSession history supplies conversation context to agents and transcript boundaries to reply delivery and activity summaries. The history reader moves database work off the Gateway thread while existing owners control admission, writes, and result publication. flowchart TD
A[Chat and activity requests] --> B[Captured transcript source]
B --> C[History worker reads]
C --> D[Current owner and mutation checks]
D --> E[Accepted model context]
D --> F[Prepared reply boundaries]
F --> G[Reply delivery and activity summaries]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +593, Tests +404, Docs +34, Other -1. Total +1030 across 55 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep transcript reads within the existing history owner while preserving synchronous SDK compatibility and final writer and turn checks. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction; current-main source and the supplied before/after workload establish the synchronous-read placement this PR targets. Is this the best way to solve the issue? Yes. It extends the existing history reader and preserves final publication fences rather than introducing another database owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2be4d4fc561b. 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)
|
…aries Keep bound ACP execution start independent of source-chat transcript capture, and clear rejected source recaptures instead of retaining an older boundary. Scope prepared facts and callbacks to each fallback candidate so retired reads cannot notify or supply a successor's transcript start. Preserve released reply callback compatibility with a registry record and type coverage, and update lifecycle fixtures to follow the real execution ordering.
Merge e9edda3 to resolve the compatibility-policy documentation conflict. Retain both the reply-start migration and main's ACP metadata compatibility section. The reviewed transcript-context and reply-start runtime changes are unchanged.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
… reader (openclaw#164989) * perf(sessions): move context and watermark reads to history reader * fix(sessions): satisfy transcript reader lint contracts * fix(sessions): preserve reply-start ownership across transcript boundaries Keep bound ACP execution start independent of source-chat transcript capture, and clear rejected source recaptures instead of retaining an older boundary. Scope prepared facts and callbacks to each fallback candidate so retired reads cannot notify or supply a successor's transcript start. Preserve released reply callback compatibility with a registry record and type coverage, and update lifecycle fixtures to follow the real execution ordering. * chore: prune retired reply-dispatch assertion baseline
Prepare the reply transcript boundary before a remote OpenClaw worker announces execution. Carry its backend through the existing start callback so chat delivery and cancellation use the same runtime ownership facts. This prevents duplicate assistant replies and lets the next turn after a worker cancellation reach the provider instead of silently settling. Both regressions were introduced by 0816aa1 (#164989) and reported in #165225. Preserve singleton reply and skill replacement E2E assertions.
Prepare the reply transcript boundary before a remote OpenClaw worker announces execution. Carry its backend through the existing start callback so chat delivery and cancellation use the same runtime ownership facts. This prevents duplicate assistant replies and lets the next turn after a worker cancellation reach the provider instead of silently settling. Both regressions were introduced by 91961ee (openclaw#164989) and reported in openclaw#165225. Preserve singleton reply and skill replacement E2E assertions.
Related: #119055, #162433.
What Problem This Solves
Normal chat turns still synchronously read transcript context validation, watermarks, and message presence on the Gateway thread, even when the surrounding workflow is asynchronous.
Why This Change Was Made
Route those reads through the existing history reader and carry acknowledged transcript-start facts from the native SessionManager through the bundled reply paths. CLI/custom harness, ACP, inline-tool, and early-event paths prepare missing facts asynchronously. The final model-context acceptance runs synchronously inside the existing anchor reader's FIFO/native-mutation fence, so a rewrite after worker validation cannot publish stale context.
The read source captures physical store identity before yielding and retains existing admission and close custody. Cold markers and hot message probes stay in one synchronous snapshot; restoration retains its existing owner. Final writer and turn authority, completion acknowledgement, and synchronous public SDK/incognito contracts remain intact. No new service, cache, schema, retention, durability, dependency, or environment-variable name.
User Impact
No intended user-visible behavior change. This reduces synchronous database work during chat turns while preserving stored transcript bytes and context selection. Measurements below establish SQL placement, not a latency improvement or reduction in total SQL.
Evidence
SQL measurements and the original focused suites below apply to
64e09112bae776421ec2d690c205d6d494b8bb30. Later landing repairs have separate evidence below; the SQL workload was not remeasured.session-accessor.sqlite-transcript-watermark.ts:38,session-accessor.sqlite-transcript-watermark-read.ts:45)session-accessor.sqlite-transcript-state.ts:75, throughvalidateSessionTranscriptContextVersion)session-accessor.sqlite-read.ts:498/502on the base)The lane's 28/turn baseline yields a measured 22/turn saving. The remaining 6/turn are two existing current-turn replay authority checks at
pre-persisted-user-turn.ts:126, reached from preparation:133and synchronous admission:158; each performs a freshness PRAGMA, cold marker read, and version read. The moved model-context acceptance uses worker validation; these final-authority checks remain explicit debt. The anchor sibling has focused boundary coverage but is not independently countable in this workload.Compared clean base
82adb7a49d36e844e4ea1989bc5d865abac916f0with measured reviewed commit64e09112bae776421ec2d690c205d6d494b8bb30, using the unchanged sqlmeasure3 workload/observer/analyzers on Node 24.21.0, SQLite 3.53.4, macOS arm64. Source manifests before build, after build, and after run match. Counts include successful SQL executions and background work; prepares and failed executions are excluded.The selected lane saves 220 warm statements; overall warm savings are 205 because other background/settling work differs by 15. Final first-turn MAIN counts are 769 → 742; the second-session phase is 866 → 865. A preserved earlier after sample (
20628e04414c3a, before mechanical lint cleanup) measured 200.7/turn and 7,682 overall, with the same 22/turn lane saving. Its first turn included 105 existing session-sharing authority fallback statements while projected facts were unavailable; the final first turn has none. Both after samples have nine such statements in their first warm turn. Background reconciliation also shifts across phase windows. The trace does not establish why projection readiness differed or exclude scheduling effects from the added awaits. No final MAIN stack contains the new read-source helpers.Both baseline and final passed all 13 top-level turns, the separately awaited child, all RPCs, real scheduled cron, committed compaction, and graceful shutdown (
[0, null]). Final counts exclude two MAIN startup catalogBEGIN IMMEDIATElock failures before the first turn, in unchangedsrc/model-catalog/remote-store.ts:79through the existing state transaction owner, plus one worker shutdown audit-pruning lock failure. All reportdatabase is locked; prepare errors are zero. Baseline excludes one worker shutdown audit failure and has no MAIN failures. These failures remain in the raw evidence; no rerun was made to obtain a cleaner result.Total successful SQL increased 46,130 → 46,502 (worker-thread 37,783 → 38,419; helpers 478 → 486). This is SQL-placement evidence, not a total-SQL or latency improvement claim. Final build: 343.6s; instrumented workload: 151.24s. All owned fixture processes settled, the temporary harness is parked outside the repository, and the worktree is clean.
The zero-caller-SQL boundary covers both cold and warm native handles, admission/version/completed-turn context, watermarks, and present/absent message checks. Lifetime/replacement coverage rejects closed owners and copied database replacement. The delayed-validation-reply regression verifies an actual synchronous SDK rewrite before asserting rejection. A negative control that bypassed only the native mutation comparison failed by resolving a SessionManager instead of rejecting (83.50s); the repair was restored byte-for-byte.
node scripts/check-changed.mjs: passed, 2,524.13s wall.TMPDIR, pinned base → final head): 172 reachable export changes; no entrypoints added or removed. Reviewed additions are prepared start facts, an optional fourth callback argument and optional event field, the internal native symbol getter, and the history-worker presence request; the subscriber parameter label also changes. Existing synchronous callback contracts remain supported. Acknowledgement digest:92abd951; 1,274.50s wall.All focused test commands used
--maxWorkers=1. Wall times include local compiler/shard setup; CI timing has not yet been measured.Focused test commands and local wall time
The worker/native SQLite boundary requires real workers to detect caller-thread SQL and delayed replies; these are local gate costs, not latency measurements.
Overlaps and retained boundaries
This intentionally overlaps Vincent Koc's draft #119055 at
openModelContextAsync; it builds on main with focused hunks. It also touches functions in the #162433 ownership-design draft without adopting that restructuring. The lane does not take lifecycle/deletion's commit-side snapshot or sibling-lane ownership.Released synchronous SDK entry points and legacy callbacks that omit prepared start facts retain their compatibility path; the bundled callers of the moved model-context/history/reply-start seams are cut over. Existing live session-owner reads remain follow-up debt:
src/gateway/server-methods/chat-send-reply-dispatch.ts:230inside final reply authority andsrc/gateway/session-activity-summaries.ts:273in current-entry assertions. The moved transcript operations' boundary excludes these retained authority reads. Unchanged synchronous final-authority consumers also remain insrc/agents/embedded-agent-runner/run/pre-persisted-user-turn.ts:126(current-turn replay),src/agents/cli-runner/history-boundary.ts:181(CLI history commit), andsrc/skills/workshop/experience-review.ts:210(source revocation). These are not claimed as migrated SDK-only paths or counted as lane savings.Update behavior preserves the existing history-reader owner, admission rules, writer owner, and close lifecycle. The reader transport cutover requires a published-driver update cell; its result is recorded with the landing evidence below. The compatibility record is static SDK migration metadata, not a database schema, backfill, or stored-data change.
Landing repairs and current proof
7081b391df1017442adbe0bd9f4f5d237afd59afrepairs source-chat versus bound-ACP transcript ownership, clears obsolete boundaries after failed recapture, and scopes prepared facts and callbacks to each fallback candidate. The ACP regression and two fallback negative controls failed on their corresponding pre-fix states. Lifecycle fixtures now emit the actual start event before model phase; strict subscriber expectations include the first-event facts.b08ded31c392925e154f2d311c42a0a413c18b75incorporates main with a merge commit; the sole conflict was compatibility documentation, resolved by retaining both records.The latest released SDK surface (
v2026.9.8) keeps the synchronous three-argumentonAgentRunStartcontract. New fourth-argument facts are optional; legacy omitted-facts behavior is retained byreply-run-start-unprepared-transcript, with migration documentation and type coverage. The refreshed local SDK report fore9edda349fae → b08ded31c392has 206 reachable exports across 30 entrypoints, 22 changed declarations, and zero export or entrypoint additions/removals. Inspection found no breaking released contract. Acknowledgement digest:0145bec2.b08ded31c392, six affected files passed 238 tests with--maxWorkers=1, 264.93s wall: Gateway reply dispatch, ACP completion, Talk consult history, directive tags, execution timing, and execution lifecycle. Isolated proof run.Initial CI run 37213585148 exposed five PR-caused files: each failed 5/5 single-file runs at
64e09112and passed 5/5 at base82adb7a. Those failures are repaired above. The UI setup-flow placement-authority race was independently reproduced on main ancestor2851e89750f5with byte-identical relevant files; exact PR and base each passed 5/5. It is inherited and intermittent, not a fixed flake. CI run 37220851923 then stopped at the assertion-safety ratchet because the repaired reply state removed two casts while its old baseline allowance remained. The canonical prune removes only that stale line; no assertion or guard is weakened. Sibling jobs cancelled by fail-fast are not passing coverage.Published-driver update cell passed on exact candidate
b08ded31c392925e154f2d311c42a0a413c18b75: published2026.9.8→ candidate2026.9.8, with candidate build identity verified. The real updater exited 0 in 364.510s; durable run finished,/readyzreturned 200, and running version was verified. Managed-service teardown passed. Whole cell: 436s; canonical package and tarball integrity/import-graph validation: 673s. The package build logged a nonfatal startup UI budget diagnostic (365.0 KiB versus 364.7 KiB); the package and update gates exited 0. Final head934fb29c279fd9bf177a1535f5aa19a46ae90f50changes only the one-line assertion-baseline prune, so these runtime/package inputs are unchanged.ClawSweeper completed on
934fb29c279fd9bf177a1535f5aa19a46ae90f50at 2026-10-04 17:57 UTC with no actionable introduced defect. Its narrative confirms unchanged storage contracts; its generic data-model checklist is triggered by the static compatibility-registry path. The required reader-transport upgrade cell above is complete.Final exact-head CI run 37222131490 passed on
934fb29c279fd9bf177a1535f5aa19a46ae90f50(662s wall from run start to last update, across parallel jobs). The current rollup has 129 successful checks, 53 intentional skips, one neutral check, and three successful commit statuses includingopenclaw/ci-gate; no failed or cancelled checks. No CI rerun or admin bypass was used for the final head.