Skip to content

fix: recognize live Codex watchers across Linux PID namespaces - #7697

Open
co1smos wants to merge 5 commits into
kunchenguid:mainfrom
co1smos:fm/codex-pid-liveness-fix
Open

co1smos wants to merge 5 commits into
kunchenguid:mainfrom
co1smos:fm/codex-pid-liveness-fix

Conversation

@co1smos

@co1smos co1smos commented Oct 23, 2026 •

Copy link
Copy Markdown

Intent

Fix #7620: on Linux, Codex’s workspace-write sandbox can expose a different PID namespace from the host, causing the Stop guard to reject a live watcher and incorrectly report TURN WOULD END BLIND.

Allow the Stop guard to recognize a live watcher across that namespace boundary, with the fallback restricted to Linux and Codex. Preserve strict lifecycle checks and reject stale or mismatched watcher evidence. Leave other platforms and agent runtimes unchanged.

What Changed

  • Add a Linux/Codex-only Stop-guard fallback that verifies cross-namespace watcher liveness using /proc, pidfds, process identity, fresh heartbeat evidence, and an unchanged lock snapshot without changing lifecycle authority.
  • Record PID namespace and boot ID in watcher locks, clean up the added metadata, and export the resolved FM_HOME from Linux/Codex checkpoints.
  • Add capability-gated cross-namespace guard regressions and direct/supervision-host checkpoint coverage; document fallback requirements and the remaining native Codex Stop verification gap.

Risk Assessment

⚠️ Medium: The read-only fallback is confined to Linux/Codex and preserves strict lifecycle checks, but its behavior at the actual native Codex Stop boundary remains explicitly unverified.

Testing

The targeted guard, watcher-lock, and checkpoint regressions passed, and live Codex 0.163.0 sandbox checks reproduced the original rejection and verified the fix, safety negatives, default-home propagation, wake delivery, and cleanup after correcting lab-only setup; transcripts and persisted-state evidence were retained, with no native model-driven Stop or native non-Linux claim and no screenshot needed for this CLI-only change.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A live Codex workspace-write sandbox watcher no longer produces a false blind-stop alarm ✅ pass live verified/live-pid-results.json: direct-published-watcher, direct-strict-rejects-inner-pid, baseline-reproduces-false-blind-stop, fixed-guard-removes-false-blind-stop.
Corrupted, stale, missing, or dead watcher proof cannot authorize a supervised stop ✅ pass live verified/live-pid-results.json: reject-mismatch-, reject-beacon-age-, reject-absent-beacon, reject-missing-*, reject-writable-lock, missing-python-blocks, and *-dead-holder-with-fresh-saved-proof-bl…
Selecting a non-Codex primary preserves strict cross-namespace blocking ✅ pass live verified/live-pid-results.json: non-codex-retains-strict-*; targeted-regression.log: Linux namespace fallback regression.
Direct and hosted Codex checkpoints propagate an initially unset FM_HOME into their actual watcher ✅ pass live verified/live-pid-results.json: direct-published-watcher, host-published-watcher, and host-cross-namespace-stop-allowed; verified/host-sandbox.stdout.
Checkpoint wake delivery and quiet hosted completion release their watcher locks ✅ pass live verified/live-pid-results.json: direct-checkpoint-close, host-checkpoint-close, direct-cleanup, host-cleanup, and *-lab-removed.
Evidence: Verification report, scenario results, setup corrections, and evidence limits

Source: Verification report, scenario results, setup corrections, and evidence limits

# Linux/Codex PID-view live verification

## Tested revision and scope

- Tested head: `3695d70a9e3990b7875e9001a7d4307219a96e01`.
- Comparison base: `8b1618a49511d67b247f5f8091868b812bfcae2d`.
- Host: Linux; installed runtime: `codex-cli 0.163.0`; real PID namespaces and Python `os.pidfd_open` available.
- No tracked source/test changes, no linter or static-analysis invocation, no full-suite invocation, no pipeline-control or publication commands.
- All labs, isolated Codex homes, copied product code, generated records, and caches were created below the gate worktree's `.test-pid-tmp/` and removed.
- No operator home, login, credentials, shared app-server, default tmux server, Herdr session, or fleet was used.

## Named scenarios and observed results

\### 1. A live Codex sandbox watcher no longer causes a false blind-stop alarm

The driver minted marked lab homes with `bin/fm-lab-home.sh create`, extracted the tested tracked tree into each home, initialized only their private Git metadata, and invoked the installed `codex sandbox -c 'sandbox_mode="workspace-write"' -- ...`.
The running product was the actual `fm-watch-checkpoint.sh`, `fm-watch.sh`, `fm-lock.sh`, and `fm-turnend-guard.sh`, not a substituted watcher or harness binary.
The guard's outside-namespace invocation used the production supervision-primary selection pin, not fabricated ancestry.

Direct-path evidence:

- Watcher recorded namespace-local PID `198`; `/proc` independently mapped its `NSpid` to host PID `216196`.
- Observer namespace `pid:[4026531836]` differed from watcher namespace `pid:[4026532917]`.
- The actual watcher environment contained the correct `FM_HOME` even though the sandbox started with it unset.
- Inside the namespace, the guard exited `0` without an alarm.
- Outside the namespace, ordinary `fm_watcher_healthy` exited `1`, while the fixed production guard exited `0` with empty stdout/stderr.
- As a counterfactual, replacing only the disposable lab's guard with the base commit's guard produced exit `2` and `TURN WOULD END BLIND` against the same running watcher and metadata; restoring the candidate guard returned exit `0`.

\### 2. Invalid, stale, missing, and dead watcher evidence still blocks

Against the real sandbox watcher, the driver independently changed each persisted proof and invoked the real guard.
Every negative returned exit `2` with the blind-stop diagnostic:

- changed process start-time identity;
- wrong boot ID, home, watcher path, namespace, or PID;
- 400-second-old, future-dated, or absent beacon;
- absent namespace, boot-ID, or identity field;
- group/world-writable resolved lock directory;
- Python unavailable from an isolated PATH containing real host tools but no Python;
- saved real watcher proof replayed with a newly touched beacon after its namespace had exited.

The real watcher was frozen during ownership-record mutation so its own independent self-eviction did not invalidate later cases.
Restoring all evidence while the watcher was live returned exit `0`.
Guard invocations did not alter the live watcher's persisted lock proof.

\### 3. Other primary-harness selections retain strict blocking

The same running cross-namespace watcher was evaluated with production primary selections for Claude, Cursor, OpenCode, Pi, pi-signed, Grok, Kimi, Gemini, Muse, Rovo, omp, agy, Devin, Command Code, Polytoken, Cortex, and Hermes.
Every non-Codex selection returned exit `2` rather than using the fallback.
These are live checks of Firstmate's guard selection interface, not claims that all vendor CLIs were launched.
The targeted existing namespace regression additionally exercised the non-Linux branch using a controlled platform shim; this is not native non-Linux evidence.

\### 4. Default-home propagation works on direct and supervision-host checkpoint paths

Both real sandbox scenarios started with `FM_HOME` absent, acquired their own session lock through `fm-lock.sh`, and ran the actual checkpoint.
Each running watcher published a matching process-environment `FM_HOME`, PID namespace, current boot ID, full identity, and watcher path.
On the hosted path, the recorded inner/host PID mapping was `367` / `221882`, with namespace `pid:[4026532904]`; the strict predicate rejected it from outside and the Codex guard accepted it.
No model engine or login was necessary: the hosted scenario stayed quiet until its normal park boundary.

\### 5. Watcher wake delivery, checkpoint boundaries, and cleanup remain functional

On the direct path, writing a terminal status drove the real watcher, which printed `signal: .../state/scenario.status`, persisted the wake queue, and returned checkpoint exit `0`.
The hosted checkpoint returned exit `124` and `checkpoint: no actionable wake within 30s`; its product ledger recorded `primary=codex` followed by its own `boundary` event.
Both paths removed all `.watch.lock*` artifacts before the dead-proof replay check and lab removal.
Neither ordinary strict liveness nor the guard mistook a fresh beacon after namespace exit for live supervision.

## Commands and supporting regression

`` `sh
unshare -rpf --mount-proc true
python3 -c 'import os; f=os.pidfd_open(os.getpid()); os.close(f)'
codex --version
codex sandbox --help
TMPDIR="$PWD/.test-pid-tmp" bin/fm-test-run.sh \
  tests/fm-turnend-guard.test.sh \
  tests/fm-watcher-lock.test.sh \
  tests/fm-watch-checkpoint.test.sh
python3 ~/.no-mistakes/evidence/01M6QHJDG177QJ4SB557V6WXWQ/live-pid-driver.py \
  "$PWD" ~/.no-mistakes/evidence/01M6QHJDG177QJ4SB557V6WXWQ/verified
`` `

The targeted runner completed successfully and its Linux namespace regression actually ran rather than capability-skipping.
Its internal MSYS-only process-identity case was skipped on Linux, as expected and unrelated to this Linux-only fix.
The complete raw log is `targeted-regression.log`.
Product responses, exact persisted proofs, namespace mappings, diagnostics, checkpoint outputs, and cleanup observations are in `verified/live-pid-results.json` and `verified/transcript.log`.
The repeatable driver is `live-pid-driver.py`.

## Setup corrections and evidence limits

The initial CLI probe used the obsolete `codex sandbox linux` spelling, which this version interprets as the command to execute; current `codex sandbox -- ...` succeeded.
The first sandbox probe also required creating its explicitly isolated `CODEX_HOME` directory before invocation.
An early hosted lab retained an extra shell wrapper, pushing harness ancestry beyond the detector's bounded walk and omitting optional namespace metadata; executing the checkpoint in place of that wrapper restored the representative process topology and passed.
A later adversarial attempt changed a live watcher's ownership record while it was still polling; the watcher correctly exited on that mismatch, so a subsequent test signal found no process.
The final driver freezes that real watcher before proof mutation and the complete re-drive passed.
Earlier transcripts are retained as setup history, not presented as product failures or successful runs.

This evidence exercises a real installed Codex workspace-write sandbox, real Linux namespaces/pidfd, and production Firstmate interfaces.
It does **not** establish native model-generated Codex Stop-hook dispatch or native non-Linux execution, and no new native model-driven Stop experiment was run.
Those are explicitly not inferred from a manually supplied guard payload or a platform shim.
There is no rendered UI change; CLI transcripts and persisted product state are the reviewer-visible artifacts, so screenshots are not applicable.
Evidence: Targeted guard, watcher-lock, and checkpoint regression output

Source: Targeted guard, watcher-lock, and checkpoint regression output

FM_TEST_BEGIN 2026-11-06T04:30:13Z tests/fm-watcher-lock.test.sh family=watcher-wake-lock expected_gate_skip=none
FM_TEST_BEGIN 2026-11-06T04:30:13Z tests/fm-turnend-guard.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - disposable watcher refuses inherited state outside its marked lab
ok - tombstone cleanup respects a live reaper and recovers a recycled reaper pid
ok - wait deadline diagnoses and reaps a stopped test child without hanging
ok - simultaneous watcher starts leave exactly one live process
ok - fm_pid_identity real ps fallback is locale-invariant
ok - fm_pid_identity is locale-invariant across LC_ALL/LC_TIME
ok - fm_pid_identity ps fallback is terminal-width-invariant
ok - /proc process identity ignores simulated btime changes
ok - /proc process identity detects pid reuse
ok - MSYS /proc process identity regression skipped on non-Windows host
ok - killed watcher stale lock is reclaimed
ok - dead watcher reclaim fails promptly when downtime marker cannot be published
tests/fm-watcher-lock.test.sh: line 2369: 10305 Killed                  FM_STATE_OVERRIDE="$state" bash -c '
    . "$1"
    fm_lock_remove_path() {
      if [ "$1" = "$STATE/.watch.lock" ]; then
        kill -KILL "${BASHPID:-$$}"
      fi
      return 1
    }
    fm_lock_try_acquire "$2"
  ' _ "$LIB" "$lockdir" > /dev/null 2>&1
ok - stale watcher reclaim publishes durable recovery evidence before clear
ok - live watcher lock with stale heartbeat is actionable
ok - live watcher lock with a beacon past the hard bound is replaced, under it is still refused
ok - a fresh watcher replaces a live holder whose pre-UTC-pin identity no longer recomputes, and the old holder stands down unsignalled
ok - a replaced holder stands down cleanly even when its successor has already exited and released the lock
ok - guard banner leads when down with pending wakes (repair-after-drain) and stays silent when live and fresh
ok - concurrent fm_lock_try_acquire yields exactly one winner
ok - dead-pid stale lock is reclaimed by a single acquirer
ok - concurrent stale-lock steal yields exactly one winner
ok - dead steal owner is reclaimed once without a nested steal marker
ok - dead nested steal chain from an interrupted reclaim is recovered
ok - a competing reaper cannot remove the successor's steal mutex
ok - a steal mutex abandoned by this process does not block its own reclaim
ok - a steal reap interrupted in this process is resumed from its own tombstone
ok - live steal mutex is not reclaimed
ok - live-held lock is not stolen
ok - lock whose recorded holder pid was reused by a live process is reclaimed
ok - live holder matching its recorded start time keeps its lock
ok - lock whose recorded identity no longer recomputes is reclaimed without signalling its pid; a matching or unrecorded identity stays held
ok - live supervise-daemon lock with a stale local-time identity and no start time is not reclaimed
ok - empty mid-acquire lock keeps a minimum grace
ok - late original claimant cannot claim a recreated lock
ok - bounded wait earns one grace window for an unpublished-pid lock, still bounds a live holder
ok - bounded deadline with an unpublished holder is retriable
ok - bounded deadline with an exited holder is retriable
ok - bounded deadline with a released lock is retriable
ok - bounded deadline preserves the live holder advisory
ok - bounded deadline rejects malformed pid data and non-directory locks
ok - paused mid-acquire claimant backs off to active stealer
ok - watch restart preserves recovery without signaling a reused pid
ok - watch restart attaches to a verified healthy peer and later surfaces a successor gap
ok - watcher self-evicts when the lock pid no longer names it
ok - watcher exits 1 with its reason when its state directory is torn down and recreated during startup
ok - arm turns clean self-eviction without a successor into a typed failure
ok - arm attaches to a live fresh watcher and fails loudly when that cycle has no successor
ok - attached arm signals record a classified lifecycle entry
ok - arm starts cleanly and resurfaces recovery after a dead-pid lock
ok - arm cleans child watcher and temp output on HUP
ok - arm defers TERM until startup watcher can run its lock cleanup
ok - arm TERM waits out a stalled singleton claim past the deadline and leaves no lock evidence
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 1 --recovery-generation 54257.1793939507.L7DURW
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 registered custom check(s), but no live watcher process holds this home lock (last beat: 7s ago).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  After draining queued wakes, repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/10136bce06cd/01M6QHJDG177QJ4SB557V6WXWQ/.test-pid-tmp/fm-test-run.vwR46E/w1/tmp/fm-wake-tangle-root.K05iEB/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/10136bce06cd/01M6QHJDG177QJ4SB557V6WXWQ/.test-pid-tmp/fm-test-run.vwR46E/w1/tmp/fm-wake-tangle-root.K05iEB/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
ok - arm propagates an immediate watcher wake before confirmation
ok - arm attaches to a peer watcher after child stands down and surfaces a missing successor
watcher: lock held by live pid 69019 but heartbeat is stale for 847225929s (>300s); inspect or stop that watcher before re-arming.
ok - arm reports FAILED and exits non-zero when no fresh watcher can be confirmed
ok - cycle-exit ledger links a verified successor and remains size-capped
ok - arm confirms a watcher whose post-claim startup exceeds the legacy budget
watcher: FAILED - startup lock ~/.no-mistakes/worktrees/10136bce06cd/01M6QHJDG177QJ4SB557V6WXWQ/.test-pid-tmp/fm-test-run.vwR46E/w1/tmp/fm-watcher-lock-tests.c5d0qp/arm-startup-lock-held/state/.wake-queue.lock held by live pid 115969
ok - arm relays a live-holder startup-lock refusal and keeps the downtime drainable
ok - staged-owner cleanup removes only unpublished empty or self-owned staging
ok - startup cleanup waits for in-flight staging and publication, preserving foreign owners
ok - a stop forced before the safe point waits for it and leaves no lock evidence
ok - a watcher that cannot publish its identity exits through its cleanup
ok - SIGSTOP distinguishes live PID from stale beacon and termination records the exit class
FM_TEST_END 2026-11-06T04:34:17Z tests/fm-watcher-lock.test.sh exit=0 duration_ms=243836 gate_skip=false
FM_TEST_BEGIN 2026-11-06T04:34:17Z tests/fm-watch-checkpoint.test.sh family=watcher-wake-lock expected_gate_skip=none
ok - fm_supervision_unhealthy: false with no state/*.meta at all
ok - fm_supervision_unhealthy: true with in-flight task and no beacon ever
ok - fm_supervision_unhealthy: true with in-flight task and a beacon far outside the grace window
ok - fm_supervision_unhealthy: false with in-flight task and a fresh beacon
ok - fm_supervision_status: FM_SUP_QUEUE_PENDING tracks state/.wake-queue
ok - fm_supervision_needed: X-mode relay poll needs supervision
ok - fm_supervision_unhealthy: source-only home needs supervision
ok - fm_supervision_needed: a registered custom check needs supervision with no task in flight
ok - fm_supervision_needed: a registered check whose bytes drifted still needs supervision
ok - fm_supervision_needed: false for a check.sh with no registration binding
ok - fm_supervision_needed: a task PR poll without a trust bind

... [1787 bytes truncated] ...

te's own child worktree (linked git worktree) even when unhealthy
ok - fm-turnend-guard: blocks a blind turn end in a treehouse-leased LINKED secondmate home (marker force-include)
ok - fm-turnend-guard: an invalid (empty) marker cannot spoof inclusion; linked worktree stays exempt
ok - fm-turnend-guard: a non-ASCII marker cannot spoof inclusion; linked worktree stays exempt
ok - fm-turnend-guard: inert in a crewmate/scout task worktree (linked git worktree) even when unhealthy
ok - fm-turnend-guard: fails open (never blocks) when jq is missing
ok - fm-turnend-guard: silent no-op on empty stdin
ok - fm-turnend-guard: runs well under the generous timing margin (1s)
ok - fm-turnend-guard-grok: forces one explicitly marked same-session resume when the shared predicate blocks
ok - fm-turnend-guard-grok: legacy environment loop guard prevents a nested resume loop
ok - fm-turnend-guard-grok: native false delegates blocking feedback with zero resume processes
ok - fm-turnend-guard-grok: native true remains bounded and starts no resume process
ok - fm-turnend-guard-grok: both spellings are typed and camelCase has deterministic precedence
ok - fm-turnend-guard-grok: malformed, invalidly typed, and missing-prerequisite payloads start neither path
ok - fm-turnend-guard-grok: missing jq and no-supervision-needed stops stay silent and bounded
ok - tracked .claude/settings.json entries: 7 inert under grok, the documented subagent exception still armed, all live under Claude
ok - .codex/hooks.json: Stop hook uses hook process root when payload cwd is outside
ok - .codex/hooks.json: Stop hook ignores nested git root guard scripts
ok - .codex Stop wrapper: clean success JSON, inherited PATH, unchanged errors and continuation without logout output
ok - .opencode primary plugin: guard path is anchored to worktree, not directory
ok - .pi primary extension: no-tool and multi-tool runs each inject exactly one guard follow-up
ok - .pi primary extension: delivery failure resets the logical-run latch
ok - .pi primary extension: a nested load keeps the live session's turn-end marker
ok - .pi primary extension: the turn-end guard reads a Windows-tagged session lock only on Windows
ok - fm-turnend-guard --claude: re-blocks a loop-guarded stop while unhealthy and unclaimed (incident regression)
ok - fm-turnend-guard --claude: X-mode-only homes re-block when auto-arm recovery is absent
ok - fm-turnend-guard --claude: a live arming epoch advances once and repeated observation is idempotent
ok - fm-turnend-guard --claude: repeated failed-to-arming races make bounded monotonic progress
ok - fm-turnend-guard --claude: terminal owner boundary excludes a concurrent start without deadlock
ok - fm-turnend-guard --claude: fresh rewake epoch prevents a duplicate continuation for the same event
ok - fm-turnend-guard --claude: an abandoned auto-arm claim no longer allows a blind stop (incident regression)
ok - fm-turnend-guard --claude: a claim whose pid was reused stops counting as recovery even while its entry reads arming
ok - fm-turnend-guard --claude: a hung owner frozen at arming with no watcher beat no longer allows a blind stop
ok - fm-turnend-guard --claude: a live open generation claim owns recovery with no lock held
ok - fm-turnend-guard --claude: a stuck generation claim no longer allows a blind stop
ok - fm-turnend-guard --claude: the terminal path clears an abandoned claim instead of stepping aside silently
ok - fm-turnend-guard --claude: fresh failed epochs preserve and advance monotonic fail-open progression
ok - fm-turnend-guard --claude: integrated fresh failures reach one bounded fail-open, stop continuation, and reset on recovery
ok - fm-turnend-guard --claude: an inert auto-arm's frozen epoch reaches one bounded fail-open and resets on recovery
ok - fm-turnend-guard --claude: a frozen unverified epoch spends the budget yet still blocks
ok - fm-turnend-guard --claude: reset contention preserves all episode state until retry
ok - fm-turnend-guard --claude: concurrent auto-arm and guard resets are idempotent and deadlock-free
ok - fm-turnend-guard --claude: the exhausted auto-arm commits the attended alarm once, then stays suppressed until recovery
ok - fm-turnend-guard --claude: a repeatedly lost host hand-back on a pending or announced handling marker reaches the attended alarm
ok - fm-turnend-guard --claude: interruption reaches the attended alarm and preserves its final rewake after commit
ok - fm-turnend-guard --claude: stale rewake epoch does not allow a blind stop
ok - fm-turnend-guard --claude: budget exhaustion alone cannot permit a blind stop
ok - fm-turnend-guard --claude: verified fail-open is loud, bounded, attended, and non-repeating
ok - fm-turnend-guard --claude: fail-open requires both exhausted retries and consumed notice
ok - fm-turnend-guard --claude: away ownership excludes the Stop-autoarm fail-open
ok - fm-turnend-guard --claude: positive watcher recovery resets failure episode state
ok - fm-turnend-guard --claude: bounded claim wait avoids a token-consuming forced continuation
ok - fm-turnend-guard --claude: secondmate home re-blocks unclaimed and allows auto-arm-claimed stops
ok - fm-turnend-guard: a live away-mode daemon satisfies supervision with no watcher holding the lock
ok - fm-turnend-guard: away-mode daemon ownership survives a leftover dead watcher lock
ok - fm-turnend-guard: away mode with no daemon and no watcher still blocks
ok - fm-turnend-guard: away mode blocks on a dead away-mode daemon
ok - fm-turnend-guard: away mode blocks on a pid-reused away-mode daemon lock
ok - fm-turnend-guard: away-mode daemon ownership never substitutes for a fresh beacon
ok - fm-turnend-guard: a daemon lock proves nothing while away mode is off
ok - fm-turnend-guard: away-mode beacon freshness uses the poll-derived grace, not the flat default
ok - fm-turnend-guard: a dead away-mode daemon still blocks under the poll-derived grace
ok - fm-turnend-guard: the poll-derived grace is bounded, not unlimited
ok - fm-turnend-guard: with away mode off, the poll-derived grace never applies
ok - fm-turnend-guard: Codex/Linux fallback accepts only a live, fresh, identity-matched cross-namespace holder
FM_TEST_END 2026-11-06T04:35:09Z tests/fm-turnend-guard.test.sh exit=0 duration_ms=295359 gate_skip=false
ok - quiet checkpoint exits 124 with a clean checkpoint line and no live lock
ok - Linux/Codex direct and host checkpoints export FM_HOME and record PID namespace and boot ID
ok - GNU timeout runs the watcher with the INT signal and kill-after bound
ok - non-GNU timeout yields to GNU gtimeout with the INT signal and kill-after bound
ok - non-GNU timeout falls back to Perl and honors the cleanup bound before escalating
ok - an announced recovery is not reannounced by the next foreground checkpoint
ok - a never-announced recovery still surfaces once from a foreground checkpoint
ok - a queue append during a foreground checkpoint still resurfaces
WAKE_ACK_REQUIRED: after handling completes run bin/fm-wake-drain.sh --ack-through 2 --recovery-generation 172876.1793939708.i1mbMA
ok - checkpoint passes through a real watcher wake and leaves the queue for drain
ok - checkpoint preserves watcher environment for registered custom checks
ok - checkpoint rejects an existing watcher singleton as unowned
ok - checkpoint: an opted-in home runs the host for the checkpoint's bound, raised only while away
ok - checkpoint: a handed-back wake passes through, and a host stand-down is a failure
ok - checkpoint: a Codex home without config/supervision-host, or with an off file, never runs the host
ok - checkpoint: the real host ends its park at the checkpoint bound as a quiet checkpoint
FM_TEST_END 2026-11-06T04:35:19Z tests/fm-watch-checkpoint.test.sh exit=0 duration_ms=61666 gate_skip=false
FM_TEST_SUMMARY total=3 failed=0 skipped_gate=0 duration_ms=305858
FM_TEST_SUMMARY_FAMILY family=watcher-wake-lock count=3 duration_ms=600861 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-turnend-guard.test.sh duration_ms=295359
FM_TEST_SLOWEST rank=2 script=tests/fm-watcher-lock.test.sh duration_ms=243836
FM_TEST_SLOWEST rank=3 script=tests/fm-watch-checkpoint.test.sh duration_ms=61666

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
A live Codex workspace-write sandbox watcher no longer produces a false blind-stop alarm ✅ pass live verified/live-pid-results.json: direct-published-watcher, direct-strict-rejects-inner-pid, baseline-reproduces-false-blind-stop, fixed-guard-removes-false-blind-stop.
Corrupted, stale, missing, or dead watcher proof cannot authorize a supervised stop ✅ pass live verified/live-pid-results.json: reject-mismatch-, reject-beacon-age-, reject-absent-beacon, reject-missing-*, reject-writable-lock, missing-python-blocks, and *-dead-holder-with-fresh-saved-proof-bl…
Selecting a non-Codex primary preserves strict cross-namespace blocking ✅ pass live verified/live-pid-results.json: non-codex-retains-strict-*; targeted-regression.log: Linux namespace fallback regression.
Direct and hosted Codex checkpoints propagate an initially unset FM_HOME into their actual watcher ✅ pass live verified/live-pid-results.json: direct-published-watcher, host-published-watcher, and host-cross-namespace-stop-allowed; verified/host-sandbox.stdout.
Checkpoint wake delivery and quiet hosted completion release their watcher locks ✅ pass live verified/live-pid-results.json: direct-checkpoint-close, host-checkpoint-close, direct-cleanup, host-cleanup, and *-lab-removed.
  • unshare -rpf --mount-proc true and a Python os.pidfd_open capability probe.
  • codex --version, codex sandbox --help, and a real codex sandbox -c 'sandbox_mode="workspace-write"' -- bash -c ... namespace probe.
  • TMPDIR="$PWD/.test-pid-tmp" bin/fm-test-run.sh tests/fm-turnend-guard.test.sh tests/fm-watcher-lock.test.sh tests/fm-watch-checkpoint.test.sh.
  • python3 ~/.no-mistakes/evidence/01M6QHJDG177QJ4SB557V6WXWQ/live-pid-driver.py "$PWD" ~/.no-mistakes/evidence/01M6QHJDG177QJ4SB557V6WXWQ/verified drove production checkpoint, watcher, session-lock, and guard scripts inside disposable Codex workspace-write sandboxes.
  • Compared the base and candidate guards against the same running sandbox watcher: the base returned the false blind-stop alarm; the candidate allowed the supervised stop.
  • Exercised invalid identity, boot ID, home, watcher path, namespace, PID, beacon, lock permissions, missing Python, dead-holder replay, and non-Codex primary selections.
  • Verified direct wake delivery, hosted checkpoint timeout, removal of watcher locks, disposable-lab cleanup, unchanged HEAD, and a clean working tree.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @co1smos. The negative cases are thorough (boot ID, identity, namespace, lock permissions, stale beacon, dead holder, other harnesses), and you've been upfront about what wasn't validated, which I appreciate.

What I checked: head b29dbd65 against main 86437e28. GitHub reports it mergeable, and the attestation binds this head. When the strict check fails on Linux with a positive codex harness result, the turn-end guard now accepts a Python /proc observer. That observer maps the lock PID through NSpid, then holds a pidfd while it rechecks identity, the beacon and the lock snapshot. It only reads: no signals, no lock acquisition. On the same Linux/Codex combination the watcher also records pid-namespace and boot-id, and the checkpoint passes FM_HOME. Every other platform and harness is byte-identical. Nothing touches workflows or anything security-sensitive. As a first-time fork run, CI and the no-mistakes checks were waiting for approval, so I've approved them.

Contract-class: new-default (my read). docs/turnend-guard.md specifies the PID-strict predicate at the turn boundary. This adds a second, default-on acceptance path for every Linux Codex home, so it relaxes a guard rather than restoring a broken path. VISION.md: One captain aligns in motive (no false "turn would end blind" for a live watcher) · Authority aligns (read-only, no lifecycle authority) · Scripts aligns (exact evidence, fails closed) · Restart aligns · Delegation cannot tell (see below) · Vendor cannot tell (it depends on what a real Codex sandbox exposes in /proc, which is unverified) · Scope aligns.

One thing is needed from you: live validation is inconclusive. Your own verification note says native Codex Stop visibility is unverified. Could you run a real Codex session (logged in) on Linux, where the watcher and the Stop hook actually sit in different PID namespaces? Then post what the guard did at the Stop boundary, or re-raise through git push no-mistakes with that scenario included. Once that evidence is in and CI is green, it goes to Kun as a merge-or-leave decision, since it's a new default path. Heads-up: main currently fails Behavior portable parallel 2 (tests/fm-test-run.test.sh "packing exactly at the budget") on its own.

@co1smos

co1smos commented Oct 24, 2026

Copy link
Copy Markdown
Author

Follow-up native Linux Codex Stop verification (2026-10-24), on unchanged PR head b29dbd65 (Codex CLI 0.163.0; custom authenticated Headroom provider, not codex login): (1) Real interactive TUI Stop dispatch was confirmed by strace execve of bin/fm-turnend-guard.sh (PID 3966276, exit 0; Codex session 01a16f6c-2df6-79c1-b138-1396a83c7796). (2) In a separate disposable lab with one in-flight task, an exited watcher caused the native Stop hook to block with TURN WOULD END BLIND. (3) With a live watcher in a different PID namespace (local PID 17 / host PID 4006366, namespace pid:[4026532914] versus host pid:[4026531836]), the native Codex TUI turn completed without a Stop-hook block (session 01a16f23-6801-7e21-a43c-a53bd661fee6, 2026-10-24T19:44:10Z). Immediate read-only checks on the same live watcher: strict fm_watcher_healthy returned 1; Linux/Codex fm_watcher_cross_namespace_healthy returned 0; beacon age about 4.5 s. Limitation: the predicate checks were sampled just after successful Stop, not instrumented inside that callback; actual native dispatch and missing-watcher blocking were observed separately. Test watcher was stopped; source tree remained clean. One existing CI job, Behavior portable parallel 2 / tests/fm-test-run.test.sh packing exactly at the budget, remains failed (19/20 passed); reviewer reports the same baseline failure on main. No product source, PR head, or no-mistakes attestation was changed. Full sanitized evidence is retained locally in data/codex-pid-liveness-fix/native-stop-direct-live-test-2026-10-24.md.

co1smos commented Oct 24, 2026

Copy link
Copy Markdown
Author

Follow-up: Native Linux Codex Stop Verification (2026-10-24)

This supplements the earlier live-test report and the original no-mistakes validation. Testing used the unchanged PR head b29dbd65, Codex CLI 0.163.0 on Linux, and an authenticated custom provider (Headroom/CLIProxyAPI) rather than native codex login. No PR source files were changed.

Observed results

  • Native Stop hook dispatch confirmed. A normal interactive Codex TUI turn launched bin/fm-turnend-guard.sh through an actual execve, recorded by strace -f. That traced smoke test had no in-flight tasks, so it proves hook dispatch, not cross-namespace fallback.
  • Missing watcher correctly rejected. With one registered in-flight task and no live watcher, the native Stop hook blocked the turn with TURN WOULD END BLIND - SUPERVISION IS OFF.
  • Cross-namespace watcher accepted in a real TUI. With a live watcher in another PID namespace (local PID 17, host PID 4006366), the Codex turn completed without a Stop-hook block. Immediately afterward, the existing strict liveness check rejected the same live watcher (exit 1), while the Linux/Codex cross-namespace fallback accepted it (exit 0). Watcher beacon age was approximately 4.5 seconds.

Sanitized primary-evidence excerpts (from the disposable test logs; not screenshots):

strace: 3966276 execve("/tmp/fm7620-native-stop.6HXVVX/project/bin/fm-turnend-guard.sh", ...)
Codex journal: 2026-10-24T19:44:10.311Z event_msg / task_complete
Host/Stop observer namespace: pid:[4026531836]
Live watcher namespace:       pid:[4026532914]
Watcher NSpid mapping:        4006366 17
Strict predicate:             exit 1
Cross-namespace predicate:    exit 0

The two Codex sessions were 01a16f6c-2df6-79c1-b138-1396a83c7796 (native Stop dispatch trace) and 01a16f23-6801-7e21-a43c-a53bd661fee6 (active-task/Watcher Stop testing). The local sanitized test report is retained at data/codex-pid-liveness-fix/native-stop-direct-live-test-2026-10-24.md in the author's FirstMate operational home; that path is not a public artifact URL. The isolated test-only watcher was stopped afterward.

Evidence limitations: The successful Stop callback was not instrumented internally. The strict/fallback predicate results were sampled immediately after the successful turn, while the same watcher was still alive, rather than inside that exact callback. Hook dispatch was directly traced and a missing-watcher Stop was directly observed separately. This is strong behavioral evidence, not a branch-by-branch trace or native codex login verification. Native non-Linux execution was also not tested.

CI: 19 checks passed; Behavior portable parallel 2 remains failing on tests/fm-test-run.test.sh (packing exactly at the budget). The reviewer has reported this same issue on main. This supplemental comment does not claim CI is green or that the original no-mistakes Test warning has been rerun or changed.

No new commit, PR-head change, PR-description edit, or no-mistakes attestation edit accompanies this comment.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @co1smos for the follow-up. It's exactly what I asked for. On the unchanged head b29dbd65 with Codex CLI 0.163.0 on Linux: a real TUI turn dispatched fm-turnend-guard.sh through the native Stop hook (strace execve), a missing watcher blocked the turn, and a live watcher in another PID namespace let the turn finish. The strict check rejected that same watcher and the fallback accepted it. I'm counting live validation as covered. The one untested scenario is a native non-Linux run. The fallback only applies on Linux with Codex, and the regression suite covers non-Linux selection, so that's fine.

CI: 18 of 19 green. Parallel 2 failed only on "packing exactly at the budget must be accepted", and it ran on a merge ref against main 86437e28, which predates the fix on main (98f3bd84). This PR doesn't touch the test runner, so that failure comes from main, not from you. The no-mistakes attestation binds b29dbd65, and the PR is mergeable.

Contract-class: new-default (unchanged from my last read). It relaxes the specified PID-strict watcher liveness check on the default Linux+Codex path to accept a cross-namespace watcher. The guards are well-built, but this is new default behavior, not a restore.

VISION, rule by rule: One captain/interface: aligns (no false "turn would end blind" blocks for a live watcher). Authority: aligns (nothing here acts for the captain; it only changes how a liveness check reads). Scripts own mechanics: aligns (exact pidfd and namespace/boot-id checks). Restart: aligns (the watcher records its pid namespace and boot id on disk). Delegation spine: aligns. Vendor: aligns (scoped to Codex on Linux, other harnesses unchanged). Scope: aligns.

Status: this is with Kun now, not waiting on you. I've flagged it for a merge-or-leave decision. If he wants it merged, the CI run will need a fresh pass on current main (a rebase or new push would do it), and I'll ask for that only if he says go.

@co1smos
co1smos force-pushed the fm/codex-pid-liveness-fix branch from b29dbd6 to 9b32578 Compare October 25, 2026 02:41
@co1smos co1smos changed the title fix(bin): verify Codex watcher liveness across Linux PID namespaces fix: validate Codex watcher liveness across PID namespaces Oct 25, 2026
@co1smos
co1smos force-pushed the fm/codex-pid-liveness-fix branch from 9b32578 to 3695d70 Compare November 6, 2026 04:45
@co1smos co1smos changed the title fix: validate Codex watcher liveness across PID namespaces fix: recognize live Codex watchers across Linux PID namespaces Nov 6, 2026
@greptile-apps

greptile-apps Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Reviews (1) · Last reviewed commit: "no-mistakes(document): Refresh Codex fal..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @co1smos. New tip 3695d70a (force-pushed rewrite of the Linux/Codex cross-namespace watcher fallback) arrived after the 2026-10-25 waiting-captain stamp on b29dbd65. I re-read it against main 8b1618a4.

What I checked on this head: attestation binds 3695d70a with every step completed (no skips) and live 5/5. Greptile 5/5, no open threads. Diff stays Linux+Codex-gated in fm-turnend-guard.sh / fm-wake-lib.sh with read-only /proc observation, lock metadata, and checkpoint FM_HOME — no workflow or credential surface. I approved first-time-fork CI 42164389511 and Require no-mistakes 42164389651 / 42164458834 so those runs can speak. Merge-tree is clean (two commits behind main only).

Contract-class: new-default (unchanged). docs/turnend-guard.md's PID-strict predicate gains a second, default-on acceptance path for every Linux Codex home. That relaxes a guard rather than restoring a broken promised path. VISION: One captain / Restart / Authority (read-only, no lifecycle authority) / Scripts align in motive; Vendor cannot-tell remains (depends on what a real Codex sandbox exposes under /proc). Linked issue #7620.

This is waiting on CI, not on you. Once quick checks are green on this head, it goes back to Kun as merge-or-leave (new-default). Until then, nothing more is needed from you.

Rockets: none. Security: none.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: tip 3695d70a is unchanged since the 07:48Z waiting-ci stamp. Quick checks are green on this head against main bf05a4fc (Require no-mistakes, coverage guard, repo invariants); attestation binds with no skips (live 5/5); Greptile 5/5, no threads; merge-tree clean. Fork CI was already approved earlier. Unlabelled Full is our label gate. Contract-class remains new-default (default-on Linux/Codex cross-namespace watcher acceptance path). Refs #7620. Nothing more from you — next is ours for full-ci, then Kun for merge-or-leave after Full is green.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: tip 3695d70a is unchanged since the 07:22Z waiting-ci stamp. Quick checks are green on this head against main bf05a4fc (Require no-mistakes, coverage guard, repo invariants); attestation binds with no skips (live 5/5); Greptile 5/5, no threads; merge-tree clean. Fork CI was already approved earlier. Unlabelled Full is our label gate. Contract-class remains new-default (default-on Linux/Codex cross-namespace watcher acceptance path). Refs #7620. Nothing more from you — next is ours for full-ci, then Kun for merge-or-leave after Full is green. Rockets: none.

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.

fix(codex): Stop hook misidentifies live sandbox watcher across PID namespaces

2 participants