Skip to content

ocr scan --batch silently ignores misspelled values #2008

Open

Description

@Walternater

Description

ocr scan --batch accepts any string without complaining. The flag help and shell completion advertise exactly three strategies (none, by-language, by-directory), but a typo like by-languag is accepted and the scan proceeds as if --batch had not been given, because internal/scan.parseBatchStrategy falls back to BatchNone for unknown values. The same command's other enum-like flag behaves differently — --format fails fast:

$ ocr scan --format bogus --preview
Error: invalid --format value "bogus": must be 'text', 'json', or 'sarif'

$ ocr scan --batch bogus --preview

Preview: 1 file(s) changed  |  +2  -0

The user asked for a batched run, and a long scan can complete with per-file batches (and per-file LLM round trips) without any indication that the requested grouping never applied. The --preview path returns before the strategy is consulted, so the typo cannot be discovered there either.

Steps to reproduce

  1. git clone https://github.com/alibaba/open-code-review && cd open-code-review (any small git repo works)
  2. Build main: go build -o ocr ./cmd/opencodereview
  3. Run ./ocr scan --batch by-languag --preview (note the missing "e")
  4. The preview prints normally; the misspelled strategy is silently discarded

Expected behavior

validateScanOptions (cmd/opencodereview/shared_flags.go) validates --format, --audience, --max-tools, etc., but not opts.batch. Since the CLI advertises a closed set (flag help + RegisterFlagCompletionFunc("batch", completeEnum("none", "by-language", "by-directory"))), I'd expect --batch to reject unknown values up front with an error like invalid --batch value "by-languag": must be 'none', 'by-language', or 'by-directory', consistent with --format and --effort.

The lenient fallback in parseBatchStrategy would remain untouched — it is documented as safe v1 behavior for the template-level BATCH_STRATEGY, where arbitrary strings can also arrive from a user-supplied scan_template.json; only the CLI surface should fail fast.

I have a small patch ready (a validateBatchStrategy in validateScanOptions plus tests) and can open a PR if the maintainers agree this is worth fixing.

AI/LLM disclosure

This issue was prepared with AI assistance (DeepSeek Harness agent, model group/smart-split) for code exploration and reproduction; every finding above was verified by running the built CLI locally on macOS (Apple Silicon), commit a74bcbb.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions