Skip to content

Cooperative cancellation is not implemented anywhere (zero OperationCanceledException catches) #1430

Description

@Widthdom

Summary

A codebase-wide search for catch (OperationCanceledException) returns zero hits, confirming that cooperative cancellation is not implemented anywhere in cdidx. This is the umbrella reason behind several other filed issues (MCP handlers without CancellationToken, IndexCommandRunner.RunFullScan not cooperative, DbWriter backfill loops not cooperative, GitHubIssueReporter.TryCreateIssueAsync swallowing OperationCanceledException).

Evidence

  • cdidx search "OperationCanceledException" --lang csharp returns "No results found" against the full repo (main @ 2ee912d).
  • A few sites pass a CancellationToken along (e.g. ConsoleUi.StartSpinner), but none catch the exception or honour it cleanly.

Impact

  • Ctrl-C, --timeout, and MCP $/cancelRequest all degrade to "wait for the next file/row".
  • No safety net for long jobs (indexing a monorepo, backfill, deep impact analysis).
  • Tests cannot reliably wrap a cdidx call in a budgeted timeout.

Proposed direction

This is the design-level umbrella; once the per-site issues are fixed individually, the entry points (CLI dispatcher in ProgramRunner, MCP dispatcher in McpServer) should:

  1. Own a top-level CancellationTokenSource.
  2. Wire Console.CancelKeyPress to it.
  3. Plumb the token through every long-running call path.
  4. Catch OperationCanceledException at the entry point exactly once and exit with a documented code (suggest CommandExitCodes.Cancelled = 130 to match POSIX).

Repro env

  • Branch: main @ 2ee912d (release v1.21.0)

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