Skip to content

[Fix] Task history disappears when user reopens a task - #1319

Draft
zoomote[bot] wants to merge 2 commits into
mainfrom
fix/preserve-task-history-25qz019og2l3b
Draft

[Fix] Task history disappears when user reopens a task#1319
zoomote[bot] wants to merge 2 commits into
mainfrom
fix/preserve-task-history-25qz019og2l3b

Conversation

@zoomote

@zoomote zoomote Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

​Created by Roomote. Follow up by mentioning @roomote, in the web UI, or in Discord.

What changed

  • Preserve finalized reasoning and other saved messages while a task is rehydrated for resume.
  • Distinguish missing, invalid, and unreadable task history from an explicitly empty history instead of converting failures to an empty conversation.
  • Retry a transient missing-file read once with jitter to bridge the safe-write rename window.
  • Merge ordinary UI and API history snapshots under the existing advisory file lock so stale writers preserve newer disk messages.
  • Keep explicit rewind, truncation, and overwrite operations authoritative rather than merging removed history back in.
  • Stop abandoned history-task hydration before it can persist after eviction.
  • Abort delegated-parent reopening when its saved UI history cannot be loaded safely.
  • Add deterministic regression coverage for hydration failures, finalized reasoning, resume/eviction races, retry behavior, merge ordering, legacy histories, and tool call/result ordering.

Why this change was made

Reopening or quickly leaving a saved task could replace valid history with an empty or shortened message list. Concurrent extension instances could also overwrite a newer history suffix with a stale snapshot. This resolves #1279 and extends the lifecycle and persistence safety work tracked by #355, #208, and #1231.

Impact

Users keep their last saved task content when reopening or resuming tasks. Temporary storage gaps are retried, ordinary concurrent writes preserve newer messages, and stale task instances cannot write after being evicted. Explicit user-driven history rewinds continue to replace history as intended.

Related PRs

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.72727% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/core/task-persistence/taskMessages.ts 96.15% 0 Missing and 1 partial ⚠️
src/core/webview/ClineProvider.ts 83.33% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@martin-rueegg

Copy link
Copy Markdown

Looks like this might also contribute to fixing some of the things I've experienced in #1231, too

@martin-rueegg martin-rueegg left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think the fix is the right approach but can be strengthened by using the new merge functionality of the safeWriteJson() method and updating the local copy with the merged result.

@roomote

Comment thread src/core/task-persistence/taskMessages.ts
Comment thread src/core/task-persistence/taskMessages.ts Outdated
Comment thread src/core/task/Task.ts
@zoomote

zoomote Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the retry and merge feedback in 3f5b2d04:

  • retries the safe-write ENOENT window once with 10–300 ms jitter;
  • merges ordinary UI/API snapshots under the advisory lock while preserving authoritative rewinds;
  • preserves equal timestamps, legacy ordering, completed/answered UI state, and API tool call/result order;
  • adds focused coverage for retry, merge routing, second-stage abort, and delegated-parent read failure.

The full Zoo Code test suite passes (7,560 tests), and the previously uncovered Task/ClineProvider branches now have direct regression coverage. All three review threads were replied to and resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Many times, it lost my latest session content

2 participants