alibaba / alibaba/open-code-review
scan does not propagate Ctrl-C cancellation to the scan runtime
- Dominant language
- Go
- Stars
- 24.4k
- Forks
- 1.8k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 105
Description
## 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
1. Configure any valid LLM provider and a scan rule that processes enough files to keep a scan in flight.
2. Run `ocr scan --rule `.
3. Press Ctrl-C while scan work is running.
4. 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.Run` and scan providers already accept a `context.Context`.
- Existing tests cover cancelled scan subtasks and resuming completed scan files.
- The proposed implementation mirrors the established `review` command behavior using `os.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.Interrupt` context 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 check` and `make test`.
Contributor guide
Research direction
Start at the Cobra scan command entrypoint and compare its context setup with the established review command behavior using os.Interrupt. Trace the context through preview, telemetry, scan.Agent.Run, and result emission, then add the deterministic pre-cancelled scan regression test described in the issue. Run make check and make test to verify cancellation and existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100