Skip to content

Commit 49a68c1

Browse files
author
Eric Wheeler
committed
fix: add debug logging for API conversation history issues
Add detailed logging to readApiMessages function to help diagnose "Unexpected: No existing API conversation history" errors. The logs will show: - When the history file exists but contains an empty array - When the old history file exists but contains an empty array - When neither history file is found This will help diagnose issues like the one in #4311 where the API conversation history file gets truncated to an empty array during task resumption with orchestrator tasks. Fixes: #4311 Signed-off-by: Eric Wheeler <[email protected]>
1 parent 664346e commit 49a68c1

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/core/task-persistence/apiMessages.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,34 @@ export async function readApiMessages({
2121
const filePath = path.join(taskDir, GlobalFileNames.apiConversationHistory)
2222

2323
if (await fileExistsAtPath(filePath)) {
24-
return JSON.parse(await fs.readFile(filePath, "utf8"))
24+
const fileContent = await fs.readFile(filePath, "utf8")
25+
const parsedData = JSON.parse(fileContent)
26+
if (Array.isArray(parsedData) && parsedData.length === 0) {
27+
console.error(
28+
`[Roo-Debug] readApiMessages: Found API conversation history file, but it's empty. TaskId: ${taskId}, Path: ${filePath}`,
29+
)
30+
}
31+
return parsedData
2532
} else {
2633
const oldPath = path.join(taskDir, "claude_messages.json")
2734

2835
if (await fileExistsAtPath(oldPath)) {
29-
const data = JSON.parse(await fs.readFile(oldPath, "utf8"))
36+
const fileContent = await fs.readFile(oldPath, "utf8")
37+
const parsedData = JSON.parse(fileContent)
38+
if (Array.isArray(parsedData) && parsedData.length === 0) {
39+
console.error(
40+
`[Roo-Debug] readApiMessages: Found OLD API conversation history file (claude_messages.json), but it's empty. TaskId: ${taskId}, Path: ${oldPath}`,
41+
)
42+
}
3043
await fs.unlink(oldPath)
31-
return data
44+
return parsedData
3245
}
3346
}
3447

48+
// If we reach here, neither the new nor the old history file was found.
49+
console.error(
50+
`[Roo-Debug] readApiMessages: API conversation history file not found for taskId: ${taskId}. Expected at: ${filePath}`,
51+
)
3552
return []
3653
}
3754

0 commit comments

Comments
 (0)