Skip to content

test(fresh-agent): deflake the b8ke handoff backoff window test - #808

Merged
danshapiro merged 1 commit into
mainfrom
fix/handoff-backoff-flake
Sep 19, 2026
Merged

danshapiro merged 1 commit into
mainfrom
fix/handoff-backoff-flake

Conversation

@danshapiro

Copy link
Copy Markdown
Owner

What

The HANDOFF_IN_PROGRESS retry waits out the backoff test (FreshAgentView.test.tsx) asserted a 350ms wall-clock sleep landed mid-backoff (750ms). Under full-suite parallel load, the act()-queueing gap before the sleep started could itself exceed the backoff, so the check landed after the timer legitimately fired.

The base gate at origin/main hit exactly this on 2026-09-19: 1 of 7,165 tests (scripts/base-gate.sh test, exit 1). The production code honors the backoff (real setTimeout(750) in SessionHandoffErrorBanner.tsx); only the test's wall-clock premise was unsound under load.

Fix

Rewrite the test to advance the fake timer clock deterministically — the same deflake precedent this file already uses for the snapshot-debounce tests (vi.useFakeTimers + act(advanceTimersByTimeAsync)), keyed on SESSION_HANDOFF_RETRY_BACKOFF_MS instead of a literal, and extend the tail: assert no stacked timer fires after the single re-invocation.

Evidence

  • Focused run: rewritten test passes; full file (219 tests) + SessionHandoffErrorBanner suite green (229 passed).
  • Mutation check: with SESSION_HANDOFF_RETRY_BACKOFF_MS = 0 the test fails at the mid-backoff boundary — it still protects the property.
  • npm run typecheck:client green; no Rust changes (rust-gate passes trivially).

…fake timers

The HANDOFF_IN_PROGRESS retry test asserted a 350ms wall-clock sleep
landed mid-backoff (750ms). Under full-suite parallel load the
act()-queueing gap before the sleep started could itself exceed the
backoff, so the check landed after the timer legitimately fired — the
base gate at origin/main hit exactly this (1 of 7,165). Advance the real
timer clock deterministically instead (the file's snapshot-debounce
deflake precedent), keyed on SESSION_HANDOFF_RETRY_BACKOFF_MS rather
than a literal, and extend the tail: no stacked timer fires after the
single re-invocation. Mutation-checked: backoff=0 fails the test.
@danshapiro
danshapiro merged commit 2c0b6ff into main Sep 19, 2026
3 checks passed
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