Skip to content

test(take-over): hold a failing attach's last line until its exit on a busy runner - #2373

Merged
devswha merged 1 commit into
mainfrom
test/flake-hunt-1030
Oct 29, 2026
Merged

devswha merged 1 commit into
mainfrom
test/flake-hunt-1030

Conversation

@devswha

@devswha devswha commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Found by the flake-hunt lane: Integration failed and passed on a rerun with no code change on run 40867226519 (feat/terminal-open-bare-filename, 2026-10-29) and run 40646297534 (ci/self-hosted-runner-cache, 2026-10-28), both at server/take-over.contract.test.ts:220 with expect(f.starts()).toHaveLength(3), Received length: 2.

Cause (test flake)

"recovers an ordinary failure without turning a click during its terminal lookup into takeover" ran with the default attach hold, ATTACH_HOLD_MS = 100 ms (server/core/terminal-process.ts:34). Its second attempt's stand-in (scripts/fixtures/attach-sequence.mjs, step failed) prints terminal attach taken over and only then exits. On a busy runner the exit can reach the bridge more than 100 ms after the print. The hold then ends first, and took() finds no refusal in that line, counts the attempt as attached, and broadcasts attach-resumed for the pane that was held since the first attempt. The test's wait for "ordinary recovery attaches again" returns on that early frame, before the third attempt starts.

Reproduced: with the stand-in's exit delayed by 300 ms after its last line (scratch change, not committed), the old test fails 5 of 5 with CI's Expected length: 3 / Received length: 2.

Change

The test holds for 2 s, as long as the bridge waits for a refusal's late exit (ATTACH_REFUSAL_EXIT_MS). That is far longer than the stand-in's exit, so the failing attempt always ends as an ordinary failure first. The sibling displacement test already passes a 5 s hold for the same reason. The recovered attach waits out the same hold before it resumes, well within the test's 10 s wait.

Proof

  • Fail-first: with the 300 ms late exit, the old test fails 5/5 and the new one passes 5/5.
  • Stress: plain runs of the test pass 10/10, and the whole file passes 9/9 three times (dori heavy).
  • Local checks: bun run check fast ok.

Test-only.

Reviews

  • omo-native-code-reviewer: APPROVE with no findings above LOW. It confirmed the cause from took()/ended(), and that with the long hold the test still checks no --takeover on attempt 3, the "taken over" text in pty-data, and no pty-exit. LOW-1 (a 5 s hold left only about 4.5 s of headroom on the 10 s wait) was taken: the hold is now 2 s. LOW-2: a future failed/taken step on the default hold would hit the same race. Both tests that use those steps now pass a long hold.
  • Test-only, so no Codex review (notes/pr-policy.md: the test-only gate is omo alone).

Second commit: the displacement test (same cause)

Found on #2380's Integration run (job 123700768179): "consumes a click when the running ordinary retry succeeds, before later displacement" failed at server/take-over.contract.test.ts:89, where pty-data contained "terminal attach taken over".

Cause: the same 100 ms default hold. Displaced by another client's --takeover, herdr prints its teardown and "terminal attach taken over", then exits. The bridge keeps an attach's last line in the output tail for the hold (tailTimer in server/core/terminal-process.ts) and drops it at a displaced exit (flushTail(displaced)). When the exit came more than 100 ms after the line, the line reached the clients first.

Change: a 2 s hold for this test too.

Proof:

  • Fail-first: with the fixture's real wrapper exiting 300 ms after herdr (scratch), the old test failed 3/3 with CI's not.toContain and the new one passed 3/3.
  • Whole file: passed 9/9 three times.
  • Local checks: bun run check fast ok.

Review (omo-native-code-reviewer): APPROVE, CLEAR. The fragment wording LOW was taken. One LOW product note is not fixed here: production also holds the tail 100 ms, so on a loaded machine, when another client takes over, a user can briefly see herdr's teardown line ("herdr: server shut down: terminal attach taken over") until the next attach redraws. It is cosmetic, brief, and less likely than in the test, which adds a node wrapper. A longer tail hold for displacement would remove it.

…a busy runner

The ordinary-failure recovery test used the 100 ms default attach hold. Its
stand-in prints "terminal attach taken over" and only then exits, so on a busy
runner the hold could end first: the attempt counted as attached, the bridge
sent attach-resumed, and the test's wait for the recovery returned before the
third attempt started (starts() 2 instead of 3). Hold for 2 s, as long as the
bridge waits for a refusal's late exit, so the exit always comes first.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between b6f555f and 7597f65.

Files selected for processing: 2
  • changelog.d/integration-flake-take-over-recovery.md
  • server/take-over.contract.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Tests
    • Updated the take-over recovery test to wait for a failed attach attempt to exit before proceeding, reducing timing-related test flakiness on busy runners.
  • Documentation
    • Added a changelog entry describing the recovery-test timing adjustment.

The ordinary-failure take-over recovery test now uses a 2,000 ms attach hold. Its comments and a maintenance changelog entry describe the timing around the failing attempt’s final output and exit.

Changes: Take-over recovery

Layer / File(s) Summary
Attach hold timing
server/take-over.contract.test.ts, changelog.d/integration-flake-take-over-recovery.md
The recovery test sets the fixture’s attach hold duration to 2,000 ms and documents the expected timing around the failing attempt’s final output and exit. The changelog records this test change.

Priority: Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Possibly related issues

  • Issue 2225 describes broader determinism concerns around attach-delivery acknowledgement and server hold margins. This change addresses a related timing case in the recovery test, but does not implement those broader concerns.

Possibly related PRs

  • devswha/ovis#1783: This PR also changes attach-EOF recovery behavior and updates the same take-over contract test.

Suggested reviewers: wouldu-pres

Merge Risk: Minimal · up to 7597f

The test timing adjustment is scoped to the test fixture, with no actionable merge-blocking risk identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main test change: holding a failing attach's last line until process exit on busy runners.
Description check Passed The description explains the failure, cause, timing fix, test-only scope, and validation results. It includes the required Change information and provides Validation information under Proof and Local …
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the failure, cause, timing fix, test-only scope, and validation results. It includes the required Change information and provides Validation information under Proof and Local checks, although it does not use the exact Validation heading.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (1 skipped: 1 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Merging 7597f65. Test-only: in server/take-over.contract.test.ts the failing attempt in the ordinary-failure recovery case now holds its last line well past the fixture's exit, so a busy runner cannot read that line as an attach before the exit arrives. Diff read by the merge pass; no CodeRabbit review needed.

@devswha
devswha merged commit fb53bb0 into main Oct 29, 2026
19 checks passed
@devswha
devswha deleted the test/flake-hunt-1030 branch October 29, 2026 20:10
devswha added a commit that referenced this pull request Oct 29, 2026
…s exit too (#2396)

This is the second commit of #2373, which merged at its first commit
(7597f65) before this one reached the branch. It was reviewed there; it
is cherry-picked onto current main here.

Found by the flake-hunt lane on #2380's Integration run (job
123700768179): `server/take-over.contract.test.ts` "consumes a click
when the running ordinary retry succeeds, before later displacement"
failed at `:89`, where `pty-data` contained "terminal attach taken
over".

## Cause (test flake)

This is the same cause as #2373: the 100 ms default attach hold.
Displaced by another client's `--takeover`, herdr prints its teardown
and "terminal attach taken over", then exits. The bridge keeps an
attach's last line in the output tail for the hold (`tailTimer` in
`server/core/terminal-process.ts`) and drops it at a displaced exit
(`flushTail(displaced)`). An exit more than 100 ms after the line, as on
a busy runner, let the line reach clients first.

## Change

A 2 s hold for this test too, as #2373 gave the ordinary-failure test.
The changelog fragment from #2373 now names both tests.

## Proof

- **Fail-first:** with the fixture's `real` wrapper exiting 300 ms after
herdr (scratch), the old test failed 3/3 with CI's `not.toContain` and
the new one passed 3/3.
- **Whole file:** passed 9/9 three times. On current main with this
cherry-pick it passed 9/9 again (`bun run check run bun test
server/take-over.contract.test.ts`).
- **Local checks:** `bun run check fast` ok.

Test-only.

## Reviews

- **omo-native-code-reviewer:** APPROVE, CLEAR (on #2373's branch). It
confirmed the tail-hold mechanism and that the test still asserts the
consumed click, the retry without `--takeover`, and no taken-over text.
- LOW product note, not fixed here: production also holds the tail 100
ms, so on a loaded machine, when another client takes over, a user can
briefly see herdr's teardown line until the next attach redraws. A
longer tail hold for displacement would remove it.
- Test-only, so no Codex review (notes/pr-policy.md).
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