-
Notifications
You must be signed in to change notification settings - Fork 3k
🐛 Fix disappearing task names in task history #4413
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -27,10 +27,40 @@ export async function taskMetadata({ | |||||
| workspace, | ||||||
| }: TaskMetadataOptions) { | ||||||
| const taskDir = await getTaskDirectoryPath(globalStoragePath, taskId) | ||||||
|
|
||||||
| // Handle edge case where there are no messages at all | ||||||
| if (!messages || messages.length === 0) { | ||||||
| const historyItem: HistoryItem = { | ||||||
| id: taskId, | ||||||
| number: taskNumber, | ||||||
| ts: Date.now(), | ||||||
| task: `Task #${taskNumber} (No messages)`, | ||||||
| tokensIn: 0, | ||||||
| tokensOut: 0, | ||||||
| cacheWrites: 0, | ||||||
| cacheReads: 0, | ||||||
| totalCost: 0, | ||||||
| size: 0, | ||||||
| workspace, | ||||||
| } | ||||||
| return { | ||||||
| historyItem, | ||||||
| tokenUsage: { | ||||||
| totalTokensIn: 0, | ||||||
| totalTokensOut: 0, | ||||||
| totalCacheWrites: 0, | ||||||
| totalCacheReads: 0, | ||||||
| totalCost: 0, | ||||||
| contextTokens: 0, | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| const taskMessage = messages[0] // First message is always the task say. | ||||||
|
|
||||||
| 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] | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to use
Suggested change
|
||||||
|
|
||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 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. |
||||||
| let taskDirSize = taskSizeCache.get<number>(taskDir) | ||||||
|
|
||||||
|
|
@@ -45,11 +75,17 @@ export async function taskMetadata({ | |||||
|
|
||||||
| const tokenUsage = getApiMetrics(combineApiRequests(combineCommandSequences(messages.slice(1)))) | ||||||
|
|
||||||
| // Ensure task name is never blank - provide fallback names | ||||||
| let taskName = taskMessage.text?.trim() || "" | ||||||
| if (!taskName) { | ||||||
| taskName = `Task #${taskNumber} (Incomplete)` | ||||||
| } | ||||||
|
|
||||||
| const historyItem: HistoryItem = { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 valuesThis eliminates the duplicate object creation and makes the code more maintainable. |
||||||
| id: taskId, | ||||||
| number: taskNumber, | ||||||
| ts: lastRelevantMessage.ts, | ||||||
| task: taskMessage.text ?? "", | ||||||
| task: taskName, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this work better here? That way
Suggested change
|
||||||
| tokensIn: tokenUsage.totalTokensIn, | ||||||
| tokensOut: tokenUsage.totalTokensOut, | ||||||
| cacheWrites: tokenUsage.totalCacheWrites, | ||||||
|
|
||||||
There was a problem hiding this comment.
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
historyItemobject is created twice - once in this early return and once at the end of the function. You could restructure this by:const hasMessages = messages && messages.length > 0taskName,timestamp,tokenUsage,taskDirSize) based on message availabilityhistoryItemobject only once at the endThis would improve maintainability and follow DRY principles.