Skip to content

Commit 1f9222d

Browse files
committed
fix: redact prompt cache keys in doctor output
1 parent 4637fc7 commit 1f9222d

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ import { paintUiText, formatUiBadge, formatUiHeader, formatUiItem, formatUiKeyVa
158158
import {
159159
buildBeginnerChecklist,
160160
buildBeginnerDoctorFindings,
161+
formatPromptCacheKey,
161162
recommendBeginnerNextAction,
162163
summarizeBeginnerAccounts,
163164
type BeginnerAccountSnapshot,
@@ -5217,7 +5218,7 @@ while (attempted.size < Math.max(1, accountCount)) {
52175218
ui,
52185219
"Prompt cache",
52195220
runtime.promptCacheEnabledRequests > 0
5220-
? `enabled=${runtime.promptCacheEnabledRequests}, missing=${runtime.promptCacheMissingRequests}, lastKey=${runtime.lastPromptCacheKey ?? "none"}`
5221+
? `enabled=${runtime.promptCacheEnabledRequests}, missing=${runtime.promptCacheMissingRequests}, lastKey=${formatPromptCacheKey(runtime.lastPromptCacheKey)}`
52215222
: `enabled=0, missing=${runtime.promptCacheMissingRequests}, lastKey=none`,
52225223
"muted",
52235224
),
@@ -5262,7 +5263,7 @@ while (attempted.size < Math.max(1, accountCount)) {
52625263
` Runtime failures: failed=${runtime.failedRequests}, rateLimited=${runtime.rateLimitedResponses}, authRefreshFailed=${runtime.authRefreshFailures}, server=${runtime.serverErrors}, network=${runtime.networkErrors}`,
52635264
);
52645265
lines.push(
5265-
` Prompt cache: enabled=${runtime.promptCacheEnabledRequests}, missing=${runtime.promptCacheMissingRequests}, lastKey=${runtime.lastPromptCacheKey ?? "none"}`,
5266+
` Prompt cache: enabled=${runtime.promptCacheEnabledRequests}, missing=${runtime.promptCacheMissingRequests}, lastKey=${formatPromptCacheKey(runtime.lastPromptCacheKey)}`,
52665267
);
52675268
}
52685269
return lines.join("\n");

lib/ui/beginner.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export interface BeginnerAccountSummary {
5050
unlabeled: number;
5151
}
5252

53+
export function formatPromptCacheKey(value: string | null | undefined): string {
54+
const normalized = value?.trim();
55+
if (!normalized) return "none";
56+
if (normalized.length <= 8) return normalized;
57+
return `${normalized.slice(0, 8)}...`;
58+
}
59+
5360
export function summarizeBeginnerAccounts(
5461
accounts: BeginnerAccountSnapshot[],
5562
now: number,

test/beginner-ui.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
buildBeginnerChecklist,
44
buildBeginnerDoctorFindings,
55
explainRuntimeErrorCategory,
6+
formatPromptCacheKey,
67
recommendBeginnerNextAction,
78
summarizeBeginnerAccounts,
89
type BeginnerAccountSnapshot,
@@ -210,3 +211,19 @@ describe("explainRuntimeErrorCategory", () => {
210211
expect(hint).toContain("codex-doctor");
211212
});
212213
});
214+
215+
describe("formatPromptCacheKey", () => {
216+
it("returns none for empty values", () => {
217+
expect(formatPromptCacheKey(null)).toBe("none");
218+
expect(formatPromptCacheKey(undefined)).toBe("none");
219+
expect(formatPromptCacheKey(" ")).toBe("none");
220+
});
221+
222+
it("keeps short values as-is", () => {
223+
expect(formatPromptCacheKey("ses_1234")).toBe("ses_1234");
224+
});
225+
226+
it("redacts longer values to an 8-char prefix", () => {
227+
expect(formatPromptCacheKey("ses_prompt_cache_key_123")).toBe("ses_prom...");
228+
});
229+
});

0 commit comments

Comments
 (0)