mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
fix(zed): defer a locked threads.db instead of reading it as empty
Zed's whole history is one source, so a SQLITE_BUSY on open or on the threads query parsed as zero calls and replaced every cached Zed thread for the run. Busy errors now reach the parse loop, which keeps the cached rows and retries on the next refresh, like the other SQLite providers.
This commit is contained in:
parent
46a521cc56
commit
9e5f729d8b
2 changed files with 21 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ import { homedir } from 'os'
|
|||
import zlib from 'zlib'
|
||||
|
||||
import { calculateCost } from '../models.js'
|
||||
import { getSqliteLoadError, isSqliteAvailable, openDatabase, type SqliteDatabase } from '../sqlite.js'
|
||||
import { getSqliteLoadError, isSqliteAvailable, isSqliteBusyError, openDatabase, type SqliteDatabase } from '../sqlite.js'
|
||||
import type { ParsedProviderCall, ProbeRoot, Provider, SessionParser, SessionSource } from './types.js'
|
||||
|
||||
// Zed's built-in agent stores one row per thread in a single SQLite database;
|
||||
|
|
@ -102,7 +102,9 @@ function parseThreads(db: SqliteDatabase, seenKeys: Set<string>): ParsedProvider
|
|||
let rows: ThreadRow[]
|
||||
try {
|
||||
rows = db.query<ThreadRow>(THREADS_QUERY)
|
||||
} catch {
|
||||
} catch (err) {
|
||||
// The whole store is one source: a locked read must defer, not cache as empty.
|
||||
if (isSqliteBusyError(err)) throw err
|
||||
return calls
|
||||
}
|
||||
|
||||
|
|
@ -178,6 +180,7 @@ function createParser(source: SessionSource, seenKeys: Set<string>): SessionPars
|
|||
try {
|
||||
db = openDatabase(source.path)
|
||||
} catch (err) {
|
||||
if (isSqliteBusyError(err)) throw err
|
||||
process.stderr.write(`codeburn: cannot open Zed database: ${err instanceof Error ? err.message : err}\n`)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,6 +225,22 @@ describe.skipIf(skipReason !== null)('zed provider (#480)', () => {
|
|||
expect((await collectCalls(dbPath)).length).toBe(0)
|
||||
})
|
||||
|
||||
it('rethrows a locked database instead of parsing it as empty', async () => {
|
||||
const dbPath = buildDb(db => insertThread(db, {
|
||||
id: 't1',
|
||||
thread: { model: { model: 'claude-sonnet-4-6' }, request_token_usage: { r1: { input_tokens: 10, output_tokens: 5 } } },
|
||||
}))
|
||||
const { DatabaseSync: Database } = requireForTest('node:sqlite')
|
||||
const writer = new Database(dbPath)
|
||||
writer.exec('BEGIN EXCLUSIVE')
|
||||
try {
|
||||
await expect(collectCalls(dbPath)).rejects.toThrow(/locked|busy/i)
|
||||
} finally {
|
||||
writer.exec('ROLLBACK')
|
||||
writer.close()
|
||||
}
|
||||
})
|
||||
|
||||
it('discovers nothing when the database does not exist', async () => {
|
||||
const provider = createZedProvider(join(tmpDir, 'missing.db'))
|
||||
expect(await provider.discoverSessions()).toEqual([])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue