Skip to content

scan --resume repeats dedup from pre-dedup checkpoints #1034

Closed

Description

@Wsp030914

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

  1. Enable batch deduplication and set DEDUP_MIN_COMMENTS to 2 for a minimal reproduction. The default template uses 4, so an unchanged default configuration must produce at least four comments in the batch.

  2. Have one file produce two comments that the dedup task groups together.

  3. Let the first run complete the batch. Its in-memory result contains one canonical comment.

  4. Inspect the session checkpoint: it contains the two pre-dedup comments.

  5. Resume the session with:

    ocr scan --resume <session-id>
    
  6. 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

  1. changed the title [-]scan --resume restores pre-dedup comments and reintroduces duplicates[/-] [+]scan --resume repeats dedup from pre-dedup checkpoints[/+] on Aug 21, 2026
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions