Skip to content

Commit 8344c43

Browse files
fix(server): keep provider output out of explanation failure logs
A refused explanation logged its raw cause, whose detail can carry provider CLI output. The warning now carries only the reason and the cause's tag and operation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8b37f1b commit 8344c43

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderFailureExplanationService.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
} from "@t3tools/contracts";
1414
import * as Effect from "effect/Effect";
1515
import * as Layer from "effect/Layer";
16+
import * as Logger from "effect/Logger";
17+
import * as References from "effect/References";
1618

1719
import * as ServerSettings from "../serverSettings.ts";
1820
import * as TextGeneration from "../textGeneration/TextGeneration.ts";
@@ -434,9 +436,26 @@ describe("ProviderFailureExplanationService", () => {
434436
}),
435437
),
436438
});
437-
const error = yield* explain().pipe(Effect.provide(harness.layer), Effect.flip);
439+
const logs: Array<{ message: unknown; annotations: unknown }> = [];
440+
const logger = Logger.make(({ fiber, message }) => {
441+
logs.push({ message, annotations: fiber.getRef(References.CurrentLogAnnotations) });
442+
});
443+
const error = yield* explain().pipe(
444+
Effect.provide(
445+
Layer.merge(harness.layer, Logger.layer([logger], { mergeWithExisting: false })),
446+
),
447+
Effect.flip,
448+
);
438449

439450
assert.equal(error.reason, "generation_failed");
451+
// The log keeps the cause's tag and operation, never its detail.
452+
assert.equal(logs.length, 1);
453+
assert.deepInclude(logs[0]?.annotations, {
454+
reason: "generation_failed",
455+
causeTag: "TextGenerationError",
456+
operation: "explainProviderFailure",
457+
});
458+
assert.notInclude(JSON.stringify(logs), "sk-secret-stderr");
440459
assert.equal(
441460
error.message,
442461
"The text generation model could not explain this error. Check the server logs for details.",

‎apps/server/src/orchestration-v2/ProviderFailureExplanationService.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,18 @@ export function formatProviderFailureContext(input: ProviderFailureContextInput)
152152
);
153153
}
154154

155+
/** The reason plus the cause's tag and operation; never its message, detail or payload. */
156+
function boundedFailureLogFields(reason: string, cause: unknown): Record<string, string> {
157+
const fields: Record<string, string> = { reason };
158+
if (typeof cause === "object" && cause !== null) {
159+
if ("_tag" in cause && typeof cause._tag === "string") fields.causeTag = cause._tag;
160+
if ("operation" in cause && typeof cause.operation === "string") {
161+
fields.operation = cause.operation;
162+
}
163+
}
164+
return fields;
165+
}
166+
155167
const make = Effect.gen(function* () {
156168
const threads = yield* ThreadManagementService.ThreadManagementService;
157169
const serverSettings = yield* ServerSettings.ServerSettingsService;
@@ -167,7 +179,10 @@ const make = Effect.gen(function* () {
167179
) =>
168180
(cause === undefined
169181
? Effect.void
170-
: Effect.logWarning("Provider failure explanation failed", reason, cause)
182+
: Effect.logWarning("Provider failure explanation failed").pipe(
183+
// Only bounded fields: a cause's detail can carry provider output.
184+
Effect.annotateLogs(boundedFailureLogFields(reason, cause)),
185+
)
171186
).pipe(
172187
Effect.andThen(
173188
Effect.fail(

0 commit comments

Comments
 (0)