Skip to content

Commit 19a0f35

Browse files
feat(logs): unwrap pasted codex://threads links in conversation search
Codex's copy-session-link clipboard carries a codex://threads/<id> deep link while clients send the bare thread id on the wire. Unwrap the wrapper inside the shared conversation matcher so the Logs conversation field, /api/logs?conversationId, and ocx logs filter --conversation all match the bare id (direct or via its persisted digest) without changing what is persisted. Co-Authored-By: Epinephrine <[email protected]>
1 parent c30b522 commit 19a0f35

5 files changed

Lines changed: 80 additions & 3 deletions

File tree

‎docs-site/src/content/docs/guides/web-dashboard.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ Logs filters combine surface, intercepted requests, provider, exact model, statu
147147
speed, and conversation ID over the currently loaded request ring. Provider and model
148148
choices also include fallback attempts; model matching ignores case and surrounding spaces
149149
but does not match partial names. Choices that disappear from the ring reset to All.
150+
The conversation field also accepts a pasted `codex://threads/<id>` deep link, the form a
151+
Codex "copy session link" puts on the clipboard — the wrapper is ignored and the bare
152+
thread id is matched, the same value an `ocx logs filter --conversation` search unwraps.
150153

151154
Time windows cover the last 15 minutes, hour, or day and refresh every 30 seconds while the
152155
Logs tab is active, even with auto-refresh off. Windows use the proxy timestamp from

‎gui/src/log-conversation-id.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@ function hasControlChars(value: string): boolean {
1717
return false;
1818
}
1919

20+
/**
21+
* Unwrap a pasted `codex://threads/<id>` deep link to the bare thread id.
22+
* Mirrors src/server/request-log-conversation.unwrapLogConversationQuery.
23+
*/
24+
export function unwrapLogConversationQuery(query: string): string {
25+
const unwrapped = /^codex:\/\/threads\/(.*?)\/*$/i.exec(query.trim())?.[1]?.trim();
26+
return unwrapped || query.trim();
27+
}
28+
2029
/** SHA-256 hex prefix used as the persisted conversation id. */
2130
export async function hashLogConversationQuery(raw: string): Promise<string | undefined> {
22-
const trimmed = raw.trim();
31+
const trimmed = unwrapLogConversationQuery(raw);
2332
if (!trimmed) return undefined;
2433
if (hasControlChars(trimmed)) return undefined;
2534
if (trimmed.length > 4096) return undefined;
@@ -33,7 +42,7 @@ export function matchesLogConversationId(
3342
queryHash?: string,
3443
): boolean {
3544
if (!stored) return false;
36-
const trimmed = query.trim();
45+
const trimmed = unwrapLogConversationQuery(query);
3746
if (!trimmed) return false;
3847
if (stored === trimmed) return true;
3948
return queryHash !== undefined && stored === queryHash;

‎gui/tests/logs-filter.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { describe, expect, test } from "bun:test";
2+
import { createHash } from "node:crypto";
23
import {
34
DEFAULT_LOG_FILTER_STATE,
45
extractLogFilterOptions,
56
filterLogs,
67
hasActiveLogFilters,
78
} from "../src/pages/logs-filter";
9+
import { hashLogConversationQuery, unwrapLogConversationQuery } from "../src/log-conversation-id";
810

911
const NOW = 2_000_000_000_000;
1012
const logs = [
@@ -189,3 +191,35 @@ test("exact model choices distinguish prefix siblings and compose with a provide
189191
expect(filterLogs(rows, { ...DEFAULT_LOG_FILTER_STATE, model: "model-a", provider: "openai" }).map(row => row.id))
190192
.toEqual(["exact", "resolved", "attempt"]);
191193
});
194+
195+
const digest32 = (raw: string) => createHash("sha256").update(raw).digest("hex").slice(0, 32);
196+
const CODEX_THREAD_ID = "019f6482-67d5-77c2-a643-02daddaa7115";
197+
198+
describe("codex://threads paste in the conversation filter", () => {
199+
test("unwraps the deep link to the bare thread id and hashes the unwrapped value", async () => {
200+
expect(unwrapLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`)).toBe(CODEX_THREAD_ID);
201+
expect(unwrapLogConversationQuery(` CODEX://THREADS/${CODEX_THREAD_ID}/ `)).toBe(CODEX_THREAD_ID);
202+
expect(unwrapLogConversationQuery(CODEX_THREAD_ID)).toBe(CODEX_THREAD_ID);
203+
expect(unwrapLogConversationQuery("codex://other/x")).toBe("codex://other/x");
204+
expect(unwrapLogConversationQuery("codex://threads/")).toBe("codex://threads/");
205+
expect(await hashLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`)).toBe(digest32(CODEX_THREAD_ID));
206+
});
207+
208+
test("filterLogs matches a stored digest or raw id behind the pasted link", async () => {
209+
const rows = [
210+
{ id: "hashed", conversationId: digest32(CODEX_THREAD_ID) },
211+
{ id: "raw", conversationId: "raw-thread" },
212+
{ id: "other", conversationId: digest32("other") },
213+
];
214+
const queryHash = await hashLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`);
215+
expect(filterLogs(rows, {
216+
...DEFAULT_LOG_FILTER_STATE,
217+
conversationId: `codex://threads/${CODEX_THREAD_ID}`,
218+
conversationQueryHash: queryHash,
219+
}, NOW).map(row => row.id)).toEqual(["hashed"]);
220+
expect(filterLogs(rows, {
221+
...DEFAULT_LOG_FILTER_STATE,
222+
conversationId: "codex://threads/raw-thread",
223+
}, NOW).map(row => row.id)).toEqual(["raw"]);
224+
});
225+
});

‎src/server/request-log-conversation.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ export function normalizeLogConversationId(raw: string | undefined | null): stri
3737
return createHash("sha256").update(trimmed).digest("hex").slice(0, LOG_CONVERSATION_ID_LEN);
3838
}
3939

40+
/**
41+
* Unwrap a pasted `codex://threads/<id>` deep link to the bare thread id. Codex's
42+
* "copy session link" clipboard carries that URI form while clients send the bare id
43+
* on the wire, so Logs search accepts either paste without changing what is persisted.
44+
*/
45+
export function unwrapLogConversationQuery(query: string): string {
46+
const unwrapped = /^codex:\/\/threads\/(.*?)\/*$/i.exec(query.trim())?.[1]?.trim();
47+
return unwrapped || query.trim();
48+
}
49+
4050
/**
4151
* Filter match: accept either the persisted digest or the original preimage
4252
* (so pasting from Logs detail or the client-facing session id both work).
@@ -46,7 +56,7 @@ export function matchesLogConversationId(
4656
query: string | undefined | null,
4757
): boolean {
4858
if (!stored) return false;
49-
const trimmed = typeof query === "string" ? query.trim() : "";
59+
const trimmed = unwrapLogConversationQuery(typeof query === "string" ? query : "");
5060
if (!trimmed) return false;
5161
if (stored === trimmed) return true;
5262
const hashed = normalizeLogConversationId(trimmed);

‎tests/usage/request-log-conversation.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ describe("matchesLogConversationId", () => {
6060
expect(matchesLogConversationId(stored, "other")).toBe(false);
6161
expect(matchesLogConversationId(undefined, raw)).toBe(false);
6262
});
63+
64+
test("unwraps a pasted codex://threads deep link to the bare thread id", () => {
65+
const threadId = "019f6482-67d5-77c2-a643-02daddaa7115";
66+
const stored = digest32(threadId);
67+
expect(matchesLogConversationId(stored, `codex://threads/${threadId}`)).toBe(true);
68+
expect(matchesLogConversationId(stored, ` CODEX://THREADS/${threadId}/ `)).toBe(true);
69+
expect(matchesLogConversationId(threadId, `codex://threads/${threadId}`)).toBe(true);
70+
expect(matchesLogConversationId(stored, "codex://threads/other-thread")).toBe(false);
71+
expect(matchesLogConversationId(stored, "codex://other/x")).toBe(false);
72+
expect(matchesLogConversationId(stored, "codex://threads/")).toBe(false);
73+
});
6374
});
6475

6576
describe("sessionIdHeaderFromRequest", () => {
@@ -192,6 +203,16 @@ describe("request log conversation persistence / filter", () => {
192203
.toEqual(["b"]);
193204
});
194205

206+
test("filterRequestLogs unwraps a pasted codex://threads link", () => {
207+
const threadId = "019f6482-67d5-77c2-a643-02daddaa7115";
208+
const logs = [
209+
log({ requestId: "a", conversationId: digest32(threadId) }),
210+
log({ requestId: "b", conversationId: digest32("conv-2") }),
211+
];
212+
const params = new URLSearchParams(`conversationId=${encodeURIComponent(`codex://threads/${threadId}`)}`);
213+
expect(filterRequestLogs(logs, params).map(e => e.requestId)).toEqual(["a"]);
214+
});
215+
195216
test("hydrated usage rows keep conversationId", () => {
196217
const persisted: PersistedUsageEntry = {
197218
requestId: "round",

0 commit comments

Comments
 (0)