Skip to content

fix(companion): harden task path parsing and availability probes - #574

Open
SomSamantray wants to merge 4 commits into
openai:mainfrom
SomSamantray:fix/393-companion-parser-path
Open

SomSamantray wants to merge 4 commits into
openai:mainfrom
SomSamantray:fix/393-companion-parser-path

Conversation

@SomSamantray

Copy link
Copy Markdown

Operators on the codex:codex-rescue → task path could see false “CLI not installed” errors after a worktree cleanup, have prompts like -m pytest turned into invalid --model values (surfacing Codex 400s as task output), or get a clean exit when the app-server had already emitted an error.

RC1 — availability: binaryAvailable() drops a non-existent cwd for version/help probes only, so a missing worktree no longer masquerades as a missing Codex install.

RC2 — prompt parsing: handleTask enables stopAtFirstPositional in parseArgs, and rescue/runtime docs require routing flags before -- and the prompt after --. Prompt fragments after the first positional are no longer parsed as CLI flags.

RC3 — result status: buildResultStatus() returns failure when turnState.error is set, even if finalTurn was inferred as completed.

node --test tests/process.test.mjs tests/args.test.mjs tests/codex-turn-status.test.mjs tests/commands.test.mjs — 19/19 pass. RC2 integration: node --test --test-name-pattern "does not treat prompt" tests/runtime.test.mjs — pass.

Fixes #393

Fix missing-cwd misreporting as CLI not installed, prevent prompt fragments from being parsed as --model on task, and fail results when turn capture records an app-server error. Adds stopAtFirstPositional for handleTask, -- before prompt in rescue docs, and node --test coverage.
@SomSamantray
SomSamantray requested a review from a team July 31, 2026 06:52

@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: 0edc4e5b8e

ℹ️ 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 plugins/codex/scripts/lib/codex.mjs Resolved
@SomSamantray

Copy link
Copy Markdown
Author

@codex review

Skip storing error notifications with willRetry and clear state.error on a real completed turn so successful retries are not reported as failures.
@SomSamantray

Copy link
Copy Markdown
Author

@codex review

@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: 4c087f1ba1

ℹ️ 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 plugins/codex/agents/codex-rescue.md Resolved
Those flags are Claude-side execution control only. Listing them among task flags before -- would queue a second detached job and return the launch message instead of Codex output.
@SomSamantray

Copy link
Copy Markdown
Author

@codex review

@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: ce4ac23bf2

ℹ️ 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 on lines 23 to +27
if (!token.startsWith("-") || token === "-") {
positionals.push(token);
if (config.stopAtFirstPositional) {
stopOptions = true;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stop parsing after any token becomes positional

When a raw task prompt starts with an unrecognized dash-prefixed token, such as --coverage run -m pytest, that token is added to positionals without enabling stopOptions because this new block only handles non-dash tokens. The later -m pytest is consequently still consumed as the model, so the prompt-parsing failure this option is intended to prevent remains for option-looking prompt prefixes. Set stopOptions whenever an unrecognized option is treated as positional as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 790d49c: when \stopAtFirstPositional\ is set, unrecognized long/short options that fall through as positionals now arm \stopOptions, so later tokens like -m\ stay in the prompt instead of being parsed as --model. Covered in \ ests/args.test.mjs.

Comment on lines +539 to +543
emitProgress(
state.onProgress,
`Codex error (retrying): ${message.params.error?.message ?? "unknown error"}`,
"failed"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep retriable errors out of the failed phase

When the app server emits an error with willRetry: true, this progress event is persisted by createJobProgressUpdater as the running job's phase, and /codex:status renders that phase directly. The job can therefore appear as running with phase failed while Codex is still retrying, potentially causing users or callers monitoring a background task to treat an active run as failed. Report a retrying/running phase here and reserve failed for terminal errors.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in 790d49c: retriable app-server errors (\willRetry: true) now emit progress phase
etrying\ via
esolveErrorProgressPhase; terminal errors still use \ ailed. Covered in \ ests/codex-turn-status.test.mjs.

Arm stopOptions when unrecognized dash tokens become positional so -m in prompts is not consumed as --model. Emit progress phase retrying (not failed) for willRetry app-server errors.
@SomSamantray

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 790d49c3e0

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

ApexAiOfficial added a commit to ApexAiOfficial/codex-plugin-cc that referenced this pull request Sep 25, 2026
Audited against open upstream reports on openai/codex-plugin-cc; each defect
was reproduced or verified against this fork and has a regression test in
tests/substrate.test.mjs (dedicated fake app-server).

- openai#302 unbounded waits: every RPC has a bounded wall-clock timeout (120s
  default, command/exec aware, CODEX_COMPANION_RPC_TIMEOUT_MS, 0 disables),
  and requests on a dead connection fail immediately. The turn watchdog does
  not use a silence timeout (legitimate turns are silent for long periods):
  it fails fast when the connection closes, and after quiet periods asks the
  app-server via thread/read whether the thread is still active, recovering a
  turn whose completion event was lost and failing only an app-server that
  stops answering.
- openai#453 zombie broker: the broker exits when its app-server child dies, so the
  next caller starts a healthy broker instead of wedging.
- openai#706/openai#707 retained subscriptions: the broker tracks per-socket thread
  ownership (subagents inherit their parent's owners) and sends
  thread/unsubscribe when the last owner disconnects; requests for a thread
  wait (bounded) for its in-flight unsubscribe. Simpler than openai#707 because this
  broker already serializes active requests and streams.
- openai#762 + openai#768 together: broker acquisition is serialized; a broker whose
  process is alive is never torn down or killed because it missed a probe
  (the caller uses a private app-server); metadata is cleared only when the
  process is provably gone; only a just-spawned broker that never became
  ready is killed, identity-checked. SessionEnd's kill is identity-checked.
- openai#574 RC3: non-retryable errors fail a turn even when completion is
  inferred. The upstream fix (any error fails) is wrong: error notifications
  carry willRetry, and retried turns can succeed.
- openai#775: fileChange start events without a change list no longer throw.
- openai#740 reproduced with real Codex 0.144.1: live thread/resume ignores the
  requested sandbox in both directions (write-capable threads stayed writable
  after a read-only resume), and a per-turn override persists to later turns.
  Every turn now sends an explicit sandboxPolicy.

Also fixes a same-process withFileLockAsync bug (a second async holder
treated the first as stale) and makes the test harness stop brokers when a
test process is killed by a signal.

Validation: npm test 156/156, tsc clean, no stray processes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ApexAiOfficial added a commit to ApexAiOfficial/codex-plugin-cc that referenced this pull request Sep 25, 2026
Both by Codex tickets through this fork, independently verified and reviewed:
- stock-fixes (upstream openai#393/openai#574 RC1-RC2, openai#757/openai#763): availability probes no
  longer mistake a missing cwd for a missing Codex; the prompt/flag boundary
  applies only to single raw-string input (slash commands, the rescue
  forwarder), where re-tokenization made "-m pytest" a model; failed turns
  persist a readable errorMessage and summary. Turn 1 regressed 17 tests and
  was returned with the failing output; turn 2 fixed the design.
- fix-integration turn 3 (ran on a fresh thread via the resume fallback):
  interrupted-integration recovery restores only entries still in their
  intended post-integration state and refuses, by name, paths the lead
  changed after the crash, keeping the journal.

Validation: npm test 164/164, tsc clean, no stray processes; all dogfood
tickets closed with decision records and their worktrees and refs removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

codex-companion task path: missing-cwd misread as 'not installed', prompt fragments parsed as --model (400 as result), dropped turn errors

1 participant