Skip to content

🐛 Fix disappearing task names in task history#4413

Closed
kiwina wants to merge 2 commits intoRooCodeInc:mainfrom
kiwina:fix/disappearing-task
Closed

🐛 Fix disappearing task names in task history#4413
kiwina wants to merge 2 commits intoRooCodeInc:mainfrom
kiwina:fix/disappearing-task

Conversation

@kiwina
Copy link
Contributor

@kiwina kiwina commented Jun 6, 2025

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 getTaskMetadata function didn't handle cases where tasks had no messages or empty/undefined names.

Key implementation details:

  • Added robust fallback logic in taskMetadata.ts to ensure tasks always have meaningful names
  • Implemented crash-resistant task naming that works even when tasks are incomplete or interrupted
  • Enhanced error handling for edge cases where message arrays are empty or malformed
  • Ensured backward compatibility with existing task history entries

Specific changes:

  • Modified getTaskMetadata() to provide fallback names like "Untitled Task", "Incomplete Task", or "Task from [timestamp]"
  • Added comprehensive error handling for tasks with no messages
  • Fixed TypeScript type issues in the return value structure
  • Improved task persistence reliability during application crashes or interruptions

Test Procedure

Manual Testing Steps:

  1. Install the updated extension
  2. Create a new task and let it run partially, then force-close VS Code
  3. Restart VS Code and check the task history - the task should have a meaningful name
  4. Create a task with no initial message and verify it gets a fallback name
  5. Test with various edge cases (empty messages, undefined names, etc.)

Verification:

  • Task history entries now consistently show meaningful names
  • No more blank entries in the task list
  • Previously created tasks with missing names are handled gracefully
  • Application remains stable during task interruptions

Type of Change

  • 🐛 Bug Fix: Non-breaking change that fixes an issue.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality: My code adheres to the project's style guidelines.
  • Testing: The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Documentation Updates

  • No documentation updates are required.

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:

  • Tasks interrupted by application crashes
  • Tasks with no initial messages
  • Tasks with empty or undefined names
  • Malformed task data

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.ts by adding fallback logic and improving error handling for edge cases.

  • Behavior:
    • Fixes disappearing task names in taskMetadata() by adding fallback names like "Untitled Task" or "Incomplete Task".
    • Handles cases with no messages by assigning a default name "Task #[number] (No messages)".
    • Ensures task names are never blank, even if tasks are incomplete or interrupted.
  • Error Handling:
    • Adds error handling for empty or malformed message arrays in taskMetadata.ts.
    • Fixes TypeScript type issues in the return value structure of taskMetadata().
  • Misc:
    • Improves task persistence reliability during application crashes or interruptions.

This description was created by Ellipsis for d93cd92. You can customize this summary. It will automatically update as commits are pushed.

kiwina added 2 commits June 6, 2025 21:04
- 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
@kiwina kiwina requested review from cte, jr and mrubens as code owners June 6, 2025 13:18
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 6, 2025
@daniel-lxs daniel-lxs added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 6, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 6, 2025
Copy link
Member

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

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) {
Copy link
Member

Choose a reason for hiding this comment

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

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:

  1. Using a boolean flag like const hasMessages = messages && messages.length > 0
  2. Pre-calculating all values (taskName, timestamp, tokenUsage, taskDirSize) based on message availability
  3. Creating the historyItem object 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]

Copy link
Member

Choose a reason for hiding this comment

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

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 = {
Copy link
Member

Choose a reason for hiding this comment

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

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 values

This 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]
Copy link
Member

Choose a reason for hiding this comment

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

It should be possible to use taskMessage here:

Suggested change
messages[0]
taskMessage

number: taskNumber,
ts: lastRelevantMessage.ts,
task: taskMessage.text ?? "",
task: taskName,
Copy link
Member

Choose a reason for hiding this comment

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

Could this work better here? That way taskName is not reassigned unnecessarily.

Suggested change
task: taskName,
task: taskMessage.text?.trim() || `Task #${taskNumber} (Incomplete)`,

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jun 9, 2025
@daniel-lxs daniel-lxs added PR - Changes Requested and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 9, 2025
@daniel-lxs
Copy link
Member

Thank you for your contribution!
Since I couldn't push the suggested changes I created a new PR #5071

@daniel-lxs daniel-lxs closed this Jun 24, 2025
@github-project-automation github-project-automation bot moved this from PR [Changes Requested] to Done in Roo Code Roadmap Jun 24, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working PR - Changes Requested size:M This PR changes 30-99 lines, ignoring generated files.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

Task History Shows Blank/Empty Task Names

2 participants