Repository navigation
#44 stage 2: observe-only pane process ownership (Refs #44) - #47
Merged
nachumi-a2zoperations merged 4 commits intoNov 15, 2026
Merged
nachumi-a2zoperations merged 4 commits into
nachumi-a2zoperations merged 4 commits into
Conversation
… (Refs #44) The close-time parent walk misses a setsid tool shell once its parent has exited. Record that set while the link exists, then signal it by start time after the existing sweep.
…ry time (Refs #44) Answers the Fable architecture review of revision 1 (a79e161, ~/nacho-run/fable-review-orca-44.md, corrected 09:50Z): the mechanism is sound, the rule too wide (1 HIGH, 6 MED, 5 LOW). - The switch has three modes: off, observe (the default) and kill. Observe logs what would be signalled and why; it sends no signal (H1). - Four stages, each its own PR: this note; observe only plus a week of fleet logs; the rule chosen from the logs, per OS; then kill mode. - M2 decided: a durable job whose waiter is gone is KEPT at close, every time. The detach helper records the job's start in the sampler's form, and the daemon marks a matching entry and its children "kept". A job whose waiter is attached is stopped as today (the waiter forwards SIGTERM). Close also gets a reason, close or restart; a restart never selects from the set. - The set is closed under children (M3), shrinks after 25 complete reads plus a cap (M4), and is kept on a recycled root (M7). The read runs under TZ=UTC, with start time in ticks on Linux (L8). Own uid only (L10). A failing sampler is counted and logged (L11). The macOS reader gains uid and comm (M5). - The stage-3 proposal: signal only processes still wired to the pane (ctty or the agent's pipes), plus an ORCA_PANE_KEEP=1 marker. Linux gets a subreaper launcher or a cgroup (M6); macOS gets kqueue fork events (M5). Linux kill goes through a pidfd (L9). - The test table gains the L12 tests: observe sends no signal; the durable job kept every time, or stopped as today with its waiter attached; restart; M3; M4; TZ; recycled root; uid; sampler failure; keep marker; narrowed rule.
The sampler and the observe log of the design note, revision 2 (Fable
review r1 + re-read r2). It sends NO signal: there is no kill path in this
code at all (S1).
- src/main/pty/process-retirement/pane-ownership/:
- sets: the recorded set per agent pane, pure logic. Closed under
children (M3); forgotten after 25 complete reads, with a 4,096 cap
that drops absent entries first (M4); kept on a recycled root (M7);
own uid only (L10).
- table: one shared read per tick (pid, ppid, pgid, uid, lstart, comm)
under TZ=UTC (L8). Linux start ticks are read for recorded rows only.
- fds: the KIND of fd 0-2 (pipe, socket, pty, file, null, other) plus
identity and peer (S4). macOS: one batched lsof helper (2 s, SIGKILL);
Linux: /proc. An entry's fds are read only at its second sighting;
root fds at most every 30 s (S2, S3).
- durable: Orca durable jobs are kept every time (M2). Match = pid plus
a start within 10 s before the meta file's startedAt; the job runner
is unchanged. An async cached index (new ids parsed once, a missing
meta retried at most every 30 s); looked up only for entries younger
than 60 s.
- wiring: fds keyed by pid + start time and pruned with the sets.
- observer: a backoff timer (1 s with agent roots, 10 s without,
failures double up to 60 s), a start line naming the reader, failure
counter (L11), daily summary. A graceful close is logged once.
At close, restart or agent exit it logs present entries in full and
gone ones as a count, with verdicts. It is given readers, a clock and
a logger, never a signal function.
- mode: ORCA_PANE_DESCENDANT_OWNERSHIP, else the one-word file
pane-ownership.mode beside the daemon PID record, re-read every tick.
Missing, empty, unknown or kill read as observe; only "off" is off.
- Terminal host: notes the close before the kill. It observes after the
kill promise settled, never awaited, every call guarded. Agent roots are
listed for the sampler; a root exit is reported. Close is unchanged.
- Daemon: the observer is built for launched daemons on macOS and Linux
and started by the endpoint winner. pane-ownership.log is written
beside daemon.log.
- Close reason: main's replacement stop passes reason 'restart' down to
the daemon kill request. It is optional both ways; absent means close.
- libproc reader: uid and comm columns (JS only; the addon already
returns both; an older addon prints "?" and the read falls back to ps).
- The note records the stage-2 decisions: the M2 match, the restart
carry-over deferred to stage 3, the table of kill callers and their
reasons, the mode file, the fd rules, the log
place, and the tool-shell finding (stdout is a regular file).
- config/scripts/orca-fork/pane-ownership-cpu-harness.ts: the CPU
measurement (S2).
Tests: new or changed tests for sets, inputs, fds, observer (incl. the
S1 import check), host wiring (incl. throwing/hanging hooks), the reason
passthrough in main and daemon, and the libproc columns. Wide run (daemon,
pty, ipc/pty, runtime/terminal, libproc, providers): 2579 passed, 0 failed.
Preflight check-changed: every static gate passes (typecheck, format,
oxlint, all ratchets, import boundaries). Unit tests: the 11 failing tests
(6 files: agent-hooks server, worktree real-git, wsl prompt) fail the same
on base 7107a03; none of them is touched here.
O1, the "shares with the agent" answer: - Whenever an entry is due, its pane's agent root is read in the SAME lsof call (no 30 s limiter), and the entry line carries that at-record answer (sharesWithAgentAtRecord). - The root's id set is REPLACED at each read, keeping only ids a recorded entry of that pane still refers to (no ever-growing union). - At most 256 ids; the overflow is counted (agentIdsDropped) and the close and entry lines carry it with the root read's age (rootReadAgeMs). O2, the lsof helper: - lsof -n -P -l -b: no name lookups, never blocks on a dead mount. - A timeout, spawn error, cut-short answer, bad exit, or exit 0 with nothing printed is FdReadFailed, never "no fds". It is counted (status fdFailures), logged once per failing run (pane-ownership-fds-failing / -recovered), and the tick's fd reads back off (2 s doubling to 60 s; table reads go on). Entries due in the back-off stay pending and are read after it; a failed entry is marked failed until a later read succeeds. Exit 1 with nothing printed = every pid asked about exited: they read as missing. The one close read is always tried. - Each entry line says how its fds were read (fdsAtRecordRead: ok / missing / failed / none; fdsAtCloseRead); not read = null fds and a null yes/no. - Checked against real lsof on the MacBook: a socket pair, a pipe, /dev/null and regular files parse the same with and without -n -P -l -b. O3: the ps path ticks every 5 s (Linux, or macOS without the in-process reader); the start line names the interval. The note says the Dells get the 5 s tick (or stage 3's event reader) before the fork runs there. The CPU harness now follows the observer's own pace. O4: a pane still alive 30 s after its close was observed (5 min if the observation never came) goes back into the sample, logged as pane-ownership-close-unfinished and counted. CPU, re-measured on this code (20 panes, 60 s, % of one core, helpers included): MacBook in process 2.9 idle / 5.5 churn / 6.2 real jobs; ps fallback at 5 s 7.9 (was 18.6 at 1 s); Dell precision-7920 at 5 s 4.5 idle / 5.2 churn (was 10.8 / 13.3). The table is in the note. O5: the note's stage 4 section says the close reason becomes a required argument at every caller before any kill mode. Moved without change in behaviour: the closing bookkeeping to pane-ownership-closing.ts, the young-entry durable marking to pane-ownership-durable.ts, inheritKept to pane-ownership-report.ts (max-lines). Tests: pane-ownership-review3.test.ts (O1 same-call, replace and cap; O2 failure, pending through the back-off, recovery, close failure; O3 pace; O4 unfinished close); fds test for the lsof args and outcomes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #44 — stage 2: observe-only pane process ownership.
The sampler and the observe log from the design note (
docs/decisions/issue-44-pane-process-ownership.md, revision 2 + "As built"). It sends no signal. There is no kill path in this code (S1). The kill mode is stage 4.The Fable read (at e71e6fe) and what changed
Verdict: S1–S4 met, safe to merge, no HIGH. The two MEDs and the LOWs are fixed in the second commit:
lsofcall whenever an entry is due (no 30 s limiter), and the entry line carries that at-record answer (sharesWithAgentAtRecord). The root's id set is REPLACED at each read, keeping only the ids a recorded entry still refers to. At most 256 ids; the overflow is counted (agentIdsDropped), and the root read's age (rootReadAgeMs) is logged.lsofwent unnoticedlsof -n -P -l -b. A timeout, spawn error, cut-short answer, bad exit or empty exit 0 is a failed read: counted (fdFailures), logged once per failing run, and the tick's fd reads back off (2 s doubling to 60 s). Due entries stay pending through the back-off. Each entry line says how its fds were read (ok/missing/failed/none); a read that did not happen givesnull, never "no fds". Checked against reallsofon the MacBook: a socket pair, a pipe,/dev/nulland files parse the same with the new flags.pspspath (Linux, or macOS without the in-process reader) ticks every 5 s; the start line names the reader and the interval. The note says the Dells get this tick, or stage 3's event reader, before the fork runs there.pane-ownership-close-unfinishedand counted.The Leader's merge conditions
pane-ownership-observer.test.tsscans the folder's imports. The host-wiring tests show that hooks which throw, reject or never settle leave the kill exactly as without them.lsof -n -P -l -bhelper per tick (2 s timeout, then SIGKILL); Linux reads/proc. The table read uses the existing libproc addon (JS columns only), withpsas the fallback.offin the mode file takes effect at the next tick, with no rebuild or restart.pane-ownership-inputs.test.tsCPU (S2), measured on this code, 20 agent panes, 60 s
config/scripts/orca-fork/pane-ownership-cpu-harness.ts, under/usr/bin/time -p, now at the observer's own pace. "Helpers included" = user+sys of the harness and every helper it waited on (ps / lsof), divided by wall time, as a share of ONE core. The second commit's code; fd failures were 0 in every run.psfallbackps+/procps+/procNotes on the numbers:
tsxstart-up and compiling the harness (about 1 s of CPU), so they read high; the Dell runs a pre-bundled.cjs.What to know before merging
pane-ownership.mode, in the daemon folder beside the PID record. It is re-read every tick.ORCA_PANE_DESCENDANT_OWNERSHIPwins when set. Missing, empty, unknown andkillall read as observe.pane-ownership.log, besidedaemon.log.reason: 'restart'on the daemon kill request. The field is optional both ways, and absent means close. The note has the table of kill callers.Tests
pane-ownership-review3.test.ts, which covers O1 (same-call read, replace, cap), O2 (failure, pending through the back-off, recovery, close failure), O3 (the pace) and O4 (unfinished close).check-changedon125c582a: 26 of 27 checks pass (typecheck, format, oxlint, every ratchet, import boundaries, localization). The step limit was raised to 120 min, so the unit step ran to the end this time; on the first head it had stopped at the 30-min limit.vitest relatedon every changed file: 44,624 tests, of which 43,052 pass and 151 fail, in 113 files. None of those files is#44code or a#44test. They are agent-hooks, cross-version e2e wire tests, Electron browser and plugin tests, real-git worktree tests and persistence.7107a03dtoo: the same 113 files were run there with the same runner.src/main/git,src/shared/git,src/main/browseror the process-host package.