fix(opencode): clone part data in Bus event to preserve token values#15780
Merged
thdxr merged 1 commit intoanomalyco:devfrom Mar 3, 2026
Merged
Conversation
The PartUpdated Bus event was passing the original part object reference, which could be mutated by Zod parse before subscribers received it. Using structuredClone ensures JSONL step_finish events contain the correct non-zero token values. Includes regression test.
3f7b23e to
92793dd
Compare
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Grappeggia
pushed a commit
to teamslop/slopcode
that referenced
this pull request
Mar 4, 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 #15779
Type of change
What does this PR do?
Session.updatePart()passes thepartobject by reference intoBus.publish(PartUpdated)inside aDatabase.effect(). Thefn()wrapper's Zodschema.parse()creates a new object from the input, and the deferred effect closure captures the original reference. If anything mutates that object between queue time and effect execution, JSONL subscribers receive stale data with zeroed token fields — while the TUI is unaffected since it reads from the DB post-persistence.The bug is timing/provider-dependent:
Database.effect()fires synchronously afterDatabase.use()returns, so in most cases the reference is still valid. It manifests under specific async timing conditions depending on the provider.The fix wraps the part in
structuredClone(part)to snapshot the values at queue time, guaranteeing isolation regardless of timing.How did you verify your code works?
bunx tsc --noEmitpassesbun test test/session/session.test.ts— 3 pass, 0 fail (includes new regression test with 10 assertions verifying non-zero tokens propagate through the Bus event)bun dev --format json runproduces non-zero tokens instep_finishJSONL outputScreenshots / recordings
Not a UI change.
Checklist