Skip to content

Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy

Rust

forward codex keepalives as stream pings

Raine Virta1410db255525
diff --git a/src/providers/codex/translate/reducer.ts b/src/providers/codex/translate/reducer.ts
index 7773aa1..2d1e4b3 100644
--- a/src/providers/codex/translate/reducer.ts
+++ b/src/providers/codex/translate/reducer.ts
@@ -29,6 +29,7 @@ export type ReducerEvent =
| { kind: "tool-start"; index: number; id: string; name: string }
| { kind: "tool-delta"; index: number; partialJson: string }
| { kind: "tool-progress"; index: number }
+ | { kind: "progress" }
| { kind: "tool-stop"; index: number }
| { kind: "finish"; stopReason: StopReason; usage: CodexUsage | undefined };
@@ -124,6 +125,11 @@ export async function* reduceUpstream(
p.rate_limits?.primary?.reset_after_seconds,
);
}
+ yield { kind: "progress" };
+ continue;
+ }
+ if (t === "keepalive") {
+ yield { kind: "progress" };
continue;
}
if (t === "response.failed" || t === "response.error" || t === "error") {
diff --git a/src/providers/codex/translate/stream.test.ts b/src/providers/codex/translate/stream.test.ts
index a8cf2cb..dcb0505 100644
--- a/src/providers/codex/translate/stream.test.ts
+++ b/src/providers/codex/translate/stream.test.ts
@@ -86,6 +86,35 @@ describe("translateStream", () => {
}
});
+ it("emits keepalive pings for upstream keepalive events", async () => {
+ Date.now = () => now;
+ try {
+ const chunks = [
+ sse("response.output_item.added", {
+ output_index: 0,
+ item: { type: "message", id: "msg_upstream" },
+ }),
+ sse("keepalive", {}),
+ sse("keepalive", {}),
+ sse("response.completed", { response: { usage: {} } }),
+ ];
+
+ const output = await collect(
+ translateStream(upstreamFromChunks(chunks, 16_000), {
+ messageId: "msg_1",
+ model: "gpt-5.5",
+ log: silentLog,
+ }),
+ );
+
+ expect(output.match(/event: ping/g)?.length).toBeGreaterThanOrEqual(2);
+ expect(output).toContain("event: message_stop");
+ } finally {
+ Date.now = realNow;
+ now = 0;
+ }
+ });
+
it("treats aborted upstream reads as cancellation", async () => {
const abort = new AbortController();
abort.abort();
diff --git a/src/providers/codex/translate/stream.ts b/src/providers/codex/translate/stream.ts
index e6c18d6..878bcbe 100644
--- a/src/providers/codex/translate/stream.ts
+++ b/src/providers/codex/translate/stream.ts
@@ -137,6 +137,7 @@ export function translateStream(
});
break;
case "tool-progress":
+ case "progress":
emitPingIfStale();
break;
case "tool-stop":