fix(git): replace mutating Stream.runFold with Stream.runForEach#25867
Open
stephanschielke wants to merge 5 commits intoanomalyco:devfrom
Open
fix(git): replace mutating Stream.runFold with Stream.runForEach#25867stephanschielke wants to merge 5 commits intoanomalyco:devfrom
stephanschielke wants to merge 5 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
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?
Replaces the
Stream.runFoldaccumulator-mutation inGit.run()'scollect()helper (introduced in #25581) withStream.runForEach+ local variables.Why / current understanding
We observed an intermittent
TypeError: Attempted to assign to readonly propertyin the compiled + minified opencode binary (Bun 1.3.13) when a normal chat/tool-call flow triggers agit statusexecution.Verified facts:
bun run ...) does not reproduce.minify: falsedoes not reproduce.ai.streamText({ tools })(LLM tool calls). It did not reproduce through the/session/:id/shellendpoint (direct shell execution).Correction vs earlier analysis: I previously claimed the thrown assignment was in the
Git.run()collect()fold reducer itself. I was not able to capture a stack trace that points at that reducer, and I could not reproduce the error in a compiled-binary stress test that callsGit.run()directly. So the exact throw site remains unconfirmed.Given that, the best explanation we have right now is still: a Bun minifier/codegen bug that only manifests with the full opencode module graph + the
streamTexttool-calling pipeline. This change appears to mitigate the crash by removing a mutation-heavy reducer pattern and shifting the generated/minified output.How did you verify your code works?
opencode serve --pure(session message → tool-call path) in a compiled+minified binary.minify: falseavoids the crash (same runtime path).bun test test/git/git.test.ts(9 pass),bun test test/project/vcs.test.ts(8 pass, 4 skip)Screenshots / recordings
N/A — not a UI change
Checklist