Skip to content

fix: prevent native Codex threads from sharing session-lock ownership - #8224

Open
karanmrn wants to merge 16 commits into
kunchenguid:mainfrom
karanmrn:fm/fm-up-codex-native-lock
Open

karanmrn wants to merge 16 commits into
kunchenguid:mainfrom
karanmrn:fm/fm-up-codex-native-lock

Conversation

@karanmrn

@karanmrn karanmrn commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • Native Codex lock ownership now requires a verified session identity and matching sidecar, with raw argument checks to identify shared servers.
  • Startup, Stop hooks, and foreground checkpoints enforce ownership so foreign threads remain read-only and can end safely.
  • The branch adds portable and installed-Codex regression coverage, documents the ownership contract, and expands portable serial CI testing to 20 shards.

Risk Assessment

✅ Low: The ownership checks enforce the required refusal boundary, and the complete source review found no material defect or unnecessary component.

Testing

Five local Codex scenarios and three targeted checks passed. Base replay confirmed the regression repair. Driver setup failures were resolved. CLI transcripts remain, all children stopped, and disposable labs were removed.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Real Codex sessions share one server: the owner re-enters, while competing and descendant threads cannot acquire ownership. ✅ pass live native-command-transcript.log
Hide python3 during real server launches with spaced directories, option-shaped directory fragments, and a spaced executable path: PID-only ownership is refused. ✅ pass live fallback-ownership-live.log; base-target-reproduction.log
Run ordinary Codex CLI prompts: readable arguments permit ownership, ambiguous unreadable app-server text refuses it, and clear unreadable arguments retain ownership. ✅ pass live ordinary-cli-live.log; ordinary-cli-product-output.json
Invoke checkpoints and Stop guards from foreign native sessions: checkpoints refuse, Stop permits safe exit, and owner state remains unchanged. ✅ pass live native-command-transcript.log
Attempt legacy and symlink lock takeover, then reclaim a dead owner: unsafe ownership fails and verified recovery succeeds. ✅ pass live native-command-transcript.log
Evidence: Native ownership, Stop guards, checkpoints, and recovery

Source: Native ownership, Stop guards, checkpoints, and recovery

PRODUCT: fm-isolated-regression/0.172.0 (Mac OS 27.2.1; arm64) dumb (fm-isolated-regression; 1)
SERVER PID: 86352
SESSIONSTART 01a231cb-e01b-7670-a04d-7bca110adef0 
================================================================================
SESSION START - {run-worktree}/.test-native-lock/tmp/fm-codex-session-7f5euzbm
================================================================================

LOCK
--------------------------------------------------------------------------------
lock acquired: harness pid 86352

HOME ROLE
--------------------------------------------------------------------------------
fm-role: user (default)

BOOTSTRAP
--------------------------------------------------------------------------------
(silent - all good)

WAKE QUEUE
--------------------------------------------------------------------------------
(no queued wakes)
================================================================================
SUPERVISION OPERATING INSTRUCTIONS - primary harness: codex
================================================================================
Current state:
- Lock: held by this session; this session owns normal supervision unless away mode says otherwise.
- Away/quiet mode: inactive.
- X mode: inactive; use the default watcher cadence.
- Ordinary wake: take the next foreground bin/fm-watch-checkpoint.sh checkpoint as directed below.


================================================================================
READ-ONCE CONTRACT
================================================================================
Everything below is printed in full for this session start: every state/*.meta,
a compact data/backlog.md listing, a bounded tail of every state/*.status,
data/projects.md, data/secondmates.md, data/captain.md, data/captain-shared.md,
and data/learnings.md.
Do NOT re-read any of them after reading this digest, and do NOT bulk-read
data/backlog.md or state/*.status: re-reading everything defeats the entire
point of this command.

Go to a source directly only when:
  - this digest flagged it ABSENT (then rebuild or create it per AGENTS.md),
  - its contents looked unparseable or corrupt,
  - an individual full status log is needed for older wake-event history, or a
    status line was capped and its tail matters (each task's full log path is
    printed with its tail),
  - a full task body is needed (bin/fm-tasks-axi.sh show <id> --full, or data/backlog.md),
  - the backlog listing disclosed omitted queued items and this turn needs them,
  - the NETWORK CHECKS section reported its checks still IN PROGRESS and this
    turn needs their verdict (bin/fm-startup-network.sh report),
  - or a STARTUP TRUNCATED banner named the stage that would have printed it, in
    which case that stage's sources were never emitted and must be reconciled.

================================================================================
FLEET STATE
================================================================================

data/backlog.md
--------------------------------------------------------------------------------
ABSENT

Work under way (state/*.meta)
--------------------------------------------------------------------------------
(none)

Orphan status logs (state/*.status without matching .meta)
--------------------------------------------------------------------------------
(none)

AFK
--------------------------------------------------------------------------------
absent

================================================================================
NETWORK CHECKS
================================================================================

================================================================================
CONTEXT
================================================================================

data/projects.md
--------------------------------------------------------------------------------
ABSENT

data/secondmates.md
--------------------------------------------------------------------------------
ABSENT

data/captain.md
--------------------------------------------------------------------------------
ABSENT

data/captain-shared.md (shared, main-authoritative, read-only in secondmate homes)
--------------------------------------------------------------------------------
ABSENT

data/learnings.md
--------------------------------------------------------------------------------
ABSENT

================================================================================
NEXT STEP
================================================================================
Follow the supervision operating instructions block above for harness 'codex'.
This script never starts supervision itself.

The digest above is complete for this session start. The READ-ONCE CONTRACT
section near the top of it governs what may still be read from disk.

SESSIONSTART 01a231cb-f469-75b2-b6ca-f78bd4ecbbc5 
================================================================================
SESSION START - {run-worktree}/.test-native-lock/tmp/fm-codex-session-7f5euzbm
================================================================================

LOCK
--------------------------------------------------------------------------------
error: another live firstmate session holds the lock (pid 86352, session codex-native:01a231cb-e01b-7670-a04d-7bca110adef0); operate read-only until resolved
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  READ-ONLY SESSION - FLEET LOCK OWNERSHIP WAS NOT VERIFIED
●  error: another live firstmate session holds the lock (pid 86352, session codex-native:01a231cb-e01b-7670-a04d-7bca110adef0); operate read-only until resolved
●  Skipping every mutating step: stale Herdr child cleanup,
●  secondmate convergence, secondmate liveness, pending remote handoff retry,
●  X-mode artifacts, fleet sync, and wake-queue drain. Detect-only bootstrap
●  diagnostics and the rest of this read-only-safe digest still ran below.
●  Operate read-only until this resolves - do not spawn, steer, merge, or
●  otherwise mutate fleet state from this session.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

HOME ROLE
--------------------------------------------------------------------------------
fm-role: user (default)

BOOTSTRAP
--------------------------------------------------------------------------------
(silent - all good)

WAKE QUEUE
--------------------------------------------------------------------------------
skipped (read-only session) - 0 record(s) remain queued because this session lacks verified fleet-lock ownership.
================================================================================
SUPERVISION OPERATING INSTRUCTIONS - primary harness: codex
================================================================================
Current state:
- Lock: read-only; do not drain, arm, spawn, steer, merge, or repair fleet state here.
- Away/quiet mode: inactive.
- X mode: inactive; use the default watcher cadence.
- Ordinary wake: take the next foreground bin/fm-watch-checkpoint.sh checkpoint as directed below.


================================================================================
READ-ONCE CONTRACT
================================================================================
Everything below is printed in full for this session start: every state/*.meta,
a compact data/backlog.md listing, a bounded tail of every state/*.status,
data/projects.md, data/secondmates.md, data/captain.md, data/captain-shared.md,
and data/learnings.md.
Do NOT re-read any of them after reading this digest, and do NOT bulk-read
data/backlog.md or state/*.status: re-reading everything defeats the entire
point of this command.

Go to a source directly only when:
  - this digest flagged it ABSENT (then rebuild or create it per AGENTS.md),
  - its contents looked unparseable or corrupt,
  - an individual full status log is needed for older wake-event history, or a
    status line was capped and its tail matters (each task's full log path is
    printed with its tail),
  - a full task body is needed (bin/fm-tasks-axi.sh show <id> --full, or data/backlog.md),
  - the backlog listing disclosed omitted queued items and this turn needs them,
  - the NETWORK CHECKS section reported its checks still IN PROGRESS and this
    turn needs their verdict (bin/fm-startup-network.sh report),
  - or a STARTUP TRUNCATED banner named the stage that would have printed it, in
    which case that stage's sources were never emitted and must be reconciled.

================================================================================
FLEET STATE
================================================================================

data/backlog.md
--------------------------------------------------------------------------------
ABSENT

Work under way (state/*.meta)
--------------------------------------------------------------------------------
(none)

Orphan status logs (state/*.status without matching .meta)
--------------------------------------------------------------------------------
(none)

AFK
--------------------------------------------------------------------------------
absent

================================================================================
NETWORK CHECKS
================================================================================
skipped (read-only session) - GitHub authentication, project clone refresh,
secondmate liveness and convergence, and pending handoff delivery were not run.
They need the fleet lock, and this session must not spawn, steer, or merge, so it
has no action they would gate. The session holding the lock runs them.

================================================================================
CONTEXT
================================================================================

data/projects.md
--------------------------------------------------------------------------------
ABSENT

data/secondmates.md
--------------------------------------------------------------------------------
ABSENT

data/captain.md
--------------------------------------------------------------------------------
ABSENT

data/captain-shared.md (shared, main-authoritative, read-only in secondmate homes)
--------------------------------------------------------------------------------
ABSENT

data/learnings.md
--------------------------------------------------------------------------------
ABSENT

================================================================================
NEXT STEP
================================================================================
This session did not acquire the fleet lock. Stay read-only: do not arm,
drain, spawn, steer, merge, or repair fleet state from here. Only a session
with verified fleet-lock ownership may perform mutable follow-up.

The digest above is complete for this session start. The READ-ONCE CONTRACT
section near the top of it governs what may still be read from disk.

PERSISTED LOCK: 86352
PERSISTED IDENTITY: codex-native:01a231cb-e01b-7670-a04d-7bca110adef0
COMMAND: same native session re-entry {"exitCode": 0, "stdout": "lock acquired: harness pid 86352\n", "stderr": ""}
COMMAND: competing native session {"exitCode": 1, "stdout": "", "stderr": "error: another live firstmate session holds the lock (pid 86352, session codex-native:01a231cb-e01b-7670-a04d-7bca110adef0); operate read-only until resolved\n"}
COMMAND: descendant thread cannot own root lock {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND: missing native identity {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND: malformed native identity {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND: foreign checkpoint refuses before watcher {"exitCode": 1, "stdout": "", "stderr": "error: native Codex session does not own the home lock; operate read-only until resolved\n"}
COMMAND: descendant checkpoint refuses before watcher {"exitCode": 1, "stdout": "", "stderr": "error: native Codex session does not own the home lock; operate read-only until resolved\n"}
COMMAND: foreign Stop fm-turnend-guard.sh opted_in=False {"exitCode": 0, "stdout": "{\"systemMessage\":\"FIRSTMATE SUPERVISION IS OWNED BY ANOTHER LIVE SESSION: this read-only session cannot and should not arm or repair the watcher (lock owner pid 86352). Allowing this turn to end safely; the owning session must restore supervision.\"}\n", "stderr": ""}
COMMAND: foreign Stop fm-codex-stop-park.sh --guard opted_in=False {"exitCode": 0, "stdout": "{\"systemMessage\":\"FIRSTMATE SUPERVISION IS OWNED BY ANOTHER LIVE SESSION: this read-only session cannot and should not arm or repair the watcher (lock owner pid 86352). Allowing this turn to end safely; the owning session must restore supervision.\"}\n", "stderr": ""}
COMMAND: foreign Stop fm-turnend-guard.sh opted_in=True {"exitCode": 0, "stdout": "{\"systemMessage\":\"FIRSTMATE SUPERVISION IS OWNED BY ANOTHER LIVE SESSION: this read-only session cannot and should not arm or repair the watcher (lock owner pid 86352). Allowing this turn to end safely; the owning session must restore supervision.\"}\n", "stderr": ""}
COMMAND: foreign Stop fm-codex-stop-park.sh --guard opted_in=True {"exitCode": 0, "stdout": "{\"systemMessage\":\"FIRSTMATE SUPERVISION IS OWNED BY ANOTHER LIVE SESSION: this read-only session cannot and should not arm or repair the watcher (lock owner pid 86352). Allowing this turn to end safely; the owning session must restore supervision.\"}\n", "stderr": ""}
COMMAND: legacy shared-PID owner cannot be guessed {"exitCode": 1, "stdout": "", "stderr": "error: another live firstmate session holds the lock (pid 86352); operate read-only until resolved\n"}
COMMAND: symlinked lock cannot prove ownership {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND: symlinked lock cannot be acquired {"exitCode": 1, "stdout": "", "stderr": "error: session lock is not a regular file; operate read-only until resolved\n"}
COMMAND: descendant cannot reclaim dead native owner {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND: verified new session reclaims dead owner {"exitCode": 0, "stdout": "lock acquired: harness pid 86352\n", "stderr": ""}
COMMAND: reclaimed session owns new lock {"exitCode": 0, "stdout": "", "stderr": ""}
FINAL LOCK: 86352 codex-native:01a231cb-f469-75b2-b6ca-f78bd4ecbbc5
PASS: native contention, guard isolation, and safe recovery
Evidence: Real processes with unreadable spaced arguments

Source: Real processes with unreadable spaced arguments

LAUNCH server-0 ['codex', '-C', '{run-worktree}/.test-native-lock/fallback/dir-0/My Home', 'app-server', '--stdio'] PID 81218
INITIALIZE {'userAgent': 'fm-live-boundaries/0.172.0 (Mac OS 27.2.1; arm64) unknown (fm-live-boundaries; 1)', 'codexHome': '{run-worktree}/.test-native-lock/fallback/server-0/codex', 'platformFamily': 'unix', 'platformOs': 'macos'}
REAL COMM ~/.local/lib/node_modules/@openai/codex/node_modules/@openai/codex-darwin-arm64/vendor/aarch64-apple-darwin/bin/codex
COMMAND prove argv reader absent {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND readable native owner acquires {"exitCode": 0, "stdout": "lock acquired: harness pid 81218\n", "stderr": ""}
READABLE IDENTITY codex-native:00000000-0000-4000-8000-000000000001
COMMAND unreadable fresh home refuses identity None {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000001 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000002 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND legacy shared-PID ownership refused {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND legacy shared-PID takeover refused {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND checkpoint refused before starting watcher {"exitCode": 1, "stdout": "", "stderr": "error: native Codex session does not own the home lock; operate read-only until resolved\n"}
PERSISTED LEGACY UNCHANGED 81218 NO IDENTITY SIDECAR
SERVER EXIT 81218 0
LAUNCH server-1 ['codex', '-C', '{run-worktree}/.test-native-lock/fallback/dir-1/My -m', 'app-server', '--stdio'] PID 86049
INITIALIZE {'userAgent': 'fm-live-boundaries/0.172.0 (Mac OS 27.2.1; arm64) unknown (fm-live-boundaries; 1)', 'codexHome': '{run-worktree}/.test-native-lock/fallback/server-1/codex', 'platformFamily': 'unix', 'platformOs': 'macos'}
REAL COMM ~/.local/lib/node_modules/@openai/codex/node_modules/@openai/codex-darwin-arm64/vendor/aarch64-apple-darwin/bin/codex
COMMAND prove argv reader absent {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND readable native owner acquires {"exitCode": 0, "stdout": "lock acquired: harness pid 86049\n", "stderr": ""}
READABLE IDENTITY codex-native:00000000-0000-4000-8000-000000000001
COMMAND unreadable fresh home refuses identity None {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000001 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000002 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND legacy shared-PID ownership refused {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND legacy shared-PID takeover refused {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND checkpoint refused before starting watcher {"exitCode": 1, "stdout": "", "stderr": "error: native Codex session does not own the home lock; operate read-only until resolved\n"}
PERSISTED LEGACY UNCHANGED 86049 NO IDENTITY SIDECAR
SERVER EXIT 86049 0
LAUNCH server-2 ['codex', '--cd', '{run-worktree}/.test-native-lock/fallback/dir-2/My --model', 'app-server', '--stdio'] PID 90305
INITIALIZE {'userAgent': 'fm-live-boundaries/0.172.0 (Mac OS 27.2.1; arm64) unknown (fm-live-boundaries; 1)', 'codexHome': '{run-worktree}/.test-native-lock/fallback/server-2/codex', 'platformFamily': 'unix', 'platformOs': 'macos'}
REAL COMM ~/.local/lib/node_modules/@openai/codex/node_modules/@openai/codex-darwin-arm64/vendor/aarch64-apple-darwin/bin/codex
COMMAND prove argv reader absent {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND readable native owner acquires {"exitCode": 0, "stdout": "lock acquired: harness pid 90305\n", "stderr": ""}
READABLE IDENTITY codex-native:00000000-0000-4000-8000-000000000001
COMMAND unreadable fresh home refuses identity None {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000001 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000002 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND legacy shared-PID ownership refused {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND legacy shared-PID takeover refused {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND checkpoint refused before starting watcher {"exitCode": 1, "stdout": "", "stderr": "error: native Codex session does not own the home lock; operate read-only until resolved\n"}
PERSISTED LEGACY UNCHANGED 90305 NO IDENTITY SIDECAR
SERVER EXIT 90305 0
LAUNCH server-3 ['{run-worktree}/.test-native-lock/fallback/My Tools/codex', '-C', '{run-worktree}/.test-native-lock/fallback/dir-3/My Home', 'app-server', '--stdio'] PID 95023
INITIALIZE {'userAgent': 'fm-live-boundaries/0.172.0 (Mac OS 27.2.1; arm64) unknown (fm-live-boundaries; 1)', 'codexHome': '{run-worktree}/.test-native-lock/fallback/server-3/codex', 'platformFamily': 'unix', 'platformOs': 'macos'}
REAL COMM {run-worktree}/.test-native-lock/fallback/My Tools/codex
COMMAND prove argv reader absent {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND readable native owner acquires {"exitCode": 0, "stdout": "lock acquired: harness pid 95023\n", "stderr": ""}
READABLE IDENTITY codex-native:00000000-0000-4000-8000-000000000001
COMMAND unreadable fresh home refuses identity None {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000001 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND unreadable fresh home refuses identity 00000000-0000-4000-8000-000000000002 {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND legacy shared-PID ownership refused {"exitCode": 1, "stdout": "", "stderr": ""}
COMMAND legacy shared-PID takeover refused {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND checkpoint refused before starting watcher {"exitCode": 1, "stdout": "", "stderr": "error: native Codex session does not own the home lock; operate read-only until resolved\n"}
PERSISTED LEGACY UNCHANGED 95023 NO IDENTITY SIDECAR
SERVER EXIT 95023 0
PASS: real spaced cwd, option-shaped cwd, and spaced executable fallback refuse PID ownership
Evidence: Base reproduces takeover, target refuses it

Source: Base reproduces takeover, target refuses it

LAUNCH before-after ['codex', '-C', '{run-worktree}/.test-native-lock/baseline/My -m', 'app-server', '--stdio'] PID 89190
INITIALIZE {'userAgent': 'fm-live-boundaries/0.172.0 (Mac OS 27.2.1; arm64) unknown (fm-live-boundaries; 1)', 'codexHome': '{run-worktree}/.test-native-lock/baseline/before-after/codex', 'platformFamily': 'unix', 'platformOs': 'macos'}
COMMAND BASE: spaced directory with argv reader hidden grants PID-only lock {"exitCode": 0, "stdout": "lock acquired: harness pid 89190\n", "stderr": ""}
BASE LOCK 89190
COMMAND BASE: another thread under same server inherits PID-only lock {"exitCode": 0, "stdout": "lock acquired: harness pid 89190\n", "stderr": ""}
COMMAND TARGET: other thread cannot inherit same legacy PID lock {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
COMMAND TARGET: same unreadable spaced launch cannot publish a fresh PID-only lock {"exitCode": 1, "stdout": "", "stderr": "error: native Codex server is shared by many threads and this thread proves no trusted session identity (CODEX_SESSION_ID, CODEX_THREAD_ID, or hook session_id; see bin/fm-session-lock-lib.sh); operate read-only until resolved\n"}
CONFIRMED: reported unsafe behavior reproduces at base and is refused at target
SERVER EXIT 89190 0
Evidence: Execution scope, results, and cleanup

Source: Execution scope, results, and cleanup

{
  "base": "8bfcc8832d002f6d864d0ecd1454b2ee41f96808",
  "target": "d03abb3a10262120a8e468e525f6b6f5b59f7d1e",
  "product": "codex-cli 0.172.0",
  "platform": "macOS 27.2.1 arm64",
  "live_scope": "Real installed Codex app-server, native SessionStart hooks, command/exec, and embedded CLI. Disposable local homes and synthetic inputs. No production accounts or model calls.",
  "scenarios": [
    {
      "name": "Native owner and competing threads",
      "evidence": "native-command-transcript.log",
      "result": "pass"
    },
    {
      "name": "Unreadable spaced cwd and executable arguments",
      "evidence": "fallback-ownership-live.log",
      "result": "pass"
    },
    {
      "name": "Ordinary CLI prompt classification",
      "evidence": "ordinary-cli-live.log, ordinary-cli-product-output.json",
      "result": "pass"
    },
    {
      "name": "Foreign Stop and checkpoint isolation",
      "evidence": "native-command-transcript.log",
      "result": "pass"
    },
    {
      "name": "Legacy and symlink locks, verified dead-owner recovery",
      "evidence": "native-command-transcript.log",
      "result": "pass"
    }
  ],
  "baseline_replay": "base-target-reproduction.log reproduced PID-only takeover on base and refusal on target",
  "setup_corrections": "The sandbox CLI route denied disposable .lock writes. A loopback Responses provider then drove embedded CLI. The initial driver returned its final response before command completion. The corrected driver awaited persisted product status before ending. These were driver/setup failures, not product failures.",
  "checks": {
    "tests/fm-codex-session-lock.test.sh": 0,
    "tests/fm-codex-session-identity-live-e2e.test.sh": 0,
    "tests/fm-watch-checkpoint.test.sh": 0,
    "live-driver.py --live": 0,
    "fallback-live.py": "Spaced-path cases passed. Later sandbox setup failed and was superseded by ordinary-cli-live.py.",
    "ordinary-cli-live.py (corrected driver)": 0,
    "baseline-replay.py": 0
  },
  "recorded_servers_confirmed_stopped": [
    81218,
    86049,
    86352,
    89190,
    90305,
    95023
  ],
  "cleanup": "All test-owned child commands finished. Recorded live servers stopped. Disposable worktree labs removed. No source changes."
}

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Real Codex sessions share one server: the owner re-enters, while competing and descendant threads cannot acquire ownership. ✅ pass live native-command-transcript.log
Hide python3 during real server launches with spaced directories, option-shaped directory fragments, and a spaced executable path: PID-only ownership is refused. ✅ pass live fallback-ownership-live.log; base-target-reproduction.log
Run ordinary Codex CLI prompts: readable arguments permit ownership, ambiguous unreadable app-server text refuses it, and clear unreadable arguments retain ownership. ✅ pass live ordinary-cli-live.log; ordinary-cli-product-output.json
Invoke checkpoints and Stop guards from foreign native sessions: checkpoints refuse, Stop permits safe exit, and owner state remains unchanged. ✅ pass live native-command-transcript.log
Attempt legacy and symlink lock takeover, then reclaim a dead owner: unsafe ownership fails and verified recovery succeeds. ✅ pass live native-command-transcript.log
  • TMPDIR=&#34;$PWD/.test-native-lock/tmp&#34; bash tests/fm-codex-session-lock.test.sh exited 0.
  • TMPDIR=&#34;$PWD/.test-native-lock/tmp&#34; bash tests/fm-codex-session-identity-live-e2e.test.sh exited 0.
  • TMPDIR=&#34;$PWD/.test-native-lock/tmp&#34; bash tests/fm-watch-checkpoint.test.sh exited 0.
  • python3 .test-native-lock/live-driver.py --live exercised native ownership, guards, and recovery; exited 0.
  • python3 .test-native-lock/fallback-live.py passed real spaced-path cases; its later sandbox setup failed and was replaced by the embedded CLI route.
  • python3 .test-native-lock/ordinary-cli-live.py passed after correcting driver completion handling; exited 0.
  • python3 .test-native-lock/baseline-replay.py reproduced unsafe base ownership and confirmed target refusal; exited 0.
  • Confirmed recorded servers stopped, removed disposable labs, and verified a clean worktree at the target commit.
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T19:27:49.993694Z
We couldn’t complete this review. Comment @codex review to try again.
a5faa44 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@karanmrn

karanmrn commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Note

🤖 Claude Opus 5.5 responding on behalf of karanmrn

Two local test failures seen while validating this change also fail identically on untouched upstream main, so they are not caused by this PR.

  • tests/fm-sessionstart-nudge.test.sh: not ok - the compact run wrapper did not forward its source to instruction refresh (missing: 'RUN_TIER_AGENTS=updated')
  • tests/fm-session-start.test.sh: not ok - a truncated session start did not say so (missing: 'STARTUP TRUNCATED - SESSION START HIT ITS') (also fails when the suite runs alone)

Both were reproduced on a clean export of main at 65a9a51f on macOS 27.2 arm64. Neither touches the native Codex session-lock path changed here.

@greptile-apps

greptile-apps Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The PR appears safe to merge, with no new actionable issues found.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Reviews (5) · Last reviewed commit: "no-mistakes(document): Clarify lock and ..." · Reviewed by Greptile

Comment thread bin/fm-session-lock-lib.sh Resolved
Comment thread bin/fm-session-lock-lib.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @karanmrn. I read tip 18dfded3 against main bf05a4fc. Native Codex threads that share one app-server can no longer both claim the home lock: ownership requires a trusted codex-native:<uuid> identity (and matching sidecar), SessionStart/Stop bind identity before ownership checks, and a non-owner native thread stays read-only without starting watch checkpoints. That matches the product promise of one supervisor per home. I approved the first-time fork CI runs on this head. Require no-mistakes, repo invariants, and the coverage guard are green. The red Full suite check is our label gate — nothing for you there.

Contract-class: restore. Main already promised single-home ownership; shared app-server PID trust was the bug. This restores that boundary for native Codex.

VISION: One captain aligns · Authority aligns (read-only refusal, no widened autonomy) · Scripts own the mechanics aligns (exact identity/ownership checks) · Restart aligns (durable lock + sidecar) · Delegation/spine aligns · Vendor aligns (binds to Codex-exposed session identity) · Scope aligns (harness adapter / supervision).

Waiting on you for one Greptile thread (outdated P1 on bin/fm-session-lock-lib.sh, "Prompt text blocks ordinary sessions"). Your tip already carries a dedicated missing-python3 / prompt-text regression in tests/fm-codex-session-lock-repro.py. If that covers it, please resolve the thread (or reply if you disagree). Then we can move this forward. Greptile is currently 4/5 with that thread open. Live evidence noted. Rockets: none. No workflow/credential changes.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @karanmrn for the clear evidence on the missing-python3 prompt-text regression, and for resolving that thread. I agree it's covered at 18dfded3.

This is still waiting on you, for one more item. I should have raised it in my last note, and I'm sorry for the extra round. The Greptile Review check is red on 18dfded3. Its summary (4/5) says the earlier spaced-path ownership failure comes back when the argv reader is unavailable. I traced it in fm_session_lock_codex_native_pid and I think it's real:

  • If fm-procinfo.py --argv prints nothing (for example, no python3), the fallback splits FM_PROC_ARGS on whitespace.
  • For codex -C '/Users/me/My Home' app-server, -C consumes /Users/me/My, and Home becomes the first positional, so the server is classified as an ordinary CLI.
  • The shared server pid then falls back to the PID-ancestry contract. A second thread under the same server can own the lock through ancestry, which is the boundary this PR restores.

The body's known limitation covers the other direction (a native thread staying read-only), not this one.

Please close this gap, or reply explaining why it can't happen. Two possible fixes:

  • When argv is unreadable and the flattened arguments contain an app-server token after the parser stopped, fail closed (no PID-only ownership). Without python3, an ordinary CLI whose prompt mentions app-server would then go read-only, which is the safer side of that trade.
  • On Linux, read /proc/<pid>/cmdline directly in bash, so only hosts with no argv reader at all reach the fallback.

Please add a regression for a spaced -C value with the argv reader hidden, then re-raise through git push no-mistakes so Greptile re-reviews and the attestation binds the new head.

The red Full suite row is our label gate, so nothing for you there. Contract-class: restore, unchanged. VISION: aligns on every rule.

@karanmrn

Copy link
Copy Markdown
Contributor Author

Note

🤖 GPT-6 responding on behalf of karanmrn

Fixed the unreadable-argv fallback gap in 6969d61c, pushed through no-mistakes.
When argv is unavailable, a standalone app-server token now prevents PID-only ownership before option parsing can consume it.
This covers spaced directory and executable paths, including option-shaped directory fragments.
Readable argv still uses exact argument boundaries.
An ordinary CLI prompt containing that token stays read-only when argv is unavailable, as requested.

The missing-Python spaced--C regression failed before the fix and passes afterward.
tests/fm-codex-session-lock-repro.py checks fresh acquisition and legacy shared-PID ownership with the argv reader unavailable.
The pipeline also passed all four live ownership, Stop, and checkpoint scenarios.

The control-byte case in tests/fm-session-lock-ps-denied.test.sh fails identically on base on this macOS host and is unrelated.

Karan Manoharan and others added 15 commits December 1, 2026 10:28
A native Codex app-server (or code-mode host) serves many threads from one
process, so every thread's hook and tool shell walks to the same server pid.
Ancestry alone therefore let a second thread acquire, trust, and supervise a
home another thread already owned.

Inside a verified native ancestry, ownership now requires the thread's trusted
session identity: CODEX_SESSION_ID and CODEX_THREAD_ID from shell tools, or the
hook payload session_id, recorded beside the lock as codex-native:<uuid>.
A descendant thread cannot own its root session's lock, and a legacy pid-only
native lock stays read-only until its process dies. Ordinary Codex CLI
sessions keep the ancestry contract.

- bin/fm-session-lock-lib.sh owns the native identity contract and reads
  process identity through fm_proc_info, so the ps-free route applies.
- fm-lock.sh no longer treats a matching line-1 pid as ownership on its own.
- SessionStart run, Stop guard, and the Codex Stop park bind the hook payload
  identity before any lock consumer runs; the nudge uses the shared verdict.
- A non-owner native thread gets the read-only Stop diagnostic and cannot
  start a watch checkpoint.
- tests/fm-codex-session-lock.test.sh and the default-on live guard
  tests/fm-codex-session-identity-live-e2e.test.sh drive the repro fixture;
  the ps-denied suite covers the native read through the ps-free route.
…keeping ambiguous app-server invocations read-only; focused regression fixture passes with zero failures
…d argument boundaries, and refusal when argv is unreadable. Added spaced-path and kernel-argv regressions. The regression failed before the fix and passes afterwards. Native-lock, ancestry, checkpoint, and ShellCheck checks pass. The full ps-denied suite retains an existing macOS rendering failure, reproduced on unmodified HEAD. The excluded rendering code remains unchanged
…er and stop at the first positional argument. The missing-python regression failed before and passes after. Native-lock, ancestry, checkpoint, focused ps-denied, and ShellCheck checks pass. Readable-argv behaviour and fm-procinfo.py remain unchanged. The full ps-denied suite retains a macOS rendering failure, also reproduced with the unchanged HEAD test
When argv is unreadable, retain app-server tokens after the option parser stops as shared-server evidence. They cannot prove a session identity, so the lock remains read-only instead of accepting PID ancestry.

Add regressions for spaced directory values with Python hidden, legacy PID-only locks, and the accepted read-only prompt tradeoff. Refresh the live Codex verification record.
The two Codex lock suites exceed the existing serial packing budget after the rebase. Add one shard and keep the packing target and job timeout.
Run the Stop payload identity and ancestry checks only when a published lock can have a foreign owner. The Stop guard keeps its existing fast path on homes without a lock.
@karanmrn
karanmrn force-pushed the fm/fm-up-codex-native-lock branch from 6969d61 to d03abb3 Compare December 1, 2026 10:45
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @karanmrn. I read the new head d03abb3a. The unreadable-argv fallback I asked about is handled: a standalone app-server token now blocks PID-only ownership, and tests/fm-codex-session-lock-repro.py covers the spaced -C path with the argv reader hidden. Greptile is 5/5 on this head.

Still waiting on you, for one item: the attestation in the body binds 6969d61c, but the head is d03abb3a, so Require no-mistakes fails ("Pipeline attestation head_sha does not match"). Please re-raise once with git push no-mistakes so every step runs on the final head.

Heads-up for Kun, not for you: this head now edits .github/workflows/ci.yml (serial shards 19 → 20) and PORTABLE_SERIAL_SHARDS. A workflow edit needs Kun's own approval of fork runs and his word on the extra required check. #8600 adds the same 20th shard, so whichever lands second needs reconciling, and that part is ours. When the attestation binds, I'll finish the full line-by-line review of the remaining delta and card it for Kun. Contract class: restore (unchanged). VISION: aligns on every rule.

@karanmrn karanmrn changed the title fix: enforce native Codex session lock ownership fix: prevent native Codex threads from sharing session-lock ownership Dec 1, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @karanmrn. Your re-raise binds the attestation to the current head ec8f61fc with every step completed, so the earlier ask is cleared. Nothing is waiting on you now; this is with Kun for a decision.

Diff review (full read of the bin/ changes: session-lock library, lock, stop-park, turn-end guard, checkpoint, sessionstart, procinfo, test runner): no P1 found. The new codex-native:<uuid> identity is accepted only inside a verified native Codex ancestry, both CODEX_SESSION_ID and CODEX_THREAD_ID must match the trusted root id, a hook payload that disagrees becomes invalid, and an unreadable argv with an app-server token fails closed (the spaced -C case I asked about is now covered). Greptile is 5/5, with no open threads and no conflict with main 8bfcc883.

Why it goes to Kun, not auto-merge:

  • It edits .github/workflows/ci.yml (portable serial shards 19 to 20, plus PORTABLE_SERIAL_SHARDS), which needs Kun's own word on the extra required check. For that reason I have not added full-ci; the Full suite has not run on this head.
  • It is a security-sensitive session-lock ownership change.
  • feat(spawn): opt-in fail-closed worker sandbox wrapper hook #8600 adds the same 20th shard, so whichever lands second needs reconciling; that part is ours.

Contract class: restore (the lock boundary the docs already promise). VISION: aligns on all seven rules, as before.

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.

2 participants