fix: replace all mutable Stream fold/collect patterns with immutable runForEach, revert effect to beta.57#25867
Open
stephanschielke wants to merge 11 commits intoanomalyco:devfrom
Open
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
PR anomalyco#25524 bumped effect from beta.57 to beta.59 as a routine chore with no feature dependency. Beta.58 (Effect-TS/effect-smol#2098) introduced a mutable Channel.runFold accumulator in Stream.mkUint8Array that crashes in Bun --compile --minify binaries. Reverting to last known-good version.
…patterns Stream.runCollect uses Channel.runFold with acc.push(o); return acc, which causes JSC to freeze the accumulator in bun --compile --minify binaries. Replace all 6 call sites with Stream.runForEach + local array accumulator. Files changed: file/ripgrep.ts (2 sites), file/index.ts (1), tool/skill.ts (1), tool/glob.ts (1), cli/cmd/debug/ripgrep.ts (1). Related: anomalyco#25873, Effect-TS/effect-smol#2126
This was referenced May 6, 2026
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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 all mutable
Stream.runCollect,Stream.runFold, andStream.mkUint8Arraycall sites with immutableStream.runForEach+ local variable accumulators. Also revertseffectfrom4.0.0-beta.59to4.0.0-beta.57.The crash is caused by two factors combined (neither alone triggers it):
minify: truein the build script (PR build(opencode): shrink single-file executable size #22362) causes Bun's JSC to freeze objects passed through fold callbacks in compiled binaries.effect@4.0.0-beta.58(Effect-TS/effect-smol#2098) changedStream.mkUint8Arrayfrom an immutable fold (new object per iteration) to a mutable accumulator (acc.push(); return acc).Stream.runCollectandChannel.runCollectalready had the same mutable pattern.v1.14.33 (minify + beta.57) worked because beta.57 creates new objects each iteration. v1.14.34+ (minify + beta.59) crashes because the fold returns the same mutated object, which JSC freezes between iterations.
Effect maintainer @mikearnaldi confirms: "This is 100% a bug in Bun's minification implementation."
Changes:
snapshot/index.ts: replacedStream.mkUint8ArraywithcollectUint8helper usingrunForEach+ local varsgit/index.ts: replaced mutableStream.runFoldwithrunForEach+ local varsfile/ripgrep.ts(2 sites): replacedStream.runCollectwithrunForEach+ local arrayfile/index.ts: replacedStream.runCollectwithrunForEach+ local arraytool/skill.ts: replacedStream.runCollectwithrunForEach+ local arraytool/glob.ts: replacedStream.runCollectwithrunForEach+ local arraycli/cmd/debug/ripgrep.ts: replacedStream.runCollectwithrunForEach+ local arraypackage.json+bun.lock: revertedeffectto4.0.0-beta.57Related PRs (alternative fixes):
Upstream: Effect-TS/effect-smol#2126, Effect-TS/effect-smol#2127
Known Bun issues: oven-sh/bun#13394, oven-sh/bun#12655
How did you verify your code works?
Stream.mkUint8Arrayis the only relevant changeopencode.dbqueries: all 4 original errors have fully parsed tool input, ruling out AI SDK JSON parsinglocal-anthropicagent on broken binary, first call succeeded, second call (tasktool, not git) failed withAttempting to define property on object that is not extensibleTS2416inbus/global.ts, same ondev)Stream.runCollect,Stream.runFold, orStream.mkUint8Arraycalls in opencode src (confirmed via grep + ast-grep)bun run,bun build --compilewithout--minify, or witheffect@4.0.0-beta.57Screenshots / recordings
N/A (not a UI change)
Checklist