Skip to content

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

Merged
Kimiyu-186 merged 1 commit into
sjf_openclaw_2026-07-31from
codex/backport-lazy-transcript-newest-event
Aug 25, 2026
Merged

Kimiyu-186 merged 1 commit into
sjf_openclaw_2026-07-31from
codex/backport-lazy-transcript-newest-event

Conversation

@Kimiyu-186

Copy link
Copy Markdown
Contributor

What Problem This Solves

On the pinned release branch, newest-event transcript lookups load every SQLite event_json row before testing the newest event. An existence or idempotency check therefore incurs CPU and heap usage proportional to the entire session transcript even when the newest row already answers the query.

Why This Change Was Made

Cleanly backport upstream #127162 (096a9708208a4f4af863069f6cc1e260e8f2120d) to sjf_openclaw_2026-07-31. Consume the existing synchronous SQLite iterator directly and stop stepping rows as soon as the matcher succeeds. No schema, protocol, ordering, malformed-row handling, or public API changes.

User Impact

Recent-event checks no longer allocate the full transcript. The upstream 10,002-row, roughly 40 MiB fixture reduced five newest-row probes from 50,010 SQLite rows and +217 MiB heap to five rows and +0.7 MiB heap.

Evidence

  • Existing upstream regression instruments SQLite statement iteration and proves a newest-event match steps exactly one transcript row.
  • 88 focused tests passed: 85 session-accessor tests and three gateway parent-id tests.
  • node scripts/run-tsgo.mjs -p tsconfig.core.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core.tsbuildinfo
  • Focused repository-native oxlint, oxfmt --check, and git diff --check passed.

Upstream: #127162

@clawsweeper

clawsweeper Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 25, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 25, 2026
@clawsweeper

clawsweeper Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 25, 2026, 1:59 AM ET / 05:59 UTC.

ClawSweeper review

What this changes

This PR backports lazy newest-first SQLite transcript scanning so recent-event and idempotency checks stop after a match instead of materializing an entire transcript.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for release-owner scope judgment. The backport matches the already-merged upstream performance fix, but its target is the separate pinned release branch, so current main does not make this work redundant.

Priority: P2
Reviewed head: ac4bd07be8a79dd080c4dd98b08302188b68770f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, source-proven upstream backport with focused regression coverage; remaining work is release inclusion and current-head CI, not a patch defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies the author as a MEMBER, so the external-contributor proof gate does not apply; the PR body still supplies focused regression-test evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies the author as a MEMBER, so the external-contributor proof gate does not apply; the PR body still supplies focused regression-test evidence.
Evidence reviewed 7 items Release-base defect: The pinned release base eagerly collects query rows before matching, so a newest-row match still steps the full transcript.
Backport behavior: The proposed implementation uses the existing lazy iterator while preserving the query, descending ordering, parsing, malformed-row handling, and match return shape.
Caller and sibling path: The public accessor serves transcript-existence probes, while the in-database helper serves scan-assistant idempotency; both retain the same newest-first matching contract.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/config/sessions/session-accessor.test.ts --reporter=verbose

Result: FAIL (partial) — step 2 expect_output finds the newest matching transcript event without loading the whole transcript: expected terminal output was not visible within 30 seconds: "finds the newest matching transcript event without loading the whole transcript"

49ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › 'commits reply session initialization …' 61ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › 'commits reply session initialization …' 67ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › 'preserves concurrent optional additio…' 63ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › does not restore pending final delivery metadata cleared after the sn
apshot 64ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › does not merge old-session delivery metadata into a rotated session 7
9ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › commits reply session initialization from a guarded legacy alias snap
shot 80ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › rejects a reply initialization key scoped to another explicit agent 0
ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › allows an unscoped legacy alias with an explicit agent owner 45ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › rejects reply session initialization when the entry is deleted during
 prepare 63ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › updates existing entries without creating missing sessions 69ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › replaces entries so deleted fields stay removed 62ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › patches entries atomically with a fallback entry 52ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › can patch metadata without refreshing session activity 54ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › applies explicit replacements without exposing mutable store rows 125
ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › prepares entry replacements without holding a write transaction 55ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › does not hold a write transaction while awaiting a lifecycle entry bu
ilder 56ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › rejects a lifecycle projection when its source row changes 56ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › reclaims SQLite transcript rows for lifecycle removals without archiv
e intent 77ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › captures SQLite archived transcript cleanup failures when requested 5
6ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › does not delete SQLite lifecycle entries when the 'exact entry' guard
 mismatches 49ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › does not delete SQLite lifecycle entries when the 'session id' guard
mismatches 48ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › does not delete SQLite lifecycle entries when the 'lifecycle revision
' guard mismatches 51ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › does not delete SQLite lifecycle entries when the 'updatedAt' guard m
ismatches 57ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session accessor seam › archives shared SQLite transcript state once when plugin rollback rem
oves aliases 91ms
 ✓  runtime-config  src/config/sessions/session-accessor.test.ts › session 
… output truncated …

Assertions:

  • FAIL expect_output: finds the newest matching transcript event without loading the whole transcript

How this fits together

Session accessors read per-agent SQLite transcript rows for event existence and assistant idempotency decisions. Their result tells gateway and transcript-write paths whether to append or suppress a message.

flowchart LR
A[Incoming message] --> B[Session accessor]
B --> C[SQLite transcript rows]
C --> D[Newest-first iterator]
D --> E{Matching event?}
E -->|Yes| F[Return immediately]
E -->|No| G[Continue or report absent]
F --> H[Gateway idempotency decision]
G --> H
Loading

Decision needed

Question Recommendation
Should the pinned release branch include this behavior-preserving SQLite performance backport? Include the backport: Accept the matching upstream fix once the exact head has green required release checks.

Why: The code matches the already-merged main fix, but repository policy makes optional backports an operator-selected release-scope decision.

Before merge

  • Resolve merge risk (P1) - This is an optional release-branch backport; inclusion requires explicit release-owner scope acceptance rather than a main-branch correctness decision.
  • Resolve merge risk (P1) - The exact head still has in-progress checks and a reported security-fast failure, so it should not be landed until that check state is resolved.
Agent review details

Security

None.

PR surface

Source 0, Tests +31. Total +31 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 32 1 +31
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 34 3 +31

Review metrics

None.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.test.ts, unknown-data-model-change: src/config/sessions/session-accessor.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    If the release owner selects this performance fix, merge the exact two-file upstream backport after exact-head release CI is green; otherwise close it as intentionally excluded from the release train.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

If the release owner selects this performance fix, merge the exact two-file upstream backport after exact-head release CI is green; otherwise close it as intentionally excluded from the release train.

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

Yes—source reproduction is high confidence: the release base materializes .rows before the matcher, while the regression test counts iterator steps and expects one row for a newest-row match. This read-only review did not execute the test.

Is this the best way to solve the issue?

Yes technically: reusing the existing lazy iterator is the narrow owner-boundary fix and matches current main; whether to carry it into this release remains a release-scope choice.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 610fefdabbce.

Labels

Label justifications:

  • P2: The PR fixes transcript-sized CPU and heap work in a bounded session hot path without changing the public behavior contract.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository state identifies the author as a MEMBER, so the external-contributor proof gate does not apply; the PR body still supplies focused regression-test evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Introduced the upstream lazy transcript scan and is the predominant recent author in the session-reader history. (role: upstream feature owner; confidence: high; commits: 096a9708208a, ac4bd07be8a7; files: src/config/sessions/session-accessor.sqlite-read.ts, src/config/sessions/session-accessor.test.ts, src/infra/kysely-sync.ts)
  • pash-openai: Authored the current pinned release-branch base commit, making them a relevant routing candidate for backport scope. (role: recent release-branch contributor; confidence: medium; commits: b2de68f59985; files: src/config/sessions/session-accessor.sqlite-read.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Resolve the current security-fast failure and allow required exact-head release checks to complete.
  • Have the release owner explicitly choose whether this optional performance backport belongs in the pinned branch.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-25T04:45:08.496Z sha ac4bd07 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T05:09:25.431Z sha ac4bd07 :: needs maintainer review before merge. :: none

@Kimiyu-186
Kimiyu-186 marked this pull request as ready for review August 25, 2026 05:54
@Kimiyu-186

Copy link
Copy Markdown
Contributor Author

/merge

@Kimiyu-186
Kimiyu-186 merged commit 0b45d2d into sjf_openclaw_2026-07-31 Aug 25, 2026
190 of 192 checks passed
@Kimiyu-186
Kimiyu-186 deleted the codex/backport-lazy-transcript-newest-event branch August 25, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants