Skip to content

fix(cli): order Codex -C before resume so maestro-cli send resumes work#954

Closed
chr1syy wants to merge 1 commit into
RunMaestro:rcfrom
chr1syy:fix/cli-codex-resume
Closed

fix(cli): order Codex -C before resume so maestro-cli send resumes work#954
chr1syy wants to merge 1 commit into
RunMaestro:rcfrom
chr1syy:fix/cli-codex-resume

Conversation

@chr1syy
Copy link
Copy Markdown
Contributor

@chr1syy chr1syy commented May 4, 2026

Summary

  • maestro-cli send failed on follow-up messages to a Codex agent with error: unexpected argument '-C' found ... Usage: codex exec resume [OPTIONS] [SESSION_ID] [PROMPT]. The first message worked because sessionId was null and the resume branch was skipped; once a session id was saved, every subsequent send hit the resume path and broke.
  • Root cause: src/cli/services/agent-spawner.ts appended resumeArgs before workingDirArgs, producing codex exec ... resume <id> -C <cwd> -- <prompt>. resume is a subcommand of codex exec, so once it's consumed, trailing flags are parsed against codex exec resume, which doesn't accept -C.
  • Fix: emit workingDirArgs before resumeArgs for Codex. Matches the canonical comment in src/main/agents/definitions.ts ([-C dir] [resume <id>]) and the desktop builder src/main/utils/agent-args.ts, which already had the right order.
  • Strengthened the existing Codex spawn test to assert -C precedes resume so this can't silently regress.

This was originally surfaced as a "Failed to get response from agent" error in the Maestro Discord bot — the bot was just relaying the upstream maestro-cli failure.

Test plan

  • vitest run src/__tests__/cli/services/agent-spawner.test.ts -t "Codex spawn preserves working-dir flag and resume args" — passes with the new ordering assertion
  • eslint clean on the two touched files
  • prettier --check clean on the two touched files
  • Manual: send two messages back-to-back to a Codex agent via maestro-cli send (or via Maestro Discord) — both should succeed; previously the second send failed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed argument ordering for agent spawn commands to ensure proper parsing of working directory configuration before session resumption.
  • Tests

    • Enhanced regression test to validate correct argument sequencing in agent spawn operations.

…work

`exec resume` is a subcommand of `codex exec`; once consumed, trailing
flags are parsed against `codex exec resume`, which doesn't accept `-C`.
Emit `workingDirArgs` before `resumeArgs` (matching the desktop builder
in `src/main/utils/agent-args.ts` and the canonical example in
`definitions.ts`). Fixes `maestro-cli send` failing on follow-up Codex
messages with `error: unexpected argument '-C' found`. Tightens the
existing CLI spawn test to assert `-C` precedes `resume`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ae14932e-9694-4cf0-b16d-5bd876f8bfc2

📥 Commits

Reviewing files that changed from the base of the PR and between 44a9bbe and 8426203.

📒 Files selected for processing (2)
  • src/__tests__/cli/services/agent-spawner.test.ts
  • src/cli/services/agent-spawner.ts

📝 Walkthrough

Walkthrough

The -C working-directory flag for Codex tools is reordered to appear before the resume subcommand in spawned agent arguments, ensuring proper flag parsing. A regression test now validates this ordering constraint.

Changes

Codex Argument Ordering Fix

Layer / File(s) Summary
Argument Order Constraint
src/cli/services/agent-spawner.ts
In spawnJsonLineAgent, workingDirArgs(cwd) is now pushed before resumeArgs(agentSessionId) for Codex toolType, with comments documenting the ordering requirement.
Test Validation
src/__tests__/cli/services/agent-spawner.test.ts
Codex resume test now asserts that the -C flag index is strictly less than the resume subcommand index, validating the argument order dependency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • RunMaestro/Maestro#909: Related changes to argument construction ordering in the same agent-spawner.ts file for different toolType handling.

Suggested labels

approved, ready to merge

Poem

🐰 Hops with glee at ordered flags!
The -C hops first, no lags,
Before resume takes the lead,
Codex parses at full speed!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main fix: reordering the Codex -C flag before the resume argument to fix maestro-cli send failures. It is concise, directly related to the changeset, and explains both the problem and its resolution.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 4, 2026

Greptile Summary

Fixes a broken argument order in src/cli/services/agent-spawner.ts where resumeArgs was pushed before workingDirArgs, causing codex exec resume <id> -C <cwd> — invalid because -C is rejected after resume is consumed as a subcommand. The fix emits -C <cwd> first, matching the canonical ordering already used in the desktop builder (src/main/utils/agent-args.ts) and documented in definitions.ts. The test is updated to assert positional ordering rather than mere containment.

Confidence Score: 5/5

Safe to merge — minimal, targeted fix with no regressions and a strengthened test guard.

The change is a two-line reorder with a clear root cause, matches the already-correct desktop code path, and adds a regression-preventing ordering assertion in the test. No other agents are affected since workingDirArgs is gated on toolType === 'codex' in the CLI spawner.

No files require special attention.

Important Files Changed

Filename Overview
src/cli/services/agent-spawner.ts Reorders workingDirArgs before resumeArgs for Codex to fix argument-parsing failure on session resume; adds explanatory comment.
src/tests/cli/services/agent-spawner.test.ts Strengthens the Codex spawn test to assert -C index is strictly less than resume index, making the ordering regression-detectable.

Sequence Diagram

sequenceDiagram
    participant CLI as maestro-cli send
    participant Spawner as agent-spawner.ts
    participant Codex as codex binary

    CLI->>Spawner: "spawnJsonLineAgent(codex, cwd, prompt, sessionId)"
    Note over Spawner: Build preOverrideArgs
    Spawner->>Spawner: "push workingDirArgs: ['-C', cwd]"
    Spawner->>Spawner: "push resumeArgs: ['resume', sessionId]"
    Note over Spawner: "args: [..., '-C', cwd, 'resume', sessionId]"
    Spawner->>Codex: "codex exec --json -C /cwd resume id -- prompt"
    Codex-->>Spawner: JSON lines response
    Spawner-->>CLI: AgentResult success
Loading

Reviews (1): Last reviewed commit: "fix(cli): order Codex -C before resume s..." | Re-trigger Greptile

@chr1syy chr1syy added the ready to merge This PR is ready to merge label May 4, 2026
@pedramamini
Copy link
Copy Markdown
Collaborator

Thanks for the contribution, @chr1syy! 🙏

Took a careful look — the fix is exactly right:

  • The root cause analysis is correct: once codex exec resume is consumed as a subcommand, trailing flags get parsed against codex exec resume, which rejects -C.
  • Emitting workingDirArgs before resumeArgs aligns the CLI spawner with the canonical comment in src/main/agents/definitions.ts ([-C dir] [resume <id>]) and the desktop builder in src/main/utils/agent-args.ts.
  • The strengthened test now asserts c < r positionally instead of just containment, so this can't silently regress.
  • Two-line behavioral change, scoped to Codex via the toolType === 'codex' gate, no risk to other agents.

Mergeable, CI green, CodeRabbit + Greptile both clean. Approving. ✅

@chr1syy
Copy link
Copy Markdown
Contributor Author

chr1syy commented May 6, 2026

Closing in favor of #960 (@pedramamini), which supersedes this PR.

#960 diagnoses the deeper root cause from #959: Codex treats -C/--cd as a root-level global flag that is silently ignored when placed after the exec subcommand. My PR only moved -C ahead of resume (still after exec), which removes the noisy unexpected argument '-C' crash on resume but leaves Codex running in the wrong cwd (most visibly on Windows).

#960 also fixes the desktop path (src/main/utils/agent-args.ts), which this PR didn't touch — so it covers interactive sessions, Auto Run, and Cue in addition to the CLI. Once #960 lands, this branch is fully redundant.

1 similar comment
@chr1syy
Copy link
Copy Markdown
Contributor Author

chr1syy commented May 6, 2026

Closing in favor of #960 (@pedramamini), which supersedes this PR.

#960 diagnoses the deeper root cause from #959: Codex treats -C/--cd as a root-level global flag that is silently ignored when placed after the exec subcommand. My PR only moved -C ahead of resume (still after exec), which removes the noisy unexpected argument '-C' crash on resume but leaves Codex running in the wrong cwd (most visibly on Windows).

#960 also fixes the desktop path (src/main/utils/agent-args.ts), which this PR didn't touch — so it covers interactive sessions, Auto Run, and Cue in addition to the CLI. Once #960 lands, this branch is fully redundant.

@chr1syy chr1syy closed this May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved ready to merge This PR is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants