Skip to content

fix(site/src/pages/AgentsPage/components/DiffViewer): dedupe diff files to prevent CodeView duplicate id crash#26597

Merged
kylecarbs merged 1 commit into
mainfrom
fix/diff-viewer-duplicate-file-id
Jun 23, 2026
Merged

fix(site/src/pages/AgentsPage/components/DiffViewer): dedupe diff files to prevent CodeView duplicate id crash#26597
kylecarbs merged 1 commit into
mainfrom
fix/diff-viewer-duplicate-file-id

Conversation

@kylecarbs

Copy link
Copy Markdown
Member

Viewing a git diff on /agents could crash the whole diff view with CodeView.addItem: duplicate id "agent/x/agentmcp/api_internal_test.go". When a diff body lists the same post-image path in more than one diff --git section, parsePatchFiles returns one FileDiffMetadata per section. DiffViewer then maps each file to a CodeView item keyed by file.name (the file tree is likewise keyed by path), so the repeated path produced two items with the same id and CodeView.addItem threw, tearing down the entire view.

Deduplicate the parsed files by path in useParsedDiff, keeping the first occurrence, so both the CodeView and the file tree always receive unique ids. useParsedDiff is the single source feeding both panels, so a malformed diff now degrades gracefully and logs one warning instead of crashing.

Root cause and verification

Confirmed against @pierre/diffs parsePatchFiles that a single patch with two diff --git sections for one path yields patchCount: 1, fileCount: 2 with both entries named agent/x/agentmcp/api_internal_test.go. That is the exact input that made CodeView.addItem throw. Dropping (rather than merging) duplicates matches the renderer's model, which can only show one item per id anyway.

Verified on the branch: pnpm test (DiffViewer suite, including the new dedupeFilesByName tests), tsc -p ., and the full pnpm lint (biome, types, circular-deps, React Compiler, knip) all pass.

Opened by Coder Agents on behalf of @kylecarbs.

@kylecarbs kylecarbs marked this pull request as ready for review June 23, 2026 03:12
@kylecarbs kylecarbs enabled auto-merge (squash) June 23, 2026 03:12
@kylecarbs kylecarbs merged commit 0b856ef into main Jun 23, 2026
37 of 38 checks passed
@kylecarbs kylecarbs deleted the fix/diff-viewer-duplicate-file-id branch June 23, 2026 03:34
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants