Repository navigation
fix(codex): log a late reply to a timed-out request instead of showing it in the chat #23893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { | |
| import { classifyJsonRpcPrefix } from './codex-app-server-record-prefix' | ||
|
|
||
| const OVERSIZED_REQUEST_ERROR_CODE = -32001 | ||
| const MAX_REMEMBERED_TIMEOUTS = 64 | ||
|
|
||
| export type CodexPendingRequest = { | ||
| method: string | ||
|
|
@@ -25,11 +26,26 @@ export function createCodexAppServerRecordDispatcher(input: { | |
| }): { | ||
| addPending: (id: number, waiter: CodexPendingRequest) => void | ||
| deletePending: (id: number) => void | ||
| timeOutPending: (id: number) => void | ||
| failPending: (error: Error) => void | ||
| dispatch: (message: Record<string, unknown>) => void | ||
| rejectOversized: (rejected: NdjsonRejectedRecord & { kind: 'line-too-long' }) => void | ||
| } { | ||
| const pending = new Map<number, CodexPendingRequest>() | ||
| const timedOutMethods = new Map<number, string>() | ||
|
|
||
| const timeOutPending = (id: number): void => { | ||
| const waiter = pending.get(id) | ||
| if (!waiter) { | ||
| return | ||
| } | ||
| pending.delete(id) | ||
| timedOutMethods.set(id, waiter.method) | ||
| const oldest = timedOutMethods.keys().next() | ||
| if (timedOutMethods.size > MAX_REMEMBERED_TIMEOUTS && !oldest.done) { | ||
| timedOutMethods.delete(oldest.value) | ||
| } | ||
| } | ||
|
|
||
| const failPending = (error: Error): void => { | ||
| for (const waiter of pending.values()) { | ||
|
|
@@ -72,7 +88,17 @@ export function createCodexAppServerRecordDispatcher(input: { | |
| } | ||
| const waiter = pending.get(message.id) | ||
| if (!waiter) { | ||
| input.handlers.onUnhandledFrame?.('response:unmatched', message) | ||
| // Transport diagnostics, not conversation: only the request that gave up could have | ||
| // interpreted this reply, and it already reported its own outcome. | ||
| const timedOutMethod = timedOutMethods.get(message.id) | ||
| timedOutMethods.delete(message.id) | ||
| const error = isAppServerRecord(message.error) ? message.error.message : undefined | ||
| console.warn( | ||
| timedOutMethod | ||
| ? `[codex-app-server] late reply to ${timedOutMethod} after timeout (id ${message.id})` | ||
| : `[codex-app-server] reply with no waiting request (id ${message.id})`, | ||
| ...(typeof error === 'string' ? [error] : []) | ||
| ) | ||
| return | ||
|
Comment on lines
+95
to
102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a Knowledge Base Used: Restore Native Chat Session Admission Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| } | ||
| pending.delete(message.id) | ||
|
|
@@ -160,6 +186,7 @@ export function createCodexAppServerRecordDispatcher(input: { | |
| return { | ||
| addPending: (id, waiter) => pending.set(id, waiter), | ||
| deletePending: (id) => pending.delete(id), | ||
| timeOutPending, | ||
| failPending, | ||
| dispatch, | ||
| rejectOversized | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every unmatched reply now produces a warning, including its full error message. The reader accepts lines of unlimited length, and the 64-entry limit only caps remembered request methods—not warnings. Repeated replies or a very large error can therefore produce excessive host log output. Consider bounding or coalescing these diagnostics.