Skip to content

Skip empty chunks in streamed agent text - #21142

Merged
OrcaWin merged 2 commits into
mainfrom
np-oom-scan-empty-streamed-deltas
Sep 18, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
np-oom-scan-empty-streamed-deltas

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​126 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​126
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2325 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2324

Problem and change

The streamed-text coalescer appended an array entry for every empty delta while charging zero bytes. The Codex notification path accepts these updates, and publishing the text leaves the entries retained. A bounded reproduction retains 65,536 empty entries in one live stream.

Skip only the empty array append. The same reproduction retains zero entries afterward; stream creation, snapshots, scheduled publications, backpressure, eviction, UTF-8 limits and cleanup retain their existing behavior.

Validation

  • 64 focused tests pass; the baseline fails the new retained-entry regression with 65,537 slots versus one nonempty prefix, while 14 controls pass.
  • Independent review reran 15 tests; root reran 43 affected tests. These runs overlap.
  • Node 26 and Electron 43 / Node 24 proofs compare current before/after source and a v1.4.198 coalescer overlay. Publication and scheduling records match exactly.
  • Node typecheck, ordinary/type-aware lint, formatting and changed-code quality pass. All checks used ORCA_BACKGROUND_LAUNCH=1.
  • Reproduction, source hashes and controls: docs/audits/empty-streamed-delta-retention/. The 23 bundled dependencies and six current caller modules match the independent main base.

The historical proof overlays the reported coalescer onto current dependencies; it does not replay the historical application. Ordinary Claude input filters empty text before this helper. Measurements count retained entries, not heap/RSS. Empty-update frequency and contribution to #19831 remain unproven; nonempty chunk overhead and transient concatenation costs are separate.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 9f30fe68-f8de-4632-b5b0-a3fafba8bf1c

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed7c4f and 0c87f12.

📒 Files selected for processing (4)
  • docs/audits/empty-streamed-delta-retention/electron-results.json
  • docs/audits/empty-streamed-delta-retention/node-results.json
  • docs/audits/empty-streamed-delta-retention/scenario.cjs
  • docs/audits/empty-streamed-delta-retention/validation.json
🚧 Files skipped from review as they are similar to previous changes (4)
  • docs/audits/empty-streamed-delta-retention/validation.json
  • docs/audits/empty-streamed-delta-retention/node-results.json
  • docs/audits/empty-streamed-delta-retention/scenario.cjs
  • docs/audits/empty-streamed-delta-retention/electron-results.json

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


📝 Walkthrough

Walkthrough

The coalescer now skips empty deltas when appending retained chunks. New tests cover empty retention, snapshots, flushing, disposal, and backpressure. The pull request also adds source-overlay audit tooling, reproduction scenarios, hash manifests, Node and Electron results, validation records, and documentation for baseline and fixed behavior.

Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to 0c87f

The audit evidence should be regenerated under the repository’s supported Node 24 runtime before relying on its standalone reproduction result. This is a bounded validation-record mismatch rather than a demonstrated product failure.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the problem, implementation, impact, and validation. However, it omits several required template sections, including the linked issue, visual proof or an explicit N/A … Add the required template sections. Include a valid issue reference after "Fixes #", add visual proof or state N/A with a reason, document manual and automated testing with platforms, complete the AI Disclosure and Agent skill upstream boun…
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (3 skipped: 3 … 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 primary change: skipping empty chunks in streamed agent text.
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 clearly explains the problem, implementation, impact, and validation. However, it omits several required template sections, including the linked issue, visual proof or an explicit N/A statement, testing checkboxes and platform details, AI disclosure, review, boundary confirmation, notes, and the checklist.

Resolution

Add the required template sections. Include a valid issue reference after "Fixes #", add visual proof or state N/A with a reason, document manual and automated testing with platforms, complete the AI Disclosure and Agent skill upstream boundary sections, address the Notes items, and complete the final checklist.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 6 files. (3 skipped: 3 unsupported.)

  • 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.

@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: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 373a30e8-13d1-427a-b1ad-fe27c50538c4

📥 Commits

Reviewing files that changed from the base of the PR and between 631b51f and 9ed7c4f.

📒 Files selected for processing (13)
  • docs/audits/empty-streamed-delta-retention/README.md
  • docs/audits/empty-streamed-delta-retention/before.config.mjs
  • docs/audits/empty-streamed-delta-retention/electron-results.json
  • docs/audits/empty-streamed-delta-retention/fix.patch
  • docs/audits/empty-streamed-delta-retention/node-results.json
  • docs/audits/empty-streamed-delta-retention/reported.patch
  • docs/audits/empty-streamed-delta-retention/reproduce.cjs
  • docs/audits/empty-streamed-delta-retention/scenario.cjs
  • docs/audits/empty-streamed-delta-retention/source-versions.json
  • docs/audits/empty-streamed-delta-retention/sources.cjs
  • docs/audits/empty-streamed-delta-retention/validation.json
  • src/main/native-chat/agent-session-wire/agent-session-delta-coalescer.ts
  • src/main/native-chat/agent-session-wire/agent-session-empty-delta-retention.test.ts

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

@@ -0,0 +1,864 @@
{
"runtime": {
"node": "26.6.0",

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:

rg -n --glob 'package.json' --glob '.nvmrc' --glob '.node-version' --glob 'mise.toml' --glob '.tool-versions' '"node"|engines|NODE_VERSION|node-version' .
sed -n '1,100p' docs/audits/empty-streamed-delta-retention/README.md
sed -n '1,90p' docs/audits/empty-streamed-delta-retention/reproduce.cjs
sed -n '1,20p' docs/audits/empty-streamed-delta-retention/node-results.json

Repository: stablyai/orca

Length of output: 7694


🏁 Script executed:

#!/bin/sh
printf '%s\n' '--- package runtime and scripts ---'
sed -n '300,370p' package.json
printf '%s\n' '--- audit files ---'
find docs/audits/empty-streamed-delta-retention -maxdepth 1 -type f -printf '%f\n' | sort
printf '%s\n' '--- audit README references ---'
rg -n -C 3 'Node|node|runtime|report|record|support|version|engine|reproduce' docs/audits/empty-streamed-delta-retention/README.md docs/audits/empty-streamed-delta-retention/*.cjs docs/audits/empty-streamed-delta-retention/*.json
printf '%s\n' '--- other checked-in runtime declarations ---'
for f in .nvmrc .node-version mise.toml .tool-versions cloud/package.json docs/site/package.json; do
  if [ -f "$f" ]; then
    echo "[$f]"
    sed -n '1,70p' "$f"
  fi
done

Repository: stablyai/orca

Length of output: 43780


🤖 get_repo_knowledge executed:

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

Length of output: 47877


🏁 Script executed:

#!/bin/sh
printf '%s\n' '--- root package scripts and package identity ---'
sed -n '1,180p' package.json
printf '%s\n' '--- audit validation metadata ---'
sed -n '1,55p' docs/audits/empty-streamed-delta-retention/validation.json
printf '%s\n' '--- audit README opening and runtime statements ---'
sed -n '1,28p' docs/audits/empty-streamed-delta-retention/README.md

Repository: stablyai/orca

Length of output: 25686


Regenerate the standalone result with Node 24.

The root package.json restricts the standalone runtime to Node 24. validation.json lists node-results.json as a proof report, and the README states that each recorded runtime executes the audit phases. Node 26.6.0 does not validate the supported standalone Node runtime. The README provides no version-independent exception.

@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.

Important

CI's static_analysis job will fail on this PR. pnpm run check:code-quality:changed reports eslint(curly) at docs/audits/empty-streamed-delta-retention/scenario.cjs:76 and exits non-zero — one brace fix is inline below. The production change itself is correct and well tested.

Reviewed changes

  • Coalescer empty-delta guard — appendWithinUtf8ByteLimit now only pushes a chunk when delta.length > 0, so repeated empty Codex deltas no longer grow the per-stream chunks array while both byte counters stay at zero (agent-session-delta-coalescer.ts:233). Snapshot text, dirty, scheduling, eviction, backpressure, and truncation are untouched.
  • Regression test — agent-session-empty-delta-retention.test.ts drives the real Codex stream caller through 4×16384 empty deltas, then measures retained slots via a synchronous Array.prototype.join spy during snapshot. The assertion is exact (toBe(1)), and I ablated the guard locally: it fails with expected 65537 to be 1 while the two control tests still pass.
  • Audit evidence — docs/audits/empty-streamed-delta-retention/ adds the reproduction scripts, current/main and v1.4.198 overlay patches, hash-pinned source loaders, and Node/Electron result reports. I verified the validation.json product hashes match the shipped files.

ℹ️ Nitpicks

  • node-results.json was recorded on Node 26.6.0, but package.json pins engines.node to 24. The Electron report already covers Node 24.21.0, so this is only an evidence-hygiene note, not a blocker.

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

const deps = {
emit(key, text, snapshot) {
assert.equal(this, deps)
if (!accepting) return false

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.

Brace this if: the changed-code quality gate reports eslint(curly) here and fails the PR's static_analysis job.

The repo-wide pnpm exec oxlint step skips docs/** (gitignore), which is why the PR's own validation only linted the two product .ts files and missed this. But config/scripts/check-changed-code-quality.mjs collects changed source-like paths from git diff --name-only (only cloud/ is excluded) and passes them explicitly to oxlint, overriding ignore — so all four audit scripts are scanned by CI.

Technical details
# Changed-code quality gate fails on the new audit script

## Affected sites
- `docs/audits/empty-streamed-delta-retention/scenario.cjs:76` — `if (!accepting) return false` violates `eslint(curly)` (error under the root oxlint config); the only violation across the four new `.cjs`/`.mjs` audit scripts.

## Reproduction
- `node config/scripts/check-changed-code-quality.mjs 631b51f508` → `::error file=docs/audits/empty-streamed-delta-retention/scenario.cjs,line=76,title=eslint(curly)` then `Changed-code quality gate failed with 1 finding(s)`.
- `pr-code-change-scope.mjs` returns `static_analysis=true` for this diff, so `.github/workflows/pr.yml` runs `pnpm run check:code-quality:changed -- <base>`.

## Required outcome
- `node config/scripts/check-changed-code-quality.mjs <base>` exits 0.
Suggested change
if (!accepting) return false
if (!accepting) {
return false
}

@OrcaWin
OrcaWin merged commit 3c138bd into main Sep 18, 2026
27 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
* fix: skip empty chunks in streamed agent text

* test: lint empty-delta retention reproducer

---------

Co-authored-by: m4air <[email protected]>
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.

1 participant