From ba91206c8e277aef1b5e59b6ca5982a64750b710 Mon Sep 17 00:00:00 2001 From: Yassin AJDI <103142364+ajdiyassin@users.noreply.github.com> Date: Mon, 27 Jul 2026 04:13:37 +0100 Subject: [PATCH] fix(ai): finalize all prepared statements in SqliteAuthCredentialStore.close() `close()` finalized 26 of the 34 cached prepared statements, leaving eight alive: `updateIfMatches`, `updateIfMatchesWithLease`, `deleteIfMatchesWithLease`, `deleteCachePrefix`, and the four credential-refresh-lease statements. Unfinalized statements keep the SQLite connection open, so `this.#db.close()` did not release the underlying file handles. On Windows the auth DB plus its `-wal`/`-shm` sidecars stayed locked after `close()`, so `removeWithRetries()` exhausted its 2s budget and test cleanup failed with EBUSY. On POSIX the handle leaked silently because open files can be unlinked. This completes the same class of fix as 14252e71c, which covered the one-off inline `this.#db.prepare()` sites but not these cached fields. Co-Authored-By: Claude --- packages/ai/CHANGELOG.md | 4 ++++ packages/ai/src/auth-storage.ts | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/ai/CHANGELOG.md b/packages/ai/CHANGELOG.md index c1b645e18..641341a67 100644 --- a/packages/ai/CHANGELOG.md +++ b/packages/ai/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Fixed `SqliteAuthCredentialStore.close()` leaking eight prepared statements (`updateIfMatches`, `updateIfMatchesWithLease`, `deleteIfMatchesWithLease`, `deleteCachePrefix`, and the four credential-refresh-lease statements), which kept the SQLite connection alive after `close()`. On Windows the auth DB and its `-wal`/`-shm` files stayed locked, so temp-dir cleanup intermittently failed with `EBUSY`; on POSIX the handle leaked silently. + ## [17.1.6] - 2026-07-27 ### Added diff --git a/packages/ai/src/auth-storage.ts b/packages/ai/src/auth-storage.ts index 51b9f25ac..ba7e2ffa6 100644 --- a/packages/ai/src/auth-storage.ts +++ b/packages/ai/src/auth-storage.ts @@ -7923,6 +7923,14 @@ export class SqliteAuthCredentialStore implements AuthCredentialStore { this.#updateUsageHistoryStmt.finalize(); this.#insertUsageCostStmt.finalize(); this.#listUsageCostsStmt.finalize(); + this.#updateIfMatchesStmt.finalize(); + this.#updateIfMatchesWithLeaseStmt.finalize(); + this.#deleteIfMatchesWithLeaseStmt.finalize(); + this.#deleteCachePrefixStmt.finalize(); + this.#acquireCredentialRefreshLeaseStmt.finalize(); + this.#getCredentialRefreshLeaseStmt.finalize(); + this.#renewCredentialRefreshLeaseStmt.finalize(); + this.#releaseCredentialRefreshLeaseStmt.finalize(); this.#db.close(); } }