Repository navigation
Commit 492cfb3
committed
fix(config): refuse secret writes during a reset and clear the guard when it fails
This branch had no write guard at all. There was no reset flag, storeSecret() had nothing telling it a
reset was in progress, and resetAllState() cleared the two caches, advanced the state-write generations,
deleted every global-state and secret key in a single Promise.all and reinitialized - with the success
path as the only path. So a save issued while a reset was still inside its deletes could land after the
deletes and put back a value the user had just erased. This commit introduces that guard; it is not
repairing an existing one, and a reviewer reading this PR should read the refusal as new behaviour rather
than as a bug fix to code that already refused writes.
What lands: a resetting field, a rejection at the top of storeSecret() (SettingsWriteError with the key in
failed, so a caller can tell a refused save from a committed one), resetting raised as the first statement
of resetAllState() and lowered in a finally wrapping the whole body. The body itself is unchanged: this
lineage has no pending-write barrier and no write-owner clears, and importing #2235's would have imported
a different unit's design rather than answering this unit's defect.
Two cases, because the guard has two halves and the refusal is the new observable on this branch, so it is
tested on its own rather than as a phase of the leak case:
- refuses a secret write issued while a reset is still inside its delete pass
- accepts a secret write again after a reset whose delete pass rejected
Assertions read captured call arguments (mockSecrets.store.mock.calls filtered on the key) and the cache
and storage read-backs, not toHaveBeenCalledWith: that matcher compares the way toEqual does and drops
undefined-valued keys, so a loose matcher would pass on a tree where nothing is refused at all.
Controls, measured in four steps rather than described. Baseline at 509f92c: Test Files 10 passed (10),
Tests 318 passed (318). Refusal case alone with production untouched: 1 failed | 318 passed (319),
AssertionError: expected undefined to be an instance of SettingsWriteError - with no refusal the mid-reset
save simply succeeds. Guard and refusal with the flag lowered only on the success path: 10 passed (10),
319 passed (319), which is the shape this branch would have had if the flag were added without a finally.
Leak case then added against exactly that shape - the negative control for the finally - fails 1 of 320
with the production consequence in the message: promise rejected "SettingsWriteError: Could not store
apiKey: secret writes are refused while state is being reset" instead of resolving. With the try/finally:
Test Files 10 passed (10), Tests 320 passed (320), identical before and after prettier.
gates: tsc -p . --noEmit exit 0, eslint --max-warnings=0 --no-warn-ignored on both files exit 0, and the
recorded suppression counts for the two touched files are unchanged at 1 and 5 across a
--prune-suppressions run; prettier --check exit 0 on the working copies and exit 0 on the HEAD copies fed
through the same invocation, so a format failure here would be this commit's. src/eslint-suppressions.json
untouched.
Size posture, with the pair printed rather than recalled. scripts/stryker-diff.mjs ci --base
e943530 (main's tip, this PR's recorded base) --head
509f92c (this commit's parent) reports the extension bucket at 500
changed executable lines - exactly at MAX_CHANGED_LINES 500, with nothing to spare before this commit.
The same command on the head being pushed here reports 518, so this commit is what starts the gate
failing on #2236 rather than a commit continuing a failure the branch already had. The diff is 28 added /
14 deleted in src/core/config/ContextProxy.ts plus 69 lines in its spec, and the spec half is excluded
from the bucket by the /__tests__/ segment at scripts/stryker-diff.mjs:85. Neither run could start Stryker
locally (spawnSync node_modules\.bin\stryker ENOENT for both packages), so no mutants were scored here and
only the size line is a real measurement; it belongs in the PR body or the maintainers' queue rather than
being argued in a commit on a branch declared final.
This is not an answer to a review row on this PR: the one live row here (ClineProvider.ts:5024, root
comment 4477459238) is a custom-modes write-path question and is being read against this head separately.
It ports the answer measured on vps2/n2-viewstates-durability for the same defect in this file so that the
three sibling units do not ship three different answers to one bug.1 parent 509f92c commit 492cfb3
2 files changed
Lines changed: 97 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
89 | 92 | | |
90 | 93 | | |
91 | 94 | | |
| |||
486 | 489 | | |
487 | 490 | | |
488 | 491 | | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
489 | 499 | | |
490 | 500 | | |
491 | 501 | | |
| |||
759 | 769 | | |
760 | 770 | | |
761 | 771 | | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
766 | | - | |
767 | | - | |
768 | | - | |
769 | | - | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
770 | 781 | | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
776 | 787 | | |
777 | | - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
778 | 792 | | |
779 | 793 | | |
780 | 794 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
165 | 234 | | |
166 | 235 | | |
167 | 236 | | |
| |||
0 commit comments