Skip to content

fix(git): replace mutating Stream.runFold with Stream.runForEach#25867

Open
stephanschielke wants to merge 5 commits intoanomalyco:devfrom
stephanschielke:fix/git-runfold-readonly-mutation
Open

fix(git): replace mutating Stream.runFold with Stream.runForEach#25867
stephanschielke wants to merge 5 commits intoanomalyco:devfrom
stephanschielke:fix/git-runfold-readonly-mutation

Conversation

@stephanschielke
Copy link
Copy Markdown

@stephanschielke stephanschielke commented May 5, 2026

Issue for this PR

Closes #25873
Related: #25835

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Replaces the Stream.runFold accumulator-mutation in Git.run()'s collect() helper (introduced in #25581) with Stream.runForEach + local variables.

Why / current understanding

We observed an intermittent TypeError: Attempted to assign to readonly property in the compiled + minified opencode binary (Bun 1.3.13) when a normal chat/tool-call flow triggers a git status execution.

Verified facts:

  • Building from source (bun run ...) does not reproduce.
  • Building a compiled binary with minify: false does not reproduce.
  • The failure only showed up for us in the full runtime path that goes through ai.streamText({ tools }) (LLM tool calls). It did not reproduce through the /session/:id/shell endpoint (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 calls Git.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 streamText tool-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?

  1. Reproduced on v1.14.34 via opencode serve --pure (session message → tool-call path) in a compiled+minified binary.
  2. Verified that minify: false avoids the crash (same runtime path).
  3. Verified that this branch's compiled+minified binary no longer hit the readonly-property crash in that reproduction.
  4. Test suite: 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels May 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Bash tool fails with 'Attempted to assign to readonly property' in v1.14.34

1 participant