Skip to content

Zero-argument CLI commands silently accept unexpected positional arguments #742

Closed

Description

@amh1k

OpenCodeReview Version

open-code-review dev linux/amd64 https://github.com/alibaba/open-code-review

Operating System

Linux (x86_64)

Installation Method

Build from source

LLM Provider

Other OpenAI-compatible endpoint

Bug Description

Several zero-argument CLI commands silently accept unexpected positional arguments instead of returning an error.

For example:

ocr version unexpected

prints the version and exits with status 0. Similarly, ocr llm providers unexpected still lists providers and exits successfully.

These commands do not define positional arguments, so unexpected values should be rejected. This behavior can hide scripting mistakes, and ocr llm test unexpected could proceed to an unintended provider request.

The issue reproduces on the latest upstream build, commit 533b526. It is independent of the configured LLM provider because argument validation should happen before any LLM request.

Steps to Reproduce

  1. Check out OpenCodeReview commit 533b526 and build it:

    git clone https://github.com/alibaba/open-code-review.git
    cd open-code-review
    git checkout 533b526
    go build -o /tmp/ocr-cli ./cmd/opencodereview
  2. Run the version command with an unexpected positional argument:

    /tmp/ocr-cli version unexpected
    echo "exit=$?"
  3. Observe that the version is printed and the command exits successfully with status 0.

  4. Repeat with another zero-argument command:

    /tmp/ocr-cli llm providers unexpected
    echo "exit=$?"
  5. Observe that the provider list is displayed and the command still exits with status 0.


This reproduction does not require an API key or an LLM request.

### Expected Behavior

Commands that do not accept positional arguments should reject unexpected arguments with a clear error and non-zero exit status.

For example:

```text
Error: unknown command "unexpected" for "ocr version"

The same validation should apply to:

  • ocr llm test
  • ocr llm providers
  • ocr session list
  • ocr delegate preview

The command handler should not run after invalid arguments are supplied. In particular, ocr llm test unexpected must fail before loading or contacting the configured LLM provider.

Normal invocations without positional arguments should continue working unchanged.

Logs / Error Output

No error is reported. The invalid argument is silently ignored.

$ /tmp/ocr-cli version unexpected
open-code-review dev linux/amd64
https://github.com/alibaba/open-code-review

$ echo $?
0

The expected behavior would be a non-zero exit status and an error such as:
Error: unknown command "unexpected" for "ocr version"

Additional Context

No response

Activity

  1. added theissue type on Aug 5, 2026
  2. added
    bug
    on Aug 5, 2026
  3. bailu-ZZ commented on Aug 6, 2026

    @bailu-ZZ
    Contributor

    Hi, I’d like to work on this issue.

    The root cause appears to be that several leaf Cobra commands do not define positional-argument validation. I plan to:

    • add Args: cobra.NoArgs to version, llm test, llm providers, session list, and delegate preview;
    • add table-driven CLI regression tests for the error message and non-zero exit status;
    • verify that invalid arguments are rejected before handlers run, especially before any LLM request;
    • ensure normal invocations, supported flags, and aliases remain unchanged.

    This should be a small, focused fix using Cobra’s built-in validation. Please assign this issue to me.

  4. amh1k commented on Aug 6, 2026

    @amh1k
    ContributorAuthor

    Hi, I’d like to work on this issue.

    The root cause appears to be that several leaf Cobra commands do not define positional-argument validation. I plan to:

    * add `Args: cobra.NoArgs` to `version`, `llm test`, `llm providers`, `session list`, and `delegate preview`;
    
    * add table-driven CLI regression tests for the error message and non-zero exit status;
    
    * verify that invalid arguments are rejected before handlers run, especially before any LLM request;
    
    * ensure normal invocations, supported flags, and aliases remain unchanged.
    

    This should be a small, focused fix using Cobra’s built-in validation. Please assign this issue to me.

    Maintainers can assign the issue to you

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions