fix: broaden thread id capture
This commit is contained in:
+61
-2
@@ -63,23 +63,44 @@ const REASONING_POINTERS = [
|
||||
];
|
||||
const REQUEST_THREAD_ID_POINTERS = [
|
||||
"/thread_id",
|
||||
"/client_metadata/thread_id",
|
||||
"/client_metadata/x-codex-thread-id",
|
||||
"/thread",
|
||||
"/thread/id",
|
||||
"/threadId",
|
||||
"/client_metadata/threadId",
|
||||
"/conversation_id",
|
||||
"/conversationId",
|
||||
"/conversation",
|
||||
"/conversation/id",
|
||||
"/metadata/thread_id",
|
||||
"/metadata/threadId",
|
||||
"/metadata/conversation_id",
|
||||
"/metadata/conversationId",
|
||||
"/x-codex-turn-metadata/thread_id",
|
||||
"/x-codex-turn-metadata/threadId",
|
||||
"/x-codex-turn-metadata/conversation_id",
|
||||
"/x-codex-turn-metadata/conversationId",
|
||||
"/previous_response_id",
|
||||
];
|
||||
const RESPONSE_THREAD_ID_POINTERS = [
|
||||
"/thread_id",
|
||||
"/client_metadata/thread_id",
|
||||
"/client_metadata/x-codex-thread-id",
|
||||
"/thread",
|
||||
"/thread/id",
|
||||
"/threadId",
|
||||
"/client_metadata/threadId",
|
||||
"/conversation_id",
|
||||
"/conversationId",
|
||||
"/conversation",
|
||||
"/conversation/id",
|
||||
"/response/thread_id",
|
||||
"/response/threadId",
|
||||
"/response/thread",
|
||||
"/response/thread/id",
|
||||
"/response/conversation_id",
|
||||
"/response/conversationId",
|
||||
"/response/conversation",
|
||||
"/response/conversation/id",
|
||||
];
|
||||
@@ -217,6 +238,38 @@ function extractResponseThreadId(payload) {
|
||||
return extractStringByPointers(payload, RESPONSE_THREAD_ID_POINTERS);
|
||||
}
|
||||
|
||||
function extractHeaderThreadId(headers) {
|
||||
if (!headers || typeof headers !== "object") {
|
||||
return null;
|
||||
}
|
||||
const candidates = [
|
||||
"thread-id",
|
||||
"x-client-request-id",
|
||||
"conversation_id",
|
||||
"conversation-id",
|
||||
"session_id",
|
||||
"session-id",
|
||||
"x-codex-parent-thread-id",
|
||||
];
|
||||
for (const key of candidates) {
|
||||
const raw = headers[key];
|
||||
if (Array.isArray(raw)) {
|
||||
for (const item of raw) {
|
||||
const text = firstNonEmptyString(item);
|
||||
if (text) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const text = firstNonEmptyString(raw);
|
||||
if (text) {
|
||||
return text;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function extractNonStreamingResponseId(payload) {
|
||||
return extractStringByPointers(payload, NON_STREAM_RESPONSE_ID_POINTERS);
|
||||
}
|
||||
@@ -1312,7 +1365,10 @@ function buildRequestEntry({ seq, startedAt, startedMs, req, pathname, requestJs
|
||||
seq,
|
||||
request_id: null,
|
||||
response_id: null,
|
||||
thread_id: extractRequestThreadId(requestJson),
|
||||
thread_id: firstNonEmptyString(
|
||||
extractRequestThreadId(requestJson),
|
||||
extractHeaderThreadId(req?.headers),
|
||||
),
|
||||
lifecycle_state: "sent",
|
||||
started_at: startedAt.toISOString(),
|
||||
first_response_at: null,
|
||||
@@ -3234,7 +3290,10 @@ async function proxyRequest(runtime, req, res) {
|
||||
let totalUpstreamAttempts = 0;
|
||||
requestEntry.request_body_bytes = rawRequestBody.length;
|
||||
requestEntry.request_id = computeRequestId(pathname, rawRequestBody);
|
||||
requestEntry.thread_id = extractRequestThreadId(parsedRequestJson);
|
||||
requestEntry.thread_id = firstNonEmptyString(
|
||||
extractRequestThreadId(parsedRequestJson),
|
||||
extractHeaderThreadId(req.headers),
|
||||
);
|
||||
requestEntry.model = requestJson?.model || null;
|
||||
requestEntry.requested_model = parsedRequestJson?.model || null;
|
||||
requestEntry.forwarded_model = forwardedModel || parsedRequestJson?.model || null;
|
||||
|
||||
Reference in New Issue
Block a user