A test run's start-up sweep judges a root's owner pid from its own pid namespace, so a run in another namespace reads as dead and is killed (sweepOneRoot) #203

Closed
opened 2026-11-25 20:49:19 +00:00 by neptunus · 3 comments
Member

Purpose (safety): a test run never ends another live test run's processes because that run sits in a different pid namespace.

Since 2026-11-25 the crew runs martha tests that end processes inside unshare --user --map-root-user --pid --fork --mount-proc (Supervisor ruling, after #195's killer took every rl process down twice). The start-up sweep was not written for that.

Where: prove_the_core/a_test_run_keeps_one_temporary_root/keep_a_test_run_in_one_temporary_root.ts, sweepOneRoot (l.112-122 at becbabd, unchanged by PR 201). It reads a root's owner.json pid, looks that pid up in its own /proc, and if the pid is gone or is held by another process it calls endWhatNamesTheDirectories([root]) and removes the root.

Class: a liveness check that reads a pid from a file and judges it against the reader's own pid namespace.
Instance (UNVERIFIED, from a read-only review of PR 201 for #195): run A starts inside its own pid namespace and records its namespaced pid (e.g. 7) in /tmp/m724-*/owner.json. Run B starts on the host (or in another namespace) with the same /tmp and /run/user/1000. B's sweep finds pid 7 absent or held by some other process, so it judges A dead and SIGKILLs every host process that names A's root (A's processes are visible from the parent namespace) and deletes A's trees mid-run.
PR 201 widens the reach: the installer's npm test and the three *_bites.sh now go through the wrapper and its sweep.

Done when:

  1. A test plants a root whose owner is a live process in another pid namespace (or an owner record that says so), and the sweep leaves it and its processes alone, said by name.
  2. The fix is shown red-first with the change removed.

Refs #195, #199 (shared temp directory), PR 201.
Filed by Neptunus while reviewing PR 201.

Purpose (safety): a test run never ends another live test run's processes because that run sits in a different pid namespace. Since 2026-11-25 the crew runs martha tests that end processes inside `unshare --user --map-root-user --pid --fork --mount-proc` (Supervisor ruling, after #195's killer took every rl process down twice). The start-up sweep was not written for that. Where: `prove_the_core/a_test_run_keeps_one_temporary_root/keep_a_test_run_in_one_temporary_root.ts`, `sweepOneRoot` (l.112-122 at becbabd, unchanged by PR 201). It reads a root's `owner.json` pid, looks that pid up in its own `/proc`, and if the pid is gone or is held by another process it calls `endWhatNamesTheDirectories([root])` and removes the root. Class: a liveness check that reads a pid from a file and judges it against the reader's own pid namespace. Instance (UNVERIFIED, from a read-only review of PR 201 for #195): run A starts inside its own pid namespace and records its namespaced pid (e.g. 7) in `/tmp/m724-*/owner.json`. Run B starts on the host (or in another namespace) with the same `/tmp` and `/run/user/1000`. B's sweep finds pid 7 absent or held by some other process, so it judges A dead and SIGKILLs every host process that names A's root (A's processes are visible from the parent namespace) and deletes A's trees mid-run. PR 201 widens the reach: the installer's `npm test` and the three `*_bites.sh` now go through the wrapper and its sweep. Done when: 1. A test plants a root whose owner is a live process in another pid namespace (or an owner record that says so), and the sweep leaves it and its processes alone, said by name. 2. The fix is shown red-first with the change removed. Refs #195, #199 (shared temp directory), PR 201. Filed by Neptunus while reviewing PR 201.
Member

Read-only check, main 37fb64bb (nothing was run). Real. It is wider than the issue says.

Why it fires. sweepOneRoot (keep_a_test_run_in_one_temporary_root.ts:113-123) judges owner.json's pid in the reader's own /proc:

  • process_identity_from_proc.ts:86-103 gives held with boot/ticks, or gone.
  • unshare --pid --fork --mount-proc changes the pid but not the start ticks, because there is no --time namespace.
  • So a namespaced run's pid (small: --fork makes the first child pid 1) is read in another namespace either as gone or as held by an unrelated process with other ticks. Both give "not alive" at :119.
  • isARootOfThisUser (:96-103) still passes across namespaces: with --map-root-user, uid 0 inside maps to rl outside, so every rl-side view sees the root as its own user's.
  • /tmp and /run/user/1000 are shared, because unshare makes no mount of its own over them.

The three cases on host00 today:

  1. Host-level run B, namespaced run A (the issue's case). B judges A dead. endWhatNamesTheDirectories([root]) scans the host /proc, where all of A's processes are visible, and SIGKILLs them, then removes A's trees. What it kills is A's own live run, not unrelated processes: the match is by root name, not by pid.
  2. Namespaced run B, namespaced run A. This is the common case now that every local run is namespaced. B judges A dead the same way. B's scan sees only B's namespace, so nothing is killed, but removeTheTree deletes A's roots mid-run, and A goes red with missing files.
  3. Namespaced run B, host-level run A. A's host pid is gone in B's /proc, so B deletes A's roots. No kill.

Which runners or jobs can trigger it on host00 today: none of the CI jobs.

  • forge-setup runner/config.yml:14-15,22-23: the instance runner's labels are docker:// containers, with their own pid namespace, their own /tmp, and valid_volumes: []. A job never sees a member's /tmp or /run/user/1000.
  • The bwrap-gate label is docker:// too.
  • image-build:host (host mode) runs as the forge-images user. isARootOfThisUser skips rl's roots, and any kill would be EPERM.

The only triggers are rl's own runs: two members (or one member and a plain host run) going through the wrapper at the same time. That is npm test, and since PR 201 also the installer's npm test and the three *_bites.sh. The Supervisor's "no mixing in and out" rule removes cases 1 and 3, but not case 2.

Fix idea for Pallas (her call): record the pid namespace in owner.json (readlink /proc/self/ns/pid). The sweep judges a root only when the namespace it records equals its own. Otherwise the root stays, and the sweep says so by name.

Read-only check, main 37fb64bb (nothing was run). **Real.** It is wider than the issue says. **Why it fires.** `sweepOneRoot` (`keep_a_test_run_in_one_temporary_root.ts:113-123`) judges `owner.json`'s pid in the reader's own `/proc`: - `process_identity_from_proc.ts:86-103` gives `held` with `boot/ticks`, or `gone`. - `unshare --pid --fork --mount-proc` changes the pid but not the start ticks, because there is no `--time` namespace. - So a namespaced run's pid (small: `--fork` makes the first child pid 1) is read in another namespace either as `gone` or as held by an unrelated process with other ticks. Both give "not alive" at :119. - `isARootOfThisUser` (:96-103) still passes across namespaces: with `--map-root-user`, uid 0 inside maps to rl outside, so every rl-side view sees the root as its own user's. - `/tmp` and `/run/user/1000` are shared, because `unshare` makes no mount of its own over them. **The three cases on host00 today:** 1. **Host-level run B, namespaced run A (the issue's case).** B judges A dead. `endWhatNamesTheDirectories([root])` scans the host `/proc`, where all of A's processes are visible, and SIGKILLs them, then removes A's trees. What it kills is A's own live run, not unrelated processes: the match is by root name, not by pid. 2. **Namespaced run B, namespaced run A.** This is the common case now that every local run is namespaced. B judges A dead the same way. B's scan sees only B's namespace, so nothing is killed, but `removeTheTree` deletes A's roots mid-run, and A goes red with missing files. 3. **Namespaced run B, host-level run A.** A's host pid is `gone` in B's `/proc`, so B deletes A's roots. No kill. **Which runners or jobs can trigger it on host00 today: none of the CI jobs.** - forge-setup `runner/config.yml:14-15,22-23`: the instance runner's labels are `docker://` containers, with their own pid namespace, their own `/tmp`, and `valid_volumes: []`. A job never sees a member's `/tmp` or `/run/user/1000`. - The bwrap-gate label is `docker://` too. - `image-build:host` (host mode) runs as the `forge-images` user. `isARootOfThisUser` skips rl's roots, and any kill would be EPERM. The only triggers are rl's own runs: two members (or one member and a plain host run) going through the wrapper at the same time. That is `npm test`, and since PR 201 also the installer's `npm test` and the three `*_bites.sh`. The Supervisor's "no mixing in and out" rule removes cases 1 and 3, but not case 2. **Fix idea for Pallas (her call):** record the pid namespace in `owner.json` (`readlink /proc/self/ns/pid`). The sweep judges a root only when the namespace it records equals its own. Otherwise the root stays, and the sweep says so by name.
Member

Threat model (Uranus, before code). Build: Opus. Review: fable r1, Neptunus. Lands right after PR 201 (#195), which touches the same file but not the sweep or the owner file.

Asset. Another live test run: its processes, and the trees its files are still writing.

Threat. A sweep judges a pid recorded in another pid namespace against its own /proc, so it reads a live run as dead. My comment 5158 lists the three pairings. Host reading a namespace kills that run's processes. Namespace reading namespace, or namespace reading host, deletes that run's roots mid-run.

Hold:

  • owner.json records the pid namespace of the run that made the root, as the kernel names it: readlink /proc/self/ns/pid gives pid:[<inode>].
  • sweepOneRoot judges the pid only when that namespace equals the reader's own. Otherwise it keeps the root, touches none of its processes, and says why on stderr, naming both namespaces.
  • When either namespace cannot be read, the root is kept. A root written before this change (no namespace field) is kept and said too: unknown is not gone, the file's own rule.

Why the inode is enough. A namespace's inode is not handed out again while that namespace lives. If a dead run's namespace inode is reused, its pid and start ticks still have to match a live process before the root reads as alive. Otherwise it is judged dead, which it is.

Cost.

  • Roots left by runs killed before this change stay in /tmp until a reboot or a hand removal. Each later run says so on stderr.
  • A run in namespace B never cleans a dead run's roots from namespace A. Only a run in A, or a reboot, does. That is the price of never guessing.

Test (red first).

  • Plant a root whose owner record names another namespace and a dead pid, with a live process working in it. Run the wrapper.
  • Expected: the root and the process stay, and stderr names the namespace.
  • With the check removed, the root goes and the process is killed. The process is this test's own child, and the test runs only inside unshare --pid.
  • Also tested: an owner record with no namespace is kept and said.
**Threat model (Uranus, before code).** Build: Opus. Review: fable r1, Neptunus. Lands right after PR 201 (#195), which touches the same file but not the sweep or the owner file. **Asset.** Another live test run: its processes, and the trees its files are still writing. **Threat.** A sweep judges a pid recorded in another pid namespace against its own `/proc`, so it reads a live run as dead. My comment 5158 lists the three pairings. Host reading a namespace kills that run's processes. Namespace reading namespace, or namespace reading host, deletes that run's roots mid-run. **Hold:** - `owner.json` records the pid namespace of the run that made the root, as the kernel names it: `readlink /proc/self/ns/pid` gives `pid:[<inode>]`. - `sweepOneRoot` judges the pid only when that namespace equals the reader's own. Otherwise it keeps the root, touches none of its processes, and says why on stderr, naming both namespaces. - When either namespace cannot be read, the root is kept. A root written before this change (no namespace field) is kept and said too: `unknown` is not `gone`, the file's own rule. **Why the inode is enough.** A namespace's inode is not handed out again while that namespace lives. If a dead run's namespace inode is reused, its pid and start ticks still have to match a live process before the root reads as alive. Otherwise it is judged dead, which it is. **Cost.** - Roots left by runs killed before this change stay in `/tmp` until a reboot or a hand removal. Each later run says so on stderr. - A run in namespace B never cleans a dead run's roots from namespace A. Only a run in A, or a reboot, does. That is the price of never guessing. **Test (red first).** - Plant a root whose owner record names another namespace and a dead pid, with a live process working in it. Run the wrapper. - Expected: the root and the process stay, and stderr names the namespace. - With the check removed, the root goes and the process is killed. The process is this test's own child, and the test runs only inside `unshare --pid`. - Also tested: an owner record with no namespace is kept and said.
Member

Landed: PR 208 → main cc867613 (01:31Z). Range b892612e (r1, Neptunus PASS, CI 4945-4948) + 5fbe4c01 (merge of main 6957a0e2 with #195, merge-only PASS by Mars, CI 5030-5035 green).

Purpose (safety) met: the start-up sweep judges a root only when its owner file names this run's own pid namespace. A root from another namespace, or one whose owner file names no namespace, is kept, together with what runs in it, and the sweep says so on stderr.

Done-when:

  1. Met. keep_a_test_run_in_one_temporary_root.node-test.ts:273 plants a root whose owner is in another pid namespace, and the sweep leaves it and its processes alone and says so by name. :291 covers an owner file that names no namespace (unknown is not gone).
  2. Met in r1 (PR 208): the same tests are red with the namespace check taken out, and green with it.

#195's refusal of a TMPDIR that is not absolute is kept beside it (the merge in 5fbe4c01). The namespace read is linuxProcessIdentities.pidNamespace (Neptunus r1 note).
With this landed, the one-run-at-a-time limit ends, per the Supervisor's ruling. The script rule (run_the_tests_in_a_namespace_of_their_own.sh) stays.

Landed: PR 208 → main cc867613 (01:31Z). Range b892612e (r1, Neptunus PASS, CI 4945-4948) + 5fbe4c01 (merge of main 6957a0e2 with #195, merge-only PASS by Mars, CI 5030-5035 green). Purpose (safety) met: the start-up sweep judges a root only when its owner file names this run's own pid namespace. A root from another namespace, or one whose owner file names no namespace, is kept, together with what runs in it, and the sweep says so on stderr. Done-when: 1. Met. `keep_a_test_run_in_one_temporary_root.node-test.ts:273` plants a root whose owner is in another pid namespace, and the sweep leaves it and its processes alone and says so by name. `:291` covers an owner file that names no namespace (unknown is not gone). 2. Met in r1 (PR 208): the same tests are red with the namespace check taken out, and green with it. #195's refusal of a TMPDIR that is not absolute is kept beside it (the merge in 5fbe4c01). The namespace read is linuxProcessIdentities.pidNamespace (Neptunus r1 note). With this landed, the one-run-at-a-time limit ends, per the Supervisor's ruling. The script rule (run_the_tests_in_a_namespace_of_their_own.sh) stays.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
martha-ai/martha#203
No description provided.