Skip to content

fix(scan): persist safe dedup checkpoints on resume - #1035

Merged
lizhengfeng101 merged 3 commits into
alibaba:mainfrom
Wsp030914:fix/scan-resume-dedup-checkpoint
Aug 22, 2026
Merged

lizhengfeng101 merged 3 commits into
alibaba:mainfrom
Wsp030914:fix/scan-resume-dedup-checkpoint

Conversation

@Wsp030914

@Wsp030914 Wsp030914 commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes scan checkpoint timing around batch deduplication. Per-file checkpoints were written before maybeRunDedup, so ocr scan --resume restored pre-dedup comments and had to invoke the best-effort dedup LLM again.

The repeated call can change the resumed result when batch inputs, configuration, model output, or availability differ from the original run.

Fixes #1034.

Corrected behavior

Restored comments are included in the resumed batch's dedup input. The earlier PR description incorrectly said resume did not deduplicate them again.

The real problem is that pre-dedup checkpoints make resume depend on an additional LLM call. If that call fails or is disabled, comments merged in the original run can reappear.

Persistence contract

Dedup can merge findings within one file or across several files, but resume checkpoints are stored per file. A canonical cross-file comment cannot safely be assigned only to its first file: if that file changes later, invalidating its checkpoint could also erase another file's finding.

The safe behavior is:

  • newly scanned same-file groups persist their canonical post-dedup comments;
  • cross-file groups persist their original comments under each source file;
  • reused items preserve the comments from their source session;
  • failed or malformed dedup keeps the original comments;
  • checkpoint comment lookup is limited to the current batch.

Implementation

  • Defer completed-item checkpoint persistence until the batch settles and dedup finishes.
  • Carry completed and reused items out of dispatchBatch for checkpointing.
  • Preserve source comments for reused items.
  • Derive safe per-file checkpoint comments at dedup-group granularity.
  • Keep canonical output for same-file groups and raw provenance for cross-file groups.
  • Drain asynchronous comment workers before dedup and checkpoint persistence.
  • Keep the existing collector output and dedup parsing behavior unchanged.

Regression tests

The tests cover:

  • two same-file comments merged into one persisted checkpoint comment;
  • resume reusing that canonical checkpoint without another LLM call;
  • chained resume retaining the canonical same-file checkpoint;
  • reused items retaining their original source comments;
  • mixed same-file and cross-file groups preserving canonicalization and provenance;
  • the fake LLM client counting every request, including requests without a preset response.

The minimal reproduction sets DEDUP_MIN_COMMENTS=2; the default scan template uses 4.

Scope

  • Affects full-scan checkpoint and resume behavior only.
  • Does not change the dedup prompt or grouping algorithm.
  • Does not change non-deduplicated scans or diff-based review modes.
  • Does not add a new session record type or change the checkpoint schema.

Verification

  • make check
  • make test
  • make coverage (91.0% total coverage)
  • make build
  • Targeted scan resume and checkpoint provenance tests

Automated review identified the reused-item provenance problem in the initial patch; the persistence contract above incorporates that feedback.

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 1 comment(s)

Comment thread internal/scan/agent.go Resolved
@Wsp030914 Wsp030914 changed the title fix(scan): persist deduplicated comments on resume fix(scan): persist safe dedup checkpoints on resume Aug 21, 2026

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great fix for the resume determinism problem — could you move error to the last position in dispatchBatch's return signature to follow Go convention, and add a brief comment on the error-path recordBatchCheckpoints call explaining why we still persist checkpoints when ctx is cancelled (to avoid re-scanning already-completed files on next resume)? Thanks for the thorough work and tests!

@Wsp030914

Wsp030914 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Great fix for the resume determinism problem — could you move error to the last position in dispatchBatch's return signature to follow Go convention, and add a brief comment on the error-path recordBatchCheckpoints call explaining why we still persist checkpoints when ctx is cancelled (to avoid re-scanning already-completed files on next resume)? Thanks for the thorough work and tests!

Thank you for the review! Addressed in 36ccea6.

  • Moved error to the last position in dispatchBatch's return signature.
  • Added a comment explaining that completed checkpoints are persisted on cancellation to avoid re-scanning those files on the next resume.

@lizhengfeng101 lizhengfeng101 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lizhengfeng101
lizhengfeng101 merged commit 132de7d into alibaba:main Aug 22, 2026
11 checks passed
Githab-capibara added a commit to Githab-capibara/open-code-review that referenced this pull request Sep 17, 2026
* fix(scan): persist deduplicated comments on resume

* fix(scan): preserve dedup checkpoint provenance

* refactor(scan): return batch error last
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scan --resume repeats dedup from pre-dedup checkpoints

2 participants