fix(core): evict cached AgentStore Database on close

Companion to the per-rootDir Database cache: when an AgentStore is
closed, drop it from the cache so the next instantiation opens a
fresh connection instead of handing out the closed handle. Also
tolerate "database is not open" on close, since multiple AgentStore
instances now share one underlying Database.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-05-03 02:07:36 -07:00
parent 63e16143c4
commit 92513dfe0b

View File

@@ -2383,8 +2383,22 @@ export class AgentStore extends EventEmitter {
* Close the underlying SQLite connection and release resources.
*/
close(): void {
if (this._db) {
if (!this._db) {
return;
}
if (!this.inMemoryDb && agentStoreDbCache.get(this.rootDir) === this._db) {
agentStoreDbCache.delete(this.rootDir);
}
try {
this._db.close();
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
if (!message.includes("database is not open")) {
throw error;
}
} finally {
this._db = null;
}
}