Keep Claude NODE_OPTIONS restore shim out of TMPDIR

Closed
AU
2mo ago
+1543-222

Fixes https://github.com/manaflow-ai/cmux/issues/12022.

Summary

  • Reproduce the long-lived Claude failure by deleting the restore preload directory while a wrapped session is alive.
  • Store the restore module atomically in cmux's persistent per-user ~/.cmuxterm/cmux-claude-node-options/ directory instead of $TMPDIR.
  • Quote the --require path for homes containing spaces and recreate inherited legacy $TMPDIR restore modules when a wrapper/launcher still references them.
  • Apply the same durable lifecycle to the Swift claude-teams and omc launchers, extracted into a budget-safe helper file.
  • Restore semantic agent-journal delivery after the origin/main merge, including attention identity, event timestamps, stop_hook_active, and non-fabricating idle/state-change classifications.
  • Wire the helper into the cmux-cli target, remove the stale duplicate implementation, and expose only the three target-internal helpers needed across CLI extension files.
  • Preserve a truly absent NODE_OPTIONS value when migrating an inherited legacy restore-only preload.

Trade-offs

  • A single per-user restore module remains on disk for the lifetime of the cmux installation instead of one temp module per session; this removes the macOS temp purge lifecycle and avoids stale per-session files.
  • If the durable per-user directory cannot be written, cmux skips the optional NODE_OPTIONS injection rather than falling back to another purgeable directory.
  • Legacy temp paths are recreated only when an existing launch environment still references them; new launches never point NODE_OPTIONS at $TMPDIR.
  • The pure helper remains in the existing CLI target rather than moving into CMUXAgentLaunch: it uses cmux-specific cache ownership, localization, and legacy-path migration policy, and the behavior-level harness already exercises the external contract. This avoids expanding a package API and avoids unrelated package migration while still wiring the source into the real cmux-cli build.
  • The tagged cloud dogfood uses CMUX_DEV_BACKEND_MODE=off because the optional backend provisioning endpoint returned a DNS failure; the app build and wrapper behavior remain cloud-built, and no local Xcode build is used.

Validation

  • python3 tests/test_claude_wrapper_node_options_survives_tmpdir_purge.py (passes)
  • Focused legacy restore regression from tests/test_claude_wrapper_hooks.py (passes)
  • bash scripts/check-pbxproj.sh (passes)
  • bash scripts/lint-pbxproj-test-wiring.sh (passes)
  • python3 -m py_compile tests/test_claude_wrapper_node_options_survives_tmpdir_purge.py
  • python3 -m json.tool Resources/Localizable.xcstrings
  • bash -n Resources/bin/cmux-claude-wrapper
  • git diff --check
  • Hosted semantic-delivery CI previously identified and this branch fixed: cross-file CLI access control, missing CMUXCLI+ClaudeNodeOptions.swift target wiring, stale duplicate helper declarations, and semantic event argument ordering.

End-to-end verification

  • Tagged cloud build issue-12022-wrapper-shim-tmpdir-83684edcd9d7 succeeded with CMUX_DEV_BACKEND_MODE=off.
  • The running tagged app exercised the real shim and wrapper through CMUX_SURFACE_ID=surface:1: it installed the durable preload outside TMPDIR, deleted the launch temp directory, started a Node child successfully, restored the original NODE_OPTIONS, and loaded the original preload.
  • No local Xcode build or local XCUITest was used.

[!NOTE]
Medium Risk
Changes how Claude/Node processes inherit and restore NODE_OPTIONS plus broad agent-hook notification and cloud catalog merge logic, which can affect long-lived sessions and UI attention state if miswired.

Overview
Moves the Claude NODE_OPTIONS restore preload out of purgeable $TMPDIR into ~/.cmuxterm/cmux-claude-node-options/, with shared logic in CMUXCLI+ClaudeNodeOptions.swift and matching updates to cmux-claude-wrapper, claude-teams, and omc. The helper quotes paths safely, strips duplicate managed --require / heap flags, preserves truly absent original options, and can recreate legacy temp restore modules still referenced by an inherited environment.

Agent integration changes clear pane notifications when a turn resumes, dedupe repeated hook notifications, adjust journal kinds (e.g. approval responses as turnStarted), and restore semantic hook argument ordering plus a Codex post-tool pane-scoped clear_notifications fallback when attention identity is missing.

Cloud work adds SurfaceCatalog+CloudRenameReconciliation for optimistic workspace renames on the legacy versioned snapshot path, expands the cloud VM SSH bootstrap script (workspace/surface exports, scoped tmux sessions), and tweaks CodeRouter help/errors to reflect an installed-only CLI passthrough.

CI wires Node 20 into Depot/Xcode tests via TEST_RUNNER_CMUX_NODE_BINARY, runs a new tmpdir-purge regression, and grandfather two flaky determinism findings.

Reviewed by Cursor Bugbot for commit e177006ab996fcbc84698d0338f2cfaff409fb4e. Bugbot is set up for automated code reviews on this repo. Configure here.

Final verification

  • Final pushed HEAD: 6820f8fa14.
  • Cloud build issue-12022-wrapper-shim-tmpdir-83684edcd9d7 compiled successfully remotely with CMUX_SKIP_ZIG_BUILD=1, CMUX_DEV_BACKEND_MODE=off, and RELOAD_CLOUD_FALLBACK_LOCAL=0.
  • The exact tagged runtime path was exercised on the previously built app: deleting the launch $TMPDIR left the wrapped Node child alive, preserved and restored the original NODE_OPTIONS, and kept the durable restore preload under ~/.cmuxterm/cmux-claude-node-options/. claude-teams --version also treated restore-only inherited options as absent and injected the durable preload plus heap flag.
  • No app product source changed after that runtime verification; later commits only adjust CI/test harness execution. The local artifact-install leg was blocked by the shared Mac reaching 99% disk usage, so no local build or XCUITest was run.
  • This is a CLI/runtime change, not a visual UI change; screenshots are not applicable.

CI fixes and trade-offs

  • Added Node 20 to both test-depot.yml and the sharded app-host job in ci.yml.
  • Passed the absolute Node executable through TEST_RUNNER_CMUX_NODE_BINARY; Xcode strips ordinary environment variables from app-host test bundles, so a plain CMUX_NODE_BINARY was insufficient.
  • Kept the OpenCode harness’s UUID isolation but rooted its temporary socket directory at /tmp; the hosted runner’s long NSTemporaryDirectory() path exceeded macOS Unix-socket limits and surfaced as a misleading EADDRINUSE.
  • Added two determinism allowlist entries for findings introduced by origin/main; this preserves strict detection of new findings without claiming pre-existing main-branch findings are regressions.
  • The current-head CI runs are 34320675254 (CI) and 34320675520 (Agent notification semantics); they are being rechecked before merge.

Verification commands

  • python3 tests/test_claude_wrapper_node_options_survives_tmpdir_purge.py
  • python3 tests/test_claude_wrapper_hooks.py
  • bash scripts/check-pbxproj.sh
  • bash scripts/lint-pbxproj-test-wiring.sh
  • python3 scripts/check-test-determinism.py --strict
  • python3 tests/test_ci_change_areas.py
  • python3 -m json.tool Resources/Localizable.xcstrings
  • bash -n Resources/bin/cmux-claude-wrapper
  • git diff --check