fix(db): delete legacy alias param-filter rows on a canonical reset

deleteParamFilterConfig("claude") bound the canonical id twice, so a
pre-#20295 row stored under the alias "cc" survived and loadAllConfigs()
mapped it back to "claude" after the reset. Delete every stored key that
resolves to the canonical provider, in one transaction, and cover the
legacy reset path with a regression test.
This commit is contained in:
Rafa Martins
2026-11-18 22:11:00 -03:00
committed by diegosouzapw
parent ca5f9ddef4
commit 7748a95d46
2 changed files with 33 additions and 3 deletions

View File

@@ -178,16 +178,26 @@ export function setParamFilterConfig(provider: string, config: ProviderParamFilt
/**
* Delete the param filter config for a provider.
* Resets to no filtering for that provider. Cleans up both canonical and alias keys (#20295).
* Resets to no filtering for that provider. Cleans up the canonical key and every stored
* alias key that resolves to it (#20295).
*/
export function deleteParamFilterConfig(provider: string): void {
const normalizedKey = toNormalizedString(provider);
if (!normalizedKey) return;
const canonical = resolveProviderId(normalizedKey);
// Legacy rows may sit under an alias key (e.g. "cc"): drop every stored key that
// resolves to the same provider, or loadAllConfigs() would map it back after a reset.
const keys = new Set([canonical, normalizedKey]);
for (const key of Object.keys(readNamespace(NAMESPACE))) {
if (resolveProviderId(key) === canonical) keys.add(key);
}
const db = getDbInstance();
const stmt = db.prepare("DELETE FROM key_value WHERE namespace = ? AND (key = ? OR key = ?)");
stmt.run(NAMESPACE, canonical, normalizedKey);
const stmt = db.prepare("DELETE FROM key_value WHERE namespace = ? AND key = ?");
db.transaction(() => {
for (const key of keys) stmt.run(NAMESPACE, key);
})();
bumpCacheGeneration();
}

View File

@@ -108,6 +108,26 @@ test("provider alias (e.g. 'cc') resolves to canonical provider ('claude') (#202
}
});
test("deleteParamFilterConfig via the canonical id removes a legacy alias row (#20295)", () => {
// Pre-#20295 databases stored filters under the alias key (e.g. "cc").
core
.getDbInstance()
.prepare("INSERT OR REPLACE INTO key_value (namespace, key, value) VALUES (?, ?, ?)")
.run(
"provider_param_filters",
"cc",
JSON.stringify({ block: ["top_p"], allow: [], autoLearn: false })
);
// Any write invalidates the in-memory cache so the seeded row is read back.
deleteParamFilterConfig("cache-bump-20295");
assert.deepEqual(getParamFilterConfig("claude")?.block, ["top_p"]);
deleteParamFilterConfig("claude");
assert.equal(getParamFilterConfig("claude"), null);
assert.equal(getParamFilterConfig("cc"), null);
});
test("deleteParamFilterConfig is a no-op for unconfigured provider", () => {
deleteParamFilterConfig("nothing-here");
});