Skip to content

fix(check): fail the run and keep evidence when teardown leaves processes behind - #1672

Merged
devswha merged 5 commits into
mainfrom
fix/check-teardown-failure
Oct 22, 2026
Merged

devswha merged 5 commits into
mainfrom
fix/check-teardown-failure

Conversation

@devswha

@devswha devswha commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Closes #1612.

Change

bun run check used to log a teardown problem and still report success: a process group that survived KILL, or an isolated herdr session that would not stop. It also deleted the temporary isolation directory, so the evidence was gone. On the self-hosted CI PC this let stray servers pile up unseen; one such leftover is herdr --session check-6e16b1, alive for 16 hours from another worktree's run.

scripts/check.ts

  • Teardown result: ending a process group now returns gone, surviving or error, with the group, the signals tried and the cause. Only ESRCH proves a group gone; EPERM is reported as unproven.
  • Collected failures: cleanup results are collected from signal handlers, output draining, concurrent lanes and the final cleanup, and the remaining independent steps still run after one fails.
  • Leftover children: a step that exits 0 but leaves a child in its group has that group ended. If the group cannot be ended, the run fails.
  • Stopping sessions: isolated herdr sessions are stopped before state is removed, and the stop command's exit status is checked. When the stop fails, the session's socket is probed: a refused connection or a missing socket counts as stopped. Without the probe, a server that needed SIGKILL, or crashed, would leave its socket and turn a green run red with no process left. Only a socket that still answers, or another error, stays a failure.
  • Failure handling: cleanup failures go into report.errors, and a run whose tests pass but whose teardown fails exits 1. The implicit isolation directory is then kept and its absolute path printed. A caller-named CHECK_DIR behaves as before.
  • Interrupted runs: they keep exit 130/143 and the interrupted status, with any cleanup failure recorded and printed. Draining a step's output after an interrupt has a bounded wait, so a group that cannot be stopped no longer hangs the checker.
  • One cleanup per group: the interrupt path and the step's own cleanup share one termination per group, so a failure is recorded once.

Elsewhere

  • scripts/check-report.ts: records teardown errors.
  • docs/development.md: says where kept evidence goes.
  • Tests (scripts/check.test.ts, scripts/check-report.test.ts): they use injectable seams for signals, probes and the clock, with no fixed sleeps. They cover:
    • a group surviving KILL;
    • EPERM;
    • a stale socket after a failed stop: refused counts as stopped, answering stays a failure;
    • SIGINT with a process outside the step's group holding stdout. This test fails when the drain deadline is removed;
    • overlapping interrupt and step cleanup;
    • the leaderless-group case, which used to time out in the full fast run.

Review

The branch was started in an earlier session (2 commits). An independent review then found three problems:

  • a step that exits 0 could leave a child alive and still succeed;
  • an interrupted run could wait forever;
  • the leaderless-group test timed out in the full fast run.

This PR rebases those commits onto main and fixes all three. A code-review agent then reviewed the whole branch: APPROVE, with two should-fix items and four notes, all fixed in 6879ca0:

  1. A stale socket after SIGKILL or a crash caused a false red. Fixed by the socket probe above, with seam and real-socket tests.
  2. The interrupted-drain bound had no failing test. It now has one, verified to fail without the bound.
  3. Notes:
    • duplicate errors when two paths ended the same group: de-duplicated;
    • the interrupted-cleanup failure was not printed to stderr: now printed;
    • an unrelated test's timeout had been raised to 180 s: reverted;
    • one test pinned exact probe times: it now asserts signal order and bounds.

Validation

  • HERDR_TEST_MODE=unit bun test scripts/check.test.ts scripts/check-report.test.ts --rerun-each 10: 520 pass, 0 fail.
  • bun run check fast: exit 0 (6,122 pass, 0 fail).
  • Real herdr: a herdr-backed check run started its isolated server check-3c8fed and left no herdr --session process behind. The /proc snapshots before and after list none started from the worktree, and the final group probe returned ESRCH.
  • Forced surviving group (through the seam): exit 1, the report names the group, and the isolation directory is kept with its path printed.
  • SIGINT after a step's readiness, with a cleanup failure injected: exit 130 in 68 ms, status interrupted, the group and EPERM named, the directory kept.

Not changed: .github/workflows/*, runner labels, CHECK_MAX_RUNS. Linux only was exercised locally; this PR's CI covers the native Windows install.

No changelog fragment: CI and contributor tooling only.

A check could report success while its teardown failed: endGroup only
printed a process group that outlived SIGKILL, the herdr session stops
ignored their exit status, and cleanup swallowed exceptions before
removing the isolated directory.

- endGroup returns an outcome (gone, surviving or error, the pgid, the
  signals tried and the cause). Only ESRCH proves the group empty; EPERM
  counts as a process still there. TERM, then KILL, keep their grace.
  Narrow kill/clock/wait seams make the escalation testable.
- Teardown stops every live herdr session (one whose socket is gone was
  already stopped; herdr answers its stop with exit 1), checks each
  stop's error, signal and status, and keeps going after a failure.
  It removes the implicit isolation directory only when nothing
  failed, process groups included; otherwise it keeps the directory and
  prints its absolute path.
- The report lists teardown failures in errors and the kept directory in
  evidence.retained. A passing run then exits 1 with status failure.
  An interrupted run keeps 130/143 and interrupted, never verified.
  Failures on the signal and output-drain paths settle instead of
  becoming unhandled rejections. CHECK_DIR stays the caller's, and
  output claims are still released at exit, after the final report.
- docs/development.md describes the kept directory.

Checked with bun run check fast and bun test ./scripts/check.test.ts
./scripts/check-report.test.ts. The new tests cover a leaderless group,
SIGKILL that cannot empty a group, EPERM, a cleanup exception, a
zero-exit command whose teardown fails, and SIGTERM/SIGINT keeping
143/130 with the kept directory. The CLI fixtures use a herdr stand-in.
An isolated check run against real herdr still passes and removes its
directory when one session is left running and another is already
stopped. No inherited-environment policy, runner routing or workflow
changes.
A command that exited 0 with its output closed could leave a process
running in its group: the run forgot the group, passed and removed its
isolated directory. Every step's process group is now tracked until it
is proved empty, ended when the step ends (closed output or not, the
concurrent unit tests included) and swept again before the teardown.

An interrupt whose step group could not be stopped waited for that step
forever. The run now records the failure, keeps its isolated state and
exits 130/143 without waiting for a step it could not stop.

Bound each lifecycle step of the leaderless-group test so a stall fails
with where it stopped, and size the CLI fixture deadlines for a loaded
PC.
Carry main's Ovis environment names into the teardown fixtures and wait for the leaderless descendant's signal handler before testing it. Drive surviving groups and permission failures through the CLI seam so successful commands cannot hide teardown failures, and cap interrupted output draining.
Probe failed session stops before retaining evidence: refused or missing sockets prove the isolated server is gone. Await probes before state removal. Exercise escaped stdout and overlapping SIGINT cleanup through deterministic seams, share pending group termination, and print drain failures. Restore the unrelated source-identity test timeout and assert grace bounds rather than poll arithmetic.
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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 8b5aaba and 6879ca0.

📒 Files selected for processing: 5
  • docs/development.md
  • scripts/check-report.test.ts
  • scripts/check-report.ts
  • scripts/check.test.ts
  • scripts/check.ts

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

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Checks now stop processes left running after a step and attempt all session cleanup, including when an earlier stop fails.
    • Cleanup failures are reported and the isolated directory is retained for investigation. A cleanup failure makes an otherwise successful run fail; interrupted runs preserve their interruption status and exit code.
  • Documentation
    • Updated Checks documentation to explain process cleanup, failure reporting, and retained directories.

The check runner now terminates processes left in step process groups and records process-group or session teardown failures. Failed cleanup retains and reports the isolated directory. Reports include retained paths, and the documentation describes cleanup behavior and exit statuses.

Changes: Check teardown lifecycle

Layer / File(s) Summary
Process-group cleanup outcomes
scripts/check.ts, scripts/check.test.ts
endGroup returns structured outcomes for terminated, surviving, or unproven process groups. Tests cover signal handling, grace periods, and group state.
Process-group cleanup in check runs
scripts/check.ts, scripts/check.test.ts
The runner tracks spawned process groups and ends remaining processes after steps, during interruption, and in concurrent runs. Cleanup failures are recorded, including when output draining times out.
Session teardown and retained evidence
scripts/check.ts, scripts/check-report.ts, scripts/check-report.test.ts, scripts/check.test.ts, docs/development.md
The runner attempts all session stops and cleanup actions. It retains isolation state on teardown failure and records retained paths and errors in reports. Tests cover report persistence, session-stop failures, and exit statuses. The documentation describes the cleanup behavior.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • CI: fail the check when its teardown leaves processes behind — The changes implement the issue’s objectives for reporting failed process and session cleanup, retaining isolation evidence, and preserving interrupted-run exit statuses.
Merge Risk: ⚪ Minimal · up to 6879c

This change makes check-run teardown failures fail the run and keep the isolation directory as evidence, with the behavior documented and tested. No concrete merge-blocking risk was identified in the supplied changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: teardown failures now fail the run and preserve evidence.
Description check Passed The description includes the required Change and Validation sections, explains the behavior and scope, references issue #1612, and lists reproducible test results and limitations.
Linked Issues check Passed The PR satisfies the coding requirements in [#1612]. scripts/check.ts returns structured process-group outcomes, treats only ESRCH as proof of removal, records EPERM as unproven, continues independe…
Out of Scope Changes check Passed The changes remain within [#1612]. Updates to scripts/check-report.ts, scripts/check-report.test.ts, scripts/check.test.ts, and docs/development.md support teardown reporting, retained evidenc…
Full details: Linked Issues check

Explanation

The PR satisfies the coding requirements in [#1612]. scripts/check.ts returns structured process-group outcomes, treats only ESRCH as proof of removal, records EPERM as unproven, continues independent cleanup, checks herdr stop results, probes failed stops, and stops sessions before state removal. Teardown failures enter report.errors; passed runs exit 1; interrupted runs retain exit 130/143 and interrupted status. Failed cleanup retains and reports the implicit isolation directory, while caller-named CHECK_DIR remains unchanged. The report schema, tests, injectable seams, and docs/development.md cover the requested reporting, testability, and evidence behavior. The supplied tests also cover surviving children and bounded interrupted output draining.

Full details: Out of Scope Changes check

Explanation

The changes remain within [#1612]. Updates to scripts/check-report.ts, scripts/check-report.test.ts, scripts/check.test.ts, and docs/development.md support teardown reporting, retained evidence, regression coverage, or documentation. No workflow, runner-label, CHECK_MAX_RUNS, agent-of-empires environment, or user-herdr signaling changes are reported.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

✨ 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
  • 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.

Review of #1672: the descendant waited on the stdin it inherits and sometimes exited on its own (8 failures in 410 runs, 'did not reach SIGTERM ... ENOENT'), which would turn Fast checks red. It now stays alive on a timer and SIGUSR1 releases it: 150 runs, 0 failures. The source-identity test gets its 180 s timeout back: it starts three nested runs, each allowed 30 s plus a slot wait, so bun's 5 s default fails it locally (CI passes --timeout 60000).
@devswha

devswha commented Oct 22, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit reviewed this PR (no actionable comments). A code-review agent also reviewed it three times before the merge; findings and how each was resolved:

Round 1 (APPROVE, 2 should-fix + 4 notes), fixed in 6879ca0

  • Stale socket. A herdr server that needed SIGKILL, or crashed, left its socket. herdr server stop then failed and turned a run red with no process left. Fixed: a failed stop now probes the socket; a refused connection or a missing socket counts as stopped. Covered by seam and real-socket tests.
  • Untested drain bound. The bound on draining an interrupted step had no failing test. It now has one, and that test fails when the bound is removed.
  • Notes:
    • Duplicate errors when two paths ended one group: de-duplicated.
    • The interrupted-cleanup failure is now also printed to stderr.
    • Exact probe times are no longer pinned.
    • A 180 s timeout was reverted. This was later found wrong and restored in round 2.

Round 2 (REQUEST_CHANGES), fixed in 979f8be

  • Flaky leaderless-group test (blocker). It failed 8 times in 410 runs: the descendant waited on its inherited stdin and sometimes exited on its own. It is now kept alive on a timer and released with SIGUSR1: 150/150 passed, against 2/150 before at the same load.
  • 180 s timeout. Restored on the source-identity test, which starts three nested runs. CI is unaffected because its unit runner passes --timeout 60000.

Round 3: APPROVE. The diff is only those two test changes; the reviewer saw 150/150 leaderless runs pass.

Left as a follow-up (low priority). After a spawn "error" event, the step's process group stays tracked until the final cleanup (scripts/check.ts:907).

Evidence from this PR's own CI: the Fast checks and Integration tests reports (report.json in the run's artifacts) have status success and no errors. The browser lanes passed, and a teardown failure would now have exited 1.

@devswha
devswha merged commit dc70d60 into main Oct 22, 2026
9 checks passed
@devswha
devswha deleted the fix/check-teardown-failure branch October 22, 2026 19:07
devswha added a commit that referenced this pull request Oct 22, 2026
….*.ts (#1673)

First PR of the i18n split: the strings that only the Settings dialog's
files use move out of the three big dictionaries into
`src/lib/i18n/settings.{ko,ja,zh}.ts`. `t()`, the English keys, every
translation, placeholders, the English fallback and all call sites stay
the same.

## What changes

- **Moved:** 281 keys in each language. The entry lines are cut byte for
byte from `src/lib/i18n.{ko,ja,zh}.ts` and keep the order they had in
each language's file. A key moves only when every file that uses it is a
Settings file: `components/SettingsDialog.tsx` (with `THEME_NAMES`),
`components/KeyBarSettings.tsx`, `components/SettingsControls.tsx`,
`components/TelemetryControls.tsx` and `lib/paletteSettings.ts`. A key
another feature also uses stays in the base file, for example "Settings"
(also used in CommandPalette and MachineSidebar) and "Pin/Unpin agent"
(AgentSidebar). The `// ---- <area> ----` sections are not used to
decide ownership: the 281 keys come from 12 different sections.
- **Composition:** each base file renames its object to `BASE` and
exports `KO_PARTS` / `JA_PARTS` / `ZH_PARTS` (`{ base, settings }`).
`KO` / `JA` / `ZH` are built from those parts with `Object.assign` and
keep their names and paths, so `src/lib/i18n.ts` and the three scripts
that import them by path are untouched. The first sentence of each base
header now says what the base file holds.
- **`src/lib/i18n.test.ts`:**
- The scan for `t()` calls now skips `lib/i18n/`. The old file-name
regex does not match the part files, and a dictionary header contains
`t("…")`.
- New "dictionary parts" tests fail when a key is in two parts, since a
spread silently keeps only the last copy. They report the key and both
part names, and also check that the composed size equals the sum of the
parts.
- They also fail when the three languages keep a key in different parts,
or when a part file passes 400 lines.
- **`CONTRIBUTING.md`:** the UI text rule now says where a feature's new
strings go. A string only one feature's files use goes in that feature's
`src/lib/i18n/` files when it has them; any other string, or one a
second feature starts using, goes in the base files.

This is not a move-only PR: alongside the moved lines it adds the
composition, the tests and the docs rule. The following split PRs
(terminal, composer, chat, …; one at a time) will contain only moved
lines, one import and one parts entry per feature, and the part file
header.

## Key list

I regenerated the list on this branch's base, `dc70d60a`, with the
ownership script from the split plan. That script collects keys the same
way as `i18n.test.ts`: `t()`/`tt()` literals plus the 13 label maps,
recorded per file. The list is identical to the plan's list from
`8b5aaba2`, with no difference. Main moved only by #1672, which touches
no i18n file.

## Checks

- **Same dictionaries:** the composed `KO`, `JA` and `ZH` (every key and
value) dumped as sorted JSON on `dc70d60a` and on this branch are
byte-identical (`EQUIVALENT`).
- **Only moved lines plus the composition:** `git diff
--color-moved=plain origin/main...HEAD` over the six dictionary files
shows every entry line as moved. The 72 non-moved `+`/`-` lines, 24 per
language, are:
  - the import and a blank line;
  - the 1-line header sentence, rewrapped to 3 lines;
  - `export const KO … = {` → `const BASE … = {`;
  - the 8-line parts block and composition;
- the part file's 6-line header, its `export const` line and its closing
`};`.
- **Same keys moved:** the keys of `SETTINGS_KO`, `SETTINGS_JA` and
`SETTINGS_ZH` each equal the 281-key list (`SAME-KEYS` for ko, ja and
zh). The scan still finds all 1,389 keys, the same count as main.
- **Part sizes:** each part file is 289 lines. `i18n.ko.ts` goes from
1,449 to 1,180 lines, `i18n.ja.ts` from 1,451 to 1,182 and `i18n.zh.ts`
from 1,453 to 1,184.
- `HERDR_TEST_MODE=unit bun test src/lib/i18n.test.ts`: 21 pass, 0 fail.
The missing, unused, placeholder and untranslated tests still run on the
composed dictionaries.
- Before opening, the new tests were run against two deliberate
breakages in a throwaway copy. A base key added to `SETTINGS_KO` fails
with `Settings (base, settings)`. One key moved back to the ja base
fails the placement test.
- `bun run typecheck`: passes. Both tsconfigs compile, including the
three browser scripts that import `KO`/`JA`/`ZH`.
- `bun run check fast`: passes.

Nothing drops out of a check's scope: no test file moves,
`scripts/ci-tests.ts` finds tests with a recursive glob, and
`src/conventions.test.ts` scans `src/**/*.{ts,tsx}`, which includes
`src/lib/i18n/`.

## Overlap with open PRs

#1639, #1598 and #1427 also edit `src/lib/i18n.{ko,ja,zh}.ts`. None of
them changes any of the moved lines; all three only add keys. If one of
them merges first, this branch is rebased, the key list is regenerated,
and any new Settings-only key moves into the part. If this PR merges
first, a new Settings-only key goes in `settings.*.ts` under the new
CONTRIBUTING rule. #1639 adds strings to `SettingsDialog.tsx`, so its
keys are the likely case.

No changelog fragment: users see no change.
devswha added a commit that referenced this pull request Oct 22, 2026
….*.ts (#1674)

Second PR of the i18n split (#2 in the split plan, after the Settings
pilot #1673). The strings that only the terminal's files use move out of
the three base dictionaries into `src/lib/i18n/terminal.{ko,ja,zh}.ts`.
`t()`, the English keys, every translation, placeholders, the English
fallback and all call sites stay the same.

## What changes

- **Moved:** 113 keys in each language, byte for byte, in the order each
language's file had them. A key moves only when every file that uses it
is a terminal file: `components/PaneTerminal.tsx`,
`components/PaneCanvas.tsx`, `components/KeyBar.tsx` (with its `ARROWS`
and `KEY_SPOKEN_NAMES` label maps), `components/FindBar.tsx`,
`components/TerminalViewportTools.tsx`,
`components/SplitDropPreview.tsx`, `components/TabStrip.tsx`,
`lib/terminalLabel.ts` and `lib/tabName.ts`. Keys these files share with
another feature stay in the base files.
- **Composition:** each base file gains one import and one `KO_PARTS` /
`JA_PARTS` / `ZH_PARTS` entry (`terminal: TERMINAL_KO`, …). Nothing else
in the base files changes.
- No test, docs or CONTRIBUTING change: the pilot's tests already cover
every part, and CONTRIBUTING already says where a feature's strings go.

## Key list

I regenerated the list with the split plan's ownership script on this
branch's base, `a717621f`. That script collects keys the same way as
`i18n.test.ts`: `t()`/`tt()` literals plus the 13 label maps, recorded
per file. It finds 113 terminal keys, identical to the plan's list from
`8b5aaba2`, with no key added or removed. Since then main gained only
#1672 (no i18n change) and the pilot #1673 (which moved only
Settings-only keys).

## Checks

- **Same dictionaries:** the composed `KO`, `JA` and `ZH` (every key and
value) dumped as sorted JSON on `a717621f` and on this branch are
byte-identical (`EQUIVALENT`).
- **`--color-moved` summary:** `git diff --color-moved=plain
origin/main...HEAD` over the base and part files shows all 339 removed
entry lines (113 × 3) as moved. The only non-moved lines are 33 added
lines, 11 per language:
  - the import;
  - the parts entry;
- the part file's 7-line header, its `export const` line and its closing
`};`.

  No line is removed other than moved entries.
- **Same keys moved:** the keys of `TERMINAL_KO`, `TERMINAL_JA` and
`TERMINAL_ZH` each equal the 113-key list (`SAME-KEYS` for ko, ja and
zh). The scan still finds all 1,389 keys, the same count as main.
- **Part sizes:** each part file is 122 lines, under the 400-line cap.
`i18n.ko.ts` goes from 1,180 to 1,069 lines, `i18n.ja.ts` from 1,182 to
1,071 and `i18n.zh.ts` from 1,184 to 1,073.
- `HERDR_TEST_MODE=unit bun test src/lib/i18n.test.ts`: 21 pass, 0 fail.
This covers missing, unused, placeholder and untranslated entries, a key
in two parts, and different placement across languages.
- `bun run typecheck`: passes.
- `bun run check fast`: passes (unit 6127 pass, 0 fail, 12 skip;
workflow syntax, generated types/themes, typecheck and build ok).

This PR contains only moved lines, one import and one parts entry per
language, and the part file header. It should qualify for the move-only
merge path if the parts entry and header are counted as part of the
move.

## Note

After this move the `// ---- key bar ----` section comment in each base
file has no entries left: its keys went to Settings (#1673) and here.
The comment is left in place to keep this diff move-only; the last split
PR can drop empty section comments.

No changelog fragment: users see no change.
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.

CI: fail the check when its teardown leaves processes behind

1 participant