@@ -9,7 +9,6 @@ import type { HistoryItem } from "@roo-code/types"
99import { GlobalFileNames } from "../../shared/globalFileNames"
1010import { safeWriteJson } from "../../utils/safeWriteJson"
1111import { getStorageBasePath } from "../../utils/storage"
12- import { taskHistoryLock } from "./TaskHistoryLock"
1312
1413/** Valid status values for a task's HistoryItem. */
1514export type HistoryItemStatus = NonNullable < HistoryItem [ "status" ] >
@@ -80,11 +79,12 @@ interface DelegationRepairIntent {
8079 * as a cache for fast list reads at startup.
8180 *
8281 * Cross-process safety for per-task files comes from `safeWriteJson`'s
83- * `proper-lockfile`. The shared `_index.json` is treated as a rebuildable
84- * cache: writers rebuild it from on-disk `history_item.json` files under a
85- * cross-process `tasks/_history.lock`, so a stale in-memory snapshot cannot
86- * clobber entries published by another extension host. Within a single
87- * process, an in-process write lock serializes mutations.
82+ * `proper-lockfile`. The shared `_index.json` is a best-effort startup
83+ * cache: it may lag or miss entries from other hosts, but
84+ * `reconcile()` rebuilds from authoritative per-task files — at startup
85+ * (`forceRefresh: true`), via `fs.watch`, and on a 5-minute periodic
86+ * fallback. Within a single extension host process,
87+ * an in-process write lock serializes mutations.
8888 */
8989/**
9090 * Options for TaskHistoryStore constructor.
@@ -884,57 +884,17 @@ export class TaskHistoryStore {
884884 }
885885
886886 /**
887- * Rebuild `_index.json` from authoritative per-task files under a
888- * cross-process lock.
889- *
890- * Must not dump `this.cache` directly: each extension host only has a
891- * partial view, and a full-cache snapshot write is a lost-update hazard
892- * when two hosts flush inside the watcher debounce window (see #1231).
893- *
894- * Safe to call while the in-process `withLock` is already held (e.g.
895- * migration) — only the shared file lock is acquired here.
887+ * Write the full index to disk.
896888 */
897889 private async writeIndex ( ) : Promise < void > {
898- await taskHistoryLock . withLock ( this . globalStoragePath , async ( ) => {
899- const indexPath = await this . getIndexPath ( )
900- const entries = await this . collectIndexEntriesFromDisk ( )
901- const index : HistoryIndex = {
902- version : 1 ,
903- updatedAt : Date . now ( ) ,
904- entries,
905- }
906-
907- await safeWriteJson ( indexPath , index )
908- } )
909- }
910-
911- /**
912- * Scan task directories and load each `history_item.json` for the index.
913- * Per-task files are the source of truth; missing/corrupt files are skipped.
914- */
915- private async collectIndexEntriesFromDisk ( ) : Promise < HistoryItem [ ] > {
916- const tasksDir = await this . getTasksDir ( )
917-
918- let dirEntries : string [ ]
919- try {
920- dirEntries = await fs . readdir ( tasksDir )
921- } catch {
922- return [ ]
923- }
924-
925- const entries : HistoryItem [ ] = [ ]
926- for ( const name of dirEntries ) {
927- if ( name . startsWith ( "_" ) || name . startsWith ( "." ) ) {
928- continue
929- }
930-
931- const item = await this . readTaskFile ( name )
932- if ( item ) {
933- entries . push ( item )
934- }
890+ const indexPath = await this . getIndexPath ( )
891+ const index : HistoryIndex = {
892+ version : 1 ,
893+ updatedAt : Date . now ( ) ,
894+ entries : this . getAll ( ) ,
935895 }
936896
937- return entries . sort ( ( a , b ) => b . ts - a . ts )
897+ await safeWriteJson ( indexPath , index )
938898 }
939899
940900 /**
0 commit comments