🐛 Fix disappearing task names in task history#4413
🐛 Fix disappearing task names in task history#4413kiwina wants to merge 2 commits intoRooCodeInc:mainfrom
Conversation
- Handle edge case where tasks have no messages at all - Provide fallback names for tasks with empty/blank names - Ensure taskHistory entries are never blank, even after crashes - Add proper error handling for incomplete tasks Fixes cases where task history would show blank entries when: - Task crashes before first message is added - First message is malformed or empty - Task creation fails completely
…mpty messages case
daniel-lxs
left a comment
There was a problem hiding this comment.
Hey @kiwina, thank you for working on this issue.
I took a look at your PR and left some suggestions to improve readability and maintainability.
I would like to know what you think!
| const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId) | ||
|
|
||
| // Handle edge case where there are no messages at all | ||
| if (!messages || messages.length === 0) { |
There was a problem hiding this comment.
Consider refactoring to eliminate code duplication here. The historyItem object is created twice - once in this early return and once at the end of the function. You could restructure this by:
- Using a boolean flag like
const hasMessages = messages && messages.length > 0 - Pre-calculating all values (
taskName,timestamp,tokenUsage,taskDirSize) based on message availability - Creating the
historyItemobject only once at the end
This would improve maintainability and follow DRY principles.
| messages[findLastIndex(messages, (m) => !(m.ask === "resume_task" || m.ask === "resume_completed_task"))] | ||
| messages[findLastIndex(messages, (m) => !(m.ask === "resume_task" || m.ask === "resume_completed_task"))] || | ||
| messages[0] | ||
|
|
There was a problem hiding this comment.
The tokenUsage object is missing the contextTokens field. Based on the TokenUsage type definition, it should include:
tokenUsage: {
totalTokensIn: 0,
totalTokensOut: 0,
totalCacheWrites: 0,
totalCacheReads: 0,
totalCost: 0,
contextTokens: 0, // <- Missing field
}This ensures type consistency with the rest of the codebase.
| taskName = `Task #${taskNumber} (Incomplete)` | ||
| } | ||
|
|
||
| const historyItem: HistoryItem = { |
There was a problem hiding this comment.
Would it be better to restructure the function to use a single object creation pattern:
// Determine message availability upfront
const hasMessages = messages && messages.length > 0
// Pre-calculate all values based on availability
let taskName: string
let timestamp: number
let tokenUsage: ReturnType<typeof getApiMetrics>
let taskDirSize: number
if (!hasMessages) {
// Handle no messages case
} else {
// Handle messages case
}
// Create historyItem once with pre-calculated valuesThis eliminates the duplicate object creation and makes the code more maintainable.
| const lastRelevantMessage = | ||
| messages[findLastIndex(messages, (m) => !(m.ask === "resume_task" || m.ask === "resume_completed_task"))] | ||
| messages[findLastIndex(messages, (m) => !(m.ask === "resume_task" || m.ask === "resume_completed_task"))] || | ||
| messages[0] |
There was a problem hiding this comment.
It should be possible to use taskMessage here:
| messages[0] | |
| taskMessage |
| number: taskNumber, | ||
| ts: lastRelevantMessage.ts, | ||
| task: taskMessage.text ?? "", | ||
| task: taskName, |
There was a problem hiding this comment.
Could this work better here? That way taskName is not reassigned unnecessarily.
| task: taskName, | |
| task: taskMessage.text?.trim() || `Task #${taskNumber} (Incomplete)`, |
|
Thank you for your contribution! |
Related GitHub Issue
Closes: #4410
Description
This PR fixes the issue where task history entries appear with blank or missing names, making it impossible for users to identify and resume previous tasks. The core problem was that the
getTaskMetadatafunction didn't handle cases where tasks had no messages or empty/undefined names.Key implementation details:
taskMetadata.tsto ensure tasks always have meaningful namesSpecific changes:
getTaskMetadata()to provide fallback names like "Untitled Task", "Incomplete Task", or "Task from [timestamp]"Test Procedure
Manual Testing Steps:
Verification:
Type of Change
Pre-Submission Checklist
mainbranch.Documentation Updates
Additional Notes
This fix addresses a critical UX issue where users couldn't identify their previous tasks due to missing names. The solution is backward-compatible and handles various edge cases including:
The implementation prioritizes data safety and ensures that even in failure scenarios, users can still access and identify their task history.
Get in Touch
Available for questions and feedback on this PR.
Important
Fixes disappearing task names in
taskMetadata.tsby adding fallback logic and improving error handling for edge cases.taskMetadata()by adding fallback names like "Untitled Task" or "Incomplete Task".taskMetadata.ts.taskMetadata().This description was created by
for d93cd92. You can customize this summary. It will automatically update as commits are pushed.