Skip to content

Commit 337d360

Browse files
Remove write-only rollback state from ContextProxy
Remove the write-only rollback state from ContextProxy. stateWriteTokens (1 repo-wide reference, the declaration), secretWriteTokens (1, declaration), durableState (3: declaration, one .set seed, one .clear), durableSecrets (5: declaration, three .set seeds, one .clear) and resetGeneration (3: declaration and two increments) had no reader anywhere: no .get, no generation comparison, and repo-wide counts across src, packages, webview-ui/src and apps equalled their in-file counts. The rollback that actually runs is stateWriteOwner plus secretWriteOwner plus the read-back, and those two maps are read - by ContextProxy.spec.ts - so they stay. Removed: the five declarations, four durable seeds, two generation increments, two clears, and the comment blocks that described only that machinery. ContextProxy.ts goes 842 lines -> 797 lines (-45). #1562 and #1565 already carry this same strip, so the two chains converge on one ContextProxy shape (799 lines on the #1562 side) rather than diverging further. No test was dropped or renamed: the twelve cases named in the review thread (spec lines 116, 219, 253, 271, 318, 331, 378, 453, 528, 562, 762, 1143) all pass unchanged, and none of their titles names a deleted field - each states the behaviour it proves ('restores the previous cached value when the durable write fails', 'does not reseed the durable record from a pre-reset write that completes after the reset', and so on), so there was nothing to rename without renaming away the assertion. Verification on this head: ContextProxy.ts 797 lines, 0 added / 45 deleted against e27b693; tsc src 0 errors, tsc webview-ui 0 errors; eslint --max-warnings=0 clean and src/eslint-suppressions.json unchanged; prettier --check clean. Vitest --no-file-parallelism: ContextProxy 87/87, api-configuration 16/16, registerCommands 66/66, webviewMessageHandler 178/178, ClineProvider 447/447 (794 tests, 0 failures). Removing write-only state is a subtraction of executable lines: 45 lines out of the extension-side scope, which moves the changed-executable-line gate down rather than up.
1 parent e27b693 commit 337d360

1 file changed

Lines changed: 0 additions & 45 deletions

File tree

‎src/core/config/ContextProxy.ts‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,6 @@ export class ContextProxy {
7878
private stateCache: GlobalState
7979
private secretCache: SecretState
8080

81-
// Per-key write tokens: a failed durable write rolls its cache value back only if it
82-
// is still the current write for that key. The rollback target is always the durable
83-
// record (see below), so the guard exists for one interleaving: a newer write that
84-
// has already moved the cache but whose success is not confirmed yet, whose failure
85-
// would otherwise be clobbered by the older write's rollback before the newer
86-
// write's success record lands.
87-
private stateWriteTokens = new Map<GlobalStateKey, symbol>()
88-
private secretWriteTokens = new Map<SecretStateKey, symbol>()
89-
90-
// Tracks the last value confirmed to be in durable storage per key (seeded by
91-
// initialize, refreshed by each confirmed write and refresh load, cleared by
92-
// resetAllState), so a failed write rolls the cache back to the durable value
93-
// instead of the cache value at call time — a superseded in-flight write may have
94-
// already overwritten that value, and restoring it would leave the cache ahead of
95-
// storage when the superseding write also fails.
96-
private durableState = new Map<GlobalStateKey, unknown>()
97-
private durableSecrets = new Map<SecretStateKey, unknown>()
98-
// Write-completion generation. A write issued before resetAllState (or
99-
// refreshSecrets) may still be in flight when that reset/refresh re-seeds the
100-
// durable records from storage: its value is then obsolete, and re-recording it
101-
// would leave a later failed write rolling the cache back to a value storage no
102-
// longer holds. Only completions from the current generation update the durable
103-
// maps; resetAllState and refreshSecrets both advance the generation.
104-
private resetGeneration = 0
10581
private _isInitialized = false
10682

10783
constructor(context: vscode.ExtensionContext) {
@@ -120,8 +96,6 @@ export class ContextProxy {
12096
try {
12197
// Revert to original assignment
12298
this.stateCache[key] = this.originalContext.globalState.get(key)
123-
// This load is a confirmed storage read: seed the rollback record.
124-
this.durableState.set(key, this.stateCache[key])
12599
} catch (error) {
126100
logger.error(`Error loading global ${key}: ${error instanceof Error ? error.message : String(error)}`)
127101
}
@@ -131,8 +105,6 @@ export class ContextProxy {
131105
...SECRET_STATE_KEYS.map(async (key) => {
132106
try {
133107
this.secretCache[key] = await this.originalContext.secrets.get(key)
134-
// This load is a confirmed storage read: seed the rollback record.
135-
this.durableSecrets.set(key, this.secretCache[key])
136108
} catch (error) {
137109
logger.error(
138110
`Error loading secret ${key}: ${error instanceof Error ? error.message : String(error)}`,
@@ -142,8 +114,6 @@ export class ContextProxy {
142114
...GLOBAL_SECRET_KEYS.map(async (key) => {
143115
try {
144116
this.secretCache[key] = await this.originalContext.secrets.get(key)
145-
// This load is a confirmed storage read: seed the rollback record.
146-
this.durableSecrets.set(key, this.secretCache[key])
147117
} catch (error) {
148118
logger.error(
149119
`Error loading global secret ${key}: ${error instanceof Error ? error.message : String(error)}`,
@@ -169,7 +139,6 @@ export class ContextProxy {
169139
if (this.secretCache[key] === undefined) {
170140
await this.originalContext.secrets.store(key, legacyValue)
171141
this.secretCache[key] = legacyValue
172-
this.durableSecrets.set(key, legacyValue)
173142
}
174143
// Erase the plaintext only after the secret write succeeded (or was
175144
// unnecessary): a failed store leaves the value for a retry instead of
@@ -566,10 +535,6 @@ export class ContextProxy {
566535
* This is useful when you need to ensure the cache has the latest values
567536
*/
568537
async refreshSecrets(): Promise<void> {
569-
// Invalidate writes issued before this refresh: once the re-seed below lands,
570-
// their completions hold obsolete values that must not re-record over the
571-
// freshly loaded durable records.
572-
this.resetGeneration += 1
573538
// The refresh re-syncs the whole secret cache from storage and re-seeds the
574539
// durable records with the loaded values, so a later rollback of a pending
575540
// pre-refresh write restores the freshly loaded value (the in-write token
@@ -792,22 +757,12 @@ export class ContextProxy {
792757
* @returns A promise that resolves when all reset operations are complete
793758
*/
794759
public async resetAllState() {
795-
// Invalidate writes issued before this reset: once the durable maps below
796-
// are cleared and re-seeded by the re-initialization, their completions hold
797-
// obsolete values that must not re-record over the re-seeded records.
798-
this.resetGeneration += 1
799760
// Clear in-memory caches. The write tokens are left in place: the durable
800761
// records below carry the rollback protection (see the in-write token guard,
801762
// which still covers the interleaving where a newer write has moved the cache
802763
// but its success is not confirmed yet).
803764
this.stateCache = {}
804765
this.secretCache = {}
805-
// The durable records are rebuilt by the initialize() at the end of this reset
806-
// (the storage delete above is awaited first), so they are cleared now: a write
807-
// failing while the re-initialization has not re-seeded them must roll back to
808-
// nothing, not to the pre-reset durable value storage no longer holds.
809-
this.durableState.clear()
810-
this.durableSecrets.clear()
811766

812767
await Promise.all([
813768
...GLOBAL_STATE_KEYS.map((key) => this.originalContext.globalState.update(key, undefined)),

0 commit comments

Comments
 (0)