fix(git): replace mutating Stream.runFold with Stream.runForEach#25867
Open
stephanschielke wants to merge 6 commits intoanomalyco:devfrom
Open
fix(git): replace mutating Stream.runFold with Stream.runForEach#25867stephanschielke wants to merge 6 commits intoanomalyco:devfrom
stephanschielke wants to merge 6 commits intoanomalyco:devfrom
Conversation
The collect() function in Git.run() mutates the fold accumulator in-place (acc.bytes += ..., acc.truncated = ..., acc.chunks.push(...)). Since effect@4.0.0-beta.59 (bumped in v1.14.34), Stream.runFold may treat accumulators as readonly, causing 'Attempted to assign to readonly property' on every git subprocess invocation. Replace with Stream.runForEach + local mutable state which is idiomatic for side-effectful stream consumption and avoids accumulator immutability assumptions entirely.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This was referenced May 5, 2026
This was referenced May 6, 2026
…utable fold accumulator crash in Bun compiled binaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #25873
Related: #25835
Type of change
What does this PR do?
Two fixes:
packages/opencode/src/git/index.ts-- replacesStream.runFoldwith mutable accumulator withStream.runForEach+ local variables (original change in this PR).packages/opencode/src/snapshot/index.ts(new commit) -- replacesStream.mkUint8Array(handle.stdout)with an explicitStream.runForEach+ local variable collector. This is the actual crash site.Root cause (fully confirmed)
TL;DR:
effect@4.0.0-beta.59changedStream.mkUint8Arrayto use a mutableChannel.runFoldaccumulator. In Bun--compile --minifybinaries, JSC freezes objects repeatedly passed to a loop step callback as a deoptimization guard. The second fold iteration receives a frozen accumulator and throws.Full chain:
effect@4.0.0-beta.59(bumped in fix(vcs): avoid unbounded diff memory usage #25581) changedStream.mkUint8Arrayfrom returning a newUint8Arrayon each iteration to mutating a shared{ bytes, arrays }accumulator insideChannel.runFold.snapshot/index.tsline 577 callsStream.mkUint8Array(handle.stdout)to collect output fromgit cat-file --batch.processor.tscallssnapshot.track()atcase "start-step"-- after the first tool call completes and before the second starts.Result: the second tool call in any session causes
snapshot.track()to rungit cat-file --batch, which callsStream.mkUint8Array, which on the second chunk throwsAttempted to assign to readonly property/Attempting to define property on object that is not extensible.Why it appeared "git-specific": The original failing session had 35 tool calls in Step 1 (no snapshot needed yet), then git commands in Step 2.
snapshot.track()fires at the step boundary, so the first git call in Step 2 triggered it. With fewer tools per step, the crash appears on call #2 regardless of tool type -- confirmed in Round 3 testing where atasktool call (no git, no subprocess) crashed as the second call.Why
bun rundoes not reproduce: JSC interprets object shapes differently when compiling with--minify. The freeze behavior is a JSC compiled-mode optimization, not present in interpreted mode.Evidence:
4.0.0-beta.57..4.0.0-beta.59shows exactly one change toStream.mkUint8Array-- switching from immutable to mutable accumulator.opencode.dbconfirms all 4 original errors arestate.status = "error"with the tool input fully parsed (secureJsonParse succeeded) -- ruling out AI SDK JSON parsing as the throw site.local-anthropicagent on broken binary: call feat: compact and other improvements #1 (bash: echo hello world) succeeded, call Roadmap & Existing Issues #2 (tasktool) failed.Why the original git/index.ts fix was correct but incomplete
The
git/index.tsStream.runFoldfix in the original commit is correct -- that mutable accumulator was also broken. Butgit/index.tsis only reached afterexecute()is called, which happens aftersnapshot.track()already crashed. So both fixes are needed.How to reproduce
bun run build --single(compiled + minified)opencode servelocal-anthropicagent (LM Studio Anthropic API) to trigger two consecutive tool callsAttempted to assign to readonly property/Attempting to define property on object that is not extensibleDoes NOT reproduce:
bun run(interpreted mode)bun build --compilewithout--minify)4.0.0-beta.57(last good version)4.0.0-beta.60(does NOT fixStream.mkUint8Array)How did you verify your code works?
beta.57..beta.59, 255 lines, only change toStream.mkUint8Arrayin Stream.ts).local-anthropicagent on broken binary reproduces on demand -- call Roadmap & Existing Issues #2 fails regardless of tool type.packages/opencode/src/snapshot/index.tsLSP diagnostics: clean after fix.Stream.mkUint8Arraycalls in the codebase (confirmed via grep).Checklist