Skip to content

fleet: stop sandboxed macos display launches before the wake (#5159) - #5173

Open
jakildev wants to merge 1 commit into
claude/5144-macos-display-wakefrom
claude/5159-macos-sandbox-display-stop
Open

jakildev wants to merge 1 commit into
claude/5144-macos-display-wakefrom
claude/5159-macos-sandbox-display-stop

Conversation

@jakildev

Copy link
Copy Markdown
Owner

Summary

A Codex shell command that misses its fleet-run allow rule (a redirection, a compound statement, an env/VAR= prefix) runs inside Codex's Seatbelt sandbox. That sandbox denies the WindowServer lookup, so the engine discovers 0 display monitors. Both awake-display incidents on #5159 come from this.

The shared display-readiness helper from #5144 (scripts/fleet/fleet_display_session.py) now checks this first. Before the wake request, before any caffeinate holder and before the CoreGraphics/AppKit probe (which aborts inside the sandbox), it asks the kernel: sandbox_check(getpid(), "mach-lookup", SANDBOX_FILTER_GLOBAL_NAME, "com.apple.windowserver.active"). If the lookup is denied, the new sandboxed condition blocks the launch. The failure line names the sandbox and the remedy (launch the command bare and allow-listed, or use fleet-jobs start render-verify|light-verify|gui-verify, per CODEX.md).

  • Every display-backed entry point that goes through the helper picks this up: ir-run capture verbs (RESULT=NO-DISPLAY, exit 69), the verifier preflight (ENV-FAIL, exit 69) and the fleet-jobs display profiles (job failed with 69; start exits 69).
  • The message contains "sandbox", so a decline that quotes it classifies as sandbox and moves the target to another runtime. No new regex was needed.
  • A query that errors (-1), a symbol that won't load, or a non-macOS host counts as "not sandboxed" and falls through to the existing path. Non-capture launches never reach the helper. A sandboxed IrredenEngineTest run is unaffected.
  • The ir-run helper CLI now prints the failure line on exit 69, as the verifiers already did, so the remedy reaches ir-run's stderr.
  • Test seam FLEET_DISPLAY_SANDBOX (denied / allowed / error). fake_display.FakeDisplay.env() pins it to allowed, so the existing fleet: display-backed runs fail whenever the macOS display has idled to sleep #5144 arms keep their meaning when the suite itself runs inside a sandbox (plan correction 2). The fake probe now logs each call, so the denied arms can assert the probe never ran.
  • docs/agents/CODEX.md § "Capability qualification": the stale ALIVE-TIMEOUT sentence is replaced by the pre-launch stop plus the NO-DISPLAY/69 backstop. Redirections, compound statements, subshells and cd … && are added to the shapes that fall back into the sandbox. docs/AGENT_FLEET_SETUP.md § "Display-backed runs on an unattended Mac" (fleet: display-backed runs fail whenever the macOS display has idled to sleep #5144's condition table) gets the sandbox condition, which is checked first and classifies as a sandbox decline rather than a host decline.

Merge after #5160 (this is stacked on it).

Acceptance evidence

Criterion Evidence Result
1. Live positive fire (macOS): fleet-run stops before launch under codex sandbox Transcript A below: the sandbox-condition line, RESULT=NO-DISPLAY … exit=69, no engine log line PASS
1. render-verify stops in its preflight under codex sandbox Transcript B: [render-verify] ENV-FAIL: display unreachable: … sandbox …, rc=69 PASS
1. Control: same fleet-run unsandboxed ends CLEAN with N ≥ 1 monitors Transcript C: Discovered 2 display monitors, RESULT=CLEAN, rc=0 PASS
2. Real kernel query, macOS only, skipped elsewhere test_real_kernel_query_reads_a_windowserver_denying_sandbox: no sandbox-exec → False; (allow default) → False; WindowServer-deny profile → True. Run under sandbox-exec -p '(version 1)(allow default)' it reports skipped 'this suite runs inside a sandbox; the profile cannot nest' PASS
3. Hermetic: test_no_display_env_fail.py denied arm exits 69, says "sandbox", never calls the fake caffeinate or probe; allowed / error / non-macOS unchanged python3 scripts/tests/test_no_display_env_fail.py → Ran 24 tests … OK (new: test_sandbox_denial_is_no_display_before_wake_or_probe, test_sandbox_allowed_or_unanswered_keeps_the_wake_path, test_sandbox_denial_leaves_other_launches_alone, test_sandbox_denial_blocks_and_names_the_remedy, test_sandbox_denial_stops_the_verifier_before_the_wake) PASS
3. Hermetic: test_fleet_jobs.py display profile under "denied" ends 69 before the verifier starts python3 scripts/fleet/tests/test_fleet_jobs.py → Ran 37 tests … OK (skipped=2) (new: DisplayHold.test_sandbox_denial_fails_the_job_before_the_wake_or_verifier) PASS
3. Mutation: removing the check turns the denied arms red With the windowserver_denied early return deleted: test_no_display_env_fail.py FAILED (failures=4, all sandbox arms); test_fleet_jobs.py sandbox arm FAIL; test_fleet_task_class.py sandbox-class arm FAIL ×3. Restored afterwards PASS
4. Backstop: a persistent zero-monitor log stays NO-DISPLAY/69 IrRunNoDisplayTest.test_persistent_zero_monitor_run_fast_fails_and_stops_child passes in the 24-test run PASS
4. Stop line classifies as sandbox; decline suite passes test_fleet_task_class.py → Ran 151 tests … OK (new: test_sandboxed_display_stop_reads_as_sandbox, covering the ENV-FAIL, not started: and ir-run: forms); bash scripts/fleet/tests/run_all.sh --only fleet_claim_decline → 1 passed, 0 failed PASS
5. Lint python3 scripts/lint_instruction_refs.py --against origin/master → none new; ruff check scripts/ → All checks passed!; git diff --check origin/master...HEAD → clean; lint_instruction_size.py --against origin/master → no introduced offenders PASS

All three live runs were on this macOS host on AC power at 2026-11-18T05:17Z, using the plan's command: codex sandbox -c 'sandbox_mode="workspace-write"' -c sandbox_workspace_write.network_access=true -c 'sandbox_workspace_write.writable_roots=[<worktree>, <its two git dirs>, ~/.fleet, ~/.cache/irreden, /tmp]' -- bash -c '…'.

A — scripts/fleet/fleet-run --timeout 60 IRShapeDebug --auto-screenshot 5, sandboxed (this branch)

CODEX_SANDBOX=seatbelt
ir-run: running debug tree <worktree>/build
ir-run: display unreachable: the launching process runs inside a sandbox that denies the WindowServer lookup (mach-lookup com.apple.windowserver.active); the engine would discover 0 display monitors — launch the command bare and allow-listed (no redirection, compound statement, subshell, `cd ... &&`, or env/VAR= prefix), or as `fleet-jobs start render-verify|light-verify|gui-verify` (docs/agents/CODEX.md "Capability qualification")
ir-run: RESULT=NO-DISPLAY exe=IRShapeDebug exit=69 — the display could not be made ready (see the line above); the exe never ran
rc=69

The same sandboxed command against master's ir-run still launched the engine and reproduced incident A's signature: Connection Invalid error for service com.apple.hiservices-xpcservice., Discovered 0 display monitors, the _LSModifyNotification failure, then ir-run: RESULT=NO-DISPLAY exe=IRShapeDebug exit=69.

B — python3 scripts/render-verify.py --target IRShapeDebug --no-build, sandboxed

CODEX_SANDBOX=seatbelt
[render-verify] target=IRShapeDebug demo=shape_debug backend=macos-debug warmup=10
[render-verify] 21 shots: zoom1_origin, … (list elided)
[render-verify] 56 extra run(s): … (list elided)
[render-verify] ENV-FAIL: display unreachable: the launching process runs inside a sandbox that denies the WindowServer lookup (mach-lookup com.apple.windowserver.active); the engine would discover 0 display monitors — launch the command bare and allow-listed (…), or as `fleet-jobs start render-verify|light-verify|gui-verify` (docs/agents/CODEX.md "Capability qualification")
rc=69

C — control, the same fleet-run run unsandboxed

ir-run: display before wake: CoreGraphics online=2 awake=2 NSScreen=2
ir-run: display wake requested: /usr/bin/caffeinate -d -u -w <pid> (pid <pid>) holds PreventUserIdleDisplaySleep for the run
ir-run: display ready after 0.1s: CoreGraphics online=2 awake=2 NSScreen=2
[EngineLog] [info] Discovered 2 display monitors
ir-run: RESULT=CLEAN exe=IRShapeDebug exit=0
rc=0

Open-PR overlap

fleet-pr-overlap --base claude/5144-macos-display-wake → VERDICT: overlap. The shared paths with #5160 are this PR's own upstream. The other two trial-merge clean:

#5169 scripts/fleet/tests/test_fleet_task_class.py clean
#5171 engine/tools/bin/ir-run clean

Plan departures

  • The kernel query loads /usr/lib/libSystem.B.dylib explicitly. The plan measured sandbox_check through ctypes without naming a library. The ctypes shape is the one the plan measured: argtypes = [c_int, c_char_p, c_int], with the service name passed as the extra variadic argument.
  • The live transcripts run the worktree's scripts/fleet/fleet-run. The plan's command uses the bare fleet-run. On PATH, that resolves through ~/bin to the main clone, which is master's ir-run. That run is the before transcript quoted under A.
  • The fleet-jobs supervisor still writes its display: discovery line before the hold. Inside the sandbox that line reads as a failed probe. The pre-existing line is left in place, and the sandbox stop runs right after it, before any wake or holder.

Closes #5159

🤖 Generated with Claude Code

@jakildev jakildev added fleet:wip Work in progress — not ready for review fleet:author-claude Implementation last authored by Claude; route review to Codex labels Nov 18, 2026
@jakildev
jakildev added this pull request to stack #5174 November 18, 2026 05:20
@jakildev jakildev added fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend and removed fleet:wip Work in progress — not ready for review labels Nov 18, 2026
@jakildev jakildev added the fleet:awaiting-upstream-review Stacked PR; reviewer is holding verdict until upstream PR is approved label Nov 18, 2026
@jakildev

Copy link
Copy Markdown
Owner Author

Holding review: upstream PR #5160 is not yet approved. This stacked PR will be re-evaluated once the upstream lands an approval label.

A Codex shell command that misses its fleet-run allow rule (a
redirection, a compound statement) runs inside Seatbelt, which denies
the WindowServer lookup, so the engine discovers 0 display monitors.
The shared display-readiness helper now asks the kernel first
(sandbox_check on the com.apple.windowserver.active mach lookup) and
blocks with a "sandboxed" condition before the wake, the caffeinate
holder and the CoreGraphics probe, which aborts there.

ir-run capture verbs, the verifier preflight and the fleet-jobs display
profiles all inherit the stop through the helper: exit 69, with a line
naming the sandbox and the bare-command remedy, which a decline quoting
it classifies as sandbox. CODEX.md and the macOS setup guide describe
the stop and the launch shapes that fall back into the sandbox.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jakildev
jakildev force-pushed the claude/5159-macos-sandbox-display-stop branch from a4e0c9f to 54e5f5a Compare November 26, 2026 08:31
@jakildev

Copy link
Copy Markdown
Owner Author

Merger: rebased onto current claude/5144-macos-display-wake (stacked base, #5160) without conflicts. The base PR had been rebased onto master, and git dropped the stale copy of its wake commit (2eeca2152) as patch-identical to 637cb12e4. This PR now carries only its own commit (54e5f5ad8), and every line it adds is still present after the rebase. Force-pushed with --force-with-lease. CI will re-run.

— fleet merger

@jakildev jakildev added the fleet:merger-cooldown Merger touched this PR this iteration; skip next iteration label Nov 26, 2026
@evin-mac-claude-app

Copy link
Copy Markdown
Contributor

Every failed workflow on this head is also red on master:

These failures are inherited and are not this pull request's to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fleet:author-claude Implementation last authored by Claude; route review to Codex fleet:authored-on-macos PR was authored and smoke-tested on macOS Metal backend fleet:awaiting-upstream-review Stacked PR; reviewer is holding verdict until upstream PR is approved fleet:merger-cooldown Merger touched this PR this iteration; skip next iteration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fleet: macOS engine launches find 0 display monitors while the display is awake

1 participant