Skip to content

fix(autocomplete): preserve literal completion-token arguments - #171

Merged
markstuart-oai merged 1 commit into
mainfrom
mark/c22-completion-dispatch
Sep 8, 2026
Merged

fix(autocomplete): preserve literal completion-token arguments#171
markstuart-oai merged 1 commit into
mainfrom
mark/c22-completion-dispatch

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

A literal __complete argument value disabled flag parsing across the CLI command tree. For example, openai models retrieve --model __complete --help failed with unexpected arguments, while --model=__complete showed normal help. A literal executable name could trigger the same problem.

Prepare the command tree for completion only when __complete is the first argument after the executable. Ordinary values and argv0 retain normal parsing. All bundled Bash, Zsh, Fish, and PowerShell completion entry forms use that position, so their completion path and statuses 0/10/11 remain intact.

Add fresh-subprocess tests of the production main() entrypoint covering literal local/global values, ordinary and equals-form controls, leading ordinary global flags, substrings, argv0, empty arguments, and all four bundled completion argument shapes. The change does not establish general support for manual global-prefix completion arrangements.

Validation

Passed locally with Go 1.27.0 on Linux, with dependency manifests unchanged:

  • Focused cmd/openai and autocomplete tests; final regression tests fail against the original entrypoint and pass with the fix.
  • Full go test ./internal/..., all-package compile-only checks, relevant race and vet checks, go mod verify, and ./scripts/lint (build only).
  • Formatting and whitespace checks; Windows amd64 test cross-compilation for all packages. No native Windows execution.
  • Fresh baseline/candidate binary comparisons with synthetic inputs and exact status/stdout/stderr checks. All four bundled completion argument shapes preserve status 0/10/11, local values, file/@ behavior, and spaced/empty values.
  • Rendered Bash and PowerShell scripts executed with matching baseline/candidate results. Zsh script execution used completion-UI stubs; Fish was unavailable and covered by entrypoint argument-shape tests only.
  • Two consecutive independent local review rounds without blockers on the unchanged complete diff.
  • Trusted current-main custom-code check on the actual committed candidate: 495/1,000 lines; isolation and generated-snapshot verification passed before push.

Full LOCAL mock suite NOT RUN: the pinned Steady launcher reports Missing or linked Steady cache. The previously blocked setup route was not retried. Full hosted CI/mock validation remains required before SDK review solicitation.

Hosted validation

CI passed for 12f7aafb368fe4b4e9accf4a33e531a21447287a on its tested merge with current main: pinned Steady security checks and mock startup, full go test ./..., Windows amd64 test cross-compilation, and mock cleanup all completed successfully. Lint, build, CodeQL, code-quality, and Castiron checks also passed. Codex code and security reviews completed on this head; Copilot recommended approval with no comments.

@markstuart-oai
markstuart-oai requested a review from a team as a code owner September 8, 2026 11:43
Copilot AI lite review requested due to automatic review settings September 8, 2026 11:43
@markstuart-oai markstuart-oai added the autoimprove Scoped automated improvement label Sep 8, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T11:45:03.355227Z 12f7aaf PR opened
🔒 Security Review Completed 2026-09-08T11:47:59.336845Z 12f7aaf PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

Castiron custom code

✅ No new custom-code files detected.

5 mixed files remain; 0 existing customizations changed.

Compared 265cf6378ab212f7aafb368f. Generated baselines verified.

5 existing customizations unchanged
  • pkg/cmd/adminorganizationcertificate.go
  • pkg/cmd/cmd.go
  • scripts/castiron/README.md
  • scripts/castiron/custom_code_report.py
  • scripts/castiron/test_custom_code_report.py

A changed generated baseline means this report cannot reliably identify which handwritten lines changed.

Inspect the custom-code diff

Download the exact patch produced by this run (requires repository access):

gh run download 34223004647 --repo openai/openai-cli \
  --name castiron-custom-code-34223004647-1 --dir /tmp/castiron-custom-code-34223004647-1
git apply --stat /tmp/castiron-custom-code-34223004647-1/custom-code.patch
cat /tmp/castiron-custom-code-34223004647-1/custom-code.patch

Or reproduce it from an SDK checkout containing the vendored reporter:

git fetch --no-tags origin 265cf6378ab2e6a27c17bc7c0b6a6cbe6dbd477b 12f7aafb368fe4b4e9accf4a33e531a21447287a
python3 scripts/castiron/custom_code_report.py report \
  --base 265cf6378ab2e6a27c17bc7c0b6a6cbe6dbd477b \
  --head 12f7aafb368fe4b4e9accf4a33e531a21447287a --fetch --require-head-hash --public \
  --out /tmp/castiron-custom-code-12f7aafb368f
cat /tmp/castiron-custom-code-12f7aafb368f/custom-code.patch

This is the current full custom patch for mixed files, not an attribution of only the handwritten lines changed by this PR.

Full report and patch

Copilot AI 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.

🟢 Approval recommended

The fix is narrowly scoped to the CLI entrypoint, aligns with the documented completion invocation contract, and is covered by targeted subprocess regression tests.

Pull request overview

This PR fixes an autocomplete edge case in the CLI entrypoint where a literal __complete value anywhere in os.Args (including flag values or argv0) unintentionally enabled completion-mode behavior across the command tree. The change restricts completion preparation to the intended invocation shape used by bundled shell completion scripts: __complete must be the first argument after the executable.

Changes:

  • Only call prepareForAutocomplete when os.Args[1] == "__complete" (instead of scanning all args).
  • Add fresh-subprocess tests that execute the production main() in a separate process and validate both ordinary parsing and completion protocol shapes across bash/zsh/fish/pwsh.
File summaries
File Description
cmd/openai/main.go Limits completion-mode setup to the argv[1] == "__complete" case to avoid breaking normal flag/value parsing.
cmd/openai/main_dispatch_test.go Adds subprocess-level regression tests for literal __complete values, argv0 shapes, and the four bundled completion argument forms/status codes.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@jbeckwith-oai jbeckwith-oai 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.

Reviewed the complete exact-head diff. The entrypoint now enables autocomplete preparation only for the protocol position used by the bundled Bash, Zsh, Fish, and PowerShell scripts, while preserving ordinary parsing when __complete is a literal argument value or argv0. Fresh-process regression coverage exercises literal, empty, equals-form, prefixed-global-flag, and all four completion-protocol shapes/statuses. Focused and internal tests, race tests, vet, lint/build, formatting, and diff checks passed locally; hosted full test/mock, build, lint, Castiron, and CodeQL checks are green. No blocking correctness, security, architecture, performance, or test-coverage findings.

@markstuart-oai
markstuart-oai added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit 01123b7 Sep 8, 2026
17 checks passed
@markstuart-oai
markstuart-oai deleted the mark/c22-completion-dispatch branch September 8, 2026 19:44
@openai-sdks openai-sdks Bot mentioned this pull request Sep 8, 2026
Ultron09 pushed a commit to Ultron09/openai-cli that referenced this pull request Sep 9, 2026
Automated Release PR
---


##
[1.13.0](openai/openai-cli@v1.12.0...v1.13.0)
(2026-09-08)


### Features

* **api:** document GPT Image 2.5 models and image options
([openai#175](openai#175))
([7a9994d](openai@7a9994d))


### Bug Fixes

* **autocomplete:** preserve literal completion-token arguments
([openai#171](openai#171))
([01123b7](openai@01123b7))
* **output:** honor case-insensitive explore format
([openai#169](openai#169))
([774c240](openai@774c240))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: openai-sdks[bot] <284451331+openai-sdks[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autoimprove Scoped automated improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants