Skip to content

fix(herdr): scope idle-shell child check to controlling terminal - #57

Merged
trillium merged 2 commits into
mainfrom
fix/robots-sq8p-herdr-idle-shell-tty
Aug 5, 2026
Merged

trillium merged 2 commits into
mainfrom
fix/robots-sq8p-herdr-idle-shell-tty

Conversation

@trillium

@trillium trillium commented Aug 5, 2026 •

Copy link
Copy Markdown
Owner

Intent

Fix fm_backend_herdr_pane_idle_shell_pid so it can converge on a box whose interactive login shell permanently forks an off-terminal helper (zsh-autosuggestions zpty), by scoping the idle-shell child check to the shell's own controlling terminal instead of requiring a flat zero children; stale Herdr projections must become cleanable again while a real pane job still refuses the proof.

What Changed

  • fm_backend_herdr_pane_idle_shell_sample now fetches tty= alongside pid=/ppid= from ps, and the awk check rejects a child only when it shares the shell's own controlling terminal — rather than requiring a flat zero-child count. A permanent rc-forked helper (e.g. the zpty that zsh-autosuggestions opens) sits on a different pty and no longer blocks the proof, so stale Herdr projections on such boxes are cleanable again.
  • The safety guarantee is preserved: any job the pane's shell actually owns (foreground or backgrounded with &) inherits the pane's controlling terminal and still causes the proof to refuse.
  • Two targeted unit tests cover the new convergence path (off-terminal rc helper passes) and the safety path (child on the pane's own terminal refuses); the fake ps in existing death-lab fixtures is updated to emit the new three-column format.

Risk Assessment

✅ Low: The fix is narrowly scoped - it adds one column to the ps invocation and replaces a flat zero-children check with a per-child tty comparison in a single awk block - with correct logic, all three fake-ps test fixtures consistently updated, and two new behavioral tests that drive the real proof function and assert observable output.

Testing

Ran the two newly-added behavioral unit tests exercising the TTY-scoped child check directly via a fake ps table: a child on a different TTY (simulating zsh-autosuggestions zpty) no longer blocks the idle-shell proof, while a child on the same terminal still correctly refuses it. The full fm-backend-herdr.test.sh suite (167 tests) and session-cleanup suite both passed with no regressions.

Evidence: Idle-shell proof test output

ok - herdr idle-shell proof: a permanent rc-forked helper on another terminal still proves the shell idle ok - herdr idle-shell proof: a job on the pane's own terminal, or an ambiguous shell row, still refuses

ok - herdr idle-shell proof: a permanent rc-forked helper on another terminal still proves the shell idle
ok - herdr idle-shell proof: a job on the pane's own terminal, or an ambiguous shell row, still refuses
Evidence: Full test run summary
Targeted test run — fix/robots-sq8p-herdr-idle-shell-tty
=========================================================

New behavioral tests added and exercised:

PASS: herdr idle-shell proof: a permanent rc-forked helper on another terminal still proves the shell idle
  → child zsh at pid 4243 on ttys009; shell at pid 4242 on ttys001 → proof converges, returns pid 4242

PASS: herdr idle-shell proof: a job on the pane's own terminal, or an ambiguous shell row, still refuses
  → child at pid 4243 on ttys001 (same as shell) → proof correctly refuses (empty output)
  → duplicate shell row (same pid twice) → proof correctly refuses (empty output)

Full test file results:
  fm-backend-herdr.test.sh:  167 passed, 0 failed
  fm-herdr-session-cleanup.test.sh:  all passed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-backend-herdr.test.sh — 167 tests passed, 0 failed; both new targeted tests (test_idle_shell_proof_converges_past_an_off_terminal_rc_helper, test_idle_shell_proof_refuses_a_background_job_on_the_pane_terminal) pass
  • bash tests/fm-herdr-session-cleanup.test.sh — all session cleanup tests passed
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Summary by CodeRabbit

  • Bug Fixes

    • Improved shell-idle detection by distinguishing jobs running on the shell’s terminal from unrelated off-terminal helper processes.
    • Cleanup now correctly rejects panes with active same-terminal jobs while allowing safe idle-shell cleanup.
  • Documentation

    • Clarified cleanup requirements and operational guidance around terminal ownership and unoccupied shells.
  • Tests

    • Added coverage for off-terminal helpers, same-terminal jobs, ambiguous process data, and end-to-end cleanup behavior.

fm_backend_herdr_pane_idle_shell_sample required the candidate shell own
exactly zero children. An interactive rc that forks a permanent off-terminal
helper makes that unsatisfiable forever: zsh-autosuggestions opens a zpty
whose child zsh becomes session leader of a DIFFERENT pty and lives for the
shell's lifetime. On such a box the proof could never converge, so
fm-herdr-session-cleanup.sh silently preserved every restored projection and
stale workspaces accumulated with no way to clear them.

Scope the child requirement to the shell's own controlling terminal instead.
This loses none of the safety the flat count was providing: any job the pane's
shell actually owns - foreground or backgrounded with & - inherits the pane's
controlling terminal and still refuses the proof. A child on another terminal,
or on none, is not pane work and would survive the shell's death anyway.
The "exactly one shell row" requirement is unchanged.

Verified on a live box: the zsh-autosuggestions zpty child sits on a different
tty than its parent shell (ttys126 vs ttys124), while `sleep 30 &` inherits the
shell's own tty. Both shapes are now covered by regression tests.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d0d40b6e-8346-47db-9d01-fa475490da43

📥 Commits

Reviewing files that changed from the base of the PR and between 3673dbd and b8b1640.

📒 Files selected for processing (7)
  • bin/backends/herdr.sh
  • bin/fm-herdr-session-cleanup.sh
  • docs/herdr-backend.md
  • docs/verification/runtime-backends.md
  • tests/fm-backend-herdr.test.sh
  • tests/fm-herdr-session-cleanup-e2e.test.sh
  • tests/fm-herdr-session-cleanup.test.sh

📝 Walkthrough

Walkthrough

Herdr now scopes idle-shell rejection to child processes sharing the shell’s controlling terminal. Cleanup documentation, verification, fixtures, and tests use the same terminal-aware requirement.

Changes

Herdr idle-shell cleanup

Layer / File(s) Summary
Terminal-scoped process proof
bin/backends/herdr.sh
Herdr reads PID, PPID, and TTY data. It rejects same-terminal children and allows off-terminal helpers.
Cleanup eligibility contract
bin/fm-herdr-session-cleanup.sh, docs/herdr-backend.md, docs/verification/runtime-backends.md
Cleanup requirements and warnings now describe an idle shell with no child process on its controlling terminal.
Process fixtures and proof tests
tests/fm-backend-herdr.test.sh, tests/fm-herdr-session-cleanup*.test.sh
Fixtures provide TTY-aware process rows. Tests cover accepted off-terminal helpers, rejected same-terminal jobs, duplicate shell rows, and convergence validation.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Cleanup
  participant Herdr
  participant ProcessTable
  Cleanup->>Herdr: Check restored shell
  Herdr->>ProcessTable: Read PID, PPID, and TTY
  ProcessTable-->>Herdr: Return process rows
  Herdr-->>Cleanup: Allow or preserve pane
Loading

Possibly related PRs

Suggested reviewers: kunchenguid

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: scoping Herdr's idle-shell child check to the controlling terminal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/robots-sq8p-herdr-idle-shell-tty

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.

@trillium
trillium merged commit 5c27061 into main Aug 5, 2026
11 checks passed
@trillium
trillium deleted the fix/robots-sq8p-herdr-idle-shell-tty branch August 5, 2026 13:07
trillium added a commit that referenced this pull request Aug 6, 2026
* herdr: scope the idle-shell child check to the shell's own terminal

fm_backend_herdr_pane_idle_shell_sample required the candidate shell own
exactly zero children. An interactive rc that forks a permanent off-terminal
helper makes that unsatisfiable forever: zsh-autosuggestions opens a zpty
whose child zsh becomes session leader of a DIFFERENT pty and lives for the
shell's lifetime. On such a box the proof could never converge, so
fm-herdr-session-cleanup.sh silently preserved every restored projection and
stale workspaces accumulated with no way to clear them.

Scope the child requirement to the shell's own controlling terminal instead.
This loses none of the safety the flat count was providing: any job the pane's
shell actually owns - foreground or backgrounded with & - inherits the pane's
controlling terminal and still refuses the proof. A child on another terminal,
or on none, is not pane work and would survive the shell's death anyway.
The "exactly one shell row" requirement is unchanged.

Verified on a live box: the zsh-autosuggestions zpty child sits on a different
tty than its parent shell (ttys126 vs ttys124), while `sleep 30 &` inherits the
shell's own tty. Both shapes are now covered by regression tests.

* no-mistakes(document): update stale "childless" guarantee in runtime-backends verification
trillium added a commit that referenced this pull request Aug 6, 2026
* herdr: scope the idle-shell child check to the shell's own terminal

fm_backend_herdr_pane_idle_shell_sample required the candidate shell own
exactly zero children. An interactive rc that forks a permanent off-terminal
helper makes that unsatisfiable forever: zsh-autosuggestions opens a zpty
whose child zsh becomes session leader of a DIFFERENT pty and lives for the
shell's lifetime. On such a box the proof could never converge, so
fm-herdr-session-cleanup.sh silently preserved every restored projection and
stale workspaces accumulated with no way to clear them.

Scope the child requirement to the shell's own controlling terminal instead.
This loses none of the safety the flat count was providing: any job the pane's
shell actually owns - foreground or backgrounded with & - inherits the pane's
controlling terminal and still refuses the proof. A child on another terminal,
or on none, is not pane work and would survive the shell's death anyway.
The "exactly one shell row" requirement is unchanged.

Verified on a live box: the zsh-autosuggestions zpty child sits on a different
tty than its parent shell (ttys126 vs ttys124), while `sleep 30 &` inherits the
shell's own tty. Both shapes are now covered by regression tests.

* no-mistakes(document): update stale "childless" guarantee in runtime-backends verification
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