-
Notifications
You must be signed in to change notification settings - Fork 650
fix(streaming): relay Darwin rewrites eagerly (#1127) #1142
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 |
|---|---|---|
|
|
@@ -2135,6 +2135,8 @@ async function handleResponsesInner( | |
| needsClientRewrite, | ||
| config.streamMode ?? "auto", | ||
| ); | ||
| const inlineEagerRewrite = needsClientRewrite | ||
| && (win32EagerRewrite || eagerPath?.useEagerRelay === true); | ||
|
Comment on lines
+2138
to
+2139
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.
On Darwin with explicit AGENTS.md reference: src/AGENTS.md:L17-L19 Useful? React with 👍 / 👎. |
||
| if (eagerPath?.useEagerRelay || win32EagerRewrite) { | ||
| const turnAc = new AbortController(); | ||
| linkAbortSignal(upstream, turnAc.signal); | ||
|
|
@@ -2191,11 +2193,11 @@ async function handleResponsesInner( | |
| }, | ||
| onClientCancel: () => options.onNativePassthroughCancel?.(), | ||
| onDone: () => unregisterTurn(turnAc), | ||
| }, win32EagerRewrite ? { rewriteBudget: translatorBudget } : undefined); | ||
| }, inlineEagerRewrite ? { rewriteBudget: translatorBudget } : undefined); | ||
|
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.
For Darwin with explicit AGENTS.md reference: src/AGENTS.md:L15-L19 Useful? React with 👍 / 👎. |
||
| // When selected, this relay closes response.completed even if upstream | ||
| // keeps the connection alive. Windows rewrite traffic applies its | ||
| // payload transform inline — never via the Bun#32111-unsafe | ||
| // tee()+JS-pull chain (#864). | ||
| // keeps the connection alive. Windows forced-rewrite traffic and Darwin | ||
| // explicit eager traffic apply client rewrites inline rather than via | ||
| // the tee()+JS-pull chain. | ||
| if (!headers.has("content-type")) headers.set("content-type", "text/event-stream"); | ||
| return markEagerRelaySseResponse( | ||
| markNativePassthroughSseResponse(new Response(eagerBody, { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,18 +270,34 @@ describe("relaySseEagerBounded — inline payload rewrite (#864)", () => { | |
| const budget = createTranslatorBudget(); | ||
| const up = controlledUpstream(); | ||
| const ac = new AbortController(); | ||
| const { hooks } = makeHooks(); | ||
| const { hooks, rec } = makeHooks(); | ||
| let resolveDone!: () => void; | ||
| const done = new Promise<void>(resolve => { resolveDone = resolve; }); | ||
| const previousOnDone = hooks.onDone; | ||
| hooks.onDone = () => { | ||
| previousOnDone(); | ||
| resolveDone(); | ||
| }; | ||
| hooks.rewritePayload = (payload: string) => payload; | ||
| relaySseEagerBounded(up.stream, ac, hooks, { rewriteBudget: budget }); | ||
|
|
||
| up.push(enc.encode(`data: {"type":"unterminated"`)); | ||
| await settle(); | ||
| // The shared terminal boundary now owns incomplete SSE framing, so the | ||
| // downstream rewrite stage never retains an unterminated block. | ||
| expect(budget.snapshot().currentBytes).toBe(0); | ||
| ac.abort(new Error("test abort")); | ||
| await settle(); | ||
| let timeout: ReturnType<typeof setTimeout> | undefined; | ||
| await Promise.race([ | ||
| done, | ||
|
Comment on lines
+290
to
+291
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.
The new AGENTS.md reference: AGENTS.md:L228-L230 Useful? React with 👍 / 👎. |
||
| new Promise<never>((_, reject) => { | ||
| timeout = setTimeout(() => reject(new Error("relay cleanup timed out")), 2_000); | ||
| }), | ||
| ]).finally(() => { | ||
| if (timeout) clearTimeout(timeout); | ||
| }); | ||
| expect(budget.snapshot().currentBytes).toBe(0); | ||
| expect(rec.dones).toBe(1); | ||
| budget.dispose(); | ||
| }); | ||
|
|
||
| test("blocks without a data field pass through untouched before the terminal", async () => { | ||
|
|
||
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.
For
darwin + needsClientRewrite + eager-relay, this selector now returnsconfig-eager, but the module header (src/lib/bun-stream-caps.ts:9-12), the mirror comment (src/server/index.ts:343-345), and the architecture contract (structure/04_transports-and-sidecars.md:51-62) still state that Darwin eager relay is restricted to no-rewrite traffic; the architecture document explicitly requires these descriptions and the platform matrix to remain in lockstep. Update those declarations with this policy change so future maintenance and source-invariant tests do not preserve the obsolete fallback.AGENTS.md reference: src/AGENTS.md:L10-L11
Useful? React with 👍 / 👎.