Repository navigation
Description
Summary
ocr scan --resume restores per-file comments that were checkpointed before batch deduplication. Restored comments are included in the resumed batch's dedup input, so resume normally invokes the dedup LLM again instead of restoring an already canonical result.
This extra best-effort LLM call makes resume sensitive to changes in batch composition, template or model configuration, LLM output, and transient dedup failures. If the repeated dedup is disabled or fails, comments merged in the original run can reappear as duplicates.
Reproduction
-
Enable batch deduplication and set
DEDUP_MIN_COMMENTSto2for a minimal reproduction. The default template uses4, so an unchanged default configuration must produce at least four comments in the batch. -
Have one file produce two comments that the dedup task groups together.
-
Let the first run complete the batch. Its in-memory result contains one canonical comment.
-
Inspect the session checkpoint: it contains the two pre-dedup comments.
-
Resume the session with:
ocr scan --resume <session-id> -
Observe that resume sends the restored comments through the dedup task again. If that best-effort call fails or is disabled, both original comments remain.
Actual behavior
The checkpoint does not represent the safe post-dedup state. Resume requires another dedup LLM call and can produce a result different from the original run.
Expected behavior
Resume should reuse post-dedup comments when they can be represented safely by the existing per-file checkpoint format, without losing comment ownership or provenance.
Root cause
dispatchBatch records per-file review_item_done and review_item_reused events before maybeRunDedup rewrites the batch slice in CommentCollector.
The previous issue description incorrectly stated that restored comments were not deduplicated again. dispatchSubtasks takes its batch snapshot before restored comments are added, so those comments are included in maybeRunDedup on resume.
Safe persistence contract
The checkpoint format is per file, while dedup may merge comments across files. Persisting the canonical cross-file result under only its first file can lose another file's finding when the canonical file later changes and is invalidated.
A safe fix therefore needs to:
- persist canonical comments for newly scanned groups whose members all belong to the same file;
- preserve original per-file comments for cross-file groups;
- preserve the original source comments for reused items;
- limit comment lookup to the current batch;
- retain raw comments when dedup fails or returns malformed output.
Regression coverage
Add deterministic tests for:
- same-file dedup persisted as one canonical checkpoint comment;
- resume reusing that checkpoint without another LLM request;
- reused checkpoints retaining their source comments;
- mixed same-file and cross-file groups preserving both canonicalization and per-file provenance.
Activity
[-]scan --resume restores pre-dedup comments and reintroduces duplicates[/-][+]scan --resume repeats dedup from pre-dedup checkpoints[/+]