Skip to content

Commit 37e9294

Browse files
luvs01devin-ai-integration[bot]codex
authored
feat(logs): accept Codex thread links in conversation filters (#6734)
* 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]> (cherry picked from commit 19a0f35) * fix(logs): drop query metadata and bound unwrap of codex://threads links Review feedback on #711: codex://threads/<id>?hostId=… pastes kept the query string in the candidate id so neither raw-id nor digest matching worked, and the lazy-wildcard regex had quadratic backtracking on malformed slash-flooded inputs run per log row. unwrapLogConversationQuery is now a bounded (512-char) linear scan: cut at ? or #, strip trailing slashes, and only return a single-segment id. Regression cases cover durable and percent-encoded remote-control hostId values across the dashboard matcher, GET /api/logs conversationId, and ocx logs filter --conversation. Co-Authored-By: Epinephrine <[email protected]> (cherry picked from commit 6d8225f) * fix(logs): keep literal codex://threads session ids searchable Devin Review on #711: a client that literally sends a codex://threads/… session id has it hashed whole for storage, but unwrapping the paste before hashing meant that digest could never match again — the unwrap must add a match path, not replace one. logConversationQueryCandidates now yields the unwrapped id AND the untouched paste; the server matcher tries each (direct + digest) and the GUI hashes every candidate so filterLogs gets both digests. Co-Authored-By: Epinephrine <[email protected]> (cherry picked from commit 0df8335) * fix(logs): batch conversation-query digests with Promise.all React Doctor flagged the sequential await-in-loop in hashLogConversationQuery; candidates are independent, so map them through crypto.subtle.digest concurrently and keep result order. Co-Authored-By: Devin AI <devin-ai-integration[bot]@users.noreply.github.com> (cherry picked from commit a600bf2) * docs(logs): record pasted thread-link search contract Record the conversation filter contract for the work from luvs01#711, including literal URI compatibility and input bounds. The four original commits remain separately cherry-picked with their author identities and source SHA trailers. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Epinephrine <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Devin AI <devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Codex <[email protected]> Co-authored-by: Epinephrine <[email protected]>
1 parent bb36029 commit 37e9294

10 files changed

Lines changed: 235 additions & 22 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ 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 and any link metadata such
152+
as `?hostId=…` are ignored and the bare thread id is matched, the same value an
153+
`ocx logs filter --conversation` search unwraps.
150154

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

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

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,61 @@ function hasControlChars(value: string): boolean {
1717
return false;
1818
}
1919

20-
/** SHA-256 hex prefix used as the persisted conversation id. */
21-
export async function hashLogConversationQuery(raw: string): Promise<string | undefined> {
22-
const trimmed = raw.trim();
23-
if (!trimmed) return undefined;
24-
if (hasControlChars(trimmed)) return undefined;
25-
if (trimmed.length > 4096) return undefined;
26-
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(trimmed));
27-
return toHex(digest).slice(0, LOG_CONVERSATION_ID_LEN);
20+
const CODEX_THREAD_LINK_PREFIX = "codex://threads/";
21+
const LOG_CONVERSATION_LINK_MAX = 512;
22+
23+
/**
24+
* Unwrap a pasted `codex://threads/<id>` deep link to the bare thread id; query/fragment
25+
* metadata (e.g. `?hostId=…`) is dropped. Bounded linear scan — no ambiguous regex.
26+
* Mirrors src/server/request-log-conversation.unwrapLogConversationQuery.
27+
*/
28+
export function unwrapLogConversationQuery(query: string): string {
29+
const trimmed = query.trim();
30+
if (
31+
trimmed.length > LOG_CONVERSATION_LINK_MAX ||
32+
trimmed.length <= CODEX_THREAD_LINK_PREFIX.length ||
33+
!trimmed.toLowerCase().startsWith(CODEX_THREAD_LINK_PREFIX)
34+
) {
35+
return trimmed;
36+
}
37+
const rest = trimmed.slice(CODEX_THREAD_LINK_PREFIX.length);
38+
const metaIndex = rest.search(/[?#]/);
39+
const segment = (metaIndex === -1 ? rest : rest.slice(0, metaIndex)).replace(/\/+$/, "");
40+
return segment !== "" && !/[/\s]/.test(segment) ? segment : trimmed;
41+
}
42+
43+
/**
44+
* The candidate ids a conversation query may legitimately match: the unwrapped link id
45+
* and the untouched paste — a client may literally send a `codex://threads/…` session
46+
* id, hashed whole for storage. Mirrors the server matcher's candidate set.
47+
*/
48+
function logConversationQueryCandidates(query: string): string[] {
49+
const trimmed = query.trim();
50+
const unwrapped = unwrapLogConversationQuery(trimmed);
51+
return unwrapped === trimmed ? [unwrapped] : [unwrapped, trimmed];
52+
}
53+
54+
/** SHA-256 hex prefixes used as persisted conversation ids, one per query candidate. */
55+
export async function hashLogConversationQuery(raw: string): Promise<string[]> {
56+
const candidates = logConversationQueryCandidates(raw).filter(
57+
candidate => candidate !== "" && !hasControlChars(candidate) && candidate.length <= 4096,
58+
);
59+
const digests = await Promise.all(
60+
candidates.map(candidate =>
61+
crypto.subtle.digest("SHA-256", new TextEncoder().encode(candidate)),
62+
),
63+
);
64+
return digests.map(digest => toHex(digest).slice(0, LOG_CONVERSATION_ID_LEN));
2865
}
2966

3067
export function matchesLogConversationId(
3168
stored: string | undefined,
3269
query: string,
33-
queryHash?: string,
70+
queryHash?: readonly string[],
3471
): boolean {
3572
if (!stored) return false;
36-
const trimmed = query.trim();
37-
if (!trimmed) return false;
38-
if (stored === trimmed) return true;
39-
return queryHash !== undefined && stored === queryHash;
73+
const candidates = logConversationQueryCandidates(query);
74+
if (!candidates.some(Boolean)) return false;
75+
if (candidates.includes(stored)) return true;
76+
return queryHash !== undefined && queryHash.includes(stored);
4077
}

‎gui/src/pages/Logs.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,11 @@ export default function Logs({ apiBase }: { apiBase: string }) {
723723
setFilters(prev => prev.conversationQueryHash === undefined ? prev : { ...prev, conversationQueryHash: undefined });
724724
return;
725725
}
726-
void hashLogConversationQuery(conversationQuery).then(hash => {
727-
if (!cancelled) setFilters(prev => prev.conversationQueryHash === hash ? prev : { ...prev, conversationQueryHash: hash });
726+
void hashLogConversationQuery(conversationQuery).then(hashes => {
727+
if (!cancelled) setFilters(prev =>
728+
prev.conversationQueryHash?.join(" ") === hashes.join(" ")
729+
? prev
730+
: { ...prev, conversationQueryHash: hashes });
728731
});
729732
return () => { cancelled = true; };
730733
}, [conversationQuery]);

‎gui/src/pages/logs-filter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface LogFilterState {
2222
maxTokPerSec?: number;
2323
interceptedOnly: boolean;
2424
conversationId: string;
25-
conversationQueryHash?: string;
25+
conversationQueryHash?: readonly string[];
2626
/** Absent means "all", so filter states saved before this field existed stay valid. */
2727
protocolMode?: LogProtocolModeFilter;
2828
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ test.each(["pointer", "keyboard"] as const)("LogsFilterBar %s reset restores foc
125125
await withFilterBar({
126126
...DEFAULT_LOG_FILTER_STATE, surface: "grok", status: "errors", provider: "xai",
127127
model: "model-a", timeWindow: "1h", minTokPerSec: 50, interceptedOnly: true,
128-
conversationId: "conversation-a", conversationQueryHash: "cached-hash",
128+
conversationId: "conversation-a", conversationQueryHash: ["cached-hash"],
129129
}, async ui => {
130130
expect(ui.container.textContent).toContain("Showing 1 of 2");
131131
const reset = ui.container.querySelector<HTMLButtonElement>(".logs-filter-status button")!;

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

Lines changed: 62 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,63 @@ 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(unwrapLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}?hostId=durable`)).toBe(CODEX_THREAD_ID);
206+
expect(unwrapLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}?hostId=remote-control%3Aexample-environment`)).toBe(CODEX_THREAD_ID);
207+
expect(unwrapLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}#frag`)).toBe(CODEX_THREAD_ID);
208+
expect(await hashLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`))
209+
.toEqual([digest32(CODEX_THREAD_ID), digest32(`codex://threads/${CODEX_THREAD_ID}`)]);
210+
expect(await hashLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}?hostId=durable`))
211+
.toEqual([digest32(CODEX_THREAD_ID), digest32(`codex://threads/${CODEX_THREAD_ID}?hostId=durable`)]);
212+
expect(await hashLogConversationQuery(CODEX_THREAD_ID)).toEqual([digest32(CODEX_THREAD_ID)]);
213+
});
214+
215+
test("a literal codex://threads id a client sent still matches its whole-string digest", async () => {
216+
const uri = `codex://threads/${CODEX_THREAD_ID}`;
217+
const rows = [{ id: "literal", conversationId: digest32(uri) }];
218+
const queryHash = await hashLogConversationQuery(uri);
219+
expect(filterLogs(rows, { ...DEFAULT_LOG_FILTER_STATE, conversationId: uri, conversationQueryHash: queryHash }, NOW)
220+
.map(row => row.id)).toEqual(["literal"]);
221+
});
222+
223+
test("malformed or oversized pastes stay plain queries and never match", () => {
224+
const slashFlood = `codex://threads/${"/".repeat(4000)}\u2028x`;
225+
expect(unwrapLogConversationQuery(slashFlood)).toBe(slashFlood.trim());
226+
expect(unwrapLogConversationQuery("codex://threads/id/extra")).toBe("codex://threads/id/extra");
227+
const rows = [{ id: "hashed", conversationId: digest32(CODEX_THREAD_ID) }];
228+
expect(filterLogs(rows, { ...DEFAULT_LOG_FILTER_STATE, conversationId: slashFlood }, NOW)).toEqual([]);
229+
expect(filterLogs(rows, {
230+
...DEFAULT_LOG_FILTER_STATE,
231+
conversationId: `codex://threads/${CODEX_THREAD_ID}?hostId=durable`,
232+
conversationQueryHash: [digest32(CODEX_THREAD_ID)],
233+
}, NOW).map(row => row.id)).toEqual(["hashed"]);
234+
});
235+
236+
test("filterLogs matches a stored digest or raw id behind the pasted link", async () => {
237+
const rows = [
238+
{ id: "hashed", conversationId: digest32(CODEX_THREAD_ID) },
239+
{ id: "raw", conversationId: "raw-thread" },
240+
{ id: "other", conversationId: digest32("other") },
241+
];
242+
const queryHash = await hashLogConversationQuery(`codex://threads/${CODEX_THREAD_ID}`);
243+
expect(filterLogs(rows, {
244+
...DEFAULT_LOG_FILTER_STATE,
245+
conversationId: `codex://threads/${CODEX_THREAD_ID}`,
246+
conversationQueryHash: queryHash,
247+
}, NOW).map(row => row.id)).toEqual(["hashed"]);
248+
expect(filterLogs(rows, {
249+
...DEFAULT_LOG_FILTER_STATE,
250+
conversationId: "codex://threads/raw-thread",
251+
}, NOW).map(row => row.id)).toEqual(["raw"]);
252+
});
253+
});

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

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,47 @@ 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+
const CODEX_THREAD_LINK_PREFIX = "codex://threads/";
41+
/** Real thread links stay well under this bound; larger pastes skip unwrapping so per-row matching stays cheap. */
42+
const LOG_CONVERSATION_LINK_MAX = 512;
43+
44+
/**
45+
* Unwrap a pasted `codex://threads/<id>` deep link to the bare thread id. Codex's
46+
* "copy session link" clipboard carries that URI form while clients send the bare id
47+
* on the wire, so Logs search accepts either paste without changing what is persisted.
48+
* Query/fragment metadata (e.g. `?hostId=…`) belongs to the link, not the id, and is
49+
* dropped. The scan is a bounded linear walk — no ambiguous regex — because this runs
50+
* per log row on every filter evaluation.
51+
*/
52+
export function unwrapLogConversationQuery(query: string): string {
53+
const trimmed = query.trim();
54+
if (
55+
trimmed.length > LOG_CONVERSATION_LINK_MAX ||
56+
trimmed.length <= CODEX_THREAD_LINK_PREFIX.length ||
57+
!trimmed.toLowerCase().startsWith(CODEX_THREAD_LINK_PREFIX)
58+
) {
59+
return trimmed;
60+
}
61+
const rest = trimmed.slice(CODEX_THREAD_LINK_PREFIX.length);
62+
const metaIndex = rest.search(/[?#]/);
63+
const segment = (metaIndex === -1 ? rest : rest.slice(0, metaIndex)).replace(/\/+$/, "");
64+
// A thread id is a single path segment; deeper paths or embedded whitespace keep the
65+
// whole paste as the query, so foreign `codex://` URIs still fail to match.
66+
return segment !== "" && !/[/\s]/.test(segment) ? segment : trimmed;
67+
}
68+
69+
/**
70+
* The candidate ids a conversation query may legitimately match. Unwrapping a pasted
71+
* `codex://threads/<id>` link must add a match path, not replace one: a client can
72+
* literally send a `codex://threads/…` session id, which is hashed whole for storage,
73+
* so the untouched paste stays a candidate too.
74+
*/
75+
export function logConversationQueryCandidates(query: string): string[] {
76+
const trimmed = query.trim();
77+
const unwrapped = unwrapLogConversationQuery(trimmed);
78+
return unwrapped === trimmed ? [unwrapped] : [unwrapped, trimmed];
79+
}
80+
4081
/**
4182
* Filter match: accept either the persisted digest or the original preimage
4283
* (so pasting from Logs detail or the client-facing session id both work).
@@ -46,11 +87,13 @@ export function matchesLogConversationId(
4687
query: string | undefined | null,
4788
): boolean {
4889
if (!stored) return false;
49-
const trimmed = typeof query === "string" ? query.trim() : "";
50-
if (!trimmed) return false;
51-
if (stored === trimmed) return true;
52-
const hashed = normalizeLogConversationId(trimmed);
53-
return hashed !== undefined && stored === hashed;
90+
for (const candidate of logConversationQueryCandidates(typeof query === "string" ? query : "")) {
91+
if (!candidate) continue;
92+
if (stored === candidate) return true;
93+
const hashed = normalizeLogConversationId(candidate);
94+
if (hashed !== undefined && stored === hashed) return true;
95+
}
96+
return false;
5497
}
5598

5699
/**

‎structure/dashboard-and-usage.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ re-validated on read; the Logs list shows it as a text badge, the detail dialog
569569
`src/server/request-log-filter.ts` owns the `/api/logs` query filters including `protocolMode`; its single-pass query applies provider, conversation, model, account, protocol mode and status before `tail`, then reports the pre-pagination count alongside the offset/limit page.
570570
[Protocol Paths](data-planes/protocol-paths.md) owns its derivation.
571571

572+
Conversation searches in the dashboard, `/api/logs` and `ocx logs filter --conversation` accept `codex://threads/<id>` links up to 512 characters, including query/fragment metadata, trailing slashes and surrounding whitespace. The server matcher in `src/server/request-log-conversation.ts` and its browser mirror in `gui/src/log-conversation-id.ts` try both the extracted single-segment id and the original trimmed query, preserving raw-id and whole-literal-URI digest matching. The prefix is case-insensitive; the id retains its case. Malformed or longer links remain plain queries subject to the existing 4096-character digest-input bound. Persistence is unchanged.
572573
Rows may also carry `genStartMs` and `lastOutputMs`, an observed request-relative pair recorded by `src/server/request-log-generation-window.ts` from the Responses and Anthropic SSE taps: the first output item or content block (reasoning included) to the last output delta. They are proxy observation times, not provider-internal token timing, and `src/usage/log.ts` keeps them only as a pair of nonnegative finite values with `lastOutputMs >= genStartMs`. `decodeTokPerSecondResult` in `src/server/management/shared.ts` prefers that window when the pair is valid and otherwise falls back to the post-TTFT window (`durationMs - firstOutputMs`); both keep the one-second minimum, the `ttft_missing` / `decode_window_too_short` unavailable reasons and `estimated: true`, so a short measured window is still an estimate rather than a provider decode benchmark. The end-to-end tok/s column is unchanged, attempts carry no generation window of their own, and the request-history view does not present one. Successful decode DTOs additionally expose `timingBasis: "generation-window" | "legacy-post-visible-output"`, derived at read time only. Logs labels the method “Generation window” or “After visible output” in the list and attempt table and uses “Output rate during generation (est.)” or “Output rate after first visible output (est.)” in request details. Missing or unfamiliar bases show “Timing unknown” and “Output rate (est.; timing method unknown)” in details rather than inferring a method. The detail grid shows a full-width muted caption explaining the method only when the decode rate is available. Both numerators include reported reasoning output tokens, so the two estimates are not directly comparable. Historical JSONL and end-to-end rates are unchanged.
573574

574575
Request-history selectors longer than 130 characters persist as a prefix plus a digest of the complete

‎tests/cli/cli-log-view-filter.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ test("conversation digest and preimage use the existing owner, including alias s
135135
expect(filterLogs(logs, { ...DEFAULT_LOG_FILTER_STATE, conversationId: "hello", conversationQueryHash: await hashLogConversationQuery("hello") }, NOW).map(row => row.id)).toEqual(["digest", "direct"]);
136136
expect(await run(logs, ["--conversationId", digest])).toBe(0);
137137
expect(ids()).toEqual(["digest"]);
138+
expect(await run(logs, ["--conversation=codex://threads/hello?hostId=durable"])).toBe(0);
139+
expect(ids()).toEqual(["digest", "direct"]);
138140
});
139141

140142
test("modern scope counts ignore server totals and unknown metadata, preserving recent ordered duplicates", async () => {

0 commit comments

Comments
 (0)