Skip to content

[PR] fix: release consumed Google array stream prefixes - #7192

Open
Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-18_release-google-array-prefix
Open

Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-18_release-google-array-prefix

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #7188.

Google's JSON-array stream parser keeps every completed element in buf. Subsequent reads can repeatedly flatten/copy the growing string, while already-consumed response text remains reachable until EOF.

After each array scan, discard the consumed prefix and rebase the cursor. Preserve the unfinished element and its string/escape/depth state; discard trailing chunks after the array has ended. The SSE branch and downstream event format are unchanged.

Evidence and regression coverage

Reproducible measurement

Added scripts/bench-google-array-stream.mjs. It imports each checkout's actual adapter by absolute path, records source SHA-256, alternates five base/new pairs per size, and verifies complete forwarded-byte hashes and counts on every run.

Node 24.22.1, Linux x64; approximately 1 KiB per element:

Array elements Original median Updated median
1,024 289.7 ms 28.1 ms
2,048 1,299.4 ms 55.9 ms
4,096 4,309.4 ms 89.0 ms

A separate post-GC sample at 75% of the 4,096-element fixture measured 3,398,328 versus 195,600 bytes of additional heap. These are fixture measurements, not a strict memory bound: an unfinished element, the current transport chunk, and V8 string backing storage can still be retained. SSE and post-array whitespace controls preserve output.

Validation

Rebased to a446a3c1; the timed adapter and component sources are unchanged by that upstream update. Only comment wording changed after timing.

  • Five targeted test files: 75 passed.
  • npm run typecheck, npm run build, npm run check:test-import-graph, and git diff --check: passed.
  • Full-suite verdict remains with remote CI.
  • Real Codex preflight found the CLI and built proxy, but the default upstream at 127.0.0.1:8199 was unreachable. The real-model four-phase run was not run and remains required before merge; skipped CI lanes do not satisfy it.

@ranxianglei ranxianglei changed the title fix: release consumed Google array stream prefixes [PR] fix: release consumed Google array stream prefixes Nov 18, 2026

This branch has not been deployed

No deployments
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.

Google JSON-array streams retain and repeatedly copy consumed response prefixes

1 participant