Skip to content

Fix checkpoints not appearing in chat when metadata is invalid #5900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions webview-ui/src/components/chat/checkpoints/CheckpointSaved.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,55 @@ export const CheckpointSaved = ({ checkpoint, ...props }: CheckpointSavedProps)

const metadata = useMemo(() => {
if (!checkpoint) {
console.warn("[CheckpointSaved] No checkpoint metadata provided", { ts: props.ts, commitHash: props.commitHash })
return undefined
}

const result = checkpointSchema.safeParse(checkpoint)

if (!result.success) {
console.warn("[CheckpointSaved] Invalid checkpoint metadata", {
checkpoint,
errors: result.error.errors,
ts: props.ts,
commitHash: props.commitHash
})
return undefined
}

return result.data
}, [checkpoint])
}, [checkpoint, props.ts, props.commitHash])

if (!metadata) {
return null
}
// Always show the checkpoint, even if metadata is invalid
// This ensures users can see that checkpoints are being created
const fallbackMetadata = useMemo(() => {
if (metadata) {
return metadata
}

// Create fallback metadata when the original is invalid
return {
isFirst: false, // Default to regular checkpoint
from: "", // Empty string as fallback
to: props.commitHash, // Use the commit hash we have
}
}, [metadata, props.commitHash])

return (
<div className="flex items-center justify-between">
<div className="flex gap-2">
<span className="codicon codicon-git-commit text-blue-400" />
<span className="font-bold">
{metadata.isFirst ? t("chat:checkpoint.initial") : t("chat:checkpoint.regular")}
{fallbackMetadata.isFirst ? t("chat:checkpoint.initial") : t("chat:checkpoint.regular")}
</span>
{isCurrent && <span className="text-muted text-sm">{t("chat:checkpoint.current")}</span>}
{!metadata && (
<span className="text-muted text-xs italic">
{t("chat:checkpoint.metadataUnavailable", "metadata unavailable")}
Copy link

Choose a reason for hiding this comment

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

Avoid providing an inline English fallback string in the translation call. Remove the second argument from t('chat:checkpoint.metadataUnavailable') and manage defaults via the translation JSON files.

Suggested change
{t("chat:checkpoint.metadataUnavailable", "metadata unavailable")}
{t("chat:checkpoint.metadataUnavailable")}

This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.

</span>
)}
</div>
<CheckpointMenu {...props} checkpoint={metadata} />
<CheckpointMenu {...props} checkpoint={fallbackMetadata} />
</div>
)
}