Skip to content

test(webview): F2a - profile-mutation state semantics and the mode-rollback guard - #1919

Open
easonLiangWorldedtech wants to merge 181 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2-f2a
Open

easonLiangWorldedtech wants to merge 181 commits into
Zoo-Code-Org:mainfrom
easonLiangWorldedtech:vps2-f2a

Conversation

@easonLiangWorldedtech

@easonLiangWorldedtech easonLiangWorldedtech commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Related GitHub Issue

This unit does not close an upstream issue: it is split unit F2a of the durable per-view state (vps2) series, whose split plan is issued and tracked on (issued before this PR opened). It supersedes the closed umbrella PR 1555, and merges in the chain order F1a 1546 → F1b 1550 → F1c 1552 → F2a → F2b → F2c 1921.

Related: #1992 — Zoo-Code-Org/Zoo-Code#1992 ([Tracking] vps2 chain: rules, port sources, chain-level rows) is the upstream tracking issue for this chain and the home of this unit's split plan, unit boundaries, acceptance criteria and review dispositions. It is written as Related: rather than Closes: on purpose: merging one unit must not close the acceptance record that #1921 and the tail units still need. There is no other upstream issue for this unit, and no upstream number is invented here.

Description

Content source of record: kind: commit, base 8554307ec → head bff2a5ca8 (PR 1555), replayed onto the current main tip so the branch carries nothing main already has.

Budget (own delta, not the stacked view): 173 a+d standalone, 12 changed executable lines.

One gate scope: the state semantics of a profile mutation must hold for every live view, not only the view that performed it, and a mode rollback must not be able to persist a profile that no longer exists.

  • Activating or upserting a profile refreshes the buffered apiConfiguration of every other live ClineProvider pinned to that profile (refreshViewLocalStateForUpdatedProfile) and re-posts each affected view's state, so no view keeps serving — or running on — settings it buffered before the mutation.
  • Deleting a profile re-pins the other live views whose buffer still names it (rePinViewLocalStateForDeletedProfile), replaces their configuration with the surviving profile's, and persists the replacement through the serialized write queue so their durable viewStates entries survive a reload.
  • deleteProviderProfile now writes only the profile list back instead of replaying a full settings snapshot, so it cannot clobber unrelated keys (notably viewStates) that concurrent views mutate directly.
  • A mode-scoped profile rollback is guarded so a profile that no longer exists cannot be re-persisted.

Also in this head (1b9d6d73f), from review: deleteProviderProfile performs two durable writes — the settings-store commit and the profile-list write. If the list write (or a later selection update) fails, the stored list still names a profile whose settings are gone and no later selection or load can recover them. The settings are now captured before the commit and written back through saveConfig when a later step fails, so the durable metadata and the store agree again (the deletion simply did not happen); the original error is rethrown and a failed compensation is logged with the residual risk stated.

Reviewer focus: the compensation is deliberately a settings restore, not a list rollback — the list write is the step that failed, so the list keeps naming the profile and the store is made to agree with it. Restoring the original id matters: a new id would orphan the task history entries that reference the profile.

Test Procedure

# from the repository root, with dependencies installed (pnpm install)
pnpm --dir src exec vitest run --globals core/webview/__tests__/ClineProvider.spec.ts
pnpm --dir src exec tsc --noEmit

New/updated tests in core/webview/__tests__/ClineProvider.spec.ts:

  • refreshes another live view's buffered settings when the profile it pins is reactivated — two live providers; the mutating view is a different instance, and the assertion is on the other view's buffer, its constructed getState(), and that its webview was re-posted.
  • re-pins another live view and persists the replacement in its durable view state when its profile is deleted — asserts the other view's in-memory pin, its replaced configuration, and the durable viewStates entry.
  • restores the deleted profile's settings when the profile-list write fails after the store commit — the store commit succeeds, the list write rejects, and the test asserts saveConfig is called with the original id and secret while the original error propagates.

Each is verified as a pin, not a mirror of the implementation: the two cross-view tests fail when the helper bodies are made to return early, and the compensation test fails when the production change is stashed.

Environment: Windows 11 / Node 22, vitest lanes run from src/. Local result at this head: ClineProvider.spec.ts 283 passed (280 baseline + 3 new); tsc --noEmit unchanged from this branch's local baseline; eslint clean on both touched files with unchanged suppression counts.

Reviewer reproduction at head 68f4cf790 (unit rebased onto vps2/f1b-getstate-merge @ 702a15d93)

# repository root, dependencies installed (pnpm install)
pnpm --dir src exec vitest run --globals core/webview activate --no-file-parallelism --testTimeout=30000
# -> Test Files 39 passed (39); Tests 1199 passed (1199)
pnpm --dir src exec tsc --noEmit
# -> no output
pnpm --dir src exec eslint --max-warnings=0 --no-warn-ignored core/webview/ClineProvider.ts core/webview/webviewMessageHandler.ts core/webview/__tests__/ClineProvider.spec.ts core/webview/__tests__/ClineProvider.sticky-mode.spec.ts core/webview/__tests__/ClineProvider.sticky-profile.spec.ts core/webview/__tests__/webviewMessageHandler.spec.ts
# -> exit 0; this is exactly the form the pre-commit lint-staged task runs
node node_modules/.pnpm/prettier@3.9.10/node_modules/prettier/bin/prettier.cjs --check src/core/webview/ClineProvider.ts src/core/webview/webviewMessageHandler.ts src/core/webview/__tests__/ClineProvider.spec.ts src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts src/core/webview/__tests__/ClineProvider.sticky-profile.spec.ts src/core/webview/__tests__/webviewMessageHandler.spec.ts src/eslint-suppressions.json
# -> "All matched files use Prettier code style!"
pnpm run check-types
# -> 11 successful / 11 total (root tsc -p tsconfig.json --noEmit plus every package's check-types, incl. webview-ui)

Suppression counts moved once and only downward: core/webview/__tests__/ClineProvider.sticky-mode.spec.ts, @typescript-eslint/no-explicit-any 26 → 25, because the removed cases took one suppressed any with them. No suppression was added and no count increased; the rest of src/eslint-suppressions.json is byte-identical to the fold base.

Fold pin. This head is the unit rebased onto vps2/f1b-getstate-merge @ 702a15d93. #1550 has since advanced (6a21695f5, db93970af, 28cae0635, 0c6f79b63, 8ef71e68e, currently e0cb48c51); this fold stays pinned to 702a15d93 and will be re-based onto the landing #1550 head rather than mix two generations of view-state machinery in one commit. Every red→green control named below is pinned to this tree.

Owed refresh (deferred deliberately, not missed). The chain fixes that merge earlier than this unit will be re-carried on that refresh: #1557 8320d7803 + eb553a40d, #1562 ec2fb3724 + f555d04a0, #2226 84a0d7644 + db5bffa49. #2226's postMessageToWebview becoming Promise<boolean> would force re-typing 27 call sites and re-verifying this unit's 1199 tests a second time, and the "test doubles silently disagree" risk it introduces only bites if #1919 merges before #2226, which the declared chain order forbids. The host-minted capability the Security Boundaries row asks for is #2226's claim token (claimToken in packages/types/src/global-settings.ts, viewStateClaim in packages/types/src/vscode-extension-host.ts, pendingViewStateClaims / postViewStateClaimToWebview in src/core/webview/ClineProvider.ts), so the adoption/binding step is scheduled on this unit after #2226 lands instead of being re-invented here.

Hook note. .husky/pre-push exists on the branch, but this worktree's installed hook set (.husky/_, which is gitignored and produced by pnpm install rather than by the branch) had a pre-commit wrapper and no pre-push wrapper, so git push did not execute pnpm run check-types; nothing was skipped with --no-verify. The hook's own command was run directly for this head and its result is quoted above, and the missing wrapper has now been installed in the worktree for subsequent pushes.

Pre-Submission Checklist

  • Issue Linked: No upstream issue is closed by this unit (see above).
  • Scope: One gate scope — cross-view state semantics for profile mutations, plus the mode-rollback guard.
  • Self-Review: Reviewed against the shipped behavior of the superseded umbrella PR 1555.
  • Testing: Three new focused unit tests, each verified as a pin.
  • Visual Snapshots: Not applicable — no rendered-state change.
  • Documentation Impact: None required; no user-facing setting or message contract changes.
  • Contribution Guidelines: Read and agreed. ### Documentation Impact

No documentation change: the user-facing flow (activate / edit / delete a provider profile) is unchanged; only the state each live view ends up with, and the durability ordering inside deletion, changed.

Split-unit issue reference

No approved upstream issue exists for this change. This pull request is one unit of a declared split of a larger change, and the split plan, the unit boundaries and this unit's acceptance criteria are recorded on the tracking issue in this repository: #1992. That issue is the home for this unit's review dispositions and follow-up registrations, which is why no approved issue is linked above.


AT-HEAD review walkthrough triage (head 8a43f2b)

All 31 review threads are resolved. The nine latest AT-HEAD walkthrough rows were re-verified against this head:

  1. Temporary-viewId adoption (ClineProvider.ts load/rekey) - addressed: rekeyPersistedViewStateEntry treats temporary ids as session counters; a stable entry wins and the temporary entry is dropped, so an unrelated earlier view's entry is not adopted as a stable rekey.
  2. undoHistoryWrite assigned without a landed history write - addressed: the closure is a no-op when no history item existed before the switch, and the comment matches the code.
  3. Deletion compensation vs concurrent profile-list mutations - addressed: the compensation re-reads the stored list and splices only the deleted profile back at its previous index (test: "restores the deleted profile without dropping one another instance upserted meanwhile").
  4. Cancelled deletion not rolled back after the settings commit - addressed (a591a1e): the catch routes every failure, including cancellation, through the compensation; the superseded-contract comments were corrected.
  5. Deleting the active profile dropped the live-state half of the old deleteApiConfiguration -> activateProviderProfile path (Major) - fixed at 8a43f2b: the deletion now completes the activation-side effects when the deleted profile was the active one (globally or for this view): the manager's own current-profile record and the current mode's profile mapping follow the survivor, the current task's API handler is rebuilt from the survivor's settings, the current task's sticky profile is refreshed, and ProviderProfileChanged is emitted. Placement mirrors activateProviderProfileUnlocked: after the try/catch, because the deletion has committed. Proofs in the thread reply.
  6. Multi-tab creation for settled openInNewTab calls (Major) - addressed: the handler unconditionally creates a new panel via openClineInNewTab; the tracked-panel reveal is not on the settled path.
  7. Queue advance contract (Major) - addressed: the queue is deliberately chained to the full run - holding the queue until the run settles is what makes the rollback safe - and the comments describing the superseded contract were corrected.
  8. Sidebar-only title commands visible in the command palette - addressed (6cc68ef, within the marked range): the *InTab variants, which target the tracked tab instance and are meaningless from the palette, are hidden with when: false; the sidebar variants are registered once at activation and target the activation-wired provider directly (no per-view registration, no visible-instance heuristic), which is the pre-unit palette behavior.
  9. Deletion compensation vs other provider instances (Major) - addressed: same merge-style restore as row 3, with a one-to-one negative control.

Verification numbers (head 8a43f2b)

  • ClineProvider.spec 316/316 (2 new tests: rebuild on active-profile deletion; no rebuild when not active)
  • webviewMessageHandler.spec 91/91, ClineProvider.sticky-profile.spec 18/18, ProviderSettingsManager.spec 55/55
  • Negative control: removing the new deletion-completion block reddens exactly the rebuild test (1 failed / 315 passed); restore byte-exact (hash match)
  • tsc 0 errors; eslint --max-warnings=0 clean on both touched files; suppression counts unchanged
  • Prettier merge-ref gate ALL-MATCHED

Post-commit activation error distinction (head 91dfd64)

  • AT-HEAD thread 4251990874 (Minor, functional correctness): a rejection in the post-commit activation block was reported by the message handler as errors.delete_api_config, misreporting a successful deletion. Fixed: the committed state is posted first, then a distinct ProfileDeletionActivationError (own module profileDeletionError.ts, re-exported by the provider) is thrown; the handler warns with the activation cause instead of the generic delete error.
  • Proofs at 91dfd64: ClineProvider.spec 317/317, webviewMessageHandler.spec 92/92 (new tests both sides); negative controls 1-red each, restores byte-exact (hash match); tsc clean except the two known local telemetry-dist noise lines; eslint clean; prettier merge-ref gate ALL-MATCHED. Ported to the sibling unit carrying the same deletion code.

CI re-trigger: heads e704ab4 and 67a9649 are empty commits over 91dfd64 (no content change) to re-run flaked lanes; the visual lane passed at e704ab4, and 67a9649 re-runs the mock-e2e 30s-timeout flake ('persists completed task across a fresh extension host' - the identical tree passed e2e-mock at 91dfd64). All verification numbers above apply unchanged.

Pre-merge ERROR-row pre-check (head d5c69d3)

  • Security Boundaries / view-state id rows: addressed at d5c69d3. setViewStateId now rejects non-string ids (crafted postMessage), bounds the key length (MAX_VIEW_STATE_ID_LENGTH), and refuses ids already owned by another live instance; a refused view stays on its temporary id against shared state. Regression tests: non-string, oversized, claimed-by-another-view. Negative controls: disabling the ownership check reddens exactly the claim test; widening the length bound reddens exactly the oversized test; restores byte-exact (hash match).
  • The spec gained an afterEach clearing the static instance registry (suites construct providers directly and never dispose most of them; leaked instances would claim ids ahead of later tests).
  • Persistence Integrity setValues/setValue ordering rows: verified already addressed by the pushed code: _saveViewLocalStateFromMutation persists the non-secret subset before updating the buffer; the re-key is a single queued write (no delete-then-write window; authorship clears only after the write lands); the mutation hook keeps the buffer synced across setValue/setValues and profile upsert/activation/deletion.
  • Deletion sibling-state: addressed - rePinViewLocalStateForDeletedProfile re-pins other live views still buffered on a deleted profile (buffer + durable entry), and deletion snapshots/compensates every store it rewrites. Re-key persistence: single queued write, temp entry survives a failed write.
  • The three shared-view handoff tests now dispose the writer before the next view adopts the id (the ownership rule being enforced); the durable entry stays in storage across the handoff.
  • Proofs at d5c69d3: sticky-mode 33/33, ClineProvider.spec 317/317, webviewMessageHandler.spec 92/92; eslint --max-warnings=0 clean; tsc clean except the two known local telemetry-dist noise lines; prettier merge-ref gate ALL-MATCHED.
  • Non-activating saves (upsertProviderProfile with activate=false, and the zoo-gateway callback's non-active path) rewrote the profile on disk but left pinned views serving the pre-save snapshot; the non-activating branch now refreshes pinned sibling views (and this view when it holds the pin), and the callback routes through upsertProviderProfile so the refresh cannot be forgotten.
  • getState() no longer spreads the pinned overlay over the shared provider settings (a key the profile never defined leaked in from the shared profile: model id, region, tuning). The overlay is a complete snapshot: used in place, with only apiProvider falling back to shared state.
  • Regression tests: "refreshes views pinned to a profile saved without activation"; "does not leak shared provider keys into a pinned view's api configuration; the zoo-gateway callback test asserts the upsert path.
  • Negative controls: dropping the else-branch refresh reddens exactly the refresh test, reverting the merge semantics reddens exactly the leak test; restores byte-exact (hash match).
  • Proofs at bf474cd: ClineProvider.spec green, sticky-mode and webviewMessageHandler green, eslint --max-warnings=0 clean, tsc clean except the two known local telemetry-dist noise lines, prettier merge-ref gate ALL-MATCHED.

Follow-up: overlay read from the view buffer (required-lane fix)

The previous round's overlay-completeness change read the overlay from the merged state values, which also carry the raw apiConfiguration state key. That key is a partial patch written by shared-store paths, not a view snapshot: with no overlay present and the raw key partial, getState() served only the partial object and dropped the shared provider settings the previous merge produced (the parallel-mode activation tests caught exactly this - the activated profile's model id vanished; required lane red on the units carrying that spec). The overlay is now read from the view buffer itself, where a present value is by contract a complete profile and an absent one means the shared store serves the settings.

Proofs: ClineProvider.parallelMode.spec green where present (the six synchronization tests that regressed), ClineProvider.spec green including the overlay-completeness tests, sticky-mode and webviewMessageHandler green; negative control: reverting the overlay to a shallow merge over the shared settings still reddens exactly the leak test; restores byte-exact (hash match); eslint --max-warnings=0 clean; tsc clean except the two known local telemetry-dist noise lines; prettier merge-ref gate ALL-MATCHED.

Follow-up: active task handlers rebuilt on non-activating saves (head 7b107d3)

A review round on the view-identity unit found that the non-activating-save refresh updated pinned views' buffers but not their active tasks' API handlers, and the posted state prefers the task's own apiConfiguration: a conversation running in a view pinned to the saved profile kept sending the old token (e.g. after the Zoo Gateway callback rotated it) even though the view's buffer had caught up. The refresh now rebuilds the affected tasks' handlers in the pinned views, and the non-activating branch rebuilds this view's own handler when it holds the pin.

Proofs: ClineProvider.spec green (the pinned-sibling refresh test now asserts the active task's handler is rebuilt with the saved settings, not just the private buffer); negative control: dropping the rebuild from the refresh reddens exactly that assertion, restores byte-exact (hash match); parallelMode/sticky-mode/webviewMessageHandler green; eslint --max-warnings=0 clean; tsc clean except the two known local telemetry-dist noise lines; prettier merge-ref gate ALL-MATCHED.

Follow-up: test-quality round from the review (head eda590a)

The review round on the api-wiring unit named four test-quality issues; the ones present in this unit are fixed here: the viewStates describe block moved out of the alwaysDenyUnapprovedCommands block (test names carried the wrong subject), the prune test's toBeDefined() survival checks replaced with exact-shape toEqual assertions (they pass even if pruning strips fields), the stale-temporary-entry test's fixed 10 ms wait replaced with awaiting the load itself (the negative assertion could pass vacuously on a slow load), and the readiness-cancel test's fake timers restored in a finally block (a failed assertion left fake timers active and hung a later real-timer test).

Proofs: global-settings 9/9 where present, ClineProvider.spec green, sticky-mode green where present, api-task-control green where present; negative controls: pruning that strips updatedAt reddens exactly the prune test, a loadViewState that adopts the unowned temporary-id entry reddens exactly the stale-entry test, restores byte-exact (hash match); eslint --max-warnings=0 clean (src and types); prettier merge-ref gate ALL-MATCHED.

Follow-up: review-round fixes from the series (head acfd9ae)

A review round on the mode-profile-writes unit found that the profile-deletion re-pin updated each sibling view's buffer but not its running task: the posted state prefers the task's own apiConfiguration, so a conversation in a view pinned to the deleted profile kept sending the deleted profile's settings. The re-pin now rebuilds the sibling's API handler with the replacement's settings and re-points the task's sticky profile name, mirroring the activation path.

Proofs: ClineProvider.spec and sticky-mode green; eslint --max-warnings=0 clean; tsc clean except the two known local telemetry-dist noise lines; prettier merge-ref gate ALL-MATCHED. The rebuild's negative control (dropping it reddens exactly the sibling re-pin test, byte-exact restore) runs in the units that own that test.


Updated this round (port of the two upstream PR 1921 review fixes)

acfd9ae -> 54b3890

Ported the two fixes landed on the sibling unit (fork PR 43 / upstream PR 1921 at 2e932e8). This unit carries the same shared code (provider-profile mutation queue + sibling re-pin), so the same review findings apply to this branch:

  1. providerProfileMutationQueue is now shared across instances (static). The per-instance queue let a second view commit between this view's shared write and its snapshot compensation, and the compensation restored a stale copy over the newer write; one queue now serializes every view's profile mutations against each other.
  2. The sibling re-pin now switches each view's task (API handler rebuild + sticky profile name) only after every sibling's re-pin landed. Running those updates inside the per-sibling loop left a successful sibling's task on the replacement's handler and sticky name while its pin was compensated back to the deleted profile after a later sibling's rejected re-pin rolled the deletion back.

Tests: this unit has no ClineProvider.parallelMode.spec.ts (parallel-mode lineage), so both regression tests land in ClineProvider.spec.ts next to the existing re-pin rollback tests - cross-instance serialization + sibling-task rollback - adapted to this unit's manager-double and saveViewState pin conventions.

Proofs: ClineProvider.spec 321/321 (2 new tests); sticky-mode + sticky-profile + webviewMessageHandler 143/143; negative controls: per-instance queue shadow reddens exactly the serialization test, task updates moved back into the per-sibling loop redden exactly the sibling-task test, both restores byte-exact (hash match 7c41a7db88ee1710); eslint --max-warnings=0 clean, suppression counts unchanged; tsc = 2 known donor telemetry-dist noise lines only (real 0); prettier touched files clean and the full merge-ref tree gate ALL-MATCHED @617037b1c (base 54b3890).


Updated this round (CodeRabbit follow-up, head 28e969c)

  • Non-activating profile saves no longer force-rebuild the API handler of a view whose active task follows a different sticky profile: both rebuild sites (the acting view's pinned branch and the pinned-sibling refresh) are guarded by taskApiConfigName === saved profile; pinned-view overlays still refresh. Regression tests cover both sites (negative control: removing either guard reddens exactly its test).
  • Test hygiene: prune assertions compare full kept entries; the webview state-payload test renamed to describe what it asserts.
  • Verified: ClineProvider.spec 323 green, sticky-mode 33 green, eslint --max-warnings=0 clean, tsc real=0, prettier clean.

Updated this round (CodeRabbit follow-up 2, head 9afc9d8)

  • Deleted-profile re-pin: the forced task-handler rebuild and the sticky-name rewrite (post-loop task pass in this unit's compensated re-pin) now require taskApiConfigName === deleted profile (the view-buffer re-pin stays unconditional), so a pinned view whose task follows another sticky profile keeps its conversation's settings and persisted profile name. Regression test included (negative control: removing the guard reddens exactly that test).
  • Verified: ClineProvider.spec 324 green, sticky-mode 33 green, eslint --max-warnings=0 clean, tsc real=0, prettier clean.

Stryker suppression comments removed

Per the AGENTS.md policy (never add Stryker directives; remove them when a file is touched), all // Stryker disable directives were dropped from this PR. Equivalence rationale for the removed suppressions:

  • Stryker disable next-line ConditionalExpression: defensive clobber guard, unreachable per the ordering argument above.
  • Stryker disable next-line StringLiteral: setPanel branches only on type === "sidebar", so any other literal routes to the identical tab-ref assignment
  • Stryker disable next-line StringLiteral: setPanel only distinguishes "sidebar"; any other value routes to the tab-ref assignment
  • Stryker disable next-line ConditionalExpression,BlockStatement: hostile non-stabilizing encodings are unreachable from the webview (its posts are plain link targets); the bound is defensive
  • Stryker disable next-line CallExpression: hostile non-stabilizing encodings are pinned by the direct decodeUntrustedPathToStable bound test; the webview never posts such values
  • Stryker disable next-line ConditionalExpression,OptionalChaining: equivalent mutant - when localStorage is unavailable the guard-false path and the throwing body both return this.fallbackState from this catch
  • Stryker disable next-line ConditionalExpression,OptionalChaining: equivalent mutant - when localStorage is unavailable the guard-false path and the throwing body both mark the write failed and return newState

CR round 2026-10-15

  • resetState() now broadcasts across live providers (broadcastResetToAllInstances, the same slice this series ships in the cross-instance-reset units): the shared durable viewStates slot is cleared once through the persisted write queue, every live view's in-memory buffer (which can hold a deleted profile's settings, API keys included) is dropped, and each sibling view is reposted. Regression test added; dropping the broadcast reddens exactly that test.
  • Corrected the stale "per instance" queue comments (compensation path and its test): the queue is static and serializes provider-profile mutations across views; the remaining hazard is the queue-bypassing profile-list writes (saveApiConfiguration/renameApiConfiguration/getListApiConfiguration handlers, launch-time listApiConfigMeta sync).

Row-9 update (head 0dae49a)

  • Deletion re-points closed views: deleteProviderProfile now re-points persisted pins of disposed views onto the surviving profile, records the write in the landed-flags set, and rolls the exact pre-deletion map back through the serialized queue on failure (CR Persistence Integrity).
  • Activation writes from the stored record (read-back feeds every post-save consumer; CR Security Boundaries).
  • Clear/re-point cache rollback on durable write failure (CR Persistence Integrity).

Verification: new tests are focused negative controls (reverting each guard reddens exactly the matching test); ClineProvider.spec, webviewMessageHandler.spec spot-checks, api specs, spec-inclusive tsc --noEmit, eslint --max-warnings=0 (suppression counts unchanged) and prettier all green on this head.

Upstream refresh (head 0dae49a)

Merged the current upstream/main (merge commit; the row-9 fix commit is unchanged and is the first parent) to clear the review gate's mergeability hold. Upstream refactored upsertProviderProfile into a new persistProviderProfile method and added a runToCompletion queue option; this unit's transactional body was ported into the new method unchanged and upstream's Promise.allSettled activation fix was adopted in it. One deliberate adaptation: upstream opts upsertProviderProfile into runToCompletion; this unit does not, because its contract is the landed-write compensation - the mutation timeout must abort the run so the compensation rolls the record and the stores back, which is what the cancellation tests pin. ClineProvider.spec, webviewMessageHandler.spec, tsc --noEmit, eslint (suppression counts unchanged) and prettier re-verified green at this head. The first refreshed head's windows unit-test lane caught that upstream's new updateProfileModel tests in ClineProvider.apiHandlerRebuild.spec.ts mock the settings manager with a static getProfile, which starves the post-save read-back; the mock now repoints getProfile at what saveConfig wrote (the real manager's behavior), and the file's 38 tests pass locally alongside the rest of the verification set. Three of upstream's new tests are adapted to this unit's abort-and-compensate upsert semantics (documented in comments): the timed-out upsert cancels and rolls back instead of running to completion, and the restore-path tests account for the compensation's record rollback and the serialized write order.

Round 2 (head 4d002c4, then merged to 1c1ac88) — CodeRabbit 00:44:15Z coverage rows

Two Trivial threads from the 00:44:15Z review on c2206c5a3, both answered test-only, written test-first and measured against the pre-change implementation before any assertion was kept:

  • src/core/config/__tests__/ProviderSettingsManager.spec.ts: storage-read-failure tests added in the DeleteConfig block (line 986) and the LoadConfig block for getProfile (line 1139), in the shape the review specified. Both measure green against c2206c5a3: deleteConfig rethrows a storage outage as Failed to delete config: …, getProfile as Failed to get profile: …, and load() as Failed to read provider profiles from secrets: …, so nothing is laundered into ProviderSettingsNotFoundError today, and deleteProviderProfile's not-found-only swallow (src/core/webview/ClineProvider.ts:3608-3617) cannot mistake an outage for a missing profile and prune a list entry whose record is still stored. Controls, one implementation edit each: typing the outage as not-found in deleteConfig → 1 failed | 64 passed (the DeleteConfig row); the same in getProfile → 1 failed | 64 passed (the LoadConfig row); production restored byte-identical (ProviderSettingsManager.ts sha256 prefix c558dde7f04939ee).
  • src/core/webview/__tests__/ClineProvider.sticky-profile.spec.ts: new test after the mid-deletion case — leaves a sibling view's shared settings on the survivor it activated mid-deletion. A second view, sharing the acting view's ContextProxy the way production builds the tab view (activate/registerCommands.ts:449; documented at src/core/webview/ClineProvider.ts:3634-3636), activates other-survivor inside the intercepted manager.deleteConfig; after the deletion both views' getProviderSettings().openRouterModelId must read openai/gpt-4o. This also measures green against c2206c5a3: the shared settings are not stale at that interception point today. Controls: dropping the activation's write of the survivor's settings (src/core/webview/ClineProvider.ts:4100) → 1 failed | 25 passed; making the deletion push its own entry-time survivor's settings over the shared store even though nothing re-points → 1 failed | 25 passed; restored byte-identical (ClineProvider.ts sha256 prefix cb8f121752f6ce5f).

Assertion shapes are stated in the threads as the repo standard for both classes — storage-failure assertions (mockRejectedValue(new Error("Storage failed")) → catch → not.toBeInstanceOf(ProviderSettingsNotFoundError) → toMatchObject({ message: expect.stringContaining("<method prefix>:") }), plus expect(mockSecrets.store).not.toHaveBeenCalled() on write paths) and cross-view assertions made against a shared ContextProxy — so #1550 and #1919 converge instead of drifting.

Verification at this head: junction pre-flight first (every src/node_modules/@roo-code/* link in this worktree pointed into split-1833/u7 and was repointed to this worktree's own packages/*), tsc --noEmit 0 errors, eslint --prune-suppressions --max-warnings=0 --no-warn-ignored exit 0 on every touched file with counts unchanged (ClineProvider.sticky-profile.spec.ts 15 → 15, ProviderSettingsManager.spec.ts no entries), prettier --check clean, ProviderSettingsManager.spec.ts 65 passed, ClineProvider.sticky-profile.spec.ts 26 passed, and neighbours ClineProvider.spec.ts 475, webviewMessageHandler.spec.ts 151, ClineProvider.apiHandlerRebuild.spec.ts 39, ClineProvider.lockApiConfig.spec.ts 2, ClineProvider.flicker-free-cancel.spec.ts 13.

Upstream merge (head 1c1ac88, parents 4d002c4 + e943530)

git merge upstream/main (e943530 — #2223 time/date-format settings on top of #2294 and #1207) conflicted in three files; each is resolved toward main's content with our behaviour kept beside it:

  • src/core/config/ContextProxy.ts: main's updateGlobalState owns the rejected-write contract now (per-key write owner, cache corrected by reading the Memento back), so our per-key generation/confirmed-value stateWrites map is removed rather than run in parallel with it. ContextProxy.spec's rejection test gained the Memento content its fixture was missing (mockGlobalState.get now models what storage holds), because the correction reads from the Memento and not from our cache; the assertion itself is unchanged and still reddens (4 failed | 62 passed) when the read-back line is removed.
  • src/core/webview/ClineProvider.ts: kept our per-view layer and the shared-write compensation in setValues, folded main's withoutInvalidDisplaySettings gate in ahead of our mode gate (different key classes, both keep their logs), and took main's three new fields (timeFormat, dateFormat, showRelativeTimes) into getStateToPostToWebview read from mergedStateValues rather than stateValues, so the per-view overlay still applies to them.
  • src/core/webview/webviewMessageHandler.ts: main's isInvalidDisplayValue guard first, then our provider-profile and host-owned boundary guards; all three log and drop the key, and none reorders the normalisation below them.

Suppression effect of the merge: two counts decreased (api/providers/__tests__/lm-studio-timeout.spec.ts 3 → 0, api/providers/qwen-code.ts 1 → 0), none increased. Post-merge verification at 1c1ac88: tsc --noEmit 0 errors; eslint exit 0 on all eight touched files; prettier reports every touched file unchanged; ContextProxy.spec.ts 66, ProviderSettingsManager.spec.ts 65, ClineProvider.sticky-profile.spec.ts 26, webviewMessageHandler.spec.ts 185, ClineProvider.apiHandlerRebuild.spec.ts 39, ClineProvider.lockApiConfig.spec.ts 2, ClineProvider.flicker-free-cancel.spec.ts 13, extension/__tests__/api-configuration.spec.ts 9, and the webview-ui settings/timestamp lane (LanguageSettings.timeFormat, SettingsView, SettingsView.change-detection, ChatRow.timestamp, MessageTimestamp) 133 passed.


Round 6 (gate-threads)

Two things landed here since 0579f8d04.

2b7a41d58 — the shared store stays paired with the selection when a deletion races a sibling write. This started as a measurement, not a guess: deleteProviderProfile decides what the shared provider-settings store owes the selection once the record is gone, but every guard in that decision keys off something re-pointing at the survivor. Every view in the host shares one ContextProxy (ContextProxy.getInstance, passed to the sidebar at extension.ts:241 and to a tab provider at registerCommands.ts:437/453), so a sibling can move the shared selection onto a survivor and carry the name alone; when that write lands after the deletion re-reads the selection, no live pin, no persisted pin and not the acting view's own pin name the deleted profile, so all the guards stay closed and the store goes on carrying the deleted profile's settings under the survivor's name - which is what every view without an overlay of its own serves. The repair works from the invariant: when the selection names a surviving profile, this deletion wrote no shared settings, and the store still equals the deleted profile's stored record, read the selected profile's settings, pin into their overlays any view that would otherwise inherit them, and replace the store. A sibling write that did carry settings has already repaired the pairing and the record comparison leaves it alone. Regression test plus controls: without the production hunks the file reports 1 failed | 498 passed (499), the failure showing apiKey: "doomed-key" under keeper-profile; with them, 499 passed. Full suite after the change: 46 failed | 12779 passed | 37 skipped (12862) against a pre-change baseline run of 47 failed | 12777 passed (12861) - one test added, no new failure (the difference in failures is a flaking Task.spec.ts case that passed this time). No test on either branch had ever exercised this interleaving: the four deletion tests that write the selection inside an async callback are all single-provider, and the only mid-deletion second operation writes the selection through the same provider's queue, so it settles after the deletion.

Thread state. Rows DOSK-bwM6z6OCB, OCN, OCP, OCS, OCb and Vop are answered with the commit that landed each fix on this branch and the control numbers from that landing, and resolved. Row OCX (the postStateToWebview inside the compensated write group) is answered and left open: the non-fatal post helper it describes has never existed on either branch (git log -S finds no commit carrying that string), so it has to be written, and which branch carries it is the lead's call. The new row 4477073508 on src/activate/registerCommands.ts (track every live tab panel; select a survivor when the tracked one closes) was verified against 2b7a41d58 and is valid - onDidChangeViewState at 492-508 already assumes several tab panels stay live while onDidDispose at 511-520 only clears the reference - answered and left open pending its own commit on this branch.


Round 6 addendum (gate-threads)

Row 4477073508 is no longer open. It landed on this branch as bc729fcc9, its own commit: the successor for the tab ref is now chosen deliberately from the live tab-mode provider instances (preference: active, then visible, then any live panel), the onDidDispose guard reads "no live panel is tracked, or the tracked one is this panel" because the provider's own view-dispose handler clears the ref first, and the last-live-panel case is pinned as its own test so the ref stays clear there rather than pointing at the panel that was just disposed. Controls and the tier measurements are on the thread; the row is resolved.

That moved the parent head, so vps2-f2c's merge of this branch was discarded and rebuilt from bc729fcc9 rather than amended: new merge commit e8b2ac051 (parents a691f24c9, bc729fcc9). Full suite on this branch after bc729fcc9: 46 failed | 12785 passed | 37 skipped (12868) - six tests added, same 46 pre-existing environmental failures. Task.spec.ts flakes between runs of the same tree, so a delta in that file either way is not a repair.

Round 7 addendum (head 4719931)

This head folds the four open review rows on this branch into one commit:

  • postStateToWebview moved out of the compensated group in deleteProviderProfileUnlocked (log-only failure), so a state-refresh rejection after the deletion committed no longer resurrects the profile record while the sibling re-pins stay on the replacement. Two rollback cases were retargeted onto a failure point inside the group (the re-pinned sibling's own post) so they measure the rollback rather than the position of the refresh; the new case pins that a failed post leaves the deletion committed and logs it. Control: with the post still inside the group, 1 failed / 499 passed - only the new case.
  • disposeFailedTabCreation now hands the tracked tab ref to pickTabPanelSurvivor() instead of clearing it, so a creation failure no longer strands live tab panels; same selector and same pool as the disposal path. Control: reverting that hunk reddens only the new failed-creation case, 1 failed / 69 passed.
  • Two afterEach hooks reset ClineProvider.getInstanceForView / getAllInstances, because vi.clearAllMocks keeps implementations and survivor fixtures were leaking registry state into later tests.
  • The sticky-profile case that deletes a child profile now disposes its sibling provider in a finally, so it stops leaving a live instance in the static registry.

Gates on this head: tsc clean, eslint clean with src/eslint-suppressions.json unchanged, prettier --check clean, hooks (lint-staged, pre-push check-types) ran on both pushes. Focused: registerCommands.spec.ts 78, ClineProvider.spec.ts 500, ClineProvider.sticky-profile.spec.ts 26. Full suite 45 failed | 12816 passed | 37 skipped - 40 __tests__/dist_assets.spec.ts (no built dist) + 5 services/rules/__tests__/rules.spec.ts (Windows symlinks), same environmental classes as the base; src/core/task/Task.spec.ts is a known inter-run flake and did not fail in this run.

Related issues

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.

2 participants