Repository navigation
Conversation
lidge-jun
left a comment
There was a problem hiding this comment.
Reviewed against the #44 root-cause analysis — this is on the right track and well-scoped.
What it fixes: the gate at src/server.ts:528 changes from if (terminalBodyWillRecord && recordTerminalOutcomes) to if (recordTerminalOutcomes), with terminalRecorder?.(status) optional-chained. So native passthrough SSE now runs consumeForInspection (which finalizes /api/logs + records usage) even when no Codex pool terminal recorder is active. That closes the secondary gap we identified — the consumeForResponseLogMetadata else-branch that inspected metadata but never finalized an entry. The regression test (completed native SSE with usage → /api/logs + /api/usage both reflect 18 tokens) is a good, targeted proof.
One gap worth confirming before merge: the primary symptom in #44 is successful turns going missing because Codex disconnects the client the instant it finishes consuming, which aborts the shared signal while the teed inspection branch (branch[1]) is still draining. On that path consumeForInspection sets cancelled = true and the abort listener cancels the reader — so onTerminal("incomplete") is guarded out (if (!reported && !cancelled)) and reportNativeTerminal never fires. This PR makes the recorder reachable without a pool recorder, but if the success terminal SSE block hasn't been parsed before the abort lands, the entry can still be missed. Two things would de-risk it:
- A regression test for success-then-immediate-client-disconnect (not just clean completion), asserting exactly one
/api/logsentry. - Confirm whether a cancel finalizer (
499/closeReason: "client_cancel") is still wanted on the abort path, or is intentionally out of scope for this PR.
Verification in the description (server-auth 30 pass, typecheck pass, request-log + passthrough-abort 22 pass) looks solid. No double-logging concern given the reported guard. Targets dev — fine. Approving direction; suggest the success-then-disconnect test before merge.
|
Reviewed against the #44 root-cause analysis — on the right track and well-scoped. What it fixes: the gate at One gap worth confirming before merge: the primary symptom in #44 is successful turns going missing because Codex disconnects the client the instant it finishes consuming, aborting the shared signal while the teed inspection branch is still draining. On that path
Verification (server-auth 30 pass, typecheck pass, request-log + passthrough-abort 22 pass) looks solid; |
Cherry-picked 2481c80 (fix(logs): finalize native passthrough SSE usage, author 0disoft). Documents the dirty-tree-safe stash/pop strategy, the recovered stash incident, and verification (57 tests, tsc clean).
Cherry-picked ea9d8b8 (fix(logs): finalize native passthrough SSE usage, author 0disoft). Documents the dirty-tree-safe stash/pop strategy, the recovered stash incident, and verification (57 tests, tsc clean).
Summary
/api/logsand/api/usagereceive reported usage from a completed native passthrough SSE responseRefs #44.
Why
Native passthrough SSE responses are marked with
markNativePassthroughSseResponse(...), soresponseWithDeferredRequestLog(...)intentionally skips the normal client-facing SSE logging wrapper. Before this change, the background inspection path finalized the request log only whenterminalBodyWillRecordwas true, which requires a Codex forward/pool terminal recorder.That left key-based native
openai-responsespassthrough streams able to deliver the upstream response while not finalizing the request log entry. The usage dashboard then could miss the completed request, or fail to count reported usage that was present in the terminal SSE payload.Changed Behavior
/api/logsVerification
bun test tests/server-auth.test.ts-> 30 passbun run typecheck-> passbun test tests/request-log.test.ts tests/passthrough-abort.test.ts-> 22 passgit diff --check-> passNotes
This only records usage when the upstream terminal SSE payload includes usage. If the native ChatGPT/OpenAI upstream omits usage entirely, the request can still be finalized as unreported; this PR does not synthesize usage from Codex session files.