Skip to content

fix(webview): invalidate live sibling view state on reset and settings import (vps2 F4) - #1562

Open
easonLiangWorldedtech wants to merge 285 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2/f4-cross-instance-reset
Open

easonLiangWorldedtech wants to merge 285 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2/f4-cross-instance-reset

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Draft PR — vps2 unit F4 (cross-instance reset and import invalidation).

Related GitHub Issue

Closes: #1561

The link is by content, not by label. Issue #1561 is open and unlabeled. It records the bug that this unit fixes: per-view state stays usable after a state reset, a profile deletion, and a settings import. This unit is unmerged. Upstream issue #980 covers the same bug and is closed as completed. Fork issue 41 is the ledger of the vps2 split; it is not the issue that this pull request closes. Issue #2488 stays open. It holds the write-ownership decision that this unit does not settle.

Description

This unit makes per-view state follow the profile that a view actually uses.

Invalidation paths:

  • A state reset calls broadcastResetToAllInstances (ClineProvider.ts:6291) after the shared reset lands, and again when the shared reset fails after it already wrote (call sites at 6400 and 6421). Every live view clears its in-memory view-local state, one queued write clears the durable viewStates entries, and every view that did not start the reset re-posts its own state.
  • A settings import calls the same broadcast after a successful import (importExport.ts:405).
  • A profile save refreshes the views that are pinned to the saved profile (refreshViewLocalStateForUpdatedProfile, 4577). A profile deletion re-pins the views that named the deleted profile to the profile that replaces it (rePinViewLocalStateForDeletedProfile, 4626). A profile rename re-points them (repointViewLocalStateAfterProfileRename, 4704, called from the webview message handler). Each fan-out rewrites the durable pin, this view's live pair, the current task's API handler, and the current task's sticky profile name.

Failure handling:

  • A failed activation keeps the switch that failed. The deletion path then restores the previous pair as one guarded pair. It re-reads ownership before it restores, and it judges ownership against what its own write produced. A failed re-read counts as unconfirmed, and the code does not write.
  • Log lines name keys, ids, and profile names. They never carry credential values.
  • Stated residual: when the live-pair check fails, the durable half is not undone. Finding D-1 decides which side wins. This unit does not change that.

Newest head, c9dd5cc6171f, adds two fixes:

  • Settle before decide. The activation fan-out issued its four writes (profile list, shared selection, shared provider settings, and this view's overlay clear) with Promise.all. Promise.all reports the first rejection while the other legs are still running. The deletion path compensates for a failed activation by restoring the selection and the shared settings that the activation moved, so a write that lands after that restore stores on top of it. The fan-out now waits for all four legs with Promise.allSettled, keeps the first rejection as the error that the caller sees, names the failed legs in the log, keeps the rebuild in the catch, and leaves the restore order unchanged.
  • Teardown skip. dispose() sets _disposed before it awaits task eviction. A view that has begun teardown is therefore still registered while its own teardown runs. The cross-view fan-outs used to re-pin, refresh, or re-point those views, which duplicates work that their own teardown already does. Six fan-out sites now skip an instance that has begun teardown. Seven sites in the file now read !instance._disposed, counting the check that the active-instance lookup already had.

Persistence integrity (error-mode review line)

Fixed in this unit: settle before decide. Measured on the parent commit 7c7556b18b0d: with the selection write rejected and the shared settings write landing two timer hops later, the durable selection read the restored profile while the durable settings read the profile that the failed switch had moved to. That mismatched pair survives a reload. The fix makes the fan-out wait for every leg and then report the first rejection. Two things are not claimed: the fix does not make every layer agree after a failed activation, and it does not undo the rule that a failed activation keeps the switch.

This pull request fixes the hazard and does not land the design: it does not reconcile the layers from the committed and failed write lists, and it does not give that reconciliation cross-window authority.

Declined for this unit, on the record. The review line asks for two further things: reconcile the layers from the committed and failed write lists with cross-window authority, and persist or record the sticky profile name when a switch fails. Issue #2488 records both as undecided at the record-level write. Issue #2488 splits the work into two steps. Step 1 is the intra-window fix that this unit ships. Step 2 is the record-level write revision with cross-window authority; it is not implemented here, and #2488 owns it. The reviewer's activation test is the acceptance criterion for that follow-up unit. The advisory mutation check reports 2,531 changed executable lines against a limit of 500 for the diff that this branch carries, so a cross-window write revision does not fit inside this unit.

Lifecycle resource cleanup (warning-mode review line)

Fixed in this unit: six cross-view fan-out sites skip a view that has begun teardown. Two discriminating tests cover the re-pin after a deletion and the refresh after a save. The read-only sibling pin check is deliberately left unguarded, because skipping a disposed sibling there would change which profile a deletion reports as still referenced.

Declined for this unit: the same two asks answered above, with the same citations — issue #2488 (step 1 shipped here, step 2 not), the reviewer's activation test as the acceptance criterion for the follow-up unit, and the advisory mutation count of 2,531 against the 500 limit.

Effect stated plainly: this work clears a warning line. It does not unblock anything. Warning mode writes prose for a human reader; it cannot flip the verdict.

Regression evidence (warning-mode review line)

Four new tests carry this head, one discriminating test per finding, each paired with a negative control on the parent blob and a hash proof:

  • keeps a late activation write from landing on top of the state the failure path restored (provider spec).
  • leaves a view that has begun teardown out of the re-pin after a profile deletion (provider spec).
  • leaves a view that has begun teardown out of the sibling refresh after a profile save (provider spec).
  • returns the in-memory state when a read throws after every write landed (webview-ui state-wrapper spec).

The three provider tests fail on the parent production file and pass on this head. The wrapper case fails when the read-failure fallback is reverted and passes on this head. Clearing this warning line does not unblock anything: warning mode writes prose for a human reader.

Description and issue links

The Closes: #1561 line above satisfies the issue-assessment line, which is error mode. The description section is rewritten here. The previous description text is preserved word for word in comment 6971596076 on this pull request; content was relocated there, not deleted. That comment also carries the corrected review-verdict read.

Test Procedure

Commands, run from the package directory:

  • Provider spec: node node_modules/vitest/vitest.mjs run core/webview/__tests__/ClineProvider.spec.ts from src/.
  • Full extension-host suite: node node_modules/vitest/vitest.mjs run from src/.
  • Full webview suite: node node_modules/vitest/vitest.mjs run from webview-ui/.
  • Typechecks: tsc --noEmit -p . in src/ and webview-ui/, and tsc --noEmit -p tsconfig.esm.json in apps/vscode-e2e/.
  • Lint: eslint <file> --max-warnings=0 --no-warn-ignored from the package directory, then eslint --prune-suppressions --max-warnings=0 on the two touched source files.
  • Format: prettier --check on the touched files.

Environment: Windows 11 host, Node 25, pnpm workspace, Vitest 3.

Results at head c9dd5cc6171f:

  • ClineProvider.spec.ts: 512 passed of 512.
  • Extension-host suite: 14,013 passed, 43 skipped, 45 failed, across 600 test files (595 passed, 2 failed, 3 skipped). All 45 failures are environment-bound and reproduce on the parent commit: 40 need wasm assets that are absent from a local dist/, and 5 need symlink creation rights (EPERM). The known local failure in ShadowCheckpointService did not occur in this run.
  • Webview suite: 2,620 passed of 2,620 across 196 test files.
  • Typechecks: exit 0 in src/, webview-ui/, and apps/vscode-e2e/.
  • Lint: exit 0 on the touched files with --max-warnings=0. The --prune-suppressions probe changed no count, and src/eslint-suppressions.json was restored byte-identical after it: 264 files, 264 entries, file sha256/16 30b343fbffc25561.
  • Format: prettier --check exit 0 on all three touched files.

Negative controls, each run and then restored byte-identical:

  • src/core/webview/ClineProvider.ts replaced by its parent blob 37c8e5ca07a9223ad2b4305d6eade4a29f678743 (sha256/16 910cdbcc9b754a93): exactly the three new provider tests fail — the activation test at the assertion that the late write settled before the caller returned, and the two teardown tests at the first assertion that the sibling was not touched. Restored to sha256/16 f98f5e5aedd2f1a6.
  • The read-failure fallback in webview-ui/src/utils/vscode.ts changed to return undefined: exactly the new wrapper case fails (1 failed, 20 passed). Restored byte-identical, sha256/16 aad3016c5386a4c0 before and after, with only the spec file modified.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I reviewed my own code with care.
  • Writing Style: The PR title and description use Simplified Technical English (ASD-STE100): short sentences, plain words, active voice, one idea per sentence, no contractions.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Test Helpers (test changes only): Shared test helpers (src/test-utils/, @/utils/test-utils) are used only for mechanical duplication; test intent and scenario-specific mocks remain visible. This head adds no shared helper; every double and gate stays inside the test that uses it.
  • Visual Snapshot (UI changes only): No user-visible rendered state changes in this unit, so no *.visual.tsx baseline applies. The webview-ui changes are the state wrapper and its tests.
  • Documentation Impact: I checked if my changes need documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I read and agree to the Contributor Guidelines.

Visual Snapshots

None. This unit is extension-host state management plus the webview state wrapper. No rendered surface changes, so no committed Playwright baseline applies.

Videos (interaction / animation only)

None. No interaction or animation changes.

Documentation Updates

  • No documentation updates are required.

The diff carries 36 files, and none of them is under docs/ or a Markdown file. The behaviour is described in the code comments and in this description.

Additional Notes

  • Mutation advisory: 2,531 changed executable lines against the 500 limit. The advisory measures the whole diff that this branch carries (36 files, +21,495 and -700 against merge-base 75a93a9d9acc), because the branch is stacked on unmerged sibling units and merges bottom-up in the order recorded in fork issue 41. The previous head measured 2,506 on the same basis. The advisory is not one of the six required contexts.
  • Required contexts at the time of this edit (server date 2026-11-18 07:47:19 GMT): all six required contexts are completed and green: check-translations, platform-unit-test (ubuntu-latest), platform-unit-test (windows-latest), compile, knip, e2e-mock. CodeRabbit had not posted a review against c9dd5cc6171f at that read.
  • Standing local noise, disclosed rather than fixed: 40 wasm asset assertions, 5 symlink-creation assertions, and one local-only failure mode in ShadowCheckpointService that did not fire in this run.
  • Description rewrite, disclosed: the previous body measured 30,606 characters in a server readback before this edit. This body measures 13247 characters, measured locally and confirmed against the server readback after the edit. Nothing was deleted: the previous text lives word for word in comment 6971596076.
  • The branch head commit merges trunk 75a93a9d9acc2e0ade07fdb6ab6a2071fca7fd4c (Require authentication for the VS Code E2E mock server, Require authentication for the VS Code E2E mock server #2474). That trunk change touches the code-qa workflow, apps/vscode-e2e, and the TLA mock-authentication files. It does not touch ClineProvider.ts or any spec that this unit touches.

Get in Touch

No Discord username is recorded for the account that authors this unit. Please comment on this pull request, or reach the GitHub account easonLiangWorldedtech.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author PR is waiting for the author to address requested changes has-conflicts PR has merge conflicts with the base branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Invalidate per-view state after reset and settings import (vps2 F4; upstream #980)

2 participants