Skip to content

Commit 85de9ca

Browse files
committed
chore(audit): apply review nits across pricing, otel, and knip
1 parent c63783c commit 85de9ca

7 files changed

Lines changed: 56 additions & 4 deletions

File tree

‎docs/PERFTRACE.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ Precedence:
7474
- **`otel.enabled: false`:** disables export when only settings provide an
7575
endpoint; an explicit env endpoint still enables export
7676

77+
Operator note: the env attribute list replaces settings wholesale instead of
78+
merging — when `OTEL_RESOURCE_ATTRIBUTES` is set, attributes left only in
79+
settings are ignored, so move every attribute you need into the env list.
80+
7781
Do not put credentials in the endpoint URL (`https://user:pass@…` is rejected).
7882
Use headers instead.
7983

‎knip.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"src/tui/smoke.ts",
66
"scripts/*.ts",
77
"e2e/*.test.ts",
8-
"evals/*.ts"
8+
"evals/**/*.ts"
99
],
1010
"project": [
1111
"src/**/*.ts",

‎src/agent/director-core.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function composeDirectedPrompt(
2828
function ephemeralNudgeTurn(text: string): ConversationTurn {
2929
return {
3030
role: "user",
31+
// Trim caller padding so the nudge matches the cached literal exactly.
3132
content: [{ type: "text", text: text.trim() }],
3233
timestamp: Date.now(),
3334
};

‎src/cost/pricing-fetcher.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { mkdir } from "node:fs/promises";
22
import { homedir } from "node:os";
33
import { dirname, join } from "node:path";
44

5+
import { getLogger } from "@intx/log";
56
import { type } from "arktype";
6-
import { SETTINGS_DIR_NAME } from "../branding.js";
7+
import { LOG_NAMESPACE_ROOT, SETTINGS_DIR_NAME } from "../branding.js";
78

89
export interface ModelPricing {
910
inputPricePerToken: number;
@@ -47,6 +48,8 @@ const DEFAULT_ENDPOINT = "https://models.dev/api.json";
4748
const DEFAULT_REFRESH_INTERVAL_MS = 24 * 60 * 60 * 1000;
4849
const DEFAULT_FETCH_TIMEOUT_MS = 5000;
4950

51+
const log = getLogger([LOG_NAMESPACE_ROOT, "cost", "pricing"]);
52+
5053
const modelPricingValidator = type({
5154
inputPricePerToken: "number",
5255
outputPricePerToken: "number",
@@ -288,7 +291,12 @@ export async function loadPricing(
288291
const pricing = await fetchPricing(options);
289292
await writePricingCache(pricing, cachePath);
290293
return pricing;
291-
} catch {
294+
} catch (err) {
295+
// Refresh runs fire-and-forget off a timer, so it must never throw. One
296+
// debug line keeps the failure observable while stale cache carries on.
297+
log.debug("pricing refresh failed, keeping cached pricing: {error}", {
298+
error: err instanceof Error ? err.message : String(err),
299+
});
292300
return readPricingCache(cachePath);
293301
}
294302
}

‎src/perf/otel-config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ export function resolveOtelExportConfig(
296296
}
297297

298298
let resourceAttributes: Record<string, string> = {};
299+
// Env replaces settings wholesale (no merge): a set-but-empty env still wins.
299300
if (envResourceAttrsRaw !== undefined) {
300301
const parsed = parseOtelKeyValueList(
301302
envResourceAttrsRaw,

‎src/pricing-fetcher.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defined } from "../testkit/defined.js";
22
import { describe, test, expect } from "bun:test";
33
import { isAbsolute, join } from "node:path";
4+
import { configureSync, getConfig, resetSync } from "@intx/log";
45
import {
56
parseModelsDevContextWindows,
67
parseModelsDevPricing,
@@ -259,6 +260,43 @@ describe("loadPricing", () => {
259260

260261
expect(result).toBeNull();
261262
});
263+
264+
test("emits a single debug line when refresh fails", async () => {
265+
const records: { level: string; text: string }[] = [];
266+
const previous = getConfig();
267+
configureSync({
268+
reset: true,
269+
sinks: {
270+
test: (record) => {
271+
records.push({
272+
level: record.level,
273+
text: record.message.map(String).join(""),
274+
});
275+
},
276+
},
277+
loggers: [{ category: [], lowestLevel: "debug", sinks: ["test"] }],
278+
});
279+
try {
280+
const failingFetch = (async (): Promise<Response> => {
281+
throw new Error("network error");
282+
}) as unknown as typeof fetch;
283+
const result = await loadPricing({
284+
fetchImpl: failingFetch,
285+
cachePath: "/tmp/nonexistent-pricing-cache-debug.json",
286+
});
287+
expect(result).toBeNull();
288+
const hits = records.filter(
289+
(record) =>
290+
record.level === "debug" &&
291+
record.text.includes("pricing refresh failed"),
292+
);
293+
expect(hits).toHaveLength(1);
294+
expect(hits[0]?.text).toContain("network error");
295+
} finally {
296+
if (previous === null) resetSync();
297+
else configureSync({ ...previous, reset: true });
298+
}
299+
});
262300
});
263301

264302
// ---------------------------------------------------------------------------

‎src/session/optimized-context-store.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ export async function createSessionStores(
19181918
extraPaths = [...new Set([...add, ...remove])];
19191919

19201920
// Array `git.add` / `git.remove` each write the index once.
1921-
// Array `remove` is isomorphic-git 1.43.0; array `add` is older.
1921+
// Array `remove` is isomorphic-git 1.44.2; array `add` is older.
19221922
// A mid-batch add failure leaves the index unwritten. Only the
19231923
// outer catch calls `resetIndexPaths`.
19241924
if (add.length > 0) {

0 commit comments

Comments
 (0)