Repository navigation
perf(sessions): admit persisted-turn replays through the transcript readers - #165367
Conversation
…eaders Validate the current writer row and transcript version in the existing reader snapshot. Keep live ownership, physical source identity, native mutation fencing, and single replay consumption through synchronous core entry.
|
🦞👀 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. Reviewed October 5, 2026, 2:30 AM ET / 06:30 UTC (Revision 3). ClawSweeper reviewWhat this changesThe branch moves persisted-turn replay validation into existing transcript readers and makes internal prompt admission awaitable while preserving synchronous agent entry. Merge readiness✅ Ready for maintainer review This remains a useful, distinct performance improvement. The reviewed source and recorded boundary proof reveal no blocking correctness or security defect. Priority: P2 Review scores
Verification
How this fits togetherReplay admission lets an interrupted agent resume an already-persisted user turn without appending it again. It checks session ownership and transcript state before publishing the prompt and starting model execution. flowchart TD
A[Interrupted user turn] --> B[Prepare transcript replay]
B --> C[Retain original database]
C --> D[Reader validates writer and version]
D --> E[Recheck permissions and run authority]
E --> F[Consume replay once]
F --> G[Start agent synchronously]
G --> H[Settle outside reader custody]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +139, Tests +212, Docs +10. Total +361 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep replay validation with the existing transcript-reader owners, preserving live authority checks and synchronous core entry. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: the performance claim has a pinned paired workload, and current-main source confirms synchronous replay checks remain. Is this the best way to solve the issue? Yes. Extending the existing reader snapshot and retaining its admission custody is a focused solution that preserves the established writer and prompt owners. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d7f9ebd8de66. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
|
Merged via squash.
|
…eaders (openclaw#165367) * perf(sessions): admit persisted-turn replays through the transcript readers Validate the current writer row and transcript version in the existing reader snapshot. Keep live ownership, physical source identity, native mutation fencing, and single replay consumption through synchronous core entry. * test(agents): extract the prompt admission fixture adapter * fix(sessions): preserve the captured replay target environment
What Problem This Solves
Persisted-turn replay admission repeatedly reads the exact session writer row and transcript context version on the Gateway thread. The sqlmeasure4 workload attributed 18 MAIN statements per warmed turn to these checks.
Why This Change Was Made
Validate the writer row and prepared context version together in the existing transcript anchor reader. Retain the physical database through each scan, validation, consumption, and cleanup; compare that source across preparation phases while obtaining fresh owner authority each time. Final replay consumption and core entry run synchronously under the reader's writer FIFO and native mutation witness. The core run settles after reader custody is released.
Run ownership, permission replacement, cancellation, the same anchor/version, and one-time consumption remain live fences. The internal prompt admission callback becomes awaitable. Public named SessionManager persistence APIs and their deprecated synchronous contracts are unchanged.
User Impact
This is an internal performance change: valid replay behavior, schemas, stored bytes, retention, durability, and update behavior are unchanged. No new service, cache, schema, dependency, or OPENCLAW_* environment name is added.
Production delta: +241 / −102 / net +139, 343 changed lines across five production files. The existing process-held incognito route keeps its owner; actor-bound reads use their captured actor. No new caller-thread SQL is added to grant callbacks.
Overlapping work: #165028 (shared anchor/source seam), #165205, #165193, and #162433. This change keeps focused hunks around current reader owners; the umbrella ownership design is outside this PR.
Evidence
Paired measurement uses clean baseline
3b60dc8ba2c34d9de93e7385e169d92801f5c3a2and final candidated14e903971c4e06f45840790fb467b04efa3c7c2on one isolated Hetzner ccx33 host (8 CPUs), Node 24.21.0 / SQLite 3.53.4. All six sqlmeasure4 harness/calibration/analyzer files are byte-for-byte unchanged; three sequential repetitions per revision use separate synthetic fixtures. Statement counts include successful native executions and preserve per-site caller attribution.The selected causal reduction is exactly 18 MAIN statements/turn; the additional 0.3 difference in the overall median includes scheduling variation. Total SQL grows by 14.0/turn (~0.61%); this is a main-thread placement improvement, not latency evidence. Medians are computed separately per metric.
Per-site attribution across ten warmed turns (baseline source line numbers; only stacks passing through persisted-turn replay):
session-accessor.sqlite-entry-read.ts:287session-accessor.sqlite-entry-read.ts:81session-accessor.sqlite-participant-projection.ts:56openclaw-agent-db-readonly.ts:116session-cold-storage-state.ts:57session-accessor.sqlite-transcript-state.ts:75All six replay caller cohorts are zero on MAIN in every candidate repetition. Both native calibrations match: 8 native calls, 2 prepares, 7 successful statements on each thread.
The byte-identical source replacement regression fails on the baseline for the intended reason: preparation resolves instead of rejecting (46.84 s wall).
All test commands use
pnpm test <files> --maxWorkers=1:attempt-session-replay.test.tsattempt-session.test.tsagent-session-loop-next-turn.test.tsThe replay suite exceeds 30 seconds because its existing end-to-end matrix proves restart/retry/compaction, writer/lifecycle replacement, and exact persisted-transcript behavior through real worker owners; the new regressions require the actual delayed worker/SDK mutation and physical-file boundaries. CI seconds are pending the PR run; no CI reruns were used as proof.
The replay boundary checks zero caller-thread SQL through initial preparation, re-preparation, and final admission. Delayed worker replies cover synchronous SDK rewrites, database closure, and run revocation. A byte-identical file replacement must not reopen replay authority. Permission and disposal tests cover the new awaited boundary before prompt publication and core entry.
Indirect caller audit: replay/session/lifecycle tests already route through the host-owned database-worker project, and session-manager/core-loop siblings use the forked agent-support project. No new routing entry was needed.
Required gates:
qaRuntimebuild passed (62.6 s on the isolated host).node scripts/check-changed.mjs --base 3b60dc8ba2c34d9de93e7385e169d92801f5c3a2passed on the final head (1892.17 s), including core production and all 27 core-test type graphs.01df0af7: 128 reachable export effects across five declarations, with 0 direct export declaration changes and 0 entrypoints added/removed. The changed callback is the host-owned@internalsymbol hook, also marked internal in v2026.9.8 and absent from supported SDK/session barrels. Public harness options and Gateway context services do not accept that callback; named public session methods retain their contracts. The anchor request/result fields are optional additions, and the raw database-reader input remains internal.The line-cap failure was repaired by extracting the test-only prompt adapter, shrinking the oversized fixture below its baseline. The captured-target typecheck failure was repaired by preserving the original captured environment rather than widening or casting it. All affected tests and the complete changed gate passed afterward.
Hosted PR CI passed on exact head
d14e903971c4e06f45840790fb467b04efa3c7c2: run 37270022415, 46 successful jobs and 23 intentional skips, with no failed or cancelled jobs. The required CI gate and security statuses passed. ClawSweeper completed its refreshed exact-head review with no actionable findings. The landing audit confirmed existing host-owned/forked test routing and the recorded SDK diff. Published-driver update proof is not applicable: the diff changes no update, Doctor, service lifecycle, migration, plugin-loading, schema, or persisted-format contract, and does not match the published-driver selector. The measured total-SQL increase is the remaining performance tradeoff; no known unresolved correctness finding remains.