Repository navigation
perf(sessions): reuse transcript projection facts within reads - #169201
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. |
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses transcript facts within SQLite snapshots and reads Activity recap pages through one shared projection. Example: Activity prepares a recap batch of up to 64 messages with a 128 KiB payload limit.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it provides a focused performance improvement beyond current main, resolves the prior wrapper finding, and has no remaining actionable findings from this review. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherTranscript workers consume canonical SQLite session data and return bounded context, replay anchors, hydration results, and recap inputs to Gateway callers. flowchart TD
A[Gateway session request] --> B[Transcript worker]
B --> C[SQLite read snapshot]
C --> D[Projection and context facts]
D --> E[Context and replay readers]
D --> F[Activity recap pages]
E --> G[Worker result]
F --> G
Technical reviewBest possible solution: Retain the snapshot reuse and completed wrapper inventory while preserving existing transcript, replay, and storage contracts. Do we have a high-confidence way to reproduce the issue? Source inspection confirms the repeated-read paths and the wrapper repair; no target code or tests were executed during this read-only review. Is this the best way to solve the issue? Extending the existing transaction-local fact owner and consolidating recap reads removes redundant work without introducing a competing cache or changing persisted data. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e6c4986438b3. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +24, Tests +106, Docs +9, Other +1. Total +140 across 13 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 11, 2026, 12:05 PM ET / 16:05 UTC (Revision 2). |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
Retain connection-owned busy-timeout policy, skip empty audit expiry deletes until due, and fold known transcript-root recency into watermark writes. These remove seven deterministic SQLite statements per warmed turn. The original four-item measurement reduced warmed all-thread statements from 336.7 to 321.5 and requests from 89.3 to 88.3. Its six-statement activity snapshot saving also landed upstream in #169201; retain that path and its regression. Gateway MAIN remains zero. Preserve the released synchronous SessionManager contract under the documented T1 escape hatch. No schema or retention change. Final-head activity/transcript proof: 69 tests. Type-aware lint, T1/dialect ratchets, export collisions, SDK surface, and cycles pass; required CI is green. Knip reports the same 41 UI findings on the final head and its main baseline, with no changed finding files. SDK API diff reports no public API changes.
…law#169201) * perf(sessions): reuse projection facts within transcript reads * docs(sessions): describe snapshot-local transcript facts * fix(sessions): remove unused transcript state type import * fix(scripts): include transcript context facts in PR wrapper
Retain connection-owned busy-timeout policy, skip empty audit expiry deletes until due, and fold known transcript-root recency into watermark writes. These remove seven deterministic SQLite statements per warmed turn. The original four-item measurement reduced warmed all-thread statements from 336.7 to 321.5 and requests from 89.3 to 88.3. Its six-statement activity snapshot saving also landed upstream in openclaw#169201; retain that path and its regression. Gateway MAIN remains zero. Preserve the released synchronous SessionManager contract under the documented T1 escape hatch. No schema or retention change. Final-head activity/transcript proof: 69 tests. Type-aware lint, T1/dialect ratchets, export collisions, SDK surface, and cycles pass; required CI is green. Knip reports the same 41 UI findings on the final head and its main baseline, with no changed finding files. SDK API diff reports no public API changes.
First-parent upstream 19fe879..0bc7491 (100 commits, including openclaw#169090 entry-writer postimages, openclaw#169201 transcript projection facts, openclaw#169113/openclaw#169107/openclaw#169125 session-actor admission, openclaw#169110 bounded worker heaps, openclaw#169130 inter-session provenance, openclaw#168931 Solid session UI). Conflicts: - session-accessor.sqlite-entry-mutation.ts: openclaw#169090 moved postimage publication into writeSessionEntry and replaced the revision-equality no-op check with postimages.changed. Took upstream's form; kept our recipient-authority advance on visibility narrowing (same transaction, after the write, before the no-op return). - session-accessor.sqlite-entry-store.ts: import union (upstream dropped withProjectedParticipants/SessionEntryWindowFacts imports; ours adds the recipient-authority advance). Overlay vs upstream is now 2 lines. - openclaw-tools.types.ts: import union (our RequestCompactionToolOpts, upstream's SessionsYieldRuntimeClaim). - plugin-sdk-surface-report.mts: upstream raised the budgets to 3672/2133; ours stays +11/+4 on top (3683/2137). - worker-access-inventory.md: regenerated on the merged tree. Auto-merged files that carry continuation overlay (21) keep the overlay byte-for-byte (interdiff of the +/- lines vs upstream before and after). Refs #1475 Co-Authored-By: Claude Opus 5.5 <[email protected]>
What Problem This Solves
Transcript context preparation reread projection readiness, watermark, and hot-state facts already selected by the same command, while activity recaps reopened the projection for each page.
User Impact
Reduces SQLite work during ordinary turns without changing transcript bytes, context limits, recap behavior, permissions, storage schemas, or update behavior.
Why This Change Was Made
Reuse the existing transaction-local transcript fact owner for projection-derived generation, sequence, mutation time, and cold state. Native writes and rollback invalidate those facts through the existing read revision. Current-turn replay consumes its selected projection's version and anchor; full hydration reads its cold state and version together. The activity owner now selects recap metadata, ancestry, and bounded pages in one snapshot. Size-limiting SQL projections stay in SQL.
Removed checks and accepted edges:
T1 scope and residuals
No new main-thread SQL is added. The targeted read owners remain 8 → 8 T1 sites: active-context 6, projection-read 1, public watermark facade 1. Including the touched transcript-state owner gives 22 → 22 (its 14 T1 write/kernel sites are unchanged); including the adjacent transcript-anchor kernel gives 24 → 24 (2 unchanged sites). Current-turn, cold-state, and activity-summary-source have zero inventory-counted sites.
These residuals are not relabeled as worker-only: active-context serves the released deprecated synchronous
SessionManagercontract, preserved until the next Plugin SDK major; the projection payload reader also serves process-held incognito history; and the mixed watermark facade serves synchronous activity-summaryensure, title reads, and compatibility callbacks. Removing those synchronous paths requires their API/owner cutovers, so this PR stops at those calls under the task escape hatch. The changed worker command paths already execute off the Gateway main thread. This PR reduces executed SQL; it does not claim completion of the remaining T1 migration.Evidence
Measured with the shared workload on one remote host in alternating order M1,C1,M2,C2,M3,C3. Base
8e17f906cde15285bbe94234fe75055f3890b64f; code candidate69052f61c90792ae54fafb169048896f92c3e75a. The final head integrates main without conflicts, adds documentation, removes one unused type-only import found by the static gate, and adds the extracted module to the PR wrapper manifest; runtime code is unchanged from the measured candidate. Each warmed result averages ten turns; table cells are median [min–max] across three runs.Warmed SQL falls 10 statements/turn (2.96%). Median candidate/base duration is 1.000 for warmed turns and 0.993 for the whole workload. All six runs passed statement conservation and request-census validation.
The primary first-turn request median rises 194 → 196, while first-turn SQL falls 1093 → 1059. The required extra alternating pair confirms redistribution: full-workload SQL 9828 → 9666 and requests 1725 → 1718, duration ratio 0.969. Its first turn rises 1132 → 1195 SQL / 194 → 199 requests; the additions are existing
sessionRows.sharedFacts,session-exact-entries, andsession-row-factsmetadata work moving earlier, with no new domain-command request types. Primary three-pair medians above remain unchanged.Connect SQL rises by 24: unchanged
database.domain.publishmemory-FTS setup 110 → 133 (+23) anduserProfiles.authority.resolve6 → 7 (+1). Combined boot+connect SQL is 3035 → 3059 (+0.79%) with requests unchanged at 114, within the combined-window tolerance. No added query comes from a changed owner.Direct owner attribution is deterministic across the three runs: activity-summary source 14 → 7 SQL (two projection SELECTs, one watermark SELECT, two BEGIN and two COMMIT removed); transcript hydration 27 → 26 and transcript anchors 12 → 11 (one cold-marker read removed each). That is 9 SQL/turn of direct owner savings. The observed raw median saving of 10 also contains unchanged session-row-facts/actor/exact-entry timing; component medians are not additive. Global BEGIN and COMMIT each fall 44.4 → 42.3 per warmed turn; the activity owner removes exactly two of each.
The code-change commit was reviewed with Codex autoreview: no actionable P0–P2 findings. The conflict-free integration retained that implementation. The later one-line type-import cleanup passed the second and final review (no P0/P1 findings).
Focused regressions cover fact reuse followed by an in-process rewrite/cold transition, and a recap read after a committed append. The new reuse regression fails on baseline for the intended reason: five SELECTs instead of one.
pnpm test src/config/sessions/session-accessor.sqlite-transcript-watermark.test.ts --maxWorkers=1took 41.00s wall / 38.26s Vitest;pnpm test src/gateway/session-activity-summaries.retry.test.ts --maxWorkers=1took 78.29s wall / 75.69s Vitest. Added regression execution: 0.895s + 1.334s = 2.229 CI seconds; the existing files account for the remaining execution/setup cost.check:changedrerun passed all guards, production typechecking, and all 28 core-test typecheck graphs. Its full-tree Knip scan stopped on the untouchedloadSubagentMaintenanceCandidatesInDatabaseexport; the same rule and file fail independently on main23ad242958a4dd4601660e3933dc6e663c89c7a1. The remaining type-aware lint was run separately and passed all 11 changed TypeScript files, with zero warnings/errors; script lint also passed. The final manifest-onlycheck:changedpassed in 137.75s, including its planner-selected guards and script lint.The first static run found one unused type-only import; the follow-up removes it without runtime changes. Initial CI then caught the new module missing from the PR wrapper extraction manifest; the one-line manifest fix passed both failed eager-import checks and all three wrapper-source closure cases (focused command walls 7.12s, 9.96s, and 3.64s).
Diff against the integrated base: production +149/−125 (net +24), tests +107/−1, docs +9/−0, wrapper manifest +1/−0. No SDK surface, storage schema, migration, update, plugin-loading, or service-lifecycle change; SDK diff and published-driver update cell do not apply.
Required CI run 38153442338 is red only on two unchanged test cases: subagent mixed-owner listing exhausts SQLite worker capacity, and ACP explicit-abort completion observes only the end lifecycle event. Both cases fail independently on main
23ad242958a4dd4601660e3933dc6e663c89c7a1: the Bun subagent case reportsoverloadedat worker admission (35.31s), and the ACP case reproduces the same[end]versus[start, end]assertion (86.18s). The inspected CI merge isf23e48bbf8528dcfd3b3e152caf3e43b7de17b31, combining maina44f088e7b9882e39f640870bd28b5fd7e71fee1with the exact PR head. Its capacity policy and failing test sources are unchanged by this PR. Landing uses the authorized inherited-failure exception; no CI rerun or assertion weakening is used.