Skip to content

fix(codex): stop recursive dynamic-launcher shims - #1441

Open
comfuture wants to merge 14 commits into
lidge-jun:devfrom
comfuture:fix/1439-mise-shim-recursion
Open

fix(codex): stop recursive dynamic-launcher shims#1441
comfuture wants to merge 14 commits into
lidge-jun:devfrom
comfuture:fix/1439-mise-shim-recursion

Conversation

@comfuture

@comfuture comfuture commented Aug 11, 2026

Copy link
Copy Markdown

Summary

  • Stop generated Unix Codex autostart shims from spinning forever when a saved dynamic launcher resolves codex back to the wrapper, as observed with mise exec -- codex.
  • Validate fresh installs, direct refreshes, and guarded auto-restores with a bypassed, bounded --version probe before committing state. Unsafe results and unexpected probe exceptions roll back the new launcher, prior owned backup, wrapper, and state transaction.
  • Isolate launcher validation in a detached process group without relying on shell job control. Timeout, background descendants, and cleanup failure are classified before rollback; terminated groups are verified with exact ESRCH handling.
  • Detect recursive redispatch even when a descendant escapes into a new session or process group by observing a probe-only private sentinel for the full five-second validation window. An inherited descendant lease provides earlier liveness evidence but is not trusted as the sole completion signal.
  • Drain launcher diagnostics with a bounded fallback, store probe metadata in a private temporary directory, and preserve user launchers across partial writes and concurrent replacements.
  • Revalidate generated wrappers after probing and use recorded fingerprints during rollback, so an updater replacement is neither committed as an owned shim nor unlinked.
  • Revision and transactionally regenerate obsolete installed Unix shims. Safe saved launchers upgrade in place; unsafe recursive backups remove the obsolete shim and restore the original launcher.
  • Keep same-PID and bounded-depth runtime guards as backstops. Exec recursion fails immediately; one legitimate new-PID nested Codex invocation remains allowed, while repeated child-process shim redispatch exits 126 with the supported ocx codex-shim uninstall recovery command.
  • Add regression coverage for same-PID, child-process, delayed detached-session redispatch, obsolete-shim migration, dash compatibility and seam activation, immediate diagnostics, descendant cleanup, timeout and exception rollback, partial writes, concurrent replacement in every install and repair path, existing-backup preservation, and valid child invocation.
  • Document launcher validation and remediation in the canonical lifecycle page and all translated lifecycle pages.
  • Rebased onto upstream/dev at 7779c05748485e45b0011c9e2f6375a1bd124286; the newest upstream-only changes are confined to PR-target workflow code and tests, with no shim overlap.

Closes #1439

Verification

  • bun run prepush on the code-equivalent head before the final upstream-only CL-07/lab rebase: 10,833 passed, 7 skipped, 0 failed; typecheck and privacy scan passed.
  • Exact latest-dev head: bun run typecheck passed and bun test tests/codex-shim.test.ts passed (56 passed, 0 failed).
  • cd docs-site && bun install --frozen-lockfile && bun run build passed and built 221 pages.
  • bun run privacy:scan passed on the current head.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
    • The canonical English lifecycle page and Korean, Russian, Japanese, and Simplified Chinese translations document validation refusal and remediation.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.
    • Probes bypass service startup, are bounded, retain only bounded temporary diagnostics inside a private directory, observe process-independent re-entry for the full five-second window, use an inherited lease as supplemental liveness evidence, terminate the original isolated process group, and roll back before state commit. Probe metadata contains no secrets.

Review readiness checklist

This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:

  • All CI tests are green on my local testing.

  • I pushed my PR to the latest dev commit.

  • I resolved all correct Codex and CodeRabbit findings.

  • My PR is ready for review.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented Unix command shims from recursively invoking themselves.
    • Installations, repairs, and upgrades now validate launchers before applying changes.
    • Unsafe, failed, timed-out, or incomplete checks are rejected and rolled back safely.
    • Improved process cleanup, diagnostics, backup protection, and restoration of original launchers.
    • Preserved valid nested command execution without affecting expected output.
  • Documentation

    • Updated lifecycle guidance in multiple languages with launcher validation and recovery details.
  • Tests

    • Expanded coverage for recursion, timeouts, cleanup, concurrency, rollback, and successful child invocation.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The Unix Codex shim now embeds revision and recursion guards, validates launchers with bounded --version probes, terminates leaked process groups, and rolls back unsafe or concurrently modified transactions. Obsolete shims receive transactional upgrades, and lifecycle documentation covers the new behavior.

Changes

Unix shim safety

Layer / File(s) Summary
Runtime recursion guard
src/codex/shim.ts, tests/codex-shim.test.ts
The generated shim emits a revision marker, detects recursive re-entry, reports status 126, and preserves valid child invocation behavior.
Installation probe and rollback
src/codex/shim.ts, tests/codex-shim.test.ts
Fresh installations run bounded probes, classify recursion, timeouts, nonzero exits, descendant leakage, and cleanup failures, then restore transaction-owned files.
Refresh transaction validation
src/codex/shim.ts, tests/codex-shim.test.ts
Refresh paths fingerprint staged files, validate wrappers before state commit, detect concurrent changes, and avoid overwriting externally changed files during rollback.
Obsolete shim upgrade and auto-restore
src/codex/shim.ts, tests/codex-shim.test.ts
Auto-restore identifies obsolete Unix shims and routes stable cases through transactional upgrades. Unsafe upgrades restore the original launcher or defer the operation.
Lifecycle documentation
docs-site/src/content/docs/**/reference/cli/lifecycle.md
The lifecycle documentation describes launcher probing, rollback, obsolete shim upgrades, and launcher restoration in five locales.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Installer
  participant GeneratedShim
  participant SavedLauncher
  participant ProcessGroup
  participant ShimState
  Installer->>GeneratedShim: run bounded --version probe
  GeneratedShim->>SavedLauncher: execute saved launcher
  SavedLauncher-->>GeneratedShim: return or recurse
  GeneratedShim->>ProcessGroup: terminate descendants
  GeneratedShim-->>Installer: return probe classification
  Installer->>SavedLauncher: restore launcher on failure
  Installer->>ShimState: commit state after successful validation
Loading

Possibly related PRs

Suggested reviewers: lidge-jun, ingwannu

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR addresses recursion and rollback, but its /bin/sh probe rejects valid native executables and symlinks required by issue #1439. Probe the launcher directly with spawn(wrapperPath, ["--version"], ...) and add regression coverage for native executables and symlinks.
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Out of Scope Changes check ✅ Passed The implementation, tests, and lifecycle documentation remain within the recursion-prevention, validation, rollback, migration, and compatibility objectives of issue #1439.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: preventing recursive dynamic-launcher shims in Codex.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Aug 11, 2026
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

✅ READY

  • all PR quality gates passed; the review readiness checklist is complete.

Review readiness checklist

  • ✅ All CI tests are green on my local testing.
  • ✅ I pushed my PR to the latest dev commit.
  • ✅ I resolved all correct Codex and CodeRabbit findings.
  • ✅ My PR is ready for review.

4/4 boxes ticked.

This pull request is already Ready for Review.
The review-ready label marks this PR as ready; review automation runs independently. If no CodeRabbit review appears, comment @coderabbitai review to request one.
Maintainers: @lidge-jun @Ingwannu @Wibias

@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 00:03

@Wibias Wibias left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes on the current head (90ad67a37061cd9a5451f2cd2887f011d259a80d). I validated these against the current implementation and #1439 acceptance criteria.

  1. Medium — fresh install still commits a recursive launcher; the PID guard only covers same-process exec recursion.

The new OCX_SHIM_ACTIVE_PID=$$ guard correctly stops the reported mise exec -- codex loop because that chain preserves the PID. However, installCodexShimInternal() still accepts any non-shim launcher from PATH, renames it to .opencodex-real, writes the OpenCodex shim, writes state, and performs no bounded behavioural validation of the saved launcher before committing the installation.

That means #1439's install-safety invariant is still unmet: installation can leave a codex -> saved launcher -> codex cycle behind. It also leaves equivalent recursion forms possible when the dynamic launcher starts a new child process rather than exec-replacing itself, because each child gets a new PID and passes the guard. A launcher that sanitises OCX_SHIM_ACTIVE_PID before redispatch likewise bypasses this guard.

Please keep the runtime fail-fast guard, but also make the install transaction validate the saved launcher before committing. A bounded probe should detect re-entry/timeout and roll back to the original launcher without overwriting an existing backup or persisting shim state. Add install-level regression coverage for same-PID redispatch, child-process redispatch, failed validation rollback, and existing-backup preservation.

  1. Medium — the fail-fast recovery instruction points to the wrong command.

The new diagnostic tells users to run ocx restore, but ocx restore restores Codex routing/config integration; it does not remove the autostart shim or rename .opencodex-real back into place. The actual shim recovery path is ocx codex-shim uninstall / remove, which calls uninstallCodexShim() and is already excluded from shim auto-restore.

When this guard fires, plain codex is already unusable, so the recovery message needs to direct users to the actual shim removal path. Please update the diagnostic and add a regression assertion for the supported recovery command.

The exact reported mise exec reproduction is fixed, and I found no credential, auth, shell-injection, Windows, or secret-disclosure regression in the patch. The remaining blockers are the incomplete install-safety contract and the incorrect recovery guidance.

@Wibias
Wibias marked this pull request as draft August 11, 2026 00:13
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] I am replying to the latest comment only. The earlier comment chain is unavailable. I will review pull request #1441.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions The pull request is marked ready. I will review the current changes.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/codex/shim.ts`:
- Around line 442-456: The probe in probeUnixShimInstall must isolate the
launcher in its own process group, terminate the entire group on timeout, and
wait until the group has exited before rollbackFreshShimInstall runs. Apply the
probe change at src/codex/shim.ts lines 442-456 and ensure the rollback flow at
src/codex/shim.ts lines 1114-1126 occurs only after termination. Update
tests/codex-shim.test.ts lines 299-330 to fork a child process and assert that
no descendant remains, replacing the direct /bin/sleep-only fixture.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1534a890-481b-4c9e-a353-200ba87e0a78

📥 Commits

Reviewing files that changed from the base of the PR and between 90ad67a and bc630f2.

📒 Files selected for processing (2)
  • src/codex/shim.ts
  • tests/codex-shim.test.ts

Comment thread src/codex/shim.ts Outdated
@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 00:41
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions The readiness gate is complete. Pull request #1441 is marked ready for review at ee4f88dd94dc82baf6259e4c53778701286e83d8.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions: Acknowledged. Pull request #1441 is ready for review at ee4f88dd94dc82baf6259e4c53778701286e83d8.

You are interacting with an AI system.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/codex/shim.ts (1)

1195-1209: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Probe both refresh paths before committing a new shim.

refreshShimFile in src/codex/shim.ts:805-826 moves a non-shim launcher to backupPath and writes a shim without calling probeUnixShimInstall. src/update/index.ts:289-295 invokes this refresh automatically after an update. A dynamic launcher such as mise ... codex can therefore make codex hit the same-PID guard and exit 126.

The expectedReplacements path used by autoRestoreCodexShim has the same gap. It checks stable metadata, then commits the replacement without executing --version. Its rollback handles transaction errors, not an unsafe launcher. Reuse the probe-and-rollback logic in both paths, or defer the refresh and restore the launcher when the probe reports an unsafe result.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/codex/shim.ts` around lines 1195 - 1209, Reuse the existing Unix safety
probe and rollback behavior in both refresh paths: update refreshShimFile and
the expectedReplacements flow used by autoRestoreCodexShim to probe the
saved/original launcher with --version before committing a generated shim. If
the probe reports recursive resolution, timeout, or lingering descendants,
restore the original launcher and return the same failed-install result/message
instead of committing the shim; preserve normal replacement behavior for safe
launchers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/codex/shim.ts`:
- Around line 498-515: Update probeUnixShimInstall() to catch failures from
terminateUnixProcessGroup(groupId) and return "descendants" or another handled
probe result instead of propagating the exception. Preserve the existing timeout
and marker classification while ensuring rollbackFreshShimInstall() and
writeState() remain reachable after any filesystem mutation.
- Around line 42-73: Update CODEX_SHIM_INSTALL_PROBE_SCRIPT to resolve sleep
through PATH instead of assuming /bin/sleep, and make the watchdog exit without
writing the timeout marker or killing the launcher when sleep cannot start.
Preserve the outer spawnSync timeout as the fallback, and update the related
/bin/sleep and /bin/ps assumptions in the codex shim tests.

In `@tests/codex-shim.test.ts`:
- Line 252: Update the stderr assertion in the relevant codex shim test to
compare against the exported CODEX_SHIM_REENTRY_DIAGNOSTIC constant rather than
a shortened literal. Export or test-only re-export that constant from
src/codex/shim.ts, preserving the existing production classifier and ensuring
the test validates the complete diagnostic generated by buildUnixCodexShim.
- Around line 330-339: Strengthen the installCodexShim regression test to record
the grandchild /bin/sleep PID and the launcher’s process-group ID from the
fixture. Wait for the launcher’s descendant-check synchronization, then assert
both the grandchild is no longer running and process.kill with the negative
group ID fails. Preserve the existing child, shim-file, and install-result
assertions, following the coverage pattern used by the timeout test.
- Line 385: Update the process-group probe assertion near the existing
process.kill call to catch the thrown error and assert its
NodeJS.ErrnoException.code is "ESRCH", rather than using a broad toThrow()
check. Preserve the probe’s intended behavior of confirming the group no longer
exists, consistent with the process-group handling in the referenced shim logic.

---

Outside diff comments:
In `@src/codex/shim.ts`:
- Around line 1195-1209: Reuse the existing Unix safety probe and rollback
behavior in both refresh paths: update refreshShimFile and the
expectedReplacements flow used by autoRestoreCodexShim to probe the
saved/original launcher with --version before committing a generated shim. If
the probe reports recursive resolution, timeout, or lingering descendants,
restore the original launcher and return the same failed-install result/message
instead of committing the shim; preserve normal replacement behavior for safe
launchers.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3d3fb9e9-bef9-4bcd-8fc1-af077bbdb5fe

📥 Commits

Reviewing files that changed from the base of the PR and between bc630f2 and ee4f88d.

📒 Files selected for processing (2)
  • src/codex/shim.ts
  • tests/codex-shim.test.ts

Comment thread src/codex/shim.ts
Comment thread src/codex/shim.ts
Comment thread tests/codex-shim.test.ts
Comment thread tests/codex-shim.test.ts
Comment thread tests/codex-shim.test.ts Outdated
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

@github-actions[bot] Acknowledged. Pull request #1441 is ready for review at ee4f88dd94dc82baf6259e4c53778701286e83d8. The readiness checklist and deterministic hygiene checks passed.

You are interacting with an AI system.

@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 01:14
@comfuture

Copy link
Copy Markdown
Author

@Wibias I addressed both requested changes on the current head 6c42d17f2:

  • Fresh install, direct refresh, and guarded auto-restore now run the same bounded behavioral probe before committing state. Same-PID recursion, child redispatch, timeout, surviving descendants, and cleanup failure all take rollback paths that preserve the replacement launcher, prior owned backup, and state.
  • The fail-fast diagnostic now points to ocx codex-shim uninstall.
  • Regression coverage includes same-PID and child-process redispatch, child/grandchild process-group cleanup, timeout rollback, existing-backup preservation, and both refresh paths.

Local bun run prepush is green: 10,820 passed, 7 skipped, 0 failed; typecheck and privacy scan passed. A re-review of the current head would be appreciated.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/codex/shim.ts`:
- Line 476: Extend the UnixShimProbeResult type and the --version probe logic
around the recursive classification to return a distinct failure result whenever
result.status is non-zero. Update the rollback handling in the saved-launcher
installation flow to restore the original launcher, remove shim state, and
report that the saved launcher failed its --version probe. Add a regression test
covering a non-zero-exit launcher and asserting both restoration and state
removal.

In `@tests/codex-shim.test.ts`:
- Line 40: Update the cross-platform PATH assignments in withInstalledShim,
including both occurrences, to use the platform delimiter imported from
node:path instead of a hardcoded colon, ensuring installCodexShim can find the
temporary codex wrapper on Windows.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ca0cdd58-9ba7-4fab-8f35-70a158f9d970

📥 Commits

Reviewing files that changed from the base of the PR and between ee4f88d and 6c42d17.

📒 Files selected for processing (2)
  • src/codex/shim.ts
  • tests/codex-shim.test.ts

Comment thread src/codex/shim.ts Outdated
Comment thread tests/codex-shim.test.ts Outdated
@github-actions
github-actions Bot marked this pull request as ready for review August 11, 2026 01:30
@comfuture

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate is complete. I will review pull request #1441.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@comfuture
comfuture marked this pull request as ready for review August 11, 2026 04:17
@comfuture

Copy link
Copy Markdown
Author

@Wibias The branch moved to current head d5a1ce5b5 after the latest exact-head Codex review and is now rebased on upstream/dev 7779c0574.

Two further upgrade-safety gaps were fixed:

  • obsolete installed Unix shims are revision-detected, transactionally regenerated, and probed; recursive saved launchers remove the obsolete shim and restore the original launcher;
  • delayed detached descendants now retain a dedicated probe lease, so changing session/process group and redirecting stderr cannot turn the probe into an early success.

Current validation: typecheck passed; focused shim suite 62 passed / 0 failed; privacy scan passed; docs production build passed (221 pages). All correct Codex and CodeRabbit threads are resolved, and the PR is Ready for Review.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate reports that pull request #1441 is ready at d5a1ce5b5691e120c8601092a0e2e7f378f9cf7d. I will review the current changes.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@comfuture

Copy link
Copy Markdown
Author

@codex review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

@github-actions[bot] The readiness gate reports that pull request #1441 is ready at d5a1ce5b5691e120c8601092a0e2e7f378f9cf7d. I will review the current changes.

⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- HEAD and PR revisions ---'
git rev-parse HEAD
gh pr view 1441 --repo lidge-jun/opencodex --json baseRefOid,headRefOid,baseRefName,headRefName

echo '--- changed files ---'
base_sha="$(gh pr view 1441 --repo lidge-jun/opencodex --json baseRefOid --jq .baseRefOid)"
git diff --find-renames --name-only "${base_sha}...HEAD"

echo '--- source and test structure ---'
ast-grep outline src/codex/shim.ts --items all --view expanded
ast-grep outline tests/codex-shim.test.ts --items all --view expanded

echo '--- probe, launcher discovery, and transaction references ---'
rg -n -C 12 'CODEX_SHIM_INSTALL_PROBE_SCRIPT|probeUnixShimInstall|launcherShellPath|spawn\(|findCodexOnPath|--version|setCodexShimProbe' src/codex/shim.ts

echo '--- direct executable and probe test references ---'
rg -n -i -C 12 'native executable|direct executable|process\.execPath|symlink|--version|probe|installCodexShim|setCodexShimProbe' tests/codex-shim.test.ts

echo '--- relevant diff ---'
git diff --find-renames --unified=35 "${base_sha}...HEAD" -- src/codex/shim.ts tests/codex-shim.test.ts

Length of output: 186190


@github-actions[bot] The readiness checklist is not correct for d5a1ce5b5691e120c8601092a0e2e7f378f9cf7d.

P1 — Execute the saved launcher directly in the validation probe

src/codex/shim.ts Line 156 runs:

spawn(launcherShellPath, [wrapperPath, "--version"], ...)

src/codex/shim.ts Line 659 supplies /bin/sh for launcherShellPath. Therefore, the probe makes /bin/sh parse wrapperPath as shell source.

findCodexOnPath() at Line 433 accepts an existing Unix path that is not a directory. This path can be a native executable or a symlink to one. For example, codex can be a symlink to process.execPath.

After the installation transaction moves that launcher to the backup path, the probe runs:

/bin/sh <backup-path> --version

The shell attempts to parse the executable. The executable does not receive --version. The probe returns a failure, and the installation transaction restores a valid launcher.

Run the launcher directly:

spawn(wrapperPath, ["--version"], {
  detached: true,
  env: process.env,
  stdio: ["ignore", "ignore", "pipe", "pipe"],
});

Remove launcherShellPath from CODEX_SHIM_INSTALL_PROBE_SCRIPT, probeUnixShimInstall(), and setCodexShimProbeShellForTests unless another independent test requires it.

Add a Unix regression test in tests/codex-shim.test.ts that:

  1. Creates codex as a symlink to process.execPath.
  2. Calls installCodexShim().
  3. Verifies that installation succeeds.
  4. Verifies that the generated shim replaces codex.
  5. Verifies that the owned backup remains a symlink.
  6. Verifies that codex-shim.json exists.

The /bin/dash test at Lines 370-433 validates a shebang shell script. It does not validate a direct executable.

I completed static inspection on the exact ready head. I could not execute the test suite in this environment.

You are interacting with an AI system.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5a1ce5b56

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/codex/shim.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 8

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs-site/src/content/docs/reference/cli/lifecycle.md`:
- Around line 290-295: The Unix launcher probe currently invokes the saved
launcher through /bin/sh, rejecting native executables and symlinks; update the
saved-launcher validation to execute it directly with --version, preserve
timeout/cleanup checks, and add regression coverage for concrete executables and
symlinks. In docs-site/src/content/docs/reference/cli/lifecycle.md:290-295,
retain the concrete-executable recovery guidance only with the corrected probe
behavior; synchronize the same behavior in
docs-site/src/content/docs/ja/reference/cli/lifecycle.md:184-184,
docs-site/src/content/docs/ko/reference/cli/lifecycle.md:238-243,
docs-site/src/content/docs/ru/reference/cli/lifecycle.md:256-262, and
docs-site/src/content/docs/zh-cn/reference/cli/lifecycle.md:181-181.

In `@src/codex/shim.ts`:
- Around line 1832-1842: The obsolete-shim upgrade path in autoRestoreCodexShim
currently maps both deferred races and terminal refusals to "ineligible". Add an
explicit deferred indicator to refreshObsoleteUnixShims results, use it to
return "deferred" while retaining "ineligible" for safety removal, and extend
the existing concurrent wrapper replacement test to call autoRestoreCodexShim
and assert the deferred status.
- Around line 1500-1509: Replace the field-by-field fingerprint checks in the
staged wrapper validation block with the existing sameFingerprint comparison,
matching the comparison used later in the same function. Preserve the current
error behavior when the staged wrapper is missing or fingerprints differ; only
retain a manual comparison if sameFingerprint includes a rename-sensitive
path-derived field, and document that field with a brief comment.
- Around line 123-153: Update finishAfterStderr so the stderr-drain timeout
marks both stderrEnded and leaseEnded before evaluating completion, allowing
shutdown to finish when no process group remains even if fd 3 is still open. Add
a regression test in tests/codex-shim.test.ts using a launcher that leaks fd 3
into a process exiting before the drain deadline, and assert installation
succeeds without reporting a timeout.
- Around line 747-790: Update rollbackFreshShimInstall to recognize ownership of
a partially written wrapper when writtenWrapperFingerprint is undefined, using
the existing SHIM_MARKER fallback ownership rule from rollbackGuardedRefresh and
rollbackObsoleteUnixShimRefresh. Ensure rollback removes the incomplete wrapper,
restores the original from backup, and does not raise the ownership-changed
error; add a regression test beside the Unix probe-infrastructure rollback test
that fails writeShim after creation and verifies the launcher is restored with
no backup or state file.
- Around line 731-737: In the process-group wait loop around the install probe
cleanup in src/codex/shim.ts, replace the temporary SharedArrayBuffer/Int32Array
and Atomics.wait delay with Bun.sleepSync(10), preserving the existing deadline
and unixProcessGroupAlive checks.

In `@tests/codex-shim.test.ts`:
- Around line 997-1006: Add a shared Unix test helper near the existing Unix
helpers that removes the exact UNIX_SHIM_REVISION_MARKER line and asserts the
resulting wrapper differs from the current content. Replace the inline
current.replace constructions in all four obsolete-shim tests, including the
test around withInstalledShim, with this helper so every test retains the drift
guard.
- Around line 23-36: Harden processState so it checks the spawnSync result
before reading stdout, returning a distinct non-empty failure state when /bin/ps
is unavailable or fails; update waitForProcessStop to treat that failure as
unresolved rather than interpreting an empty string as a stopped process, while
preserving normal process-state polling.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a05982f9-2e9d-4c0a-be4d-2eefc13b157c

📥 Commits

Reviewing files that changed from the base of the PR and between aa8525a and d5a1ce5.

📒 Files selected for processing (7)
  • docs-site/src/content/docs/ja/reference/cli/lifecycle.md
  • docs-site/src/content/docs/ko/reference/cli/lifecycle.md
  • docs-site/src/content/docs/reference/cli/lifecycle.md
  • docs-site/src/content/docs/ru/reference/cli/lifecycle.md
  • docs-site/src/content/docs/zh-cn/reference/cli/lifecycle.md
  • src/codex/shim.ts
  • tests/codex-shim.test.ts

Comment thread docs-site/src/content/docs/reference/cli/lifecycle.md
Comment thread src/codex/shim.ts
Comment thread src/codex/shim.ts
Comment thread src/codex/shim.ts
Comment thread src/codex/shim.ts
Comment thread src/codex/shim.ts
Comment thread tests/codex-shim.test.ts
Comment thread tests/codex-shim.test.ts
@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 04:26
@comfuture
comfuture marked this pull request as ready for review August 11, 2026 04:26
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- HEAD and PR revisions ---'
git rev-parse HEAD
gh pr view 1441 --repo lidge-jun/opencodex --json baseRefOid,headRefOid,baseRefName,headRefName

printf '%s\n' '--- source structure ---'
ast-grep outline src/codex/shim.ts --items all --view expanded

printf '%s\n' '--- probe and launcher discovery ---'
rg -n -C 12 'CODEX_SHIM_INSTALL_PROBE_SCRIPT|probeUnixShimInstall|launcherShellPath|spawn\(|findCodexOnPath|setCodexShimProbeShellForTests|--version' src/codex/shim.ts

printf '%s\n' '--- direct-executable regression coverage ---'
rg -n -i -C 12 'native executable|direct executable|process\.execPath|symlink|--version|probe|installCodexShim|setCodexShimProbeShellForTests' tests/codex-shim.test.ts

Length of output: 69744


@github-actions[bot] The readiness checklist is not correct for current head 36cae1b0c4ee5a045bb0cf0f77ac403207015343.

P1 — Execute the saved launcher directly in the validation probe

src/codex/shim.ts Line 176 runs:

spawn(launcherShellPath, [wrapperPath, "--version"], ...)

src/codex/shim.ts Line 685 supplies /bin/sh as launcherShellPath.

findCodexOnPath() accepts existing paths that are not directories. A valid target can be a native executable or a symlink to one. After installation moves that launcher to its backup path, the probe runs /bin/sh <backup-path> --version. The shell parses the executable as shell source. The launcher does not receive --version. The probe fails and the install transaction restores a valid launcher.

Update CODEX_SHIM_INSTALL_PROBE_SCRIPT to run the saved launcher directly:

spawn(wrapperPath, ["--version"], {
  detached: true,
  env: process.env,
  stdio: ["ignore", "ignore", "pipe", "pipe"],
});

Remove launcherShellPath from the probe arguments. Remove setCodexShimProbeShellForTests if no independent test requires it.

Add a Unix regression test in tests/codex-shim.test.ts that creates codex as a symlink to process.execPath. The test must verify that installCodexShim() succeeds, writes the generated shim, retains the symlink in the owned backup, and writes codex-shim.json.

The current /bin/dash test at Lines 372-403 validates a shebang script. It does not validate a direct executable.

I completed static inspection on the current head. I did not execute the test suite.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- PR head ---'
gh pr view 1441 --repo lidge-jun/opencodex --json headRefOid --jq .headRefOid
git rev-parse HEAD

echo '--- relevant declarations ---'
ast-grep outline src/codex/shim.ts --items all --view expanded | \
  rg -n -C 3 'CODEX_SHIM_INSTALL_PROBE_SCRIPT|probeUnixShimInstall|findCodexOnPath|setCodexShimProbeShellForTests'

echo '--- probe and target discovery ---'
rg -n -C 12 'CODEX_SHIM_INSTALL_PROBE_SCRIPT|probeUnixShimInstall|launcherShellPath|spawn\(|findCodexOnPath|setCodexShimProbeShellForTests|--version' src/codex/shim.ts

echo '--- direct-executable coverage ---'
rg -n -i -C 12 'native executable|direct executable|process\.execPath|symlink|--version|probe|installCodexShim|setCodexShimProbeShellForTests' tests/codex-shim.test.ts

Length of output: 61569


@github-actions[bot] The readiness checklist is not correct for 36cae1b0c4ee5a045bb0cf0f77ac403207015343.

P1 — Execute the saved launcher directly in the validation probe

src/codex/shim.ts Line 176 still runs:

spawn(launcherShellPath, [wrapperPath, "--version"], ...)

src/codex/shim.ts Line 685 supplies /bin/sh when no test override exists. The probe therefore runs:

/bin/sh <saved-launcher> --version

findCodexOnPath() accepts an existing path that is not a directory. This can be a native executable or a symlink to one. For example, codex can be a symlink to process.execPath.

After installation moves that launcher to the owned backup path, /bin/sh parses the executable as shell source. The launcher does not receive --version. The probe fails, and installation restores a valid launcher.

Update CODEX_SHIM_INSTALL_PROBE_SCRIPT to execute the saved launcher directly:

spawn(wrapperPath, ["--version"], {
  detached: true,
  env: process.env,
  stdio: ["ignore", "ignore", "pipe", "pipe"],
});

Remove launcherShellPath from the probe arguments. Remove setCodexShimProbeShellForTests() unless another independent test requires it.

Add a Unix regression test in tests/codex-shim.test.ts that creates codex as a symlink to process.execPath. Verify that installCodexShim() succeeds, replaces codex with the generated shim, preserves the symlink as the owned backup, and writes codex-shim.json.

The existing /bin/dash test at Lines 372-403 validates a shell-script launcher only. It does not cover a direct executable or a symlink to one.

Static inspection completed on the exact ready head. I did not execute the test suite.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- HEAD and PR head ---'
git rev-parse HEAD
gh pr view 1441 --repo lidge-jun/opencodex --json headRefOid,baseRefOid,headRefName,baseRefName

echo '--- source structure ---'
ast-grep outline src/codex/shim.ts --items all --view expanded

echo '--- probe implementation and launcher discovery ---'
rg -n -C 12 'CODEX_SHIM_INSTALL_PROBE_SCRIPT|probeUnixShimInstall|launcherShellPath|spawn\(|findCodexOnPath|setCodexShimProbeShellForTests|--version' src/codex/shim.ts

echo '--- relevant source ranges ---'
nl -ba src/codex/shim.ts | sed -n '1,220p;400,470p;630,710p'

echo '--- direct-executable regression coverage ---'
rg -n -i -C 10 'native executable|direct executable|process\.execPath|symlink|--version|probe|installCodexShim|setCodexShimProbeShellForTests' tests/codex-shim.test.ts

echo '--- relevant PR diff ---'
base_sha="$(gh pr view 1441 --repo lidge-jun/opencodex --json baseRefOid --jq .baseRefOid)"
git diff --find-renames --unified=25 "${base_sha}...HEAD" -- src/codex/shim.ts tests/codex-shim.test.ts

Length of output: 25402


@github-actions[bot] The readiness checklist is not correct for 36cae1b0c4ee5a045bb0cf0f77ac403207015343.

P1 — Execute the saved launcher directly in the validation probe

The exact PR head still contains the native-launcher compatibility defect.

In src/codex/shim.ts:

  • Line 48 passes launcherShellPath into CODEX_SHIM_INSTALL_PROBE_SCRIPT.

  • Lines 176-180 run:

    spawn(launcherShellPath, [wrapperPath, "--version"], ...)
  • Lines 678-690 pass codexShimProbeShellForTests ?? "/bin/sh" as that shell path.

findCodexOnPath() accepts a Unix launcher path that exists and is not a directory. This can be a native executable or a symlink to one. After installation moves that launcher to its backup path, the probe executes:

/bin/sh <backup-path> --version

/bin/sh parses a native executable as shell source. The launcher does not receive --version. The probe reports failure, and the installation transaction restores a valid launcher.

Run the saved launcher directly:

spawn(wrapperPath, ["--version"], {
  detached: true,
  env: process.env,
  stdio: ["ignore", "ignore", "pipe", "pipe"],
});

Remove launcherShellPath from the probe script and probeUnixShimInstall(). Remove setCodexShimProbeShellForTests() unless another independent test needs it.

Add a Unix regression test in tests/codex-shim.test.ts that creates codex as a symlink to process.execPath. Verify that installCodexShim() succeeds, the generated shim replaces codex, the owned backup remains a symlink, and codex-shim.json exists.

The inspection command ended early because nl is unavailable. However, the completed rg output confirms this P1 defect on the exact ready SHA. The PR remains not ready until this compatibility case is fixed.

You are interacting with an AI system.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 36cae1b0c4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/codex/shim.ts
@github-actions
github-actions Bot marked this pull request as draft August 11, 2026 04:31
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- PR revision ---'
gh pr view 1441 --repo lidge-jun/opencodex --json headRefOid,baseRefOid --jq '{headRefOid,baseRefOid}'
echo '--- checked-out revision ---'
git rev-parse HEAD

echo '--- shim symbols ---'
ast-grep outline src/codex/shim.ts --items all --view expanded | \
  rg -n -C 2 'CODEX_SHIM_INSTALL_PROBE_SCRIPT|probeUnixShimInstall|findCodexOnPath|setCodexShimProbeShellForTests'

echo '--- probe and target discovery ---'
rg -n -C 12 'CODEX_SHIM_INSTALL_PROBE_SCRIPT|probeUnixShimInstall|launcherShellPath|spawn\(|findCodexOnPath|setCodexShimProbeShellForTests|--version' src/codex/shim.ts

echo '--- direct-executable regression coverage ---'
rg -n -i -C 10 'native executable|direct executable|process\.execPath|symlink|--version|probe|installCodexShim|setCodexShimProbeShellForTests' tests/codex-shim.test.ts || true

Length of output: 62877


@github-actions[bot] The readiness status is not correct.

The gate payload reports completed SHA 36cae1b0c4ee5a045bb0cf0f77ac403207015343. The current PR head is 864dbe4101c0e97a1a3cd834320ea8efb921300a. The P1 native-launcher defect remains on the current head.

In src/codex/shim.ts:

  • Line 48 passes launcherShellPath to CODEX_SHIM_INSTALL_PROBE_SCRIPT.
  • Lines 176-180 run spawn(launcherShellPath, [wrapperPath, "--version"], ...).
  • Line 697 supplies codexShimProbeShellForTests ?? "/bin/sh".

findCodexOnPath() at Line 459 accepts an existing path that is not a directory. This includes a native executable and a symlink to one. The probe therefore runs /bin/sh <saved-launcher> --version. /bin/sh parses a native executable as shell source. The native executable does not receive --version. The probe fails and the transaction restores a valid launcher.

The new regression tests in tests/codex-shim.test.ts at Lines 449-502 correctly add native executable and symlink cases. They do not fix the production behavior. With the current implementation, those tests should fail on a Unix system with /usr/bin/true.

Update the probe to execute the saved launcher directly:

spawn(wrapperPath, ["--version"], {
  detached: true,
  env: process.env,
  stdio: ["ignore", "ignore", "pipe", "pipe"],
});

Remove launcherShellPath from CODEX_SHIM_INSTALL_PROBE_SCRIPT and probeUnixShimInstall(). Remove setCodexShimProbeShellForTests() unless another test needs that seam.

The pull request is not ready until this compatibility case is fixed and the native executable and symlink tests pass.

You are interacting with an AI system.

@comfuture
comfuture marked this pull request as ready for review August 11, 2026 04:36
@comfuture

Copy link
Copy Markdown
Author

@codex review
Review head: e2bdba007ca770b2ba358326983e46277cfde84a

Focus only on the bounded Unix runtime re-entry contract changed by the preceding fix: one legitimate new-PID nested Codex invocation remains allowed, while repeated argument- or directory-dependent child-process shim redispatch must terminate instead of looping.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- revisions ---'
git rev-parse HEAD
gh pr view 1441 --repo lidge-jun/opencodex --json headRefOid,baseRefOid,headRefName,baseRefName

echo '--- shim structure ---'
ast-grep outline src/codex/shim.ts --items all --view expanded

echo '--- runtime re-entry references ---'
rg -n -C 14 -i 're-entr|reentr|recurs|redispatch|same.pid|same_pid|parent.pid|parent_pid|PPID|pid|directory|cwd|argument|argv|guard|sentinel' src/codex/shim.ts

echo '--- focused runtime re-entry test references ---'
rg -n -C 14 -i 're-entr|reentr|recurs|redispatch|same.pid|same_pid|parent.pid|parent_pid|PPID|pid|directory|cwd|argument|argv|guard|sentinel' tests/codex-shim.test.ts

echo '--- diff after the reported review head parent ---'
git show --stat --oneline --decorate HEAD
git show --format=fuller --find-renames --unified=50 HEAD -- src/codex/shim.ts tests/codex-shim.test.ts

Length of output: 138613


@github-actions[bot] I found no blocking issue in the requested bounded Unix runtime re-entry scope.

src/codex/shim.ts Lines 576-597 keeps the same-PID guard and adds the inherited OCX_SHIM_ACTIVE_DEPTH guard.

  • The initial shim invocation sets depth 1.
  • One legitimate new-PID nested invocation changes depth to 2.
  • A further child-process redispatch inherits depth 2 and exits with status 126.
  • The rejection occurs before ensure and before exec starts the saved launcher.

The depth guard does not use command arguments or the working directory. Therefore, it bounds both argument-dependent and directory-dependent child-process redispatch.

tests/codex-shim.test.ts Lines 351-388 covers the argument-dependent redispatch case. tests/codex-shim.test.ts Lines 868-906 verifies that one new-PID nested invocation remains valid.

I completed static inspection of e2bdba007ca770b2ba358326983e46277cfde84a. I did not execute the test suite.

You are interacting with an AI system.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- PR revision ---'
gh pr view 1441 --repo lidge-jun/opencodex --json headRefOid,baseRefOid,headRefName,baseRefName

echo '--- checked-out revision ---'
git rev-parse HEAD

echo '--- changed files at PR scope ---'
base_sha="$(gh pr view 1441 --repo lidge-jun/opencodex --json baseRefOid --jq .baseRefOid)"
git diff --find-renames --name-only "${base_sha}...HEAD"

echo '--- implementation and test structure ---'
ast-grep outline src/codex/shim.ts --items all --view expanded
ast-grep outline tests/codex-shim.test.ts --items all --view expanded

echo '--- Unix runtime re-entry implementation ---'
rg -n -C 16 -i 're-entry|reentry|recurs|redispatch|same-pid|parent.*pid|process\.pid|CODEx.*SHIM|CODEX.*SHIM|argv|cwd|directory' \
  src/codex/shim.ts

echo '--- Focused runtime re-entry tests ---'
rg -n -C 16 -i 're-entry|reentry|recurs|redispatch|same-pid|new-pid|nested|child invocation|argument|directory|cwd' \
  tests/codex-shim.test.ts

echo '--- Diff for relevant files ---'
git diff --find-renames --unified=45 "${base_sha}...HEAD" -- \
  src/codex/shim.ts tests/codex-shim.test.ts

Length of output: 113618


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- exact head ---'
git rev-parse HEAD
git show -s --format='%H%n%P%n%s' HEAD

echo '--- runtime guard symbols with line numbers ---'
rg -n -i 'OCX_SHIM_ACTIVE_PID|OCX_SHIM_ACTIVE_DEPTH|REENTRY|re-entry|reentry|redispatch' \
  src/codex/shim.ts tests/codex-shim.test.ts

echo '--- generated Unix wrapper implementation ---'
line="$(rg -n 'export function buildUnixCodexShim|function buildUnixCodexShim' src/codex/shim.ts | head -n1 | cut -d: -f1)"
sed -n "${line},$((line + 180))p" src/codex/shim.ts

echo '--- focused runtime tests ---'
for test_name in \
  'Unix runtime guard stops argument-dependent child-process redispatch' \
  'Unix shim permits a real Codex process to start a new child invocation'
do
  line="$(rg -n -F "$test_name" tests/codex-shim.test.ts | head -n1 | cut -d: -f1)"
  echo "--- ${test_name} at line ${line} ---"
  sed -n "${line},$((line + 90))p" tests/codex-shim.test.ts
done

echo '--- changes introduced by the reviewed head ---'
parent="$(git rev-parse HEAD^)"
git diff --unified=50 "${parent}...HEAD" -- src/codex/shim.ts tests/codex-shim.test.ts

Length of output: 35592


@github-actions[bot] I found no blocking defect in the bounded Unix runtime re-entry logic at e2bdba007ca770b2ba358326983e46277cfde84a.

src/codex/shim.ts Lines 576-597 enforce the required bound:

  • Same-PID exec re-entry exits with status 126.
  • The initial wrapper invocation sets OCX_SHIM_ACTIVE_DEPTH=1.
  • One new-PID nested invocation advances the depth to 2.
  • Any later child-process redispatch exits with status 126.

The implementation applies this check before argument parsing and does not depend on the working directory. Therefore, argument-dependent and directory-dependent redispatch inherit the same depth limit.

tests/codex-shim.test.ts Line 351 covers argument-dependent child-process redispatch. Line 868 covers the allowed one-level new-PID nested invocation.

A non-blocking test gap remains: add a directory-dependent redispatch regression. The launcher can change directory and invoke codex again. The test should assert status 126 and the existing re-entry diagnostic. This test would preserve the stated directory-dependent contract.

I completed static inspection only. I could not execute the test suite in this environment.

You are interacting with an AI system.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e2bdba007c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/codex/shim.ts
@comfuture

Copy link
Copy Markdown
Author

Scope decision for the final focused review on e2bdba007ca770b2ba358326983e46277cfde84a:

The clean-environment child-spawn scenario is a real limitation of cooperative runtime guards, but solving it requires non-cooperative platform-specific containment or a persistent ancestry registry rather than another focused shim fix. That would add new runtime state, PID/concurrency semantics, and cross-platform architecture outside #1439. The concrete reported mise chain preserves inherited state and is covered by the current same-PID, bounded probe, and child-depth regressions.

No further implementation or automated re-review is requested for that out-of-scope architecture line. The PR remains Ready for Review with current checks green and the thread resolved with this rationale.

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

Labels

bug Something isn't working review-ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants