Skip to content

#44 stage 2: observe-only pane process ownership (Refs #44) - #47

Merged
nachumi-a2zoperations merged 4 commits into
blowzer/fork-onlyfrom
nachumi-a2zoperations/issue-44-stage2-observe
Nov 15, 2026
Merged

nachumi-a2zoperations merged 4 commits into
blowzer/fork-onlyfrom
nachumi-a2zoperations/issue-44-stage2-observe

Conversation

@nachumi-a2zoperations

@nachumi-a2zoperations nachumi-a2zoperations commented Nov 15, 2026 •

Copy link
Copy Markdown

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:

Point Now
O1 MED "shares with the agent" said no too often The root is read in the SAME lsof call 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.
O2 MED a stalled lsof went unnoticed lsof -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 gives null, never "no fds". Checked against real lsof on the MacBook: a socket pair, a pipe, /dev/null and files parse the same with the new flags.
O3 LOW 18.6 % on ps The ps path (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.
O4 LOW a close that did not finish was never sampled again 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.
O5 LOW the reason must be required before kill Written into the note's stage 4 section.

The Leader's merge conditions

Condition Where
S1 No code path from the set to a signal, with a test The observer gets readers, a clock and a logger; it is never given a signal function. pane-ownership-observer.test.ts scans the folder's imports. The host-wiring tests show that hooks which throw, reject or never settle leave the kill exactly as without them.
S2 CPU measured on the MacBook and one Dell, helpers included See the table below.
S3 No new native code inside the terminal host macOS fds come from ONE batched lsof -n -P -l -b helper per tick (2 s timeout, then SIGKILL); Linux reads /proc. The table read uses the existing libproc addon (JS columns only), with ps as the fallback. off in the mode file takes effect at the next tick, with no rebuild or restart.
S4 The log records the KIND of fd 0/1/2 pipe, socket, pty, file, null or other, plus identity and peer, at record and at close. There is a socket-pair fixture, and the real tool-shell case (stdout is a regular file).
(a) M2 deviation and stage-3 deferral in the note The note's "As built" section.
(b) Missing, empty or unknown mode file reads as observe, with a test pane-ownership-inputs.test.ts
(c) CPU numbers in this body Below, and in the note.

CPU (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.

Machine Reader Tick Load Sampler alone Helpers included Before the Fable fixes
MacBook in process (libproc), as the app reads on macOS 1 s idle 1.7% 2.9% 3.1%
MacBook in process 1 s churn 2.1% 5.5% 7.3%
MacBook in process, real durable-job folder (~1,800 jobs) 1 s churn 3.0% 6.2% 8.9%
MacBook ps fallback 5 s churn 0.6% 7.9% 18.6% (1 s)
Dell precision-7920 (Slurm) ps + /proc 5 s idle 0.6% 4.5% 10.8% (1 s)
Dell precision-7920 ps + /proc 5 s churn 1.0% 5.2% 13.3% (1 s)

Notes on the numbers:

  • The Mac rows include tsx start-up and compiling the harness (about 1 s of CPU), so they read high; the Dell runs a pre-bundled .cjs.
  • They exclude the rest of the daemon's work; the harness runs only the sampler.
  • The harness launches its own panes (setsid via a launcher shell) and kills only those at the end.
  • The Mac load average was 30–60 during the runs, from other work. CPU time is still the right measure, but the wall-time ratios are approximate.
  • The fork is not installed on the Dells. The Dell rows are the harness run there through Slurm, not a running Orca.

What to know before merging

  • The mode file is pane-ownership.mode, in the daemon folder beside the PID record. It is re-read every tick. ORCA_PANE_DESCENDANT_OWNERSHIP wins when set. Missing, empty, unknown and kill all read as observe.
  • The observer runs only in a daemon built from this code, and only in the endpoint winner. The log is pane-ownership.log, beside daemon.log.
  • The close reason: main's replacement stop (account move, renderer or Codex restart) sends 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.
  • Restart carry-over is deferred to stage 3. It is written in the note.

Tests

  • The pane-ownership folder and the host wiring: 56 tests, all pass. That includes 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).
  • Preflight check-changed on 125c582a: 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.
  • The unit step runs vitest related on every changed file: 44,624 tests, of which 43,052 pass and 151 fail, in 113 files. None of those files is #44 code or a #44 test. They are agent-hooks, cross-version e2e wire tests, Electron browser and plugin tests, real-git worktree tests and persistence.
    • 102 of the 113 files fail on base 7107a03d too: the same 113 files were run there with the same runner.
    • 13 files had a failure seen only on this head in that run (11 pass on base; 2 fail there, but with other tests). They were rerun on head and on base, one run after the other with 2 workers: they then fail on both, or pass on this head.
    • The three that still failed only on this head (git-admission-storm, a 5 s child-start deadline; two Electron popup suites, a 60 s hook deadline) pass when run alone on this head, twice each: 1/1, 15/15, 14/14. This branch touches nothing under src/main/git, src/shared/git, src/main/browser or the process-host package.
    • The Mac's load average was 60–100 throughout.

… (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.
@nachumi-a2zoperations
nachumi-a2zoperations merged commit cdfaf80 into blowzer/fork-only Nov 15, 2026
2 checks passed
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