Skip to content

Bound AI Vault transcript record assembly before allocation - #20963

Merged
nwparker merged 2 commits into
mainfrom
np-oom-scan-transcript-record-budget
Sep 20, 2026
Merged

nwparker merged 2 commits into
mainfrom
np-oom-scan-transcript-record-budget

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​377 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​371
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​438 $\color{#cf222e}{\Huge{\mathbf{−}}}$​31 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​407

ELI5

AI chat history is stored as individual records. One enormous record could make a history scan allocate a very large amount of memory. This change stops assembling a local record after 10 MiB.

What Changed

Apply the existing remote-record budget while assembling local AI Vault records. Report the affected session as a scan issue and leave its source file unchanged.

Why

Checking after parsing is too late to prevent the large allocation. Reading in smaller chunks does not help if those chunks are eventually joined into the same giant record.

Tradeoff

This introduces a local-record limit. A valid record over 10 MiB makes its entire session unavailable in that scan; adding later lines does not bypass it. Preserving the session requires token-aware projection or disk-backed oversized-record handling that retains all required search and history semantics.

Linked Issue

Related to #19831 as memory hardening; this PR does not prove that incident was caused by transcript scanning.

Visual Proof

No before/after UI capture is attached; this is a background-scan behavior change. Automated behavior evidence is linked under Testing.

Testing

The audit covers oversized records, chunk boundaries, resumable reads, and comparative allocation evidence.

Audit evidence

Review

The session-visibility tradeoff is intentional and should be accepted explicitly before merge.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No blocking issues — the change is well-scoped and well-tested. One defer-able nit below.

Reviewed changes

  • Shared record-byte cap — MAX_SESSION_TRANSCRIPT_RECORD_BYTES (10 MiB) moves out of remote-session-content-lines.ts into new session-transcript-record-budget.ts; the remote streamed reader now passes the shared constant, same value, so remote behavior is unchanged. Net effect: records over 10 MiB that the local reader previously assembled unbounded now throw and surface as a per-session scan issue.
  • Three budget checks in consumeCompleteJsonlLines — before retaining a newline-free chunk, before concatenating a carried prefix with a completed line, and before copying a chunk tail. Traced each site: every retain/concat/decode path is preceded by a check, and at the tail site remainderLength is provably 0, so the count is exact rather than under-counted.
  • Tests — session-scanner-jsonl-reader.test.ts covers oversized records through all three assembly paths (asserting the stream closes and nothing decodes), exact-cap acceptance, a larger multi-record file, and UTF-8 byte-vs-char counting; session-scanner-record-budget.test.ts drives a real temp file and asserts the cached entry identity and resume offset survive rejection and that repair reads the append exactly once.
  • Audit docs — docs/audits/transcript-record-retention/ with a self-guarding reproduction (the baseline transform fails loudly if the three check sites move) and captured measurements.

I verified the error path is handled at every production caller without new fallout: session-scanner.ts:274 records a scan issue, session-search-index-pass.ts:72 logs and continues, session-title-file-reader.ts:65 returns null. I also ran the two changed suites locally — 10/10 pass.

ℹ️ Nitpicks

  • The three files under docs/audits/ aren't matched by the .gitignore allow-list — docs/** is ignored and only docs/site/**, docs/reference/, etc. are negated, so these are present via force-add only and a clean git add silently skips them. If they should survive a fresh checkout, add !docs/audits/ + !docs/audits/**; consistent with the repo's existing force-added docs, this is fine to leave as-is.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

📝 Walkthrough

Walkthrough

The change applies a shared 10 MiB limit to transcript JSONL readers. Oversized records are skipped before decoding, with byte offsets and approximate sizes recorded. Resume state merges this metadata across append reads, and session scanning reports a notice. Tests cover chunk boundaries, UTF-8 sizes, unterminated records, resume offsets, and later valid records. An audit harness compares baseline and transformed readers using 64 MiB inputs.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to ceb28

Oversized records are handled safely, but notices can understate discarded content and the retention audit cannot reproduce the current behavior. Update both before merge for accurate reporting and maintainable audit evidence.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, behavior change, tradeoff, and testing evidence. However, it omits several template sections and required details, including the Agent skill upstream boundary, No… Complete the missing template sections. State the AI Disclosure status, complete the Agent skill upstream boundary, Notes, and Checklist sections, identify tested platforms, mark the testing checkboxes, and write Visual Proof as N/A with …
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: limiting transcript record assembly before large memory allocations.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the problem, behavior change, tradeoff, and testing evidence. However, it omits several template sections and required details, including the Agent skill upstream boundary, Notes, Checklist, AI Disclosure status, testing checkboxes and platform coverage, and the required exact N/A wording for Visual Proof. The Linked Issue section also uses Related to #19831`` instead of the requested Fixes # format.

Resolution

Complete the missing template sections. State the AI Disclosure status, complete the Agent skill upstream boundary, Notes, and Checklist sections, identify tested platforms, mark the testing checkboxes, and write Visual Proof as N/A with the reason. Use the required Linked Issue format or explain why the issue is related without being fixed.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

An agent transcript record over the 10 MiB budget threw out of the JSONL
fold, so the whole session vanished from Agent Session History and from
search. A 10 MiB base64 image or a runaway tool result is ordinary.

The reader now discards the offending record up to its newline and keeps
folding. The in-progress record always starts at `consumedThrough`, which
is what makes both its running size and the resume offset past a discarded
span exact; an unterminated oversized tail leaves the cursor at the
record's start so a still-growing record is re-read rather than guessed at.
Skips accumulate on the resume point keyed by start offset, and the scanner
reports them as a per-session `notice` so nothing is silently lost.

The budget itself is unchanged.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Regenerate the retention audit artifacts. · results.json:1-59

docs/audits/transcript-record-retention/results.json:1-59
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Regenerate the retention audit artifacts. The current reader skips oversized records and reports them through skippedRecords; it does not throw the committed Error: Session transcript record exceeds 10485760 byte limit. The reproduction harness also still expects three removed assertSessionTranscriptRecordBytes(...) calls, which no longer exist. The documented reproduction is therefore stale, and the committed result and README can mislead maintainers about the current reader contract.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 8cf54c01-0e32-4b64-80fc-92884d94c859

📥 Commits

Reviewing files that changed from the base of the PR and between 4beab0c and ceb28ad.

📒 Files selected for processing (8)
  • src/main/ai-vault/session-parse-cache-store.ts
  • src/main/ai-vault/session-scanner-jsonl-reader.test.ts
  • src/main/ai-vault/session-scanner-jsonl-reader.ts
  • src/main/ai-vault/session-scanner-record-budget.test.ts
  • src/main/ai-vault/session-scanner.ts
  • src/main/ai-vault/session-transcript-reader.ts
  • src/main/ai-vault/session-transcript-record-budget.test.ts
  • src/main/ai-vault/session-transcript-record-budget.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

}
return [...byOffset.values()]
.sort((a, b) => a.byteOffset - b.byteOffset)
.slice(0, MAX_TRACKED_SKIPPED_RECORDS)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,100p' src/main/ai-vault/session-transcript-record-budget.ts
sed -n '275,315p' src/main/ai-vault/session-scanner.ts
sed -n '1,80p' src/main/ai-vault/session-transcript-record-budget.test.ts
rg -n -C3 'skippedRecords|MAX_TRACKED_SKIPPED_RECORDS|skipped oversized|at least 32' src/main/ai-vault

Repository: stablyai/orca

Length of output: 20425


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings

Length of output: 16208


🏁 Script executed:

#!/bin/bash
rg -n -C5 'describeSkippedTranscriptRecords|Skipped [0-9]|oversized transcript|skippedRecordIssue|MAX_TRACKED_SKIPPED_RECORDS|bounded|at least' src/main/ai-vault README.md docs 2>/dev/null || true

Repository: stablyai/orca

Length of output: 50370


Do not report the capped list length as the total skipped count.

When more than 32 records are skipped, mergeSkippedTranscriptRecords retains only 32 records. describeSkippedTranscriptRecords then reports records.length as the exact count. Track the omitted count, or report “at least 32” when the list reaches the cap.

@nwparker
nwparker merged commit 403c088 into main Sep 20, 2026
29 of 30 checks passed
@nwparker
nwparker deleted the np-oom-scan-transcript-record-budget branch September 20, 2026 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants