## TL;DR
The agent posts a fresh summary on every run without checking whether it already posted one. Make the summary idempotent: look for the bot's existing comment via a marker line, update it if found, and only create a new one if it is absent.

## The error
```text
review agent failed to dedupe: double-posted its summary comment after a retry: how to fix
(two identical "Review summary" comments from the bot on the same PR)
```

## Steps
### 1. Give the summary a marker
Start the comment body with a distinctive first line the agent can search for, such as `## Review summary [bot-managed]`.
Expected output: every summary the bot posts is identifiable later.

### 2. List existing comments before posting
On each run, fetch the PR's comments and filter by the bot author plus the marker line.
Expected output: the agent knows whether a summary already exists.

### 3. Update instead of create
If the marker is found, PATCH the existing comment with the new body. Only POST when no marked comment exists.
Expected output: one summary comment that reflects the latest run.

### 4. Test the retry path
Trigger a retry on a test PR and confirm the outcome.
Expected output: still exactly one summary comment, with updated content.

## When to use
- The review agent double-posts its summary after a retry or re-run
- Workflow re-runs create a second identical bot comment
- Scheduled review jobs stack up duplicate summaries

## When not to use
- Duplicate inline review threads on code lines (different dedupe logic per thread)
- Human-posted duplicate comments
- Comments the bot intentionally posts once per commit or per push

## Tool compatibility
- GitHub PR comments API (list, create, update); same pattern works on GitLab notes
- Applies to custom review agents, GitHub Actions bots, and reviewdog-style summary posts
- The marker approach survives across workflow re-runs and separate jobs

## Variant phrasings
### bot posted two summaries after the workflow was re-run
Same fix. Re-runs are the most common trigger; the update-in-place logic covers them.

### duplicate inline review comments from the agent
Dedupe per thread: track which diff position already has a bot thread and skip re-posting there.

### agent posts a new summary on every push
Decide the intended behavior first. If one rolling summary is wanted, use the marker update. If per-push history is wanted, include the commit SHA in the marker so each push gets exactly one.

## Why it happens
Retries re-execute the whole job from scratch, including the post-comment step, with no memory of the previous attempt. Without a check-then-update pattern, each attempt adds another comment. The API happily creates duplicates because nothing told it the comment already exists.

## Edge cases
- Concurrent runs racing each other: both may see no existing comment and both post. Serialize the summary step or accept last-write-wins with a short lock.
- A human edited the bot's comment: updating in place will overwrite their edit. Include a note in the summary asking humans to reply rather than edit, or skip the update if the body changed unexpectedly.
- Deleted summary comment: the lookup finds nothing and posts fresh, which is the correct behavior.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_AXWsUxG1nNFXi-MSnVOapA
