Reorganize worker observability layer into worker/observability/ (M8 part 3/3)

Collects the five post-run diagnostic + escalation modules into src/main/worker/observability/: run_events persistence, stdout/stderr noise filter, credential-shape log redactor, self-wake circuit breaker, and retry-aware failure escalation pipeline. circuit-breaker.ts and failure-escalation.ts remain as standalone files inside the directory — each owns a distinct state machine that deserves its own boundary — rather than collapsing into a single index.ts. handlers/*.ts and tests/unit/*.test.ts updated to point at the new paths.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-20 11:41:07 -04:00
1 parent da3543fcd9
commit 2c6dd8ed08
11 files changed
+10 -10

No files matched your search

@@ -0,0 +1,33 @@
import type { AppDatabase } from "../../database";
interface PersistInput {
companyId: string;
runId: string;
agentId: string;
eventType: string;
stream?: "stdout" | "stderr" | null;
level?: string | null;
message?: string | null;
payload?: Record<string, unknown> | null;
}
/**
* Best-effort `run_events` row writer used by the worker message handler.
* Failures are logged and swallowed because the run lifecycle must not be
* gated on audit-log writes.
*/
export function persistRunEvent(
db: AppDatabase,
logger: { warn: (...args: unknown[]) => void },
input: PersistInput,
) {
try {
db.appendRunEvent(input);
} catch (error) {
logger.warn(
`[run-events] Failed to append ${input.eventType} for ${input.runId}: ${
error instanceof Error ? error.message : String(error)
}`,
);
}
}