Skip to content

fix(core): no herdr-core program outlives its pane unseen; list, adopt or end orphans - #125

Closed
colangelo wants to merge 13 commits into
masterfrom
issue/347-orphan-terminal
Closed

colangelo wants to merge 13 commits into
masterfrom
issue/347-orphan-terminal

Conversation

@colangelo

Copy link
Copy Markdown
Owner

Summary

herdrdev#347 https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347: a herdr-core program never outlives its pane unseen. On m4m, core terminal t2v (an idle zsh, labelled for gone pane w1H:p2) was found running with no pane after the 0.14.1 handoff.

Likely cause: a pane moved to another workspace gets a new id, but its core terminal kept the old herdr.pane_id label. On the next restore or handoff the attach was refused, the search by the new id found nothing, a fresh shell started, and the old terminal ran on unseen.

 pane move to another workspace
+  relabel the core terminal with the new pane id
 restore / handoff import, terminal labelled for an old id
-  refused -> fresh shell, old terminal orphaned
+  retry with the pane's saved former ids (also on every waiting retry), attach, relabel
 live handoff export
+  send former ids, as a session save does
 herdr server restart
-  kept every runtime, popups included
+  keeps only programs of panes the session saves
 close / respawn whose kill core does not confirm
+  warn + notice naming the terminal and `herdr pane orphans`
+API pane.orphan.list / pane.orphan.adopt / pane.orphan.end
+CLI herdr pane orphans | pane adopt <terminal> | pane end-orphan <terminal>
+  only this Mac's core orphans labelled for this session; run on a worker, never on the server loop
+  look in every core that answers, preferred or not; adopt saves the old id as a former id
+  end-orphan kills and sweeps the program's session like a close

Evidence

Row Test
workspace close ends its core terminals closing_a_workspace_ends_its_core_terminals
pane or tab close ends it; unconfirmed kill names it closing_a_pane_or_a_tab_ends_its_core_terminal, a_close_core_does_not_confirm_names_the_program_left_running
cross-workspace move keeps the program and takes the new id a_pane_moved_to_another_workspace_keeps_its_program_and_takes_its_new_id
restart keeps only saved panes' programs a_restart_keeps_only_the_programs_of_saved_panes
restore attaches a terminal labelled for a former id a_terminal_labelled_for_a_former_id_attaches_and_takes_the_new_one
startup orphan listed, not killed; adopt and end an_orphan_at_startup_is_listed_not_killed_and_can_be_adopted_or_ended
review fixes an_adopted_orphan_whose_relabel_failed_attaches_again_after_a_restart, a_pane_waiting_for_core_attaches_by_its_former_id_when_core_answers, a_slow_core_never_holds_the_server_loop_for_an_orphan_request, ending_an_orphan_sweeps_its_session_and_its_detached_jobs, the_orphan_commands_see_core_programs_after_a_switch_to_pty
  • Check: just check passes on the PR head (m4m).
  • Review: one independent review (Codex, GPT-6 Astra high) found 5 P2. All are fixed, each with a test that fails without it.
  • Found while doing this: Configurable environment variables per workspace/worktree herdrdev/herdr#404. The fake core's pid 4242 can make a test sweep a real session. It is fixed separately.
  • Known limits:
    • Machine panes are not relabelled on a move.
    • Orphan requests are not serialised, so an end racing an adopt of the same terminal is possible.

Merge Danger

Door: two-way

There are new API methods (advertised, fork-only) and no frozen-fixture change.

Blast Radius: medium

It affects restore, handoff, restart and close for core-backed panes. A pane found by a former id now attaches instead of starting fresh. herdr server restart no longer keeps popup runtimes.

A close whose terminal.kill core does not confirm now logs the terminal
at warn and posts a notice naming it, instead of leaving it running with
no word. A restart keeps only the programs of panes the session saves,
so a popup's program ends with the server. A pane moved to another
workspace relabels its terminal's herdr.pane_id with its new id; a
restore attaches a terminal still labelled for a former id of the pane
(moved before this, or before the relabel landed) and relabels it, where
it used to start the pane fresh and leave the old program running. A
live handoff now carries the panes' former ids, as a session save does.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
pane.orphan.list names this session's live core terminals that no pane
shows (the startup check's orphans); pane.orphan.adopt attaches a new
pane to one, in a new workspace or a new tab of a given one, starting
nothing; pane.orphan.end ends one with core's kill. Both act only on a
terminal that is still an orphan of this Mac's core. The CLI is herdr
pane orphans, herdr pane adopt and herdr pane end-orphan, and the
startup and close notices name it.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
…he pane

Workspace, tab and pane closes end their terminals; a close core does
not confirm names the program; a move keeps the program and relabels
it; a restart keeps only saved panes' programs; a terminal labelled for
a pane's former id attaches on restore; an orphan at startup is listed,
not killed, and can be adopted or ended. The fake core learns
terminal.label. The CLI inventory pins the new commands.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
…ys so

A respawn replaces the pane's program; when core did not confirm the
old one ended, it may run on with no pane, so the same notice names it.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
…a failed relabel never strands it

The adoption saves the orphan's herdr.pane_id as a former public id of the
pane that adopted it, as a move's is. A relabel that fails, or a restart
before it lands, leaves the terminal labelled for the old id; the next
restore finds it by that id instead of starting the pane fresh.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
…retry

A pane that waited because core did not answer at restore kept only its
current id; once core answered, a terminal still labelled for the id the
pane had before a move failed the ownership check on every retry. The
retry now tries the pane's former ids, as the first restore does, and
labels the terminal for the pane's id now.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
…rred or not

pane.orphan.list, adopt and end reused the startup scanner, which answers
none when this server neither prefers core nor shows a core pane. After a
switch to runtime = "pty" and the close of the last core panes with
kills core did not confirm, the commands the close's notice names found
nothing. They now scan every known core session that answers; the startup
check keeps its guard.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
…close does

pane.orphan.end called only terminal.kill, so a detached job of the
orphaned shell (nohup sleep 300 &) could outlive it, and with the
terminal finished no listing showed the job. The end now shares the
close's kill-and-sweep: it lists the program's session before the kill,
skips the sweep when that session is core's own, and signals the rest.
The startup test's ended orphan now runs a program of the test's own,
since the end sweeps its pid's session.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
…ver loop

pane.orphan.list, adopt and end scanned every known core session on the
server loop: up to two lists per session with 5 s timeouts each, so a slow
core froze input and requests for seconds. As worktree reads do, the
server hands them to a worker thread with the loop's claims. A list or an
end answers from the worker; an adopt's worker reads the orphan's record
and hands it back to the loop (AppEvent::CoreOrphanFound), which checks
the workspace and the claims again and adds the pane.

refs https://gitea.cat-bluegill.ts.net/AC-forks/herdr-max/issues/347
Work-Ref: WORK-05
@colangelo
colangelo force-pushed the issue/347-orphan-terminal branch from 11f8ff5 to 83c7f99 Compare November 29, 2026 13:57
@colangelo

Copy link
Copy Markdown
Owner Author

Landed on master after all-green CI and a passing just check.

@colangelo colangelo closed this Nov 29, 2026
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