From 2c6dd8ed086cd8d09c5a1a2e1b9bf56a612177bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E7=94=B5=E8=8A=BD=E8=A1=A3?= Date: Mon, 20 Apr 2026 11:41:07 -0400 Subject: [PATCH] Reorganize worker observability layer into worker/observability/ (M8 part 3/3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/main/worker/handlers/run-finished-helpers.ts | 6 +++--- src/main/worker/handlers/run-log-handler.ts | 4 ++-- src/main/worker/handlers/run-status-handler.ts | 2 +- src/main/worker/{ => observability}/circuit-breaker.ts | 0 src/main/worker/{ => observability}/failure-escalation.ts | 0 src/main/worker/{ => observability}/log-redactor.ts | 0 src/main/worker/{ => observability}/run-event-recorder.ts | 2 +- src/main/worker/{ => observability}/run-log-filter.ts | 0 tests/unit/failure-escalation.test.ts | 2 +- tests/unit/log-redactor.test.ts | 2 +- tests/unit/self-wake.test.ts | 2 +- 11 files changed, 10 insertions(+), 10 deletions(-) rename src/main/worker/{ => observability}/circuit-breaker.ts (100%) rename src/main/worker/{ => observability}/failure-escalation.ts (100%) rename src/main/worker/{ => observability}/log-redactor.ts (100%) rename src/main/worker/{ => observability}/run-event-recorder.ts (94%) rename src/main/worker/{ => observability}/run-log-filter.ts (100%) diff --git a/src/main/worker/handlers/run-finished-helpers.ts b/src/main/worker/handlers/run-finished-helpers.ts index 06c04478..4d652008 100644 --- a/src/main/worker/handlers/run-finished-helpers.ts +++ b/src/main/worker/handlers/run-finished-helpers.ts @@ -1,7 +1,7 @@ import type { z } from "zod"; -import { createCircuitBreaker } from "../circuit-breaker"; -import { handleFailureEscalation, handleSuccessReset } from "../failure-escalation"; -import { persistRunEvent } from "../run-event-recorder"; +import { createCircuitBreaker } from "../observability/circuit-breaker"; +import { handleFailureEscalation, handleSuccessReset } from "../observability/failure-escalation"; +import { persistRunEvent } from "../observability/run-event-recorder"; import type { workerMessageSchema } from "../entry/types"; import type { HandlerContext, HandlerDeps, WorkerMessageEvent } from "./handler-context"; diff --git a/src/main/worker/handlers/run-log-handler.ts b/src/main/worker/handlers/run-log-handler.ts index 89f2aadc..a1457294 100644 --- a/src/main/worker/handlers/run-log-handler.ts +++ b/src/main/worker/handlers/run-log-handler.ts @@ -1,5 +1,5 @@ -import { filterRunLogChunk } from "../run-log-filter"; -import { persistRunEvent } from "../run-event-recorder"; +import { filterRunLogChunk } from "../observability/run-log-filter"; +import { persistRunEvent } from "../observability/run-event-recorder"; import type { HandlerContext, HandlerDeps, WorkerMessageEvent } from "./handler-context"; const LEASE_RENEWAL_INTERVAL_MS = 5 * 60 * 1000; // 5 minutes diff --git a/src/main/worker/handlers/run-status-handler.ts b/src/main/worker/handlers/run-status-handler.ts index a5a47d20..b08bf6f1 100644 --- a/src/main/worker/handlers/run-status-handler.ts +++ b/src/main/worker/handlers/run-status-handler.ts @@ -1,4 +1,4 @@ -import { persistRunEvent } from "../run-event-recorder"; +import { persistRunEvent } from "../observability/run-event-recorder"; import type { HandlerContext, HandlerDeps, WorkerMessageEvent } from "./handler-context"; export function handleRunStatus( diff --git a/src/main/worker/circuit-breaker.ts b/src/main/worker/observability/circuit-breaker.ts similarity index 100% rename from src/main/worker/circuit-breaker.ts rename to src/main/worker/observability/circuit-breaker.ts diff --git a/src/main/worker/failure-escalation.ts b/src/main/worker/observability/failure-escalation.ts similarity index 100% rename from src/main/worker/failure-escalation.ts rename to src/main/worker/observability/failure-escalation.ts diff --git a/src/main/worker/log-redactor.ts b/src/main/worker/observability/log-redactor.ts similarity index 100% rename from src/main/worker/log-redactor.ts rename to src/main/worker/observability/log-redactor.ts diff --git a/src/main/worker/run-event-recorder.ts b/src/main/worker/observability/run-event-recorder.ts similarity index 94% rename from src/main/worker/run-event-recorder.ts rename to src/main/worker/observability/run-event-recorder.ts index d7e3624d..0910f72b 100644 --- a/src/main/worker/run-event-recorder.ts +++ b/src/main/worker/observability/run-event-recorder.ts @@ -1,4 +1,4 @@ -import type { AppDatabase } from "../database"; +import type { AppDatabase } from "../../database"; interface PersistInput { companyId: string; diff --git a/src/main/worker/run-log-filter.ts b/src/main/worker/observability/run-log-filter.ts similarity index 100% rename from src/main/worker/run-log-filter.ts rename to src/main/worker/observability/run-log-filter.ts diff --git a/tests/unit/failure-escalation.test.ts b/tests/unit/failure-escalation.test.ts index 2cccf439..6f039e56 100644 --- a/tests/unit/failure-escalation.test.ts +++ b/tests/unit/failure-escalation.test.ts @@ -3,7 +3,7 @@ import { handleFailureEscalation, handleSuccessReset, type EscalationDeps, -} from "@main/worker/failure-escalation"; +} from "@main/worker/observability/failure-escalation"; /** * Tests for the retry-aware failure escalation pipeline. diff --git a/tests/unit/log-redactor.test.ts b/tests/unit/log-redactor.test.ts index be3650a6..9bc0aa4a 100644 --- a/tests/unit/log-redactor.test.ts +++ b/tests/unit/log-redactor.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { redactTokens } from "../../src/main/worker/log-redactor"; +import { redactTokens } from "../../src/main/worker/observability/log-redactor"; /** Verifies the worker process token redactor strips known * credential-shaped substrings from log strings before they leave the diff --git a/tests/unit/self-wake.test.ts b/tests/unit/self-wake.test.ts index d1d119e2..47d33346 100644 --- a/tests/unit/self-wake.test.ts +++ b/tests/unit/self-wake.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { createCircuitBreaker, MAX_CONSECUTIVE_WAKES } from "@main/worker/circuit-breaker"; +import { createCircuitBreaker, MAX_CONSECUTIVE_WAKES } from "@main/worker/observability/circuit-breaker"; /** * Tests for the self-wake circuit breaker used in worker-message-handler.ts.