Repository navigation
Commit 7cf1937
committed
fix(webview): discard a view-state load that a reset cleared underneath
resetState() bumps viewStatesResetGeneration and then clears every live instance's
viewLocalState. loadViewState() awaits the mode list and the profile lookup before it
applies what it read, and its only discard check compares viewStateId, which a reset
does not touch. A load that started before a reset therefore wrote its pre-reset mode,
profile name and apiConfiguration back into a buffer the reset had just emptied, and
getValues() served them afterwards.
The load now captures the generation the durable write queue already uses for the same
race and refuses the load if it changed while the lookups were in flight, leaving the
existing view-id check untouched. A load that begins after the bump captures the new
generation and is unaffected.
Test: it("discards a load that a reset cleared underneath it instead of applying
pre-reset selections"). Registering the stable id starts the load and the test holds it
inside providerSettingsManager.getProfile, then performs the two moves resetState()
itself performs on a live instance - bump the generation, clear viewLocalState - resolves
the lookup and awaits the load. It asserts on the buffer and on getValues(), not on call
counts. It uses its own view id and profile name because every case in this file shares
one mockContext and therefore one persisted viewStates slot: reusing another case's id
made that case fail on a claim token it no longer owned.
Measured with five runs of vitest run webview/__tests__/ClineProvider.spec.ts in this
worktree, and the lines below are from those runs, which are the same runs that produced
the numstat quoted at the end:
HEAD Test Files 1 passed (1) Tests 389 passed (389) (exit 0)
case, production at HEAD Test Files 1 failed (1) Tests 1 failed | 389 passed (390), AssertionError: expected { apiConfiguration: {} } to not have property "apiConfiguration"
case + generation check Test Files 1 passed (1) Tests 390 passed (390) (exit 0)
CONTROL check reverted, Test Files 1 failed (1) Tests 1 failed | 389 passed (390), AssertionError: expected { apiConfiguration: {} } to not have property "apiConfiguration"
case kept; the revert is git checkout -- of the one file, so
the case is what differs between the second and fourth lines.
final shapes after Test Files 1 passed (1) Tests 390 passed (390) (exit 0)
Not closed here, measured and reported: a load that begins after the bump but reads the
persisted map before resetAllState() wipes it still applies what it read, because it
captured the post-bump generation. Closing that needs cancelling loads at clear time
rather than a token captured at load start, which this change does not attempt.
Scope: the fix adds one discard and one log line. It introduces no new error, refusal,
option or setting, so there is no new observable beyond the discard the case asserts.
Gates: tsc --noEmit -p . exit 0. eslint --max-warnings=0 exit 0 on both files.
eslint --prune-suppressions leaves ClineProvider.ts {"@typescript-eslint/no-explicit-any":{"count":7}} | spec {"@typescript-eslint/no-explicit-any":{"count":195}} exactly as recorded and the
suppressions file is not in this commit. prettier --check exits 0 on the copies
committed here and 0/0 (file/spec) on the HEAD copies fed through the same
invocation, so neither file changes format. 11 added / 0 deleted in ClineProvider.ts and 37 added /
0 deleted in the spec, from the git diff --numstat that fed this message.1 parent d746c4a commit 7cf1937
2 files changed
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1007 | 1007 | | |
1008 | 1008 | | |
1009 | 1009 | | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
1010 | 1013 | | |
1011 | 1014 | | |
1012 | 1015 | | |
| |||
1046 | 1049 | | |
1047 | 1050 | | |
1048 | 1051 | | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
1049 | 1060 | | |
1050 | 1061 | | |
1051 | 1062 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6743 | 6743 | | |
6744 | 6744 | | |
6745 | 6745 | | |
| 6746 | + | |
| 6747 | + | |
| 6748 | + | |
| 6749 | + | |
| 6750 | + | |
| 6751 | + | |
| 6752 | + | |
| 6753 | + | |
| 6754 | + | |
| 6755 | + | |
| 6756 | + | |
| 6757 | + | |
| 6758 | + | |
| 6759 | + | |
| 6760 | + | |
| 6761 | + | |
| 6762 | + | |
| 6763 | + | |
| 6764 | + | |
| 6765 | + | |
| 6766 | + | |
| 6767 | + | |
| 6768 | + | |
| 6769 | + | |
| 6770 | + | |
| 6771 | + | |
| 6772 | + | |
| 6773 | + | |
| 6774 | + | |
| 6775 | + | |
| 6776 | + | |
| 6777 | + | |
| 6778 | + | |
| 6779 | + | |
| 6780 | + | |
| 6781 | + | |
| 6782 | + | |
6746 | 6783 | | |
6747 | 6784 | | |
6748 | 6785 | | |
| |||
0 commit comments