Skip to content

perf(sessions): avoid loading full transcripts for newest-event checks - #127162

Merged
steipete merged 1 commit into
mainfrom
codex/perf-lazy-transcript-event-find
Aug 21, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-lazy-transcript-event-find

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where transcript existence and assistant-idempotency checks loaded every SQLite event_json row before testing the newest event, so a newest-row match still scaled with the complete transcript size.

Why This Change Was Made

The canonical newest-first lookup now consumes the existing synchronous SQLite iterator directly and stops stepping rows as soon as its matcher succeeds. Ordering, malformed-row skipping, first-match behavior, transaction lifetime, schema, and public APIs are unchanged.

This is AI-assisted. No agent transcript is attached.

User Impact

Large sessions no longer incur transcript-sized CPU and heap work for newest-event checks. In a 10,002-row, approximately 40 MiB fixture, five newest-row probes improved from 50,010 rows stepped, 225.416 ms wall time, and +217.335 MiB heap to 5 rows, 5.213 ms, and +0.662 MiB heap (about 43x faster wall time).

Evidence

  • Pre-fix focused regression: failed with expected 3 rows, received 1, proving eager materialization occurred before the matcher returned.
  • Final-head focused and sibling tests:
    • node scripts/run-vitest.mjs src/config/sessions/session-accessor.test.ts src/gateway/server-methods/chat.inject.parentid.test.ts --reporter=dot
    • 108 session-accessor tests and 6 Gateway tests passed.
  • node scripts/check-changed.mjs -- src/config/sessions/session-accessor.sqlite-read.ts src/config/sessions/session-accessor.test.ts passed formatting, core/core-test typechecks, lint, dead exports, database/schema guards, and import-cycle checks.
  • git diff --check origin/main...HEAD passed.
  • Fresh structured autoreview on the exact branch head: clean, no accepted/actionable findings; patch correct confidence 0.99.
  • Live open PR/issue searches found no duplicate for findTranscriptEvent or lazy SQLite transcript scanning. Open PRs fix(sessions): preserve transcript idempotency keys #125221, fix(sessions): guard sync transcript rewrite against concurrent commits #124899, and fix(sessions): detect concurrent transcript conflicts in sync rewrite (#124393) #124749 touch adjacent transcript code for distinct idempotency-key or rewrite-conflict work.

@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 21, 2026 11:10
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready proof for exact head 5430a126688ac9088f64eb4be53711c19b01056e:

  • Current-main red regression stepped 3 SQLite transcript rows before the matcher could return; the final head steps exactly 1 newest row.
  • node scripts/run-vitest.mjs src/config/sessions/session-accessor.test.ts src/gateway/server-methods/chat.inject.parentid.test.ts --reporter=dot passed 108 accessor tests and 6 Gateway sibling tests.
  • node scripts/check-changed.mjs -- src/config/sessions/session-accessor.sqlite-read.ts src/config/sessions/session-accessor.test.ts passed formatting, core/core-test typechecks, lint, dead exports, database/schema guards, and import-cycle checks.
  • Fresh structured autoreview was clean with no accepted/actionable findings (patch is correct, confidence 0.99).
  • Repository-native review artifacts validated with READY FOR /prepare-pr, zero findings, and branch/silent-drop sweep passing.
  • Exact-head hosted CI run https://github.com/openclaw/openclaw/actions/runs/32476023400 completed green.
  • OPENCLAW_TESTBOX=1 scripts/pr prepare-run 127162 passed at 2026-08-21T11:18:43Z and verified the remote PR tree matches the prepared head.
  • Production LOC is +2/-2 (net 0); tests are +32/-1. No schema, persistence, public API, protocol, ordering, or output changes.

ClawSweeper disposition: the latest comment is still the review-start placeholder and contains no Rank-up moves: list, so there are no moves to apply or skip. Per repository policy, the publisher refresh does not block an otherwise exact-head-green landing.

AI-assisted; no agent transcript is attached.

@steipete
steipete merged commit 096a970 into main Aug 21, 2026
292 checks passed
@steipete
steipete deleted the codex/perf-lazy-transcript-event-find branch August 21, 2026 11:20

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants