scan does not propagate Ctrl-C cancellation to the scan runtime
OpenCodeReview Version
open-code-review v1.9.5 (ea1de41a) darwin/arm64
Built at: 2026-08-17T03:52:37Z
Operating System
macOS (Apple Silicon)
Installation Method
Built from source (local build).
LLM Provider
Other OpenAI-compatible endpoint — this bug is provider-independent: Ctrl-C is handled before any provider-specific behavior matters.
Bug Description
ocr scan starts its runtime from a fresh context.Background(). Unlike ocr review, the command does not install an os.Interrupt context and therefore cannot pass Ctrl-C cancellation to preview, telemetry, or scan.Agent.Run.
When Ctrl-C arrives during a scan, the process receives the default interrupt termination instead of allowing the scan runtime to observe cancellation and execute its existing cancellation, session-finalization, and checkpoint/resume paths.
Steps to Reproduce
- Configure any valid LLM provider and a scan rule that processes enough files to keep a scan in flight.
- Run
ocr scan --rule <rule>. - Press Ctrl-C while scan work is running.
- Observe that scan has no command-level cancellation context; the process is interrupted without delivering cancellation to the scan runtime.
Expected Behavior
Ctrl-C should cancel the scan through a command-owned context. That context should flow through preview, telemetry, scan.Agent.Run, and result emission so existing checkpoint and resume behavior can preserve completed work.
Logs / Error Output
No provider-specific error output is required to demonstrate the defect. The relevant behavior is the missing signal context at the scan command entrypoint; the issue is reproducible with any configured provider.
Additional Context
internal/scan.Agent.Runand scan providers already accept acontext.Context.- Existing tests cover cancelled scan subtasks and resuming completed scan files.
- The proposed implementation mirrors the established
reviewcommand behavior usingos.Interrupt. - No open upstream Issue or PR was found for scan cancellation when checked on 2026-08-18.
Proposed Fix and Test Plan
- Create an
os.Interruptcontext at the Cobra scan command entrypoint. - Thread it through preview, telemetry, scan execution, and result emission.
- Add a deterministic regression test that a pre-cancelled scan context stops before setup.
- Validate with
make checkandmake test.
Thanks for investigating this and for testing the cancellation path. I can see the value in picking up a long scan without paying to review the same files twice.
I’m closing this as not planned. My concern is the ongoing maintenance cost: making cancellation a reliably resumable outcome means keeping checkpoint behavior, session status, and what users see in the CLI and viewer consistent as the scanner evolves. For a workflow that already has an explicit --resume option, I don’t think the additional guarantee is worth that cost.
This is a scope decision, not an objection to handling SIGINT or SIGTERM gracefully. Stopping in-flight work cleanly is a separate, narrower concern.