Skip to content

fix(sessions): avoid repeated unchanged transcript reads - #191100

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-session-reader-revision-reuse-2114
Nov 2, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-session-reader-revision-reuse-2114

Conversation

@steipete

@steipete steipete commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Concurrent or repeated reads of an unchanged session could hydrate the same transcript repeatedly, while cold accounting recomputed the same active-byte aggregate.

User Impact

Repeated session reads use less SQLite I/O and CPU, with identical transcript and accounting results. Hydration reader-operation labels now have fixed caller suffixes; aggregate sessions.transcript-hydration.* as documented. No schema or configuration changes.

Why This Change Was Made

Admitted readers outside active actor custody could consume the existing transcript replica but could not populate it. Hydration now seeds that owner and shares identical in-flight bounded requests by native revision, request shape, fence, and worker lane. Each consumer keeps independent cancellation and mutable results. The existing bounded window owner records cold accounting facts by database handle and full transcript revision. Fixed caller labels distinguish model preparation, cron/subagent opens, reloads, previews, compaction, exports, and other consumers.

Full streaming/compaction reads retain their contracts. Sequential hydration without a retained actor remains a miss; the first cold accounting computation is unchanged.

Evidence

Synthetic Linux fixture: 17.13 GB, 5,000 sessions, three transcripts exceeding 600 MiB. Separate pinned baseline/candidate sources, A/A controls, five repeated sequences per process, exact physical-reader counters, complete result digests, CPU, and separate allocation sampling. All results match.

Cold repeated sequence Reader operations Physical reads Process CPU Wall time
Hydration, retained actor 14 → 4 18.88 → 15.01 MB 778 → 263 ms 471 → 149 ms
Accounting, no retained actor 12 → 12 299.36 → 49.32 MB 1,016 → 333 ms 716 → 147 ms

Without an actor, four identical concurrent hydrations dispatch once instead of four times. Hydration worker-owner sampled allocations fall about 63% with a retained actor; accounting JavaScript allocations remain within A/A spread. First-process cold accounting reads remain 174,776,320 bytes on both versions. An initial slower unchanged control is retained in the investigation; fresh profiled and topology-warmed controls found no new hotspot. This is synthetic Linux/overlayfs evidence, not a deployment or filesystem-specific claim.

  • 163 focused tests across nine files passed in 236 seconds, including prefix stability, recovery, exports, cancellation, and revision invalidation. Exact original-owner swaps fail both work-count regressions.
  • Affected UI browser test and two UI e2e tests passed. Worker-reader suite also passed.
  • All changed-check gates passed after pruning the assertion allowance made obsolete by removing a cast. The final aggregate run passed every other gate; the corrected assertion gate was replayed separately.
  • Isolated Codex local review against fe912d6852d89c4ac75b8438961f0dbf7791950f: scoped-clean through P2, no actionable findings.

Production delta: +244 lines, including +134 for fixed caller attribution. Reuses existing completed-snapshot/scalar owners; adds only transient in-flight sharing. Test growth +252 lines has a task-specific allocation for real-worker attribution/cancellation and revision invalidation. Simplification removes duplicate validation and normalization.

CI follow-up

The first run exposed a missing runtime inventory entry for the new caller module. The one-line repair is independently reviewed; both closure checks pass locally and their repaired-head CI job is green.

CI run 41451062375 on a34a152c6334fd006dc81486b4bbb64187cbd28b has one failed workload: the invited-project membership test. It is a proven main regression introduced by #191027, cfde51dfe792: discovery now reads spawnedCwd, but this fixture still supplies execCwd. The unchanged test fails identically on CI’s exact main parent 75be4d0f93324db4b2e9ed81e5e2c5f433cf33d0 (one failed, one passed). Swapping only the introducing owner reproduces the failure; changing only the fixture field passes both cases. The failed test and discovery inputs are unchanged by this PR.

The other 112 jobs succeeded and 25 were skipped; the aggregate gate reflects that single failed workload. Landing uses the authorized pinned-head inherited-failure exception, retaining failed CI and the exact checkout/parent/introducer evidence. The stale fixture remains a main follow-up, not a flaky result or an ignored failure.

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: XL labels Nov 2, 2026
@steipete
steipete marked this pull request as ready for review November 2, 2026 12:47
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T12:50:17.657492Z 6eca8ee Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR shares identical in-flight transcript reads, populates the existing replica, reuses revision-matched accounting, and adds fixed caller metrics.

Example: Four concurrent bounded reads request the same unchanged session without a retained actor.

  • Before: Four hydration requests reach the worker.
  • After: One worker request supplies independently mutable results to the four readers.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful measured optimization with production-owner evidence, blocked by a confirmed wrapper extraction defect.
Proof confidence 🦐 gold shrimp (3/6) Ordinary contributor proof gating does not apply to this maintainer-authored PR; its synthetic Linux measurements exercise the changed hydration and accounting owners through real worker transport.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Repeated unchanged session reads consume avoidable SQLite I/O and CPU.
Reason: The maintainer-authored direction has measured owner-level benefits and preserves transcript results without new configuration or persistent storage.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this maintainer-authored PR addresses measured redundant transcript work, but its new runtime import breaks the trusted PR wrapper’s source closure.

Priority: P2
Reviewed head: 6eca8eeec9ba42ac33c31dbc5cd25b0953fe819e

Before merge

  • Include the caller module in the trusted wrapper inventory (P2) - This runtime import makes session-transcript-hydration-caller.ts part of the PR wrapper’s transitive dependency graph, but scripts/pr-lib/wrapper-components.txt does not include it. The wrapper extracts only its inventoried sources, leaving the imported module absent when that graph loads. Exact-head CI confirms the missing path in pr-wrapper-source-closure.test.ts and eager-import-closure.test.ts, including an unresolved import in the extracted dependency context. Add the module to the inventory and rerun both closure suites.

Findings

  • [P2] Include the caller module in the trusted wrapper inventory — src/config/sessions/session-transcript-worker-readers.ts:17

Tests

  • Missing end-to-end proof: The supplied measurements exercise production readers and real workers, without demonstrating a shipped Gateway or CLI flow.
Agent review details

How this fits together

SessionManager and Gateway consumers request transcript views through admitted history workers; the actor replica retains bounded snapshots, while SQLite projection readers calculate accounting.

flowchart TD
  A[Session and Gateway consumers] --> B[Admitted hydration reader]
  B --> C[Existing actor replica]
  B --> D[Revision scoped in flight sharing]
  D --> E[History worker]
  E --> F[SQLite transcript and accounting]
  E --> C
Loading

Technical review

Best possible solution:

Retain the existing replica and accounting owners, and include the new attribution module in the trusted wrapper inventory.

Do we have a high-confidence way to reproduce the issue?

Current-main source repeats cold hydration and accounting work, and the supplied benchmark reports matching outputs with reduced work; no target code was executed during this review.

Is this the best way to solve the issue?

The approach uses existing retained owners and transient sharing with request-shape and revision keys; the added cancellation, mutable-result, and accounting invalidation tests cover distinct failures.

Full review comments:

  • [P2] Include the caller module in the trusted wrapper inventory — src/config/sessions/session-transcript-worker-readers.ts:17
    This runtime import makes session-transcript-hydration-caller.ts part of the PR wrapper’s transitive dependency graph, but scripts/pr-lib/wrapper-components.txt does not include it. The wrapper extracts only its inventoried sources, leaving the imported module absent when that graph loads. Exact-head CI confirms the missing path in pr-wrapper-source-closure.test.ts and eager-import-closure.test.ts, including an unresolved import in the extracted dependency context. Add the module to the inventory and rerun both closure suites.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against baaf869a3a4e.

Provenance checked

  • Admitted replica hydration keeps the original intent (55de901: Reuse current resident transcript facts after admission while preserving physical identity, revision, fence, and mutable-output contracts.)
  • Read and acceptance ordering keeps the original intent (8bc6317: Avoid reserving the database writer during slow worker reads, then validate the snapshot before synchronous consumption.)
  • Context accounting keeps the original intent (87ca2c8: Keep context accounting bounded and reuse owner-published statistics; the new cold-result reuse remains scoped to the database handle and transcript version.)
  • Trajectory and manager simplification keeps the original intent (fix(agents): preserve prompt-released session metadata #93194: Preserve canonical branch and loaded-manager state; removed checks remain enforced by the canonical entry predicate, normalized target, and captureTranscriptView.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test test/scripts/pr-wrapper-source-closure.test.ts test/scripts/eager-import-closure.test.ts --maxWorkers=1
  • git diff --check

What I checked:

PR surface

Source +244, Tests +252, Docs +8, Other +319. Total +823 across 44 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 35 458 214 +244
Tests 4 261 9 +252
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 4 321 2 +319
Total 44 1048 225 +823

Labels

Label changes:

  • add P2: This is a measured performance improvement with a focused automation defect.
  • add merge-risk: 🚨 automation: The introduced runtime dependency is omitted from the trusted wrapper extraction inventory, breaking its source closure.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This is a measured performance improvement with a focused automation defect.
  • merge-risk: 🚨 automation: The introduced runtime dependency is omitted from the trusted wrapper extraction inventory, breaking its source closure.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 2, 2026, 8:05 AM ET / 13:05 UTC.

@steipete
steipete enabled auto-merge (squash) November 2, 2026 13:27
@steipete
steipete disabled auto-merge November 2, 2026 13:29
@steipete
steipete merged commit ffd163f into main Nov 2, 2026
221 of 226 checks passed
@steipete
steipete deleted the steipete/perf-session-reader-revision-reuse-2114 branch November 2, 2026 14:07
@steipete

steipete commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…1100)

* fix(sessions): reuse unchanged transcript reads

* fix(ci): include hydration caller in PR runtime inventory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant