Skip to content

test(cli): stop the CLI-21 check from freezing the provider it watches - #488

Merged
GeiserX merged 1 commit into
mainfrom
fix/cli21-flake
Oct 30, 2026
Merged

GeiserX merged 1 commit into
mainfrom
fix/cli21-flake

Conversation

@GeiserX

@GeiserX GeiserX commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Problem

The CLI-21 ask test (Ctrl-C ends akou ask, its harness processes end, the call keeps recording) failed once on check (macos-latest) with "timed out after 10000 ms waiting for the harness and its child to end", then passed on rerun. akou was not leaving processes behind. The test was holding up the cleanup it was waiting for.

Cause

The test checked for the harness with Bun.spawnSync(["ps", "-ax", ...]) on every poll. The app and its harness provider run inside the test process, so each ps froze the event loop that handles the abort, fires the 2 s SIGKILL timer and reaps the harness.

Evidence, from a loaded Mac with timing logs added to a scratch copy:

  • The provider's abort ran within 70 ms of the Ctrl-C every time, and the harness always exited by SIGTERM (exit 143), never by the SIGKILL fallback.
  • One ps -ax took 10 to 46 s under that load. A separate sampler outside the test process saw the same gaps between its own ps calls, and during the wait saw a <defunct> (dead, not yet reaped) process-group leader that was a child of a bun process. That matches the harness, though the sampler did not record pids to prove it.
  • In one run the 10 s wait returned after 46 s: a single poll had blocked that long. The provider saw the harness exit 1 to 100 ms after the test saw it gone, every time, because reaping had been waiting on the frozen loop.
  • The same blocking ps in afterAll overran its 5 s default. That was the other failure the loop turned up.

Fix

The fake harness already supports FAKE_PIDFILE. It now writes its own pid there, the child's pid goes to its existing file, and the test checks both with kill(pid, 0). No ps remains. afterAll kills from those files only if the test never saw both processes end, so it can't kill a reused pid. The product is unchanged. The ask test carries [CLI-21] itself, because the trap-coverage scanner does not read the id through describe.skipIf(...)(. TRAPS.md gets the trap.

Positive control: with the provider's abort kill removed, or with it killing only the harness and not its process group, the fixed test fails at its 10 s wait.

Repeat loop (the CLI-21 tests, 60 runs, yes burners in the loop's process group)

burners failed ask test median max
before 20 8 / 60 0.67 s 47.4 s
before 40 24 / 60 12.9 s 60.2 s
after 20 0 / 60 0.16 s 0.60 s
after 40 0 / 60 0.33 s 0.75 s

bun run check on the same machine: 3580 pass, 38 skip. Its one failure (TS-6, the trap had no test named after it) led to the test rename above, and the rename fixed it.

Summary by CodeRabbit

  • Tests
    • Updated terminal interruption coverage to verify that Ctrl-C exits with status 130 and terminates the harness and its child processes while call recording continues.
    • Improved process-exit checks to avoid blocking during cleanup.
  • Documentation
    • Documented the expected behavior when interrupting a terminal ask command.

The ask case polled `ps -ax` through Bun.spawnSync. The app and its harness
provider run in the test process, so each poll froze the event loop that
handles the abort, fires the SIGKILL timer and reaps the harness. Under load
one `ps -ax` took 10 to 46 s, so the 10 s wait failed while akou had sent
SIGTERM within 50 ms and the harness had died of it.

The fake harness now writes its own pid (FAKE_PIDFILE), and the test checks
the harness and its child with kill(pid, 0). Written down as trap CLI-21.
@coderabbitai

coderabbitai Bot commented Oct 30, 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 f367612 and 3dd4860.

Files selected for processing: 2
  • docs/TRAPS.md
  • tests/cli-terminal.e2e.test.ts

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

Walkthrough

The terminal test now uses PID files to check that the harness and child processes are alive before Ctrl-C and have exited afterward. The trap documents that recording must continue.

Changes: Terminal Ctrl-C process checks

Layer / File(s) Summary
Document and check Ctrl-C process lifecycle
docs/TRAPS.md, tests/cli-terminal.e2e.test.ts
The trap documents the expected process cleanup and recording behavior. The test uses PID files instead of ps, checks that the harness and child are alive before Ctrl-C, and waits for both to exit. It uses the repository fixture directly and avoids cleanup of processes already marked as ended.

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

Change: Other

Merge Risk: Minimal · up to 3dd48

No merge-blocking regression was identified in the updated process checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the CLI-21 test fix and accurately describes the change that prevents provider monitoring from freezing the test.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. 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: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. 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 2 functions across 1 files. (1 skipped: 1 unsupported.)

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

Warning

Some tools did not complete. Review the errors below.

Biome (2.5.15)
tests/cli-terminal.e2e.test.ts

Biome could not lint this file: configuration resulted in errors. Check the repository's Biome configuration and plugins.

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.

@GeiserX
GeiserX merged commit a3f0e6c into main Oct 30, 2026
42 of 44 checks passed
@GeiserX
GeiserX deleted the fix/cli21-flake branch October 30, 2026 20:31
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