Skip to content

Commit 9be7196

Browse files
committed
fix(logs): harden reasoning diagnostics
1 parent 3ab721a commit 9be7196

4 files changed

Lines changed: 48 additions & 6 deletions

File tree

‎src/server/request-log.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export function recordAdapterReasoning(
325325
|| (reasoning.wireField !== "reasoning_effort"
326326
&& reasoning.wireField !== "thinking_budget"
327327
&& reasoning.wireField !== "thinking.type")
328-
|| (typeof reasoning.wireValue !== "string"
328+
|| (!(typeof reasoning.wireValue === "string" && reasoning.wireValue)
329329
&& !(typeof reasoning.wireValue === "number"
330330
&& Number.isFinite(reasoning.wireValue)
331331
&& reasoning.wireValue >= 0))) {

‎src/web-search/loop.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
273273
headers: selectedForwardHeaders,
274274
abortSignal: headerDeadline.signal,
275275
});
276-
deps.onRequestBuilt?.(request);
276+
try {
277+
deps.onRequestBuilt?.(request);
278+
} catch {
279+
// Diagnostics are best-effort and must never abort a web-search iteration.
280+
}
277281
const response = requestAdapter.fetchResponse
278282
? await requestAdapter.fetchResponse(request, {
279283
abortSignal: headerDeadline.signal,

‎tests/request-log.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ describe("request log metadata", () => {
103103
{ effectiveEffort: null, wireField: "reasoning_effort", wireValue: "high" },
104104
{ effectiveEffort: {}, wireField: "reasoning_effort", wireValue: "high" },
105105
{ effectiveEffort: "high", wireField: "unknown", wireValue: "high" },
106+
{ effectiveEffort: "high", wireField: "reasoning_effort", wireValue: "" },
106107
{ effectiveEffort: "high", wireField: "thinking_budget", wireValue: null },
107108
{ effectiveEffort: "high", wireField: "thinking_budget", wireValue: {} },
108109
{ effectiveEffort: "high", wireField: "thinking_budget", wireValue: Number.NaN },

‎tests/web-search.test.ts‎

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe("BUG-R86 routed web-search timeout semantics", () => {
325325
expect(text).toContain("event: response.completed");
326326
});
327327

328-
test("routed iterations use upstream streaming and never call parseResponse", async () => {
328+
test("routed iterations isolate diagnostic failures and never call parseResponse", async () => {
329329
const seenStream: boolean[] = [];
330330
const reasoningLogs: unknown[] = [];
331331
let parseStreamCalls = 0;
@@ -366,7 +366,10 @@ describe("BUG-R86 routed web-search timeout semantics", () => {
366366
selectedForwardHeaders: new Headers({ authorization: "Bearer token" }),
367367
settings: { model: "gpt-5.6-luna", reasoning: "low", timeoutMs: 30_000 },
368368
maxSearches: 1,
369-
onRequestBuilt: request => reasoningLogs.push(request.reasoningLog),
369+
onRequestBuilt: request => {
370+
reasoningLogs.push(request.reasoningLog);
371+
throw new Error("diagnostic hook failure must not abort delivery");
372+
},
370373
});
371374

372375
expect(response.status).toBe(200);
@@ -498,16 +501,37 @@ describe("web-search sidecar native web_search_call emission", () => {
498501
))) as typeof fetch;
499502

500503
// First adapter always 429s via fetchResponse; the rotated adapter answers.
504+
const reasoningLogs: unknown[] = [];
501505
const firstAdapter: ProviderAdapter = {
502506
name: "mock-429",
503-
buildRequest: () => ({ url: "https://routed.test/v1", method: "POST", headers: {}, body: "{}" }),
507+
buildRequest: () => ({
508+
url: "https://routed.test/v1",
509+
method: "POST",
510+
headers: {},
511+
body: "{}",
512+
reasoningLog: {
513+
effectiveEffort: "low",
514+
wireField: "reasoning_effort",
515+
wireValue: "low",
516+
},
517+
}),
504518
fetchResponse: async () => new Response("rate limited", { status: 429, headers: { "retry-after": "30" } }),
505519
async *parseStream() { /* unused */ },
506520
async parseResponse() { return [{ type: "text_delta", text: "should not reach" }, { type: "done" }] as AdapterEvent[]; },
507521
};
508522
const rotatedAdapter: ProviderAdapter = {
509523
name: "mock-rotated",
510-
buildRequest: () => ({ url: "https://routed.test/v1", method: "POST", headers: {}, body: "{}" }),
524+
buildRequest: () => ({
525+
url: "https://routed.test/v1",
526+
method: "POST",
527+
headers: {},
528+
body: "{}",
529+
reasoningLog: {
530+
effectiveEffort: "high",
531+
wireField: "reasoning_effort",
532+
wireValue: "high",
533+
},
534+
}),
511535
fetchResponse: async () => new Response("{}", { status: 200 }),
512536
async *parseStream() {
513537
yield { type: "text_delta", text: "answer from rotated key" };
@@ -525,6 +549,7 @@ describe("web-search sidecar native web_search_call emission", () => {
525549
selectedForwardHeaders: new Headers({ authorization: "Bearer token" }),
526550
settings: { model: "gpt-5.4-mini", reasoning: "low", timeoutMs: 30_000 },
527551
maxSearches: 1,
552+
onRequestBuilt: request => reasoningLogs.push(request.reasoningLog),
528553
on429: retryAfter => {
529554
rotations++;
530555
expect(retryAfter).toBe("30");
@@ -537,6 +562,18 @@ describe("web-search sidecar native web_search_call emission", () => {
537562
const output = completed.output as { type: string; content?: { text?: string }[] }[];
538563
expect(output.find(o => o.type === "message")?.content?.[0]?.text).toBe("answer from rotated key");
539564
expect(rotations).toBe(1);
565+
expect(reasoningLogs).toEqual([
566+
{
567+
effectiveEffort: "low",
568+
wireField: "reasoning_effort",
569+
wireValue: "low",
570+
},
571+
{
572+
effectiveEffort: "high",
573+
wireField: "reasoning_effort",
574+
wireValue: "high",
575+
},
576+
]);
540577
});
541578

542579
test("loop 429 with exhausted pool (on429 null) surfaces the provider error", async () => {

0 commit comments

Comments
 (0)