Skip to content

Fix Codex lock compiler: move --model flag after exec subcommand#33841

Merged
pelikhan merged 6 commits into
mainfrom
copilot/fix-codex-lock-compiler-flag-position
May 21, 2026
Merged

Fix Codex lock compiler: move --model flag after exec subcommand#33841
pelikhan merged 6 commits into
mainfrom
copilot/fix-codex-lock-compiler-flag-position

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 21, 2026

The Codex lock compiler was emitting the --model flag before the exec subcommand. Codex CLI treats flags in that position as global options and silently ignores them, causing all custom model selections to fall back to the default.

Before (broken):

codex ${GH_AW_MODEL_AGENT_CODEX:+--model "$GH_AW_MODEL_AGENT_CODEX" }exec -c web_search="disabled" ...

After (fixed):

codex exec${GH_AW_MODEL_AGENT_CODEX:+ --model "$GH_AW_MODEL_AGENT_CODEX"} -c web_search="disabled" ...

Changes

  • codex_engine.go: Reorder both format strings (harness and non-harness paths) so exec precedes modelParam; adjust shell expansion from trailing-space to leading-space form (${VAR:+ --model "$VAR"}) so spacing is correct in both the set and unset cases.
  • model_env_vars_test.go: Update expected pattern to match new format; add regression test TestCodexModelFlagPositionAfterExec that asserts exec appears before the model expansion in the generated command.
  • engine_includes_test.go: Update assertion from "codex ${""codex exec${".
  • testdata/TestWasmGolden_AllEngines/codex.golden: Update snapshot.
  • .changeset/patch-fix-codex-model-flag.md: Update description to accurately describe the position fix.

pr-sous-chef: requested branch update from run https://github.com/github/gh-aw/actions/runs/26248288802

Generated by 👨‍🍳 PR Sous Chef · ● 2.6M ·

Copilot AI and others added 2 commits May 21, 2026 18:51
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix model flag position in Codex lock compiler command Fix Codex lock compiler: move --model flag after exec subcommand May 21, 2026
Copilot AI requested a review from lpcox May 21, 2026 19:01
Copilot finished work on behalf of lpcox May 21, 2026 19:01
@pelikhan pelikhan marked this pull request as ready for review May 21, 2026 19:03
Copilot AI review requested due to automatic review settings May 21, 2026 19:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Codex CLI invocation generation so the optional --model flag is emitted after the exec subcommand (so Codex treats it as a subcommand flag rather than a global flag and doesn’t ignore it).

Changes:

  • Reordered Codex command construction (harness and non-harness) to codex exec … followed by the conditional model expansion.
  • Updated tests and golden snapshots to match the new command shape.
  • Updated the changeset text describing the fix.
Show a summary per file
File Description
pkg/workflow/codex_engine.go Reorders generated Codex CLI command so exec precedes the conditional --model expansion.
pkg/workflow/model_env_vars_test.go Updates expected model expansion formatting; adds a regression test for exec vs --model ordering.
pkg/workflow/engine_includes_test.go Updates lock-file assertion to match codex exec${...} pattern.
pkg/workflow/testdata/TestWasmGolden_AllEngines/codex.golden Updates snapshot to reflect corrected Codex command ordering.
.github/workflows/pr-code-quality-reviewer.lock.yml Lock file regenerated; notably drops shared/reporting.md runtime-import.
.changeset/patch-fix-codex-model-flag.md Updates release note describing the Codex model-flag positioning fix.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 6/6 changed files
  • Comments generated: 3

Comment on lines +490 to +503
// Find the model shell expansion pattern in the generated command
modelPattern := "${" + constants.EnvVarModelAgentCodex + ":+"
modelIdx := strings.Index(stepsContent, modelPattern)
if modelIdx == -1 {
t.Fatalf("Model expansion pattern '%s' not found in steps:\n%s", modelPattern, stepsContent)
}

// Find "exec" in the generated command (look for the last occurrence before the model pattern
// to handle multi-line step content)
execIdx := strings.LastIndex(stepsContent[:modelIdx], "exec")
if execIdx == -1 {
t.Errorf("'exec' subcommand must appear before the model flag '%s' in the generated command.\n"+
"This indicates the model flag is placed before 'exec', causing Codex to ignore it.\n"+
"Got:\n%s", modelPattern, stepsContent)
---

Fixed the Codex engine to pass the model via `--model` instead of the deprecated TOML override so engine model selection works with newer Codex CLI versions.
Fixed the Codex engine to emit `codex exec --model "$VAR"` instead of `codex "$VAR"exec` so the model flag is correctly positioned after the `exec` subcommand. Previously the model parameter was placed before `exec`, causing Codex CLI to ignore it and silently fall back to the default model.
Comment on lines 299 to 309
cat "${RUNNER_TEMP}/gh-aw/prompts/github_mcp_tools_with_safeoutputs_prompt.md"
if [ "$GITHUB_EVENT_NAME" = "issue_comment" ] && [ -n "$GH_AW_IS_PR_COMMENT" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review_comment" ] || [ "$GITHUB_EVENT_NAME" = "pull_request_review" ]; then
cat "${RUNNER_TEMP}/gh-aw/prompts/pr_context_prompt.md"
fi
cat << 'GH_AW_PROMPT_03f9bc9676534c1b_EOF'
cat << 'GH_AW_PROMPT_4f5501639950bddf_EOF'
</system>
{{#runtime-import .github/workflows/shared/reporting.md}}
{{#runtime-import .github/workflows/shared/otlp.md}}
{{#runtime-import .github/workflows/shared/github-guard-policy.md}}
{{#runtime-import .github/workflows/shared/pr-code-review-config.md}}
{{#runtime-import .github/workflows/shared/noop-reminder.md}}
{{#runtime-import .github/workflows/pr-code-quality-reviewer.md}}
@github-actions
Copy link
Copy Markdown
Contributor

``
Please rerun checks after the flag-position fix and confirm the branch update cleared the remaining issues.

Generated by 👨‍🍳 PR Sous Chef · ● 2.6M ·

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 21, 2026

@copilot address review feedback and merge main

Copilot AI and others added 2 commits May 21, 2026 20:10
…k-compiler-flag-position

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
…geset, revert unintended lock file, merge main

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

@copilot address review feedback and merge main

Done. Three changes addressed from the review:

  1. Regression test (model_env_vars_test.go): Changed the search string from "exec" to "codex exec" so the test can't pass on a false positive from GH_AW_NODE_EXEC.

  2. Changeset description (.changeset/patch-fix-codex-model-flag.md): Updated to accurately show the old broken shell expansion form (codex ${VAR:+--model "$VAR" }exec) rather than the misleading codex "$VAR"exec.

  3. Unintentional lock file change: Reverted .github/workflows/pr-code-quality-reviewer.lock.yml to its pre-PR state.

Also merged main (with conflict resolved in the golden snapshot — main had a pre-existing inconsistency in that file, so I regenerated it from the current source).

Copilot finished work on behalf of lpcox May 21, 2026 20:14
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot lint go

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 21, 2026

@copilot lint go

Fixed in the latest commit. The strings.Index in model_env_vars_test.go was flagged by the modernize linter and replaced with strings.CutbeforeModel (the text before the model pattern) is used directly instead of stepsContent[:modelIdx], which is both cleaner and avoids the separate index variable. Linter now reports 0 issues.

Copilot AI requested a review from pelikhan May 21, 2026 20:44
@pelikhan pelikhan merged commit 61f44a9 into main May 21, 2026
@pelikhan pelikhan deleted the copilot/fix-codex-lock-compiler-flag-position branch May 21, 2026 20:45
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 lock compiler places --model flag before exec subcommand

4 participants