Apply backpressure to app-server request replay on thread resume (#62609)

## Why

When a client resumes a thread with many pending server requests, replay
can fill the connection's bounded outbound queue if the client reads
slowly. Replaying inline can also stall the thread listener.

## What changed

Replay pending requests in a background task after sending the
`thread/resume` response. Allow one outstanding replay write per
connection and wait for its write receipt to complete or be dropped
before sending the next request. This extends the write-receipt
backpressure used by `command/exec`.
https://github.com/openai/codex/pull/15547

A new resume replaces the previous replay for the same thread and
connection while honoring any outstanding write receipt. Unsubscribing
or disconnecting stops the replay. Before sending each request, check
that it is still pending and apply the human approval eligibility check
where required.

## Testing

Add a regression test with more pending requests than the outbound queue
can hold. It checks that a second resume succeeds while a replay write is
stalled, dropped write receipts let replay advance, and unsubscribe and
disconnect stop replay.

GitOrigin-RevId: 77fc415be0e7b50744f5ccfcaa09857359dd5c55
This commit is contained in:
ztanner-oai
2026-11-19 22:15:23 +00:00
committed by copyberry
parent efcc0cf917
commit 6633c6e09a
7 changed files with 386 additions and 48 deletions
@@ -881,6 +881,7 @@ impl MessageProcessor {
connection_id: ConnectionId,
request_attestation: bool,
) {
self.outgoing.connection_initialized(connection_id).await;
self.account_processor
.notify_workspace_routing_to_connection(connection_id);
self.thread_processor
@@ -943,6 +944,7 @@ impl MessageProcessor {
session_state: &ConnectionSessionState,
) {
session_state.disconnect.cancel();
self.outgoing.stop_connection_replays(connection_id).await;
session_state.rpc_gate.close().await;
self.account_processor
.gateway_connection_closed(connection_id);