Repository navigation
perf(sessions): reuse transcript admission and projection facts - #169523
Conversation
Use committed admission bounds, remove duplicate projection and search revision reads, and migrate bundled memory search to the async combined-store SDK loader. Preserve final projection source validation, chunk ownership, and account authority checks.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs changes before merge. What this changesThis PR reuses transcript admission and projection facts and moves bundled memory session-store reads onto database workers. Example: A message containing 'needle' is appended while a completed search awaits projection readiness.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this useful, maintainer-authored optimization still has an unfixed context-admission regression that blocks merge. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherSession context and memory consumers read per-agent SQLite stores through database workers, while projection maintenance owns derived history and search indexes. flowchart TD
A[Session and memory consumers] --> B[Transcript read owners]
B --> C[Database workers]
C --> D[Agent SQLite store]
D --> E[Projection maintenance]
E --> F[Context and search results]
Technical reviewBest possible solution: Reuse receipt bounds during preparation while validating current admitted-message membership and generation at final context acceptance. Do we have a high-confidence way to reproduce the issue? Source establishes the final-acceptance regression, corroborated by the prior-head removed-admission boundary failure; this read-only review executed no target code. Is this the best way to solve the issue? Reusing owner-published facts is appropriate, but preparation receipts cannot replace final validation after supported transcript rewrites. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9a1b712a9b80. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource -112, Tests -151, Docs +22. Total -241 across 30 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label 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 (9 earlier review cycles; latest 8 shown)
Reviewed October 12, 2026, 3:36 AM ET / 07:36 UTC (Revision 10). |
## What Problem This Solves Transcript payload preparation discovers database text encoding with synchronous SQL on the caller thread. SQLite encoding is immutable after schema creation and belongs with the database's admitted facts. ## Design Capture encoding with admitted schema facts and transfer it through the existing worker admission contract. Payload preparation consumes the admitted value. Pre-admission migration uses the shared native metadata helper. The old per-handle encoding cache and repeated SQL read are removed. UTF-8 and UTF-16 payload behavior is preserved. There is no stored-format, retention, or schema-version change. Boot admission and explicit pre-admission migration metadata reads remain permitted native work. Removed check and accepted edge: payload preparation trusts admission's encoding; replacing a database outside the Gateway owner's lifecycle is unsupported. ## Evidence - Two Codex review rounds completed with no actionable P0/P1 findings. - Changed-file oxfmt, oxlint and `git diff --check` pass. Broad checks run in PR CI under RELAXED TESTING v6. - First CI found raw test handles missing schema admission, the historical schema-read count missing the new encoding field, and a cold-writer fixture that incorrectly warmed its database before exercising discovery. These fixtures are corrected; their data, snapshot and lost-write assertions remain intact. The later full CI found the same missing admission on the competing media writer; that fixture now opens through the tracked native owner and admits before the snapshot exercise. - Owned lexical T1 sites: **23 → 22**; the removed payload encoding query is one source site. Boot admission/migration metadata reads are explicit exceptions. - One live baseline/candidate pair completed: base `d23ecfbd6fe8691909e8c25445df2258de353106`, candidate `5ec1a5d67afa2bb4f70ae56d8d1e369efaa6f224`. Later changes are test-only fixes and conflict-free integration. Both runs completed all 13 turns, child execution, every RPC, cron, compaction, and shutdown. | Metric | Base | Candidate | | --- | ---: | ---: | | Warmed all-thread statements/turn | 343.6 | 333.2 | | Warmed requests/turn | 105.4 | 101.7 | | Warmed MAIN statements/turn | 0.4 | 0 | | Whole-workload statements | 9,607 | 9,653 (+0.48%) | | Whole-workload requests | 1,942 | 1,943 (+0.05%) | | Whole-workload MAIN statements | 1,988 | 1,990 | The payload encoding SELECT ran 3 times on the base and 0 on the candidate. Shared admission added 16 encoding reads (4 boot, 7 connect, 5 first-turn startup); 2 were permitted MAIN boot reads and 14 ran in workers/helpers. Net: **+13 cold statements, no new requests, no new warmed reads**. The whole-workload increase is within the T1 MOVE exception with warmed counts lower. The remaining variation comes from unchanged background owners; no causal warmed saving or runtime speedup is claimed. Warmed duration ratio was 0.943. - Published-driver × candidate update cell passed in combined CI 38217360424, job 114712232724: published driver `2026.10.2` updated to candidate `3254d6171c275`, then readiness returned 200 and the running version matched. Later changes are test-only. [Update artifact](https://github.com/openclaw/openclaw/actions/runs/38217360424/artifacts/11734172334). It is required because this changes migration implementation, despite preserving storage format and version. - Final static CI 38217360424 passed types, lint, source contracts, database ratchets, SDK API diff (digest `5ff6265e`) and Madge. Knip reports the exact same untouched UI exports as main run 38216343022; it is inherited. SDK surface check and runtime API guardrail tests passed on the earlier measured head `95d395c19a94`; the lane inputs for both checks remain unchanged, so that proof is reused. - Integrated-head CI [38223201252](https://github.com/openclaw/openclaw/actions/runs/38223201252), at `4faaed07c01bb`, passed production/test types, lint, source contracts, Madge, and database/worker/dialect ratchets. Its one failed test root is the inherited type-suppression inventory assertion (18 expected, 19 actual): main added the annotation in `scripts/lib/managed-cleanup-handoff.mts` at `04cfcd8e25871`; both the script and test are byte-identical on the integrated main and PR head. Security-sensitive review and dependency review are green. The authorized inherited-failure landing route applies. - Knip reuse: main scheduled run [38220958692](https://github.com/openclaw/openclaw/actions/runs/38220958692), job `114717131950`, reports the same `renderPublicSessionCardSvg` unused export. This PR changes neither that owner nor its consumers or Knip configuration; its only new production export, `readSqliteTextEncoding`, is used by the migrated payload and migration readers. The later combined child scan also reports the inherited `gateway-prewarm.mjs` unused file. These findings do not arise from the encoding-only diff. - Main integration at `4faaed07c01bb` preserves the exact encoding-only diff. The only conflict kept the two imports used by the admitted competing-writer fixture; local format/lint/diff checks pass. Earlier production, SDK and update proof remains applicable. - Current encoding-only diff against its parent: **20 files, +144 / −78 lines**. Parent #169523 is merged. This PR now targets main; the review diff contains only encoding changes and their fixture corrections.
The cursor fixture starts a separate rebuild while transcript writes already schedule reconciliation, allowing a later rebuild to replace the expected stale-cursor error with a rebuilding error. Join the existing writer-owned reconciliation at both checkpoints. Preserve exact transcript, stale/foreign cursor and equal-length branch replacement assertions. Test-only: four lines added, four removed; no SDK API change. The competing fixture rebuild predates the worker append migration. Reconcile changes in 5aa61b5 (#169523) exposed this ordering issue and added the second direct rebuild; automatic reconciliation already existed. This is source-supported attribution, not a bisected first-bad or sole culprit claim. Validation: pnpm test src/plugin-sdk/session-transcript-runtime.test.ts --maxWorkers=1 passed 14/14 on composition b3c4dcb (450.21s runner, 752.61s wrapper), with a clean final checkout and no owned survivors. The exact changed file also passed 14/14 in CI run 38275924955. Codex scoped review found no actionable issue. V9 build, types, lint, dependencies, topology, contracts and baseline ratchets passed; the SDK API-report passed on V11 (run 38283393506, job 114926173322), with this test file unchanged. These results qualify the unchanged file in those compositions, not the whole current main head.
…claw#169523) ## What Problem This Solves Transcript context, search, and rebuild paths repeat reads of facts already owned by the Gateway. The bundled memory visibility loader also enters the synchronous session-store path. ## User Impact No configuration or storage-format change. Bundled memory visibility loads the complete cross-session view through the existing worker. The public synchronous loader remains compatible, emits a bounded deprecation warning, and is scheduled for removal in the next SDK major; its replacement is `loadCombinedSessionStoreForGatewayAsync`. ## Design Use committed admission receipts for transcript bounds, return the completed search snapshot with projection readiness, and stop recounting/rechecking acknowledged rebuild work. Final publication retains source validation and bounded append catch-up. SQL projections that avoid materializing large payloads remain in SQL. Removed checks and accepted edges: - Admission identity/role/generation reread: direct SQLite edits outside the Gateway owner are unsupported; the admission receipt supplies committed bounds. Store/session/user-role validation and effect-boundary authority remain. - Search connection revision reread: an append racing a completed search appears on the next search. - Rebuild claim source/clean-index rereads: stale prepared work can temporarily dirty a derived index before final publication rejects it. - Rebuild chunk recount/classification reread: acknowledged chunks are authoritative; final source validation remains. Native-incognito paths remain for the separate incognito-removal migration. Deprecated public synchronous contracts and explicit offline maintenance remain honestly classified. Follow-up target/caller cutovers are being shipped separately; this PR does not claim the entire lane is at zero. ## Evidence - Two Codex autoreview rounds completed without actionable findings. - Before the testing-policy change: 28 focused suites / 402 tests passed. These cover admitted context, append catch-up, complete async projection fields, incognito exclusion, and zero caller-thread SQL in the async SDK loader. The last changed/mock-consumer batch passed 75 tests in 646.8 seconds. - Local changed-file oxfmt, oxlint, and `git diff --check` pass. - Ordinary PR CI run 38213044338 passed at `d23ecfbd6fe8691909e8c25445df2258de353106`, including the repaired built lifecycle fixture. Static CI run 38214212751 passed production/full Knip export scans, all types/lint, source contracts and ratchets; SDK API diff passed (base `10f79e8d1c24`, head `d23ecfbd6fe8`, acknowledgement `99e4d8f2`). Its unused-file check found two unrelated script entrypoints; main removed both in `07389389f157`, now incorporated conflict-free in `91338fabd80f7`. Final static run 38217360424 passed types, lint, source contracts, database ratchets and SDK diff (digest `5ff6265e`); it tests byte-identical PR1 source files as part of child head `3254d6171c275`. Madge reports zero cycles. Knip fails identically on main run 38216343022 in untouched UI exports `ComposerRunStatusContent` and `ChatPaneVersionsMenu`; this is an inherited static failure. Final PR1 ordinary CI 38221257521 at `1dcc93a2641d5` fails only the untouched stale-version actor test, whose implementation came from main openclaw#169651. These failures use the authorized inherited-failure landing route. - Owned lexical T1 sites: **27 → 23** (read fence 1 → 0, rebuild 12 → 10, search 4 → 3). These are source sites, not per-turn statements. - Two live alternating baseline/candidate pairs completed (the v6 pair plus the RAW TURN INCREASE follow-up). Source base `07df9bd4b780ddacbd23bcf76cd5fd19814c5819`, candidate `95d395c19a94e5781df0f3d2827f944aef462288`; later changes are CI test-fixture repairs and conflict-free main integration. Shared workload is unchanged; temporary state is isolated on external storage. | Metric | Base median [min–max] | Candidate median [min–max] | | --- | ---: | ---: | | Warmed all-thread statements/turn | 350.45 [348.2–352.7] | 340.15 [323.1–357.2] | | Warmed requests/turn | 107.4 [107.2–107.6] | 104.9 [98.9–110.9] | | Warmed MAIN statements/turn | 0.3 [0.2–0.4] | 0.1 [0–0.2] | | Whole-workload statements | 9,968.5 [9,941–9,996] | 9,920.5 [9,633–10,208] | | Whole-workload requests | 2,070.5 [2,046–2,095] | 2,052 [1,950–2,154] | The first pair increased whole-workload statements/requests by 267/108; the follow-up decreased them by 363/145, satisfying the RAW TURN INCREASE lower-total condition. Warmed transcript publication remains exactly 27 statements / 7 requests per turn in all four runs. Whole-workload transcript publication was 478/103 → 478/103, then 477/102 → 478/103; Memory publication was 451/113 → 492/128, then 605/153 → 297/77; model context was 27/5 → 49/8, then 29/5 → 34/6. The trace shows existing context fallback after Memory writes but does not identify the failed fallback predicate. Host load and background work varied substantially, so these results do not establish a causal SQL saving or runtime speedup. Warmed candidate/base duration ratios were 1.328 and 0.212. All four runs completed 13 turns, child execution, cron, compaction and shutdown. The first candidate's optional `mentions.dismiss` returned UNAVAILABLE before mention SQL; every RPC passed in both follow-up runs. That first sample is not claimed as entirely green. - Broad CI also exposed two stale fixtures, now corrected: the memory-flush test asserting the removed source reread is deleted, and the cursor fixture awaits the existing projection reconciliation before checking replacement identity. - Update cell is not applicable: no update, Doctor, schema/migration, plugin-loading, or service-lifecycle change. - Diff against integrated main: **32 files, +279 / −539 lines**.
## What Problem This Solves Transcript payload preparation discovers database text encoding with synchronous SQL on the caller thread. SQLite encoding is immutable after schema creation and belongs with the database's admitted facts. ## Design Capture encoding with admitted schema facts and transfer it through the existing worker admission contract. Payload preparation consumes the admitted value. Pre-admission migration uses the shared native metadata helper. The old per-handle encoding cache and repeated SQL read are removed. UTF-8 and UTF-16 payload behavior is preserved. There is no stored-format, retention, or schema-version change. Boot admission and explicit pre-admission migration metadata reads remain permitted native work. Removed check and accepted edge: payload preparation trusts admission's encoding; replacing a database outside the Gateway owner's lifecycle is unsupported. ## Evidence - Two Codex review rounds completed with no actionable P0/P1 findings. - Changed-file oxfmt, oxlint and `git diff --check` pass. Broad checks run in PR CI under RELAXED TESTING v6. - First CI found raw test handles missing schema admission, the historical schema-read count missing the new encoding field, and a cold-writer fixture that incorrectly warmed its database before exercising discovery. These fixtures are corrected; their data, snapshot and lost-write assertions remain intact. The later full CI found the same missing admission on the competing media writer; that fixture now opens through the tracked native owner and admits before the snapshot exercise. - Owned lexical T1 sites: **23 → 22**; the removed payload encoding query is one source site. Boot admission/migration metadata reads are explicit exceptions. - One live baseline/candidate pair completed: base `d23ecfbd6fe8691909e8c25445df2258de353106`, candidate `5ec1a5d67afa2bb4f70ae56d8d1e369efaa6f224`. Later changes are test-only fixes and conflict-free integration. Both runs completed all 13 turns, child execution, every RPC, cron, compaction, and shutdown. | Metric | Base | Candidate | | --- | ---: | ---: | | Warmed all-thread statements/turn | 343.6 | 333.2 | | Warmed requests/turn | 105.4 | 101.7 | | Warmed MAIN statements/turn | 0.4 | 0 | | Whole-workload statements | 9,607 | 9,653 (+0.48%) | | Whole-workload requests | 1,942 | 1,943 (+0.05%) | | Whole-workload MAIN statements | 1,988 | 1,990 | The payload encoding SELECT ran 3 times on the base and 0 on the candidate. Shared admission added 16 encoding reads (4 boot, 7 connect, 5 first-turn startup); 2 were permitted MAIN boot reads and 14 ran in workers/helpers. Net: **+13 cold statements, no new requests, no new warmed reads**. The whole-workload increase is within the T1 MOVE exception with warmed counts lower. The remaining variation comes from unchanged background owners; no causal warmed saving or runtime speedup is claimed. Warmed duration ratio was 0.943. - Published-driver × candidate update cell passed in combined CI 38217360424, job 114712232724: published driver `2026.10.2` updated to candidate `3254d6171c275`, then readiness returned 200 and the running version matched. Later changes are test-only. [Update artifact](https://github.com/openclaw/openclaw/actions/runs/38217360424/artifacts/11734172334). It is required because this changes migration implementation, despite preserving storage format and version. - Final static CI 38217360424 passed types, lint, source contracts, database ratchets, SDK API diff (digest `5ff6265e`) and Madge. Knip reports the exact same untouched UI exports as main run 38216343022; it is inherited. SDK surface check and runtime API guardrail tests passed on the earlier measured head `95d395c19a94`; the lane inputs for both checks remain unchanged, so that proof is reused. - Integrated-head CI [38223201252](https://github.com/openclaw/openclaw/actions/runs/38223201252), at `4faaed07c01bb`, passed production/test types, lint, source contracts, Madge, and database/worker/dialect ratchets. Its one failed test root is the inherited type-suppression inventory assertion (18 expected, 19 actual): main added the annotation in `scripts/lib/managed-cleanup-handoff.mts` at `2efdcb956c136`; both the script and test are byte-identical on the integrated main and PR head. Security-sensitive review and dependency review are green. The authorized inherited-failure landing route applies. - Knip reuse: main scheduled run [38220958692](https://github.com/openclaw/openclaw/actions/runs/38220958692), job `114717131950`, reports the same `renderPublicSessionCardSvg` unused export. This PR changes neither that owner nor its consumers or Knip configuration; its only new production export, `readSqliteTextEncoding`, is used by the migrated payload and migration readers. The later combined child scan also reports the inherited `gateway-prewarm.mjs` unused file. These findings do not arise from the encoding-only diff. - Main integration at `4faaed07c01bb` preserves the exact encoding-only diff. The only conflict kept the two imports used by the admitted competing-writer fixture; local format/lint/diff checks pass. Earlier production, SDK and update proof remains applicable. - Current encoding-only diff against its parent: **20 files, +144 / −78 lines**. Parent openclaw#169523 is merged. This PR now targets main; the review diff contains only encoding changes and their fixture corrections.
The cursor fixture starts a separate rebuild while transcript writes already schedule reconciliation, allowing a later rebuild to replace the expected stale-cursor error with a rebuilding error. Join the existing writer-owned reconciliation at both checkpoints. Preserve exact transcript, stale/foreign cursor and equal-length branch replacement assertions. Test-only: four lines added, four removed; no SDK API change. The competing fixture rebuild predates the worker append migration. Reconcile changes in de750b9 (openclaw#169523) exposed this ordering issue and added the second direct rebuild; automatic reconciliation already existed. This is source-supported attribution, not a bisected first-bad or sole culprit claim. Validation: pnpm test src/plugin-sdk/session-transcript-runtime.test.ts --maxWorkers=1 passed 14/14 on composition b3c4dcb (450.21s runner, 752.61s wrapper), with a clean final checkout and no owned survivors. The exact changed file also passed 14/14 in CI run 38275924955. Codex scoped review found no actionable issue. V9 build, types, lint, dependencies, topology, contracts and baseline ratchets passed; the SDK API-report passed on V11 (run 38283393506, job 114926173322), with this test file unchanged. These results qualify the unchanged file in those compositions, not the whole current main head.
What Problem This Solves
Transcript context, search, and rebuild paths repeat reads of facts already owned by the Gateway. The bundled memory visibility loader also enters the synchronous session-store path.
User Impact
No configuration or storage-format change. Bundled memory visibility loads the complete cross-session view through the existing worker. The public synchronous loader remains compatible, emits a bounded deprecation warning, and is scheduled for removal in the next SDK major; its replacement is
loadCombinedSessionStoreForGatewayAsync.Design
Use committed admission receipts for transcript bounds, return the completed search snapshot with projection readiness, and stop recounting/rechecking acknowledged rebuild work. Final publication retains source validation and bounded append catch-up. SQL projections that avoid materializing large payloads remain in SQL.
Removed checks and accepted edges:
Native-incognito paths remain for the separate incognito-removal migration. Deprecated public synchronous contracts and explicit offline maintenance remain honestly classified. Follow-up target/caller cutovers are being shipped separately; this PR does not claim the entire lane is at zero.
Evidence
git diff --checkpass.d23ecfbd6fe8691909e8c25445df2258de353106, including the repaired built lifecycle fixture. Static CI run 38214212751 passed production/full Knip export scans, all types/lint, source contracts and ratchets; SDK API diff passed (base4de0aa670075, headd23ecfbd6fe8, acknowledgement99e4d8f2). Its unused-file check found two unrelated script entrypoints; main removed both in3a20164800a9, now incorporated conflict-free in91338fabd80f7. Final static run 38217360424 passed types, lint, source contracts, database ratchets and SDK diff (digest5ff6265e); it tests byte-identical PR1 source files as part of child head3254d6171c275. Madge reports zero cycles. Knip fails identically on main run 38216343022 in untouched UI exportsComposerRunStatusContentandChatPaneVersionsMenu; this is an inherited static failure. Final PR1 ordinary CI 38221257521 at1dcc93a2641d5fails only the untouched stale-version actor test, whose implementation came from main perf(sessions): skip snapshot reads for prepared appends #169651. These failures use the authorized inherited-failure landing route.403e966fa7814238ad9fb67bc93641a59b04af1e, candidate95d395c19a94e5781df0f3d2827f944aef462288; later changes are CI test-fixture repairs and conflict-free main integration. Shared workload is unchanged; temporary state is isolated on external storage.The first pair increased whole-workload statements/requests by 267/108; the follow-up decreased them by 363/145, satisfying the RAW TURN INCREASE lower-total condition. Warmed transcript publication remains exactly 27 statements / 7 requests per turn in all four runs. Whole-workload transcript publication was 478/103 → 478/103, then 477/102 → 478/103; Memory publication was 451/113 → 492/128, then 605/153 → 297/77; model context was 27/5 → 49/8, then 29/5 → 34/6. The trace shows existing context fallback after Memory writes but does not identify the failed fallback predicate.
Host load and background work varied substantially, so these results do not establish a causal SQL saving or runtime speedup. Warmed candidate/base duration ratios were 1.328 and 0.212. All four runs completed 13 turns, child execution, cron, compaction and shutdown. The first candidate's optional
mentions.dismissreturned UNAVAILABLE before mention SQL; every RPC passed in both follow-up runs. That first sample is not claimed as entirely green.