Skip to content

ClineProvider.getState() reports shared state instead of the view's own hydrated per-view selections #1549

Open

Description

@easonLiangWorldedtech

Bug description

ClineProvider.getState() reads every state field directly from the shared ContextProxy (global extension state). Per-view selections held in the provider's view-local buffer (viewLocalState: mode, currentApiConfigName, apiConfiguration) are hydrated per webview from the durable viewStates map, but getState() never merges that buffer in — so every webview reports the same shared mode / API profile / provider configuration regardless of what that view actually selected.

Extension-side consumers of getState() therefore see the wrong mode / profile / apiConfiguration when multiple views hold different selections: a per-view mode or profile switch does not take effect for the view that made it, and provider settings reported for a view can belong to another view's selection.

Expected behavior

getState() should serve each per-view-capable field from the view's hydrated state when that view has a selection, falling back to the shared global value otherwise (view-local wins; fields the view has not selected are unchanged, with the existing defaults).

Proposed fix

In getState(), merge the view-local buffer on top of the context values before reading the state fields:

const stateValues = this.contextProxy.getValues()
const mergedStateValues = { ...stateValues, ...this.viewLocalState }

and read the per-view fields (including the apiConfiguration object, merged over the provider settings) from mergedStateValues. The write path already drops unknown modes and keeps the buffer consistent (validation on setValues / setValue), so the read path stays a pure merge with no new validation.

Reproduction

  1. Create two ClineProvider instances over the same extension context (e.g. sidebar + editor webviews).
  2. On each, save a per-view selection (mode, currentApiConfigName, or apiConfiguration) via the view-state save path.
  3. Call getState() on both instances.
  4. Both return the shared global values — the per-view selections are not reflected in the reported state.

Part of the vps2 durable per-view state series — tracked in easonLiangWorldedtech#41.

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