Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
98c8120
fix(link): decide a relayed request's body observation and return its…
lidge-jun Nov 13, 2026
34e45b3
test(link): a relayed POST aborted before its headers never decodes i…
lidge-jun Nov 13, 2026
13df0a9
docs(link): note that the hold check copy keeps the inbound limit res…
lidge-jun Nov 13, 2026
9497a83
fix(responses): read a link turn's upstream only as its client drains…
lidge-jun Nov 13, 2026
68cbe0b
test(link): synchronize the RSS acceptance on the stall the Home repo…
lidge-jun Nov 13, 2026
e9f23c0
fix(responses): keep no parsed copy of the outbound body while a pass…
lidge-jun Nov 13, 2026
891d5a2
docs(structure): a passthrough turn keeps its outbound body as text w…
lidge-jun Nov 13, 2026
24e5be6
fix(responses): release a combo preflight's replayed prefix once the …
lidge-jun Nov 13, 2026
e00c1d7
test(responses): the outbound body copy test also watches the parsed …
lidge-jun Nov 13, 2026
ff07c03
docs(structure): a combo preflight replay releases its prefix and kee…
lidge-jun Nov 13, 2026
f05e87f
test(responses): the combo replay regression buffers its whole multi-…
lidge-jun Nov 13, 2026
87bec00
feat(link): the HTTP link relay reports when it waits for its reader,…
lidge-jun Nov 13, 2026
13bcd2a
fix(link): a link socket hands the pipeline the create it parsed inst…
lidge-jun Nov 13, 2026
329af54
docs(link): where a large link create was held, and the acceptance pa…
lidge-jun Nov 13, 2026
034e68a
fix(link): bind a link create's parsed body to its own request, so co…
lidge-jun Nov 13, 2026
85b8b57
docs(link): a link create's parsed body belongs to its own request
lidge-jun Nov 13, 2026
a108b53
test(link): announce the RSS load's stall only after every reader sta…
lidge-jun Nov 13, 2026
1e90443
docs(link): record the third canonical acceptance run
lidge-jun Nov 13, 2026
eeecec9
test(link): drop the three-turn confirmation; the WebSocket stall is …
lidge-jun Nov 13, 2026
f5ee646
docs(link): record the canonical runs under the final synchronization
lidge-jun Nov 13, 2026
1828c1e
test(responses): pin the combo replay's released slots through its bu…
lidge-jun Nov 13, 2026
6271af5
fix(responses): keep only the outbound body's tool scope for its read…
lidge-jun Nov 13, 2026
aa6d619
fix(link): return a relayed request's lease even when ending its brok…
lidge-jun Nov 13, 2026
0ad9736
test(responses): pin the eager control below the tee allowance and ca…
lidge-jun Nov 13, 2026
b933e2e
docs(structure): the outbound tool scope, the stages before the paced…
lidge-jun Nov 13, 2026
af3d8ea
test(responses): register the extracted bare namespace alias module w…
lidge-jun Nov 13, 2026
af088ba
Merge branch 'fix/responses-stalled-reader-memory' into fix/link-webs…
lidge-jun Nov 13, 2026
dd5f74a
test(link): the acceptance comment names the stall each Home reports
lidge-jun Nov 13, 2026
9d46df1
docs(link): say what the RSS announcements mark, and drop trailing bl…
lidge-jun Nov 13, 2026
eab8bb9
Merge remote-tracking branch 'origin/dev' into fix/responses-stalled-…
lidge-jun Nov 13, 2026
bb45190
Merge branch 'fix/responses-stalled-reader-memory' into fix/link-webs…
lidge-jun Nov 13, 2026
7f74093
Tie fix/responses-stalled-reader-memory (eab8bb900) to its squash f43…
lidge-jun Nov 13, 2026
07de08e
Merge the tie to squash f4386e79a (#8622) into fix/link-websocket-cre…
lidge-jun Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/lib/paced-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ export function carryPacedStream<T extends ReadableStream<Uint8Array>>(source: R
if (source && paced.has(source)) paced.add(output);
return output;
}

12 changes: 11 additions & 1 deletion src/server/index/link-relay-sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { linkActivityCounts, type LinkActivity } from "../../link/child-activity
import type { LinkSessionGrant, LinkUpgradeOutcome } from "./link-websocket";
import type { LinkTrafficBook } from "../../link/traffic";
import { LINK_HOME_FEATURES_HEADER } from "../../link/request-compression";
import { linkRelayWaitObserver } from "./link-websocket-limits";

/** A 200 `GET /v1/catalog` whose body the Child read to the end (wp2 catalog freshness). */
export interface LinkCatalogServed { linkId: string | null; keyId: string | null; etag: string }
Expand Down Expand Up @@ -230,9 +231,14 @@ export function createLinkRelaySessions(options: LinkRelaySessionOptions) {
let ended = false;
// A cancel resolves a pending read as done; that end is not a completed body.
let cancelled = false;
// Test-only stall signal (link-websocket-limits.ts): set from each chunk handed over until the reader asks again.
const waitObserver = sessionLink !== null ? linkRelayWaitObserver() : null;
let waiting = false;
const stopWaiting = (): void => { if (waiting) { waiting = false; waitObserver?.(false); } };
const finish = () => {
if (ended) return;
ended = true;
stopWaiting();
req.signal.removeEventListener("abort", aborted);
release();
};
Expand All @@ -246,10 +252,14 @@ export function createLinkRelaySessions(options: LinkRelaySessionOptions) {
if (req.signal.aborted) aborted();
const body = new ReadableStream<Uint8Array>({
async pull(controller) {
stopWaiting();
try {
const next = await reader.read();
if (next.done) { flow?.end(!cancelled); finish(); controller.close(); if (!cancelled) reportCatalog(); }
else { catalogHash?.update(next.value); flow?.fromHome(next.value.byteLength); controller.enqueue(next.value); }
else {
catalogHash?.update(next.value); flow?.fromHome(next.value.byteLength); controller.enqueue(next.value);
if (waitObserver && !ended) { waiting = true; waitObserver(true); }
}
} catch (error) { flow?.end(false); finish(); controller.error(error); }
},
cancel,
Expand Down
13 changes: 13 additions & 0 deletions src/server/index/link-websocket-limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,16 @@ export function setLinkPumpWaitObserverForTests(observer: ((waiting: boolean) =>
pumpWaitObserver = observer;
}

/**
* Test-only: told when a relayed HTTP link response has handed its reader a chunk and waits for the next read (true),
* and when that wait ends (false). Bun stops reading a body whose socket does not drain, so a stalled Child reader
* leaves its relay waiting: the HTTP counterpart of the pump wait above (#8600).
*/
let relayWaitObserver: ((waiting: boolean) => void) | null = null;

export function linkRelayWaitObserver(): ((waiting: boolean) => void) | null { return relayWaitObserver; }

export function setLinkRelayWaitObserverForTests(observer: ((waiting: boolean) => void) | null): void {
relayWaitObserver = observer;
}

9 changes: 7 additions & 2 deletions src/server/index/websocket-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ import {
} from "../live";
import type { ServeOptionsContext } from "./serve-options";
import type { RequestMetricsRecorder } from "../request-metrics";
import { resolveInboundBodyLimitBytes } from "../request-decompress";
import { attachParsedRequestBody, resolveInboundBodyLimitBytes } from "../request-decompress";
import { responseToolOwnership } from "../responses/response-tool-ownership";
import { runTurnStateCallerScope } from "../turn-state-handles";
import { admitHttpWorkflowTurn, workflowDecisionRefusalResponse } from "../workflow-refusal";
Expand Down Expand Up @@ -345,11 +345,16 @@ export function createWebsocketHandler(
const baseHeaders = ws.data.headers ?? new Headers();
const fwd = new Headers({ "content-type": "application/json" });
baseHeaders.forEach((value, key) => fwd.set(key, value));
// A Remote Link socket hands the pipeline the create it parsed (#8600): serializing it into the request and
// parsing it back would hold two more request-sized copies for the turn. Local sockets keep the request body.
const turnBody = { ...payload, stream: true };
const linkSocket = ws.data.link !== undefined;
const req = new Request("http://localhost/v1/responses", {
method: "POST",
headers: fwd,
body: JSON.stringify({ ...payload, stream: true }),
...(linkSocket ? {} : { body: JSON.stringify(turnBody) }),
});
if (linkSocket) attachParsedRequestBody(req, turnBody);
try {
// A socket can be the first ingress for a root. Admit every inference frame,
// then keep its workflow lease with the turn until terminal output or cancellation.
Expand Down
28 changes: 28 additions & 0 deletions src/server/request-decompress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,31 @@ export function readJsonRequestBody(
): Promise<unknown> {
return readBoundedJsonRequestBody(req, maxBytes, budget);
}

/**
* Admit a body the caller already parsed (a Remote Link WebSocket create, #8600) as if it had been read: its serialized
* size is held to the same limit and observed by the same budget as the parse at the end of the bounded reader.
*/
export function admitParsedJsonRequestBody(body: unknown, maxBytes: number, budget?: TranslatorBudget): unknown {
const parsedBytes = serializedJsonByteLength(body);
if (parsedBytes > maxBytes) throw new DecompressedBodyTooLargeError(parsedBytes, maxBytes, "decoded_exact");
budget?.observeAcceptedRequestCopy(parsedBytes);
return body;
}

/**
* A parsed body bound to the one Request it stands for (#8600). It goes with that request alone: a request the pipeline
* builds for a combo child, a recovery or a retry is another Request and reads its own body. Taken once, like a body.
*/
const parsedBodies = new WeakMap<Request, unknown>();

export function attachParsedRequestBody(req: Request, body: unknown): void {
parsedBodies.set(req, body);
}

export function takeParsedRequestBody(req: Request): { body: unknown } | undefined {
if (!parsedBodies.has(req)) return undefined;
const body = parsedBodies.get(req);
parsedBodies.delete(req);
return { body };
}
1 change: 0 additions & 1 deletion src/server/responses/bare-namespace-aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ export function authorizedBareNamespaceToolAliases(toolNsMap: Iterable<[string,
),
);
}

6 changes: 4 additions & 2 deletions src/server/responses/request-prepare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
restoreCachedEncryptedAgentTasks,
recoverEncryptedAgentTaskWithResult,
} from "./agent-task-recovery";
import { readJsonRequestBody, resolveInboundBodyLimitBytes } from "../request-decompress";
import { admitParsedJsonRequestBody, readJsonRequestBody, resolveInboundBodyLimitBytes, takeParsedRequestBody } from "../request-decompress";
import {
clientCancelledResponse,
decodeRequestErrorResponse,
Expand Down Expand Up @@ -248,7 +248,9 @@ export async function prepareResponsesRequest(
const agentTaskRecovery = agentTaskRecoveryConfig(config);
let body: unknown;
try {
body = await readJsonRequestBody(req, translatorBudget, resolveInboundBodyLimitBytes(config.maxInboundBodyBytes));
const limit = resolveInboundBodyLimitBytes(config.maxInboundBodyBytes);
const attached = takeParsedRequestBody(req);
body = attached ? admitParsedJsonRequestBody(attached.body, limit, translatorBudget) : await readJsonRequestBody(req, translatorBudget, limit);
} catch (err) {
if (options.abortSignal?.aborted || req.signal.aborted) {
return clientCancelledResponse();
Expand Down
Loading
Loading