fix(sqlite): retain completed evidence through reply finalization

This commit is contained in:
morluto committed 2026-10-26 17:56:47 +08:00
1 parent f2b4468183
commit e596a48251
3 files changed
+287 -54

No files matched your search

+21 -9
View File
@@ -48,6 +48,7 @@ import { SQLITE_DATABASE_LIMITS } from "./SqliteDatabaseLimits.js";
import {
executeSqliteDatabaseWorker,
sqliteReplyFinalizationFailure,
type SqliteWorkerLauncher,
} from "./SqliteDatabaseWorkerExecution.js";
@@ -283,7 +284,7 @@ export class SqliteDatabaseProvider implements SqliteDatabasePort {
options?.signal,
);
phase = "worker";
const inspection = await executeSqliteDatabaseWorker({
const completed = await executeSqliteDatabaseWorker({
input,
root: root.path,
snapshotPath: snapshot.snapshotPath,
@@ -303,18 +304,29 @@ export class SqliteDatabaseProvider implements SqliteDatabasePort {
const validated = sqliteDatabaseSchema.safeParse({
artifact: snapshot.artifact,
wal: snapshot.wal,
...inspection,
...completed.inspection,
worker_timeout_ms: workerTimeoutMs,
});
if (!validated.success)
throw new AnalysisOutputError(
operation,
"SQLite worker report dimensions or identity fields are invalid",
retainedOutput === undefined
? undefined
: { capturedOutput: retainedOutput },
throw sqliteReplyFinalizationFailure(
new AnalysisOutputError(
operation,
"SQLite worker report dimensions or identity fields are invalid",
retainedOutput === undefined
? undefined
: { capturedOutput: retainedOutput },
),
completed.finalization,
);
result = ok(createSqliteObservation(validated.data, input.path));
const execution = createSqliteObservation(validated.data, input.path);
result =
completed.finalization === undefined
? ok(execution)
: err(
completed.finalization.retainPartialObservation(
completedSqliteEvidence(input, execution),
),
);
} catch (cause: unknown) {
// A failure rethrown after retainCleanup carries no owner of its own;
// keep the retained worker instead of discarding it.