Repository navigation
fix(task): guard saveClineMessages against abandoned tasks (fixes #1021) #1496
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
base: main
Are you sure you want to change the base?
Changes from all commits
e6df210
089d242
fb92f85
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 |
|---|---|---|
|
|
@@ -1889,6 +1889,32 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike { | |
| this.debouncedEmitTokenUsage(tokenUsage, this.toolUsage) | ||
|
|
||
| const provider = this.providerRef.deref() | ||
|
|
||
| // Fire-and-forget saveClineMessages() calls can reach this point after | ||
| // abandonSubtask's atomicUpdatePair() cleared parentTaskId/rootTaskId. Writing | ||
| // this live Task's stale link values would silently reattach the severed | ||
| // parent-child link. Keep the upsert (so a plain cancel still records its | ||
| // metadata) but omit the link keys when the store already has this task's row: | ||
| // upsertCore merges over the existing record, so omitted keys keep the | ||
| // severed/null values while tokens, cost, ts and title are refreshed. | ||
| if (this.abandoned) { | ||
| const existing = provider?.taskHistoryStore.get(this.taskId) | ||
| if (!existing) { | ||
|
Contributor
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. Preserve the first history row during task eviction. If a new task's first save is pending, creating another task evicts it through Both the pending save and final abort save now return here without creating the row. Previously, either save could insert it. Saved messages then remain inaccessible through Distinguish first persistence from deletion, or persist the initial row before exposing the task. Preserve deletion handling and the existing-row relationship omission.
|
||
| // The message write succeeded, and the boolean reflects the message write | ||
| // only (see method docs): returning false here would make callers retry an | ||
| // already-persisted save (persistQueuedFeedbackAndAcknowledge) or skip a | ||
| // durable-state-gated update whose on-disk record is in fact current | ||
| // (finalizePartialToolAsk). No stored row means there is no link to | ||
| // reattach, and creating one here would write a task the store never had. | ||
| return true | ||
| } | ||
| const { parentTaskId: _parentTaskId, rootTaskId: _rootTaskId, ...detachedHistoryItem } = historyItem | ||
| await provider?.updateTaskHistory( | ||
| existing.status ? { ...detachedHistoryItem, status: existing.status } : detachedHistoryItem, | ||
| ) | ||
| return true | ||
| } | ||
|
|
||
| const existingStatus = provider?.taskHistoryStore.get(this.taskId)?.status | ||
| await provider?.updateTaskHistory(existingStatus ? { ...historyItem, status: existingStatus } : historyItem) | ||
| } catch (error) { | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.