Skip to content

[BUG] Legacy taskHistory blob stays in globalState after file-backed migration #1771

Open

Description

@PierrunoYT

Problem (one or two sentences)

After task history migrated to per-task history_item.json files, the old "taskHistory" array stays in extension globalState indefinitely. VS Code weighs the total extension state on every read and write, so the large-state warning keeps appearing even though Zoo Code no longer writes new history there (#1664).

Context (who is affected and when)

Users who ran a version from before the file-backed migration and built up a large task history. The blob is never removed, so it persists across updates. Split out of #1664 (for #1542) at the maintainer's request: #1664 (comment)

Reproduction steps

  1. Use a pre-migration version and build up a large task history.
  2. Update to a version with file-backed history, so migration runs and sets taskHistoryMigratedToFiles.
  3. Inspect extension globalState: taskHistory still holds the full legacy array.

Expected result

After a successful, verified migration, the legacy taskHistory blob is removed (or reduced), so it no longer counts toward extension state size.

Actual result

The blob stays in globalState indefinitely, and the large-state warning persists.

Variations tried (optional)

A first attempt cleared the blob in initializeTaskHistoryStore right after the migration marker was set (reverted from #1664 in 720f1e9). Handling old blobs needs its own design. Open questions:

  • When cleanup is safe: clear only after migration is verified complete. Fallbacks such as getTaskWithId and the mode/API-config update handlers still read globalState.taskHistory while the store is uninitialized or migration failed.
  • Partial failures: what happens if the cleanup write fails, and whether it is retried on the next startup without making stale legacy history authoritative again.
  • Multiple windows: coordinating with other windows or instances that may still be migrating or reading the blob.
  • Downgrades: older versions that still rely on the blob would lose their history view after a downgrade. Consider a delay or a backup before deleting.
  • Users who already migrated: they need a one-time cleanup path.

App Version

3.82.2

Activity

  1. gh311 commented on Dec 6, 2026

    @gh311
    Contributor

    Spec-first fix opened as PR #2873 (head 01ab2855f).

    Root cause: the file-backed migration sets taskHistoryMigratedToFiles but nothing ever removes the legacy globalState.taskHistory array, so every install that ever ran a pre-migration version keeps weighing the whole extension state on every read/write and the large-state warning persists.

    Fix (PR #2873): a one-time sweep in initializeTaskHistoryStore once the store is initialized:

    • delete only when the file-backed store holds every blob entry whose task directory exists (per-entry verification; any miss keeps the blob — entries an older build appended after the marker are never deleted);
    • back up the full array (orphans included) to legacy-task-history.backup.json in global storage and read it back before the delete;
    • any failure keeps the blob and retries on the next startup (the blob's presence is the retry condition — no extra marker, idempotent, multi-window safe through update(key, undefined));
    • a provider whose startup failed keeps its legacy fallback: getTaskHistoryItem now also reads the sweep backup when the blob is gone, so a failed window does not report existing tasks as missing after a peer swept (the gap the previous [BUG] Legacy taskHistory blob stays in globalState after file-backed migration #1771 PR left open — it was auto-closed for author inactivity, not rejected on the approach).

    SDD (per docs/architecture/tla/AGENTS.md): new spec TaskHistoryMigration.tla (+MC module, base + 4 sabotage cfgs). Base passes in 650 states; NoSweep (the pre-fix behavior) fails SweptWhenVerifiable (218 states); NoVerify fails ClearRequiresVerification (392); NoBackup fails ClearRequiresBackup (97); StaleResurrect fails PeerClearedStaysCleared (515). Each variant run violates only its named invariant.

    Tests: 7 sweep cases in ClineProvider.taskHistory.spec.ts fail on the pre-fix code exactly at the sweep assertions, plus the property test legacyTaskHistoryBlob.spec.ts (seeded 500-scenario loop: clear ⇒ backup written ∧ every non-orphan entry held). Sabotage-verified: removing the orphan exclusion, the verification gate, the backup-failure handling, or the empty-blob guard fails the matching test.

    UI/UX: none — after migration the webview already reads the file-backed store; the large-state warning clearing is the issue's expected outcome.

  2. added 5 commits that reference this issue on Dec 6, 2026
    b43fc8a
    57fd66e
    ffbf0b5
    87c7927
    be7cda1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions