Skip to content

Commit 01f7716

Browse files
feat(web): fall back to symbolic ref when a pinned commit is gone
If the pinned commit SHA can no longer be resolved (e.g. a force-push + GC pruned it), refetch the evidence-panel file once at the symbolic ref so the citation still renders instead of erroring. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f409a0d commit 01f7716

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

packages/web/src/ee/features/chat/components/chatThread/referencedFileSourceListItemContainer.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,26 @@ const ReferencedFileSourceListItemContainerComponent = ({
4343
const fetchRef = fileSource.commitSha ?? fileSource.revision;
4444

4545
const { data, isLoading, isError, error } = useQuery({
46-
queryKey: ['fileSource', fileSource.path, fileSource.repo, fetchRef],
47-
queryFn: () => unwrapServiceError(getFileSource({
48-
path: fileSource.path,
49-
repo: fileSource.repo,
50-
ref: fetchRef,
51-
})),
46+
queryKey: ['fileSource', fileSource.path, fileSource.repo, fetchRef, fileSource.revision],
47+
queryFn: async () => {
48+
const pinned = await getFileSource({
49+
path: fileSource.path,
50+
repo: fileSource.repo,
51+
ref: fetchRef,
52+
});
53+
54+
// The pinned commit can disappear (e.g. a force-push + GC prunes it).
55+
// Fall back once to the symbolic ref so the file still renders.
56+
if (isServiceError(pinned) && fetchRef !== fileSource.revision) {
57+
return unwrapServiceError(getFileSource({
58+
path: fileSource.path,
59+
repo: fileSource.repo,
60+
ref: fileSource.revision,
61+
}));
62+
}
63+
64+
return unwrapServiceError(Promise.resolve(pinned));
65+
},
5266
staleTime: Infinity,
5367
});
5468

0 commit comments

Comments
 (0)