Skip to content

fix(api): stop asserting which fiber won in the turn-retry test - #366

Merged
Makisuo merged 1 commit into
mainfrom
fix/chat-turn-retry-flaky-test
Aug 8, 2026
Merged

fix(api): stop asserting which fiber won in the turn-retry test#366
Makisuo merged 1 commit into
mainfrom
fix/chat-turn-retry-flaky-test

Conversation

@Makisuo

@Makisuo Makisuo commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

CI on main has been red since 4977476. One job failed — TypeScript — on one test:

FAIL src/chat/loop/turn.test.ts > runChatTurn retry > retracts nothing when the failed attempt's batch never flushed
AssertionError: expected 8 to equal +0

It's a flaky assertion, not a product bug. The fixture emits textDelta("Hello wo") — 8 chars, under DELTA_BATCH_SIZE — then fails the stream, so whether that text ever reached a consumer is a race between the provider failure and the 16 ms DELTA_BATCH_WINDOW. Stream.groupedWithin drops a pending buffer on upstream failure, but a window that fires first ships it. Locally the failure always wins; on a loaded CI runner the timer won and retractChars was a correct 8 against an asserted literal 0. Both outcomes are correct behaviour — the assertion was pinning which fiber won.

This asserts the invariant that actually matters instead: retractChars equals exactly the text flushed before the marker, and the reader's fold lands on the retry's text alone. That holds on either side of the race.

Coverage is unchanged — the deterministic exact-retraction case is still pinned by the neighbouring test, which fills a whole batch and flushes on the size cap regardless of timing.

Verified: vitest run src/chat/loop/turn.test.ts → 27 passed; bun typecheck in apps/api clean.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

The fixture emits 8 chars — under DELTA_BATCH_SIZE — then fails the
stream, so whether that text ever reached a consumer is a race between
the provider failure and the 16ms DELTA_BATCH_WINDOW. groupedWithin
drops a pending buffer on upstream failure, but a window that fires
first ships it. Locally the failure always won; on a loaded CI runner
the timer won and retractChars was a correct 8 against an asserted 0.

Assert the invariant instead: retractChars equals exactly the text
flushed before the marker, and the reader's fold lands on the retry's
text alone. Holds on either side of the race. The deterministic
exact-retraction case is still pinned by the neighbouring test, which
fills a whole batch and flushes on the size cap regardless of timing.
@Makisuo
Makisuo merged commit 95b9557 into main Aug 8, 2026
10 checks passed
@Makisuo
Makisuo deleted the fix/chat-turn-retry-flaky-test branch August 8, 2026 13:22
@railway-app
railway-app Bot temporarily deployed to maple / production August 8, 2026 13:22 Inactive
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

🍁 Maple PR preview

Warning

Preview cleanup could not be confirmed. The Alchemy teardown outcome was failure.

Final commit 95b9557 · View workflow run

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.

1 participant