Skip to content

Commit 214e47e

Browse files
anandgupta42claude
andcommitted
fix(analyst): sql_check rethrows probe timeouts that lost local session state
- The `predicate_effect` probe converted every `QueryTimeoutError` into `skipped: "timeout"`, including SQLite/DuckDB timeouts whose helper restart discarded temporary tables, settings, open transactions and `:memory:` databases. A timeout carrying `stateLost: true` is now rethrown so the caller receives the state-loss disclosure; timeouts without it still skip. The catalog-estimate path reaches the same catch, so both probes are covered. - tests: catalog-estimate and predicate-query timeouts with and without `stateLost`, on SQLite and DuckDB. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent fa0f628 commit 214e47e

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/tools/sql-check.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export async function checkSql(input: SqlCheckPublicInput) {
409409
"A predicate that returns NULL counts as not kept.",
410410
])
411411
} catch (error) {
412-
if (!isQueryTimeoutError(error)) throw error
412+
if (!isQueryTimeoutError(error) || (error as { stateLost?: boolean }).stateLost === true) throw error
413413
return result(args.check, { skipped: "timeout" }, [
414414
"predicate_effect: skipped: timeout; use a narrower base_sql.",
415415
])

‎packages/opencode/test/altimate/tools/sql-check.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,47 @@ for (const warehouse of ["sqlite_fixture", "scratch"] as const) {
592592
expect((await checkSql({ warehouse, check: "grain", sql: leftSql, columns: ["id"] })).metadata.total_rows).toBe(5)
593593
})
594594

595+
for (const [probe, baseSql, query] of [
596+
["catalog estimate", "orders", /pragma_table_list|duckdb_tables/],
597+
["predicate query", leftSql, /SELECT COUNT\(\*\) AS total/],
598+
] as const) {
599+
for (const stateLost of [true, undefined]) {
600+
test(`predicate_effect ${stateLost ? "rethrows" : "skips"} ${probe} timeouts ${stateLost ? "with" : "without"} state loss`, async () => {
601+
const connector = await Registry.get(warehouse)
602+
const error = Object.assign(new Error("query deadline exceeded"), {
603+
name: "QueryTimeoutError",
604+
code: "QUERY_TIMEOUT",
605+
engine: warehouse === "scratch" ? "duckdb" : "sqlite",
606+
timeoutMs: 4321,
607+
cancelled: true,
608+
...(stateLost ? { stateLost: true } : {}),
609+
})
610+
const execute = spyOn(connector, "execute").mockRejectedValue(error)
611+
try {
612+
const pending = checkSql({
613+
warehouse,
614+
check: "predicate_effect",
615+
base_sql: baseSql,
616+
predicates: ["amount > 0"],
617+
query_timeout_ms: 4321,
618+
})
619+
if (stateLost) {
620+
await expect(pending).rejects.toBe(error)
621+
await expect(pending).rejects.toMatchObject({ stateLost: true })
622+
} else {
623+
const result = await pending
624+
expect(result.metadata.skipped).toBe("timeout")
625+
expect(result.output).toContain("skipped: timeout")
626+
}
627+
expect(execute).toHaveBeenCalledTimes(1)
628+
expect(execute.mock.calls[0][0]).toMatch(query)
629+
} finally {
630+
execute.mockRestore()
631+
}
632+
})
633+
}
634+
}
635+
595636
test("forwards the query timeout and suppresses connector LIMIT injection", async () => {
596637
const connector = await Registry.get(warehouse)
597638
const execute = spyOn(connector, "execute")

0 commit comments

Comments
 (0)