From 85de9caec198a22326062b28214733414f94ab6d Mon Sep 17 00:00:00 2001 From: Sawyer Cutler Date: Fri, 16 Oct 2026 18:18:53 -0700 Subject: [PATCH 1/2] chore(audit): apply review nits across pricing, otel, and knip --- docs/PERFTRACE.md | 4 +++ knip.json | 2 +- src/agent/director-core.ts | 1 + src/cost/pricing-fetcher.ts | 12 ++++++-- src/perf/otel-config.ts | 1 + src/pricing-fetcher.test.ts | 38 ++++++++++++++++++++++++++ src/session/optimized-context-store.ts | 2 +- 7 files changed, 56 insertions(+), 4 deletions(-) diff --git a/docs/PERFTRACE.md b/docs/PERFTRACE.md index f631cb673..d3b42ee4e 100644 --- a/docs/PERFTRACE.md +++ b/docs/PERFTRACE.md @@ -74,6 +74,10 @@ Precedence: - **`otel.enabled: false`:** disables export when only settings provide an endpoint; an explicit env endpoint still enables export +Operator note: the env attribute list replaces settings wholesale instead of +merging — when `OTEL_RESOURCE_ATTRIBUTES` is set, attributes left only in +settings are ignored, so move every attribute you need into the env list. + Do not put credentials in the endpoint URL (`https://user:pass@…` is rejected). Use headers instead. diff --git a/knip.json b/knip.json index 9e9c47c61..6884daccb 100644 --- a/knip.json +++ b/knip.json @@ -5,7 +5,7 @@ "src/tui/smoke.ts", "scripts/*.ts", "e2e/*.test.ts", - "evals/*.ts" + "evals/**/*.ts" ], "project": [ "src/**/*.ts", diff --git a/src/agent/director-core.ts b/src/agent/director-core.ts index c2ae14fdb..34782d325 100644 --- a/src/agent/director-core.ts +++ b/src/agent/director-core.ts @@ -28,6 +28,7 @@ export function composeDirectedPrompt( function ephemeralNudgeTurn(text: string): ConversationTurn { return { role: "user", + // Trim caller padding so the nudge matches the cached literal exactly. content: [{ type: "text", text: text.trim() }], timestamp: Date.now(), }; diff --git a/src/cost/pricing-fetcher.ts b/src/cost/pricing-fetcher.ts index c10fcb4b0..a7030c9a5 100644 --- a/src/cost/pricing-fetcher.ts +++ b/src/cost/pricing-fetcher.ts @@ -2,8 +2,9 @@ import { mkdir } from "node:fs/promises"; import { homedir } from "node:os"; import { dirname, join } from "node:path"; +import { getLogger } from "@intx/log"; import { type } from "arktype"; -import { SETTINGS_DIR_NAME } from "../branding.js"; +import { LOG_NAMESPACE_ROOT, SETTINGS_DIR_NAME } from "../branding.js"; export interface ModelPricing { inputPricePerToken: number; @@ -47,6 +48,8 @@ const DEFAULT_ENDPOINT = "https://models.dev/api.json"; const DEFAULT_REFRESH_INTERVAL_MS = 24 * 60 * 60 * 1000; const DEFAULT_FETCH_TIMEOUT_MS = 5000; +const log = getLogger([LOG_NAMESPACE_ROOT, "cost", "pricing"]); + const modelPricingValidator = type({ inputPricePerToken: "number", outputPricePerToken: "number", @@ -288,7 +291,12 @@ export async function loadPricing( const pricing = await fetchPricing(options); await writePricingCache(pricing, cachePath); return pricing; - } catch { + } catch (err) { + // Refresh runs fire-and-forget off a timer, so it must never throw. One + // debug line keeps the failure observable while stale cache carries on. + log.debug("pricing refresh failed, keeping cached pricing: {error}", { + error: err instanceof Error ? err.message : String(err), + }); return readPricingCache(cachePath); } } diff --git a/src/perf/otel-config.ts b/src/perf/otel-config.ts index 25370d765..504165ad3 100644 --- a/src/perf/otel-config.ts +++ b/src/perf/otel-config.ts @@ -296,6 +296,7 @@ export function resolveOtelExportConfig( } let resourceAttributes: Record = {}; + // Env replaces settings wholesale (no merge): a set-but-empty env still wins. if (envResourceAttrsRaw !== undefined) { const parsed = parseOtelKeyValueList( envResourceAttrsRaw, diff --git a/src/pricing-fetcher.test.ts b/src/pricing-fetcher.test.ts index af52a0132..c4db4414b 100644 --- a/src/pricing-fetcher.test.ts +++ b/src/pricing-fetcher.test.ts @@ -1,6 +1,7 @@ import { defined } from "../testkit/defined.js"; import { describe, test, expect } from "bun:test"; import { isAbsolute, join } from "node:path"; +import { configureSync, getConfig, resetSync } from "@intx/log"; import { parseModelsDevContextWindows, parseModelsDevPricing, @@ -259,6 +260,43 @@ describe("loadPricing", () => { expect(result).toBeNull(); }); + + test("emits a single debug line when refresh fails", async () => { + const records: { level: string; text: string }[] = []; + const previous = getConfig(); + configureSync({ + reset: true, + sinks: { + test: (record) => { + records.push({ + level: record.level, + text: record.message.map(String).join(""), + }); + }, + }, + loggers: [{ category: [], lowestLevel: "debug", sinks: ["test"] }], + }); + try { + const failingFetch = (async (): Promise => { + throw new Error("network error"); + }) as unknown as typeof fetch; + const result = await loadPricing({ + fetchImpl: failingFetch, + cachePath: "/tmp/nonexistent-pricing-cache-debug.json", + }); + expect(result).toBeNull(); + const hits = records.filter( + (record) => + record.level === "debug" && + record.text.includes("pricing refresh failed"), + ); + expect(hits).toHaveLength(1); + expect(hits[0]?.text).toContain("network error"); + } finally { + if (previous === null) resetSync(); + else configureSync({ ...previous, reset: true }); + } + }); }); // --------------------------------------------------------------------------- diff --git a/src/session/optimized-context-store.ts b/src/session/optimized-context-store.ts index 0cc038c1b..13fee27a1 100644 --- a/src/session/optimized-context-store.ts +++ b/src/session/optimized-context-store.ts @@ -1918,7 +1918,7 @@ export async function createSessionStores( extraPaths = [...new Set([...add, ...remove])]; // Array `git.add` / `git.remove` each write the index once. - // Array `remove` is isomorphic-git 1.43.0; array `add` is older. + // Array `remove` is isomorphic-git 1.44.2; array `add` is older. // A mid-batch add failure leaves the index unwritten. Only the // outer catch calls `resetIndexPaths`. if (add.length > 0) { From 5587512a9ff9d40c176eb5ebce914e20bd557ef0 Mon Sep 17 00:00:00 2001 From: Sawyer Cutler Date: Fri, 16 Oct 2026 18:26:27 -0700 Subject: [PATCH 2/2] chore(audit): keep only the pricing refresh log --- docs/PERFTRACE.md | 4 ---- knip.json | 2 +- src/agent/director-core.ts | 1 - src/cost/pricing-fetcher.ts | 3 +-- src/perf/otel-config.ts | 1 - src/session/optimized-context-store.ts | 2 +- 6 files changed, 3 insertions(+), 10 deletions(-) diff --git a/docs/PERFTRACE.md b/docs/PERFTRACE.md index d3b42ee4e..f631cb673 100644 --- a/docs/PERFTRACE.md +++ b/docs/PERFTRACE.md @@ -74,10 +74,6 @@ Precedence: - **`otel.enabled: false`:** disables export when only settings provide an endpoint; an explicit env endpoint still enables export -Operator note: the env attribute list replaces settings wholesale instead of -merging — when `OTEL_RESOURCE_ATTRIBUTES` is set, attributes left only in -settings are ignored, so move every attribute you need into the env list. - Do not put credentials in the endpoint URL (`https://user:pass@…` is rejected). Use headers instead. diff --git a/knip.json b/knip.json index 6884daccb..9e9c47c61 100644 --- a/knip.json +++ b/knip.json @@ -5,7 +5,7 @@ "src/tui/smoke.ts", "scripts/*.ts", "e2e/*.test.ts", - "evals/**/*.ts" + "evals/*.ts" ], "project": [ "src/**/*.ts", diff --git a/src/agent/director-core.ts b/src/agent/director-core.ts index 34782d325..c2ae14fdb 100644 --- a/src/agent/director-core.ts +++ b/src/agent/director-core.ts @@ -28,7 +28,6 @@ export function composeDirectedPrompt( function ephemeralNudgeTurn(text: string): ConversationTurn { return { role: "user", - // Trim caller padding so the nudge matches the cached literal exactly. content: [{ type: "text", text: text.trim() }], timestamp: Date.now(), }; diff --git a/src/cost/pricing-fetcher.ts b/src/cost/pricing-fetcher.ts index a7030c9a5..8e78fd15f 100644 --- a/src/cost/pricing-fetcher.ts +++ b/src/cost/pricing-fetcher.ts @@ -292,8 +292,7 @@ export async function loadPricing( await writePricingCache(pricing, cachePath); return pricing; } catch (err) { - // Refresh runs fire-and-forget off a timer, so it must never throw. One - // debug line keeps the failure observable while stale cache carries on. + // One debug line keeps a failed refresh observable while stale cache carries on. log.debug("pricing refresh failed, keeping cached pricing: {error}", { error: err instanceof Error ? err.message : String(err), }); diff --git a/src/perf/otel-config.ts b/src/perf/otel-config.ts index 504165ad3..25370d765 100644 --- a/src/perf/otel-config.ts +++ b/src/perf/otel-config.ts @@ -296,7 +296,6 @@ export function resolveOtelExportConfig( } let resourceAttributes: Record = {}; - // Env replaces settings wholesale (no merge): a set-but-empty env still wins. if (envResourceAttrsRaw !== undefined) { const parsed = parseOtelKeyValueList( envResourceAttrsRaw, diff --git a/src/session/optimized-context-store.ts b/src/session/optimized-context-store.ts index 13fee27a1..0cc038c1b 100644 --- a/src/session/optimized-context-store.ts +++ b/src/session/optimized-context-store.ts @@ -1918,7 +1918,7 @@ export async function createSessionStores( extraPaths = [...new Set([...add, ...remove])]; // Array `git.add` / `git.remove` each write the index once. - // Array `remove` is isomorphic-git 1.44.2; array `add` is older. + // Array `remove` is isomorphic-git 1.43.0; array `add` is older. // A mid-batch add failure leaves the index unwritten. Only the // outer catch calls `resetIndexPaths`. if (add.length > 0) {