feat: add per-task file-based history store for cross-instance safety#11490
Merged
hannesrudolph merged 4 commits intomainfrom Feb 19, 2026
Merged
feat: add per-task file-based history store for cross-instance safety#11490hannesrudolph merged 4 commits intomainfrom
hannesrudolph merged 4 commits intomainfrom
Conversation
Implement TaskHistoryStore service that stores each task's HistoryItem as an individual JSON file in its existing task directory. This prevents silent data loss when multiple VS Code windows write to the shared globalState taskHistory array concurrently. Key changes: - New TaskHistoryStore class with per-task file writes via safeWriteJson - Index file (_index.json) for fast startup reads - Reconciliation logic to detect and fix drift between instances - fs.watch for cross-instance reactivity - Debounced index writes (2s window) for streaming performance - Migration from globalState on first startup - Write-through to globalState during transition period - Fallback lookups from globalState for backward compatibility Files created: - src/core/task-persistence/TaskHistoryStore.ts - src/core/task-persistence/__tests__/TaskHistoryStore.spec.ts - src/core/task-persistence/__tests__/TaskHistoryStore.crossInstance.spec.ts Files modified: - src/shared/globalFileNames.ts (added historyItem, historyIndex) - src/core/task-persistence/index.ts (export TaskHistoryStore) - src/core/webview/ClineProvider.ts (integrate store, remove write lock) - Test files updated for new store-based approach
Contributor
Author
All 3 concurrency issues from earlier reviews remain addressed. Commit 8941c61 debounces the globalState write-through (5s window) instead of writing on every mutation -- the debounce pattern is sound and tests are updated accordingly. No new issues found.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
…rough serialization
- reconcile() now runs through withLock() to prevent interleaving with
upsert/delete at async boundaries
- Added initialized promise so callers can await store readiness before
reading (getStateToPostToWebview now awaits it)
- Write-through to globalState now happens inside the store lock via
onWrite callback, preventing concurrent call races on the transition
period fallback
- Removed separate updateGlobalState("taskHistory") calls from
ClineProvider since the onWrite callback handles it serialized
…e.spec.ts The test mocks task-persistence with an explicit factory that was missing the new TaskHistoryStore export, causing all 9 tests to fail with "No TaskHistoryStore export is defined on the mock".
…n every mutation Instead of writing the entire HistoryItem[] array to globalState on every upsert/delete (expensive with 5000+ tasks), the write-through is now debounced with a 5-second window. Per-task file writes remain immediate (~200 bytes each). The globalState is flushed on dispose to ensure no data loss on shutdown. This makes the hot path during streaming (token count updates) write only the per-task file, not the full array.
hannesrudolph
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When Roo Code runs in two VS Code windows simultaneously, both instances share a single
taskHistoryarray inglobalState. Every write replaces the entire array, so concurrent read-modify-write cycles cause silent data loss.Solution
This PR introduces
TaskHistoryStore, a service that stores each task'sHistoryItemas an individual JSON file in its existing task directory (globalStorage/tasks/<taskId>/history_item.json). Cross-process safety comes fromsafeWriteJson'sproper-lockfileon per-task file writes.Key changes
New
TaskHistoryStoreclass (src/core/task-persistence/TaskHistoryStore.ts)safeWriteJson(source of truth)_index.json) for fast startup readsfs.watchfor cross-instance reactivitywithTaskHistoryLockfrom ClineProvider)Migration from globalState
history_item.jsonfrom existingglobalState("taskHistory")Backward compatibility
globalState("taskHistory")during transition periodClineProvider integration
updateTaskHistory(),deleteTaskFromState(),deleteTaskWithId(),getTaskWithId(),getRecentTasks(),getStateToPostToWebview(),handleModeSwitch(),persistStickyProviderProfileToCurrentTask()all use the storetaskHistoryWriteLockandwithTaskHistoryLock()(lock moved into store)Test coverage
View task on Roo Code Cloud