Skip to content

Return structured JSON for bounded find cursor validation errors #5412

Description

@Widthdom

Problem

Bounded CLI find output can emit a human-only cursor validation error despite an explicit --json selector. Machine consumers receive empty stdout and must parse stderr to recover the category and hint.

This was found during #5399 validation, but it also reproduces with the existing line-local regex mode and is outside that feature's implementation scope.

Reproduction

From an indexed checkout, using the repository-built Debug net8.0 binary:

dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll find using --regex \
  --path src/CodeIndex/Cli/QueryCommandRunner.Find.cs --json --fields path \
  --cursor bad --db .cdidx/codeindex.db > /tmp/cursor.stdout 2> /tmp/cursor.stderr

Actual: exit 1, empty stdout, stderr:

Error [E010_USAGE_ERROR]: cursor_malformed: --cursor must be an opaque response:v2 cursor returned as next_cursor.
Hint: Use the command help to pass positive --limit/--max-json-bytes values and a next_cursor returned by the same query.

Changing a result-affecting flag while replaying a valid bounded find cursor likewise produces a human cursor-mismatch diagnostic. Observed on macOS arm64 with .NET 8, version 1.50.3, while developing from origin/main 3606a5eaa533a27bfbddc606b0fb41dcd9d075cb.

Expected

Explicit machine output should return a versioned structured error on stdout with exit 1, command/error identity, the cursor reason and recovery guidance, without human-only stderr. Preserve existing human-mode diagnostics and handle an insufficient output byte budget truthfully.

Start with the bounded response validation/error paths in src/CodeIndex/Cli/JsonEnvelopeWrapper.Bounded.cs. Cover malformed, query-mismatched and stale cursors with the supported JSON/envelope/field selectors; retain ordinary human and count-cursor behavior.

Open-issue duplicate searches for cursor JSON, cursor stderr, pagination JSON and structured errors found no matching issue other than #5399.

Activity

  1. Widthdom commented on Sep 22, 2026

    @Widthdom
    OwnerAuthor

    Work started on branch fix-issue5412, based on the latest fetched origin/main. I will address structured bounded find cursor validation errors, add regression coverage, and update the matching documentation and bilingual changelog fragment.

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions