Skip to content

pane ownership: observe the ORCA_PANE_KEEP=1 keep marker (orca #44, stage 3 piece b) - #66

Merged
nachumi-a2zoperations merged 2 commits into
blowzer/fork-onlyfrom
nachumi-a2zoperations/issue-44-keep-marker
Nov 16, 2026
Merged

nachumi-a2zoperations merged 2 commits into
blowzer/fork-onlyfrom
nachumi-a2zoperations/issue-44-keep-marker

Conversation

@nachumi-a2zoperations

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

Copy link
Copy Markdown

Refs #44: stage 3 piece (b), the keep marker, observe only. The design note was approved by the lane lead (~/nacho-run/orca-44-observe-ab.md, md5 a6013a07).

What it does

  • ORCA_PANE_KEEP=1 in a process's start environment marks its recorded entry kept: marker. The existing kept walk covers its children.
  • When it is read: ONCE, at close, for the recorded processes still present: at most 32 per close and 5 s in total (MARKER_CLOSE_BUDGET_MS), with the rest null. A verdict is needed only then, and the start environment does not change.
  • How it is read:
    • Linux: /proc/<pid>/environ.
    • macOS: per pid, two reads, each with a 2 s timeout and each one pid per call (see the measurement below):
      1. ps -wwo command= -p <pid>: the command line;
      2. ps -wwE -o command= -p <pid>: the command line, then the environment.
    • Only what follows the plain line is searched (anchored, after Fable-3's S1), so no argument can match. A command line that changed between the two reads is null. This replaces the note's KERN_PROCARGS2, so there is no native code (S3).
    • Same uid only: another uid's or root's process reads as null.
  • What the log shows:
    • each entry line: marker (true / false / null = not read);
    • the verdict kept: marker;
    • the daily line: topMarked (the 10 most common marked comms);
    • status().markerFailures.
  • A failed read leaves null ("not read"), never "no marker", and the close goes on.
  • No environment text reaches the log. Only the answer leaves pane-ownership-marker.ts. Three MUST rows pin it with a fake token:
    • the success path;
    • a ps that exits 2 with the token in stdout AND stderr;
    • a read that throws Error(<token>).
  • The two error-path rows were RED under Fable-3's mutation (the error message carries ps output, and applyKeepMarkers re-throws, so observeClose logs String(error)). They are green on the code. psEnvOutput names only the failure kind.

Observe only (S1)

  • The new module imports no signal or kill function. The stage-2 import-scan test still covers the folder, and a new test scans the module.
  • The observer is still given no way to signal. off in the mode file turns this off with the rest.

Remaining limit (named, after S1)

  • Arguments can no longer match: exact (echo ORCA_PANE_KEEP=1) or inside sh -c 'ORCA_PANE_KEEP=1 …'. Tests pin both.
  • macOS ps still joins the environment entries with spaces, so a word inside an environment VALUE (FOO='x ORCA_PANE_KEEP=1') reads as the marker. A test names it.
  • In observe this changes only a label. Linux is exact (NUL-separated entries).
  • Fable-3 S1, my choice: anchor the parse (not only reword), and name the residual.

CPU (S2), the stage-2 harness, 20 agent panes, 60 s, churn, MacBook in-process reader, helpers included (/usr/bin/time)

Three rounds, because the first two designs were too costly:

Design Marker reads / run Without markers With markers
1. Read every NEW entry each tick, one batched ps 608–677 7.4–7.7 % 22.4–22.9 %
2. Read at close only, one batched ps per close 31–34 7.1–7.3 % 16.4–18.7 %
3. Read at close only, one ps per pid (this PR) 41–58 7.0 % 7.35–7.41 %
  • The MacBook's load average was 31–71 during the runs, from other work, so the wall-time ratios are approximate.
  • Each row ran with and without markers back to back, under the same load.

The finding behind round 3: on macOS, ps -p with one pid reads only that process (~0 s CPU). With two or more pids (a comma list or repeated -p), it reads the whole process table: about 0.8 s of CPU at ~1,900 processes (measured; the same without -E).

  • The stage-2 lsof fd helper, which also passes a pid list, is NOT affected: lsof -p with 1, 2 and 30 pids costs 0.03–0.04 s each, measured today. Stage 2 needs no change.
  • Stage 2's ps table read uses -A on purpose, so it is also unaffected.

Tests

  • New pane-ownership-marker.test.ts:
    • environ parse (exact entry);
    • ps token parse (exact token; the argument-collision case);
    • the ps outcome rules;
    • the macOS reader: one call per pid, a gone pid = null;
    • the Linux reader: unreadable = null;
    • the 64 cap;
    • observer: kept: marker + child, nothing read per tick, a gone process not read;
    • a failed read = null + counted;
    • no env text in the log;
    • daily topMarked;
    • the S1 scan.
  • Red first: on fork-only d18bbcf4 the file failed at import.
  • Exact command for the count (Fable-3 asked):
    • cwd: the fork checkout;
    • PATH=$HOME/.local/node/node-v24.22.1-darwin-arm64/bin:$PATH node config/scripts/test-runtime/execution-policy/run-vitest.mjs run src/main/pty/process-retirement/pane-ownership src/main/daemon/terminal-host --config config/vitest.config.ts.
    • That was 109 at 468e4a0 and is 114/114 (21 files) at the new head: +5 rows (2 M1, 3 S1/budget).
  • src/main/pty/process-retirement/refused-tree-kill-root-termination.test.ts (not touched here): 2/2 pass with the same command and PATH. Fable-3's child.once is not a function there (on base too) looks like its borrowed node_modules/process-host resolution.

Gates (MacBook, Node 24.22.1 first on PATH for the run, no override)

  • pnpm check:changed --base=origin/blowzer/fork-only: 24/24 at 468e4a0 and again 24/24 at af41fdc, including typecheck (node, web, cli) and the unit step.
  • The pre-commit hook (oxlint, oxfmt) ran clean. The marker logic was moved into pane-ownership-marker.ts (applyKeepMarkers) to keep the observer under the 300-line limit.

Docs

  • docs/decisions/issue-44-pane-process-ownership.md, section 6: "As built" for (b), including the per-pid rule and the limit.

Next: piece (a), restart carry-over, as its own PR after this one.

…tage 3 piece b)

Observe only: no signal path (S1 holds; a test scans the new module).
At close, the recorded processes still present are read once for
ORCA_PANE_KEEP=1 in their start environment: /proc/<pid>/environ on
Linux, `ps -wwE -o pid=,command= -p <pid>` once per pid on macOS (a
pid list makes macOS ps read the whole process table: 0.8 s of CPU at
~1,900 processes). At most 64 per close. A marked process and its
children get the verdict `kept: marker`; the entry line carries
`marker` (true / false / null = not read); the daily line lists
topMarked. A failed read leaves null and counts markerFailures. Only the
answer is kept: no environment text reaches the log (a test pins it).
No native code (S3): it replaces KERN_PROCARGS2 from the design note.
Known limit, named: on macOS an ARGUMENT exactly ORCA_PANE_KEEP=1 reads
as the marker (a label only, in observe).

The CPU harness gains --no-markers for the comparison.

Refs #44

Signed-off-by: Nachumi Eliyahu <[email protected]>
… piece b)

M1 (secrets on the error path): two more MUST rows. A ps that exits 2
with the fake token in stdout AND stderr, and a read that throws
Error(<token>): neither the logs nor status() may contain it. Both were
red with Fable-3's mutation (error message carries ps output, and
applyKeepMarkers re-throws so observeClose logs String(error)), green
on the code. psEnvOutput keeps naming only the failure kind.

S1 (the macOS parse matched any word): it is now anchored to the
environment. Per pid, `ps -wwo command=` then `ps -wwE -o command=`;
only what follows the plain line is searched, so no argument can match
(exact, or inside sh -c). A command line that changed between the two
reads is null. Remaining, named limit: a word inside an environment
VALUE still matches (ps joins entries with spaces). Cap 32 pids per
close (two reads each).

Nit: MARKER_CLOSE_BUDGET_MS = 5 s in total per close; the pids left
are null (not read).

Refs #44

Signed-off-by: Nachumi Eliyahu <[email protected]>
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