Merge pull request #2209 from cfis/fix/host-sweep-test-uses-in-memory-db

fix(host-sweep): orphan-claim delete missed in tests (regression from #2183)
This commit is contained in:
gavrielc
2026-05-05 15:57:31 +03:00
committed by GitHub

View File

@@ -256,7 +256,7 @@ export function _resetStuckProcessingRowsForTesting(
session: Session, session: Session,
reason: string, reason: string,
): void { ): void {
resetStuckProcessingRows(inDb, outDb, session, reason); resetStuckProcessingRows(inDb, outDb, session, reason, outDb);
} }
function resetStuckProcessingRows( function resetStuckProcessingRows(
@@ -264,6 +264,7 @@ function resetStuckProcessingRows(
outDb: Database.Database, outDb: Database.Database,
session: Session, session: Session,
reason: string, reason: string,
writableOutDb?: Database.Database,
): void { ): void {
const claims = getProcessingClaims(outDb); const claims = getProcessingClaims(outDb);
const now = Date.now(); const now = Date.now();
@@ -300,19 +301,17 @@ function resetStuckProcessingRows(
// would re-read them, see the old status_changed timestamp, conclude the // would re-read them, see the old status_changed timestamp, conclude the
// freshly respawned container is stuck, and SIGKILL it before its // freshly respawned container is stuck, and SIGKILL it before its
// agent-runner has a chance to run clearStaleProcessingAcks() on startup. // agent-runner has a chance to run clearStaleProcessingAcks() on startup.
// We're safe to write outbound.db here because we just killed the container const ownsDb = !writableOutDb;
// that owned it (or it crashed and left no writer behind). let useDb: Database.Database | null = writableOutDb ?? null;
// outDb was opened readonly for reads above; reopen with write access for this delete.
let outDbRw: Database.Database | null = null;
try { try {
outDbRw = openOutboundDbRw(session.agent_group_id, session.id); if (!useDb) useDb = openOutboundDbRw(session.agent_group_id, session.id);
const cleared = deleteOrphanProcessingClaims(outDbRw); const cleared = deleteOrphanProcessingClaims(useDb);
if (cleared > 0) { if (cleared > 0) {
log.info('Cleared orphan processing claims', { sessionId: session.id, cleared, reason }); log.info('Cleared orphan processing claims', { sessionId: session.id, cleared, reason });
} }
} catch (err) { } catch (err) {
log.warn('Failed to clear orphan processing claims', { sessionId: session.id, err }); log.warn('Failed to clear orphan processing claims', { sessionId: session.id, err });
} finally { } finally {
outDbRw?.close(); if (ownsDb) useDb?.close();
} }
} }