Repository navigation
fix(claude): enforce history window quota while reading - #21021
Conversation
There was a problem hiding this comment.
ℹ️ No critical issues — one optional nitpick below.
Reviewed changes
- Bounded history read —
readClaudeProviderHistoryWindownow reads the Claude project JSONL throughreadNodeFileWithinLimit(..., MAX_HISTORY_WINDOW_SOURCE_BYTES)instead of astatsize check followed by an unboundedreadFile, closing the stat/read race where post-check growth was fully allocated and accepted. Overflow throwsNodeFileReadTooLargeError, which the existingcatchmaps to the sameINCONSISTENTresult. No new size policy; the constant is unchanged. - Source-budget tests — a new seven-case suite mocks
node:fs/promisesto inject an append immediately after the size snapshot and pins accepted bytes, overflow rejection, permitted in-quota growth, read-error and missing-anchor behavior, plus descriptor open/close parity. - Audit harness —
docs/audits/claude-history-window-budget/adds a reproducible before/after ablation (reproduce.mjs+fix.patch+results.json) recording read bytes, size snapshots, descriptor counts and source hashes.
I verified the focused suite passes (7/7), typecheck:node and check:code-quality:changed pass, and the committed results.json hashes match the working tree (after/current sha256, and before equals applyPatch(current, reversePatch(fix.patch))). An on-disk ablation of the fix failed exactly the one overflow test and passed the other six, matching the recorded before/after split — the test is not theatre.
ℹ️ Nitpicks
docs/audits/**has no.gitignoreallow-list entry, so these three new audit files are present only because they were force-added. Thedocs/**rule at.gitignore:96still matches them, so a cleangit addafter any later edit todocs/audits/claude-history-window-budget/*silently skips it. Add the documented pair for a newdocs/<dir>/:!docs/audits/and!docs/audits/**.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe Claude history reader now uses Priority: ⬇️ Low 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
…firmed Two silent paths hid the cause of an unconfirmed submission. The reconciler's bare `continue` on an `unknown` outcome dropped the reason it already carried, and the transcript read swallowed its error, collapsing an oversize file and a genuine read failure into the same verdict. Log both. No control flow changes.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Oversize vs. read-failure logging —
readClaudeProviderHistoryWindow's catch now takeserror, distinguishesNodeFileReadTooLargeError(oversize: N bytes exceeds M byte window budget) from a genericread failed, and warns with the transcript path and session id. TheINCONSISTENTverdict is unchanged. - Unconfirmed-submission logging —
reconcileJournalSubmissionsAgainstHistorynow logs theunknownoutcome'sclientMessageId,reason, andfencebefore itscontinue, so a submission left unconfirmed is no longer silent.
No control-flow changes; both logs use raw console.warn, matching the existing main-process convention. The focused suites pass (16/16) and oxlint on both changed files is clean.
ℹ️ The static analysis check is red on main, not on this PR
The only failing check on this head is static analysis (and verify, which fails transitively), reporting src/renderer/src/components/editor/DiffViewer.tsx — a file this PR does not touch — at 402 counted lines against the 400 max-lines budget. That file was last changed by main commit 3e7da29 (#11955, merged after this PR's earlier green run), so the failure is pre-existing and unrelated; no change is needed here.
Technical details
# Pre-existing `max-lines` failure on main
## Affected sites
- `src/renderer/src/components/editor/DiffViewer.tsx` — not in this PR's diff; 402 counted lines vs the 400 budget in `.oxlintrc.json`.
## Evidence
- Check runs for `b1fa4ce`: only `static analysis` fails; its annotation is the `DiffViewer.tsx` max-lines error.
- `repos/stablyai/orca/commits?path=.../DiffViewer.tsx` → latest change is main `3e7da29` (`#11955`), 2026-09-19T22:53Z.
- `pnpm exec oxlint` on both files this commit touches: 0 errors.
## Required outcome
- None in this PR. The `max-lines` budget is owned by main; do not add a disable or per-file bump here (AGENTS.md forbids both).DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
After Claude restarts, Orca reads history to check whether a message was delivered. That read already has a 16 MiB limit, but a growing file could slip past it. This change enforces the limit during the read too.
What Changed
Reuse the existing bounded reader instead of checking the file size and then reading without a bound. An oversized or failed read leaves delivery unconfirmed rather than treating an incomplete prefix as proof that a message was absent.
Why
The initial size check cannot protect against later growth. Prefix-only history could produce a false delivery decision.
Tradeoff
A history file that crosses the quota can leave delivery unresolved; Orca does not automatically resend or discard the message. A zero-loss replacement requires disk-backed canonical fingerprints and reconciliation, not just a smaller read buffer.
Linked Issue
Related to #19768 and #19831 as memory hardening; this reader did not exist in v1.4.198.
Visual Proof
No before/after UI capture is attached; this is a lifecycle behavior change. Automated behavior evidence is linked under Testing.
Testing
A real-file proof grew 305 bytes to 17 MiB after the size check; the fixed reader stopped at 16 MiB plus one byte. Controls cover exact limits, permitted growth, read failures, missing anchors, and descriptor cleanup. Audit evidence is in
docs/audits/claude-history-window-budget/.Review
The pre-existing unused test import that failed typecheck and lint has been removed. The renderer typecheck and focused lint pass; fresh CI is pending. The audit now declares its patching dependency directly (
diff8.0.4), and rerunning it reproduces the checked-in results exactly: six baseline controls pass with one expected failure; all seven fixed cases pass. Production source change: 11 lines changed (6 added, 5 deleted), excluding tests, audit documents, and development dependencies.The unresolved-delivery behavior is unchanged: crossing the existing quota leaves reconciliation unresolved. This is a small preventive quota fix, without measured incident-scale OOM savings.