Skip to content

Persist per-view view-state identity and durable viewStates in ClineProvider #1536

Description

@easonLiangWorldedtech

Summary

In parallel mode each visible task runs in its own webview (its own ClineProvider instance), but all instances share a single global state store. Settings such as mode, currentApiConfigName, and apiConfiguration are therefore written globally: a switch in one view leaks into every other view, and restoring a task from history rewrites the shared global mode for all views.

This change gives every ClineProvider instance a per-view identity and a durable per-view state bucket:

  • Per-view identity — every provider instance owns a unique viewId (renderContext plus a monotonic counter) and registers a stable viewStateId (sanitized; __proto__ rejected) under which its state is persisted.
  • Durable per-view storage — a new viewStates global-state key holds a map from view id to that view's non-secret mode / currentApiConfigName / apiConfiguration overrides. Writes go through a serialized queue so concurrent provider instances merge without lost updates, and the map is pruned to the newest 50 entries.
  • View-local restore — reopening a task from history now pins the restored mode into the view-local buffer (persisted durably) instead of writing the shared global mode.

The in-memory viewLocalState buffer continues to feed postStateToWebview; getState() merging of hydrated per-view values arrives in a follow-up.

Context

Part of the durable per-view state series tracked in easonLiangWorldedtech#41 (fix unit F1a of the F1 → F1a/F1b/F1c split).

Reproduction (before)

  1. Open two task views in parallel mode.
  2. Switch the mode in one view (e.g. Code → Architect).
  3. The other view's mode follows the change — the switch leaked through shared global state.

Expected (after)

Each view keeps its own mode and API configuration; switching in one view no longer affects the other, and the restored mode of a reopened task is pinned to that view only.

Activity

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