Repository navigation
perf(sessions): reuse actor transcripts across scoped worker writes - #170199
Conversation
Carry exact canonical replacement rows in the existing transcript authority receipt. Settle resident payloads with the owning transaction and preserve fallback for content changes, rollback, intervening writes, and bounded-context overflow. Cover the actual prompt-capture to anchor and activity-summary read flow.
…anchorreuse-rewrite
|
🦞👀 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 changes before merge. What this changesThis PR preserves resident actor transcripts across compatible metadata rewrites and trajectory writes, allowing more reads to reuse committed context. Example: A turn persists “Next question,” captures the identical model prompt, and appends “Next answer.”
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep this PR open: it contains useful, maintainer-directed transcript reuse work, and no concrete introduced defect was established. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherThe session actor sits between chat-turn operations and per-agent SQLite workers, publishing committed facts to bounded replicas used by transcript and Activity readers. flowchart TD
A[Chat turn] --> B[Session actor]
B --> C[SQLite worker]
C --> D[Committed receipts]
D --> E[Bounded actor replica]
E --> F[Anchors hydration and recaps]
F --> C
Technical reviewBest possible solution: Complete the existing actor-owned reuse path while preserving canonical fallbacks, exact stored bytes, and current caller authorization. Do we have a high-confidence way to reproduce the issue? Current-main source and the prior committed-context work explain why compatible prompt rewrites discard reusable transcript context; no reproduction was executed during this read-only review. Is this the best way to solve the issue? The implementation extends existing actor and receipt owners, shares recap selection policy, and preserves bounded canonical reads rather than introducing another cache or freshness mechanism. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d7be70250a4b. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +256, Tests +605, Docs +26, Other +7. Total +894 across 41 files. Added test files: 2. View PR surface stats
LabelsLabel changes: No label changes. Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 HistoryReviewed October 12, 2026, 5:11 PM ET / 21:11 UTC (Revision 3). |
What Problem This Solves
Ordinary turns discarded the session actor's retained transcript twice: trajectory-only writes invalidated unrelated session/transcript facts, then prompt capture rewrote the admitted user message without publishing a reusable committed result. That forced anchor reads even when the actor already held current context; activity-summary reads also lacked a replica path. Durable trajectory recording also retained a synchronous production fallback.
This PR combines the trajectory prerequisite from #170133 with committed rewrite reuse. Trajectory receipts name the affected session and sequence bounds; trajectory-only DML certifies that no session/transcript rows changed. Durable recording always uses the existing worker. For admission- and navigation-preserving rewrites, the existing transcript authority receipt carries canonical replacement rows and the resident actor postimage. The transaction owner publishes once after commit, and the bounded replica installs that result. A complete current actor can then serve anchors and hydration. When no admission fence is present, it can also serve activity-summary batches under the canonical byte/message/omission policy.
Content or topology changes, cold/incomplete state, and capacity overflow use the canonical reader. Rollback leaves stored messages unchanged and preserves the database owner's existing failed-write cache invalidation. This adds no cache owner, freshness query, generation, handshake, or synchronous fallback. Schema, retention policy, permissions, public SDK signatures, and update/service lifecycle behavior are unchanged.
SQL and main-thread impact
Trajectory T1 calls: 6 → 0, covering three append and three retention operations. The synchronous fixture implementation moved to test support; worker-only runtime code is classified accordingly.
Incremental committed-rewrite measurement
One unchanged shared-harness v2 pair on the same isolated Linux runner, ten warmed turns each: baseline
ed573c1a3b8ad25e30d589b499202f6ec4b14d8a, candidate9c6e73e6a17a9cc019bfc483d1159215088b806e. Native provisioning verified both source revisions/trees, and the harness hashes match. Counts below are turn-caused, all-thread counts, with background work attributed separately.The incremental saving is 11 statements and one request per warmed turn (5.4% fewer statements). Anchor reads reach zero; the activity-summary read remains, so the combined anchor/summary target is only partly achieved. No hydration reduction is claimed for this step. Summary reuse deliberately requires both complete resident context and an unfenced read. The measured transcript contains ordinary model-snapshot and runtime-context custom entries, which the current simple-path eligibility rejects. Anchors can use snapshot/tail facts, but summaries require complete rows and retain their existing 7-statement/1-request read. Follow-up: support these ordinary linear metadata entries through canonical projection semantics, with a real-turn regression; keep the canonical reader for unsupported or incomplete paths.
None of the five shared causal families rises. Whole-workload statements: 7,063 → 6,913; requests: 1,251 → 1,239; MAIN: 1,067 → 1,059. Background SQL/minute: 909.09 → 963.31; legacy wall-window SQL/turn: 227.2 → 217.2. Those background/window values use different attribution bases and are not added to the causal saving. Both runs passed all 13 turns, child process, RPCs, cron, compaction, and shutdown, with no failed native calls or remaining fixture children. Workload times were 44.9 s and 49.3 s; no latency improvement is claimed.
This frozen pair isolates the incremental rewrite implementation. Final head
1e4edf6dca6dea81fc6a441d4ba1c4dc6992da32also contains subsequent type/test/docs corrections and integration of main's projection receipts. Its exact-head CI is reported below; this pair is not a measurement of the complete final integrated tree. Earlier prerequisite savings use a different base and are not additive.Earlier prerequisite measurement (different base; not additive)
Measured prerequisite step
One unchanged shared-harness v2 pair, ten warmed turns each: baseline
1c12d0c8e6cc8154feea661a3bb3fec8058699c6, candidateb2bf9f9c01683a3b7b33446fd96010e5af0e9824. These are turn-caused all-thread counts, excluding separately attributed background work. This pair measures the trajectory/scoped-summary prerequisite; it does not measure the subsequent rewrite-reuse change.The observed mean reduction is 15.5 statements and 6.3 requests per warmed turn. Excluding unrelated auth-profile admission scheduling variation leaves a conservative attributable saving of 7.0 SQL statements and 4.6 requests per turn. Trajectory INSERT shapes and counts remain unchanged: two per warmed turn.
Whole workload, including startup/shutdown: statements 8,212 → 7,337; requests 1,561 → 1,259; MAIN 1,103 → 1,096. No shared causal family rises. Both runs completed all 13 turns, native child, RPCs, cron, compaction, and shutdown with matching native calibration. Background and wall-window counts vary with host load; no latency improvement is claimed.
Main independently adopted the empty trajectory write scope in #170127 while this lane was in review. The historical prerequisite saving therefore is not all incremental against current main; the source SHAs above delimit that measurement.
Removed checks and accepted edges
The exact-row SQL compare-and-swap, transcript ownership fences, summary admission restriction, retention data checks, and execution-authority checks remain: they protect stored user messages, deletion correctness, and current source authority. Transcript append outside the actor, content rewrite, replacement, suffix trim, rewind, compaction, reset/deletion, and archive/restore retain invalidation coverage.
Evidence
The production-path regression exercises asynchronous prompt capture, assistant append, and public anchor/summary/hydration reads without history/discovery worker requests. Native transaction coverage proves one publication after commit, no publication and unchanged canonical messages after rollback, and invalidation after consecutive rewrites in one transaction. Other regressions cover trajectory append/trim/retention, every transcript writer class above, archive/restore, metadata byte growth, multibyte payloads, summary invalidation, role-aware omission, 64-message batches, and mutation isolation.
Basic changed-file formatting, oxlint, and
git diff --checkpassed. Each reviewed implementation component completed at most two independent Codex review rounds. The prerequisite's final round had no actionable findings; the rewrite component's implementation and correction reviews were scoped-clean. The prerequisite byte-boundary concern was checked against the SQL/JSONL accounting and covered at cap/cap+1. Main integration preserves the existing preview/projection receipts and trajectory write scope. Replica type declarations moved to a leaf file to keep the combined implementation within the existing lint limit; this extraction changes no runtime behavior.Final integrated-head CI 38308037252, source
1e4edf6dca6dea81fc6a441d4ba1c4dc6992da32, passes all production/test type stripes, lint stripes and aggregate lint, source contracts, Madge, T1/dialect/baseline ratchets, build artifacts, and the extension-package boundary. All 135 owner cases across ten files pass on this head: transcript replica (11), residency (4), public reuse (1), actor (17), transcript authority (9), summary retry (28), summary source (1), trajectory retention (21), trajectory store (29), and trajectory writer/mock caller (14). The public reuse regression took 7.855 s in CI. A CI bundle stopped on an unrelated earlier test before running the pure transcript replica file; its focused final-head run passes all 11 cases (12.10 s Vitest, 22.90 s runner).Final-head Knip: inherited failure, not green. The production scan reports exactly the same three findings as scheduled main run 38305224828, job 114997826780:
hasActiveDeliveryOwnerinsrc/infra/outbound/delivery-queue-storage.ts, andlistOpenClawStateFeatureSchemasplusOpenClawStateFeatureSchemainsrc/state/openclaw-state-feature-schema.ts. Both files are untouched by this PR; the red-main repair owner has the evidence. This qualifies for the authorized inherited-static-failure exception. The CI command stopped before its full export scan. A separate final-head full-tree-only scan hit its unchanged 600-second deadline (605.492 seconds including termination grace) without diagnostics; it is incomplete proof, not a pass. Earlier prerequisite full-tree scans were clean. No blanket final-head Knip success is claimed.Aggregate CI is not claimed green. At the final evidence cutoff, 252 inspected failing cases matched the same cases on main, one matched an independent branch, and 46 cases across seven untouched files remained unclassified. Additional unhandled runtime-config errors are recorded separately. The unclassified files cover cron runs, media authority, concurrent OAuth agents, chat abort incarnation, embedded/yielded session abort, and run-orchestrator suspension. Runtime/config preparation errors and one OAuth timeout account for part of that unresolved evidence; these are not asserted to be inherited. No changed owner test fails, and no product regression caused by this PR has been established. The red-main repair owner received 50 records covering 49 matching test files plus Knip. These limits are disclosed under the authorized relaxed landing policy.
No published-driver update cell or SDK API diff is required: update, Doctor, schema migration, plugin loading, service lifecycle, and public SDK surfaces are unchanged.
Combined diff against integrated main
21f043cf86f5fd6bd2c5d279c8d205996661d237: 41 files, +1,582 / −688 lines, including regression tests and the regenerated inventory. The committed inventory changes global T1 from 481 to 465 and T1-compat from 2 to 9; this includes refreshed classifications already present on main. This lane claims only the verified trajectory 6 → 0 cutover. Final integrated source is1e4edf6dca6dea81fc6a441d4ba1c4dc6992da32; same-revision CI 38308037252 provides the static and owner-test results above. The push-triggered PR run retained the old stacked-base event and stopped before tests on imported-main locale artifacts; that scope failure is not a source regression. An initial manual dispatch also stopped at preflight because the main validation tier requires identical workflow and source revisions. The corrected same-revision dispatch supplies final validation; neither preflight failure ran source checks.