open-code-review icon indicating copy to clipboard operation
open-code-review copied to clipboard

Zero-argument CLI commands silently accept unexpected positional arguments

Open amh1k opened this issue 3 months ago • 2 comments

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

amh1k avatar Aug 05 '26 18:08 amh1k

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.

bailu-ZZ avatar Aug 06 '26 02:08 bailu-ZZ

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

amh1k avatar Aug 06 '26 05:08 amh1k