fix: /resume nonexistent conversation (#548)

Co-authored-by: Letta <noreply@letta.com>
This commit is contained in:
Charles Packer
2026-01-14 20:31:13 -08:00
committed by GitHub
parent c799937b7b
commit f964b020d5
4 changed files with 147 additions and 62 deletions

View File

@@ -4332,18 +4332,8 @@ export default function App({
refreshDerived();
try {
// Update conversation ID and settings
setConversationId(targetConvId);
settingsManager.setLocalLastSession(
{ agentId, conversationId: targetConvId },
process.cwd(),
);
settingsManager.setGlobalLastSession({
agentId,
conversationId: targetConvId,
});
// Fetch message history for the selected conversation
// Validate conversation exists BEFORE updating state
// (getResumeData throws 404/422 for non-existent conversations)
if (agentState) {
const client = await getClient();
const resumeData = await getResumeData(
@@ -4352,6 +4342,17 @@ export default function App({
targetConvId,
);
// Only update state after validation succeeds
setConversationId(targetConvId);
settingsManager.setLocalLastSession(
{ agentId, conversationId: targetConvId },
process.cwd(),
);
settingsManager.setGlobalLastSession({
agentId,
conversationId: targetConvId,
});
// Clear current transcript and static items
buffersRef.current.byId.clear();
buffersRef.current.order = [];
@@ -4442,16 +4443,28 @@ export default function App({
}
}
} catch (error) {
const errorCmdId = uid("cmd");
buffersRef.current.byId.set(errorCmdId, {
// Update existing loading message instead of creating new one
// Format error message to be user-friendly (avoid raw JSON/internal details)
let errorMsg = "Unknown error";
if (error instanceof APIError) {
if (error.status === 404) {
errorMsg = "Conversation not found";
} else if (error.status === 422) {
errorMsg = "Invalid conversation ID";
} else {
errorMsg = error.message;
}
} else if (error instanceof Error) {
errorMsg = error.message;
}
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: errorCmdId,
id: cmdId,
input: msg.trim(),
output: `Failed to switch conversation: ${error instanceof Error ? error.message : String(error)}`,
output: `Failed to switch conversation: ${errorMsg}`,
phase: "finished",
success: false,
});
buffersRef.current.order.push(errorCmdId);
refreshDerived();
} finally {
setCommandRunning(false);
@@ -7454,18 +7467,8 @@ Plan file path: ${planFilePath}`;
refreshDerived();
try {
// Update conversation ID and settings
setConversationId(convId);
settingsManager.setLocalLastSession(
{ agentId, conversationId: convId },
process.cwd(),
);
settingsManager.setGlobalLastSession({
agentId,
conversationId: convId,
});
// Fetch message history for the selected conversation
// Validate conversation exists BEFORE updating state
// (getResumeData throws 404/422 for non-existent conversations)
if (agentState) {
const client = await getClient();
const resumeData = await getResumeData(
@@ -7474,6 +7477,17 @@ Plan file path: ${planFilePath}`;
convId,
);
// Only update state after validation succeeds
setConversationId(convId);
settingsManager.setLocalLastSession(
{ agentId, conversationId: convId },
process.cwd(),
);
settingsManager.setGlobalLastSession({
agentId,
conversationId: convId,
});
// Clear current transcript and static items
buffersRef.current.byId.clear();
buffersRef.current.order = [];
@@ -7574,16 +7588,28 @@ Plan file path: ${planFilePath}`;
}
}
} catch (error) {
const errorCmdId = uid("cmd");
buffersRef.current.byId.set(errorCmdId, {
// Update existing loading message instead of creating new one
// Format error message to be user-friendly (avoid raw JSON/internal details)
let errorMsg = "Unknown error";
if (error instanceof APIError) {
if (error.status === 404) {
errorMsg = "Conversation not found";
} else if (error.status === 422) {
errorMsg = "Invalid conversation ID";
} else {
errorMsg = error.message;
}
} else if (error instanceof Error) {
errorMsg = error.message;
}
buffersRef.current.byId.set(cmdId, {
kind: "command",
id: errorCmdId,
id: cmdId,
input: inputCmd,
output: `Failed to switch conversation: ${error instanceof Error ? error.message : String(error)}`,
output: `Failed to switch conversation: ${errorMsg}`,
phase: "finished",
success: false,
});
buffersRef.current.order.push(errorCmdId);
refreshDerived();
} finally {
setCommandRunning(false);