fix(harness): discard the delta coalescer's held text on a provider-retry restart - #6668
Merged
Merged
Conversation
…etry restart buildOptions/runClaudeCode already drops `pending` when a transient provider rejection restarts the attempt, since a dead attempt's buffered chunks aren't part of the next one. The delta coalescer added alongside it (#6664) can independently be holding an un-flushed text/reasoning delta at that same point — nothing cleared it, so a later drain() would splice the dead attempt's partial text into the new attempt's stream, or merge it into an unrelated delta on an id that gets reused. Added discard() to the coalescer and call it next to the pending.length = 0 reset.
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.
Follows #6664 (token-level streaming, merged today), hardening the retry path it added.
On a transient provider rejection,
runClaudeCoderestarts the attempt and clearspending(pending.length = 0) since the dead attempt's buffered chunks aren't part of the next one. ThecreateDeltaCoalesceradded in the same PR can independently be holding an un-flushed text/reasoning delta at that exact point (deltas can accumulate before the turn's first assistant message, i.e. beforestartedflips — the same windowcanRestartCleanly()checks) — nothing cleared it. A laterdrain()on the new attempt would then splice the dead attempt's partial, abandoned text into the new attempt's stream, or worse, merge it into an unrelated delta if the new attempt reuses the same block id.Failure scenario: provider rejects the request mid-stream after emitting a partial (<200 char) text delta that never got flushed; the retry restarts a fresh SDK session, and the abandoned delta text reappears prefixed onto (or merged into) the first delta of the successful retry.
Fix: added
discard()to the coalescer (drops the held delta without emitting it) and call it right next topending.length = 0in the transient-provider-rejection retry branch.Regression test:
discard drops what is held instead of emitting itinpackages/harness-runner/claude-code.test.ts— pushes a delta, discards, drains (expects empty), then verifies a fresh push after discard is not merged with the discarded text.To confirm:
bun test packages/harness-runner/claude-code.test.ts.Locally ran:
bun run fmt,bunx tsc --noEmit(packages/harness-runner), the targeted test file above (39 pass), andbunx oxlinton both changed files (0 warnings/errors). Full CI validates the rest.Summary by cubic
Fixes the delta coalescer retaining abandoned text across provider-retry restarts, which could splice a dead attempt's partial delta into the new attempt's stream or merge it with an unrelated delta.
discard()tocreateDeltaCoalescerand calls it alongside thependingreset during retry.Written for commit e496ce8. Summary will update on new commits.