The best way to control Claude Code, Codex and more from any computer or phone
fix(server): agent activity publish keeps retrying after a network drop (#39402)
Julius Marminge committed
Nov 19, 2026 at 14:54 UTC
cb391b5b5741553ef136d93486a3f6cf89d0c026
2 files changed
+55
-8
apps/server/src/relay/AgentAwarenessRelay.test.ts
+44
-3
@@ -291,9 +291,13 @@ const makeTestRelay = Effect.fnUntraced(function* (
291
authorization: new Headers(init?.headers).get("authorization"),
292
state: payload.state,
293
});
294
- return Promise.resolve(
295
- options.respond?.(publications.length) ?? Response.json({ ok: true, deliveries: [] }),
296
- );
294
+ try {
295
+ return Promise.resolve(
296
+ options.respond?.(publications.length) ?? Response.json({ ok: true, deliveries: [] }),
297
+ );
298
+ } catch (error) {
299
+ return Promise.reject(error);
300
+ }
301
},
302
{ preconnect: () => {} },
303
);
@@ -972,6 +976,43 @@ describe("AgentAwarenessRelay", () => {
976
}),
977
);
978
979
+ it.effect("delivers a completion once the network returns after the retry budget runs out", () =>
980
+ Effect.gen(function* () {
981
+ let networkUp = true;
982
+ const delivered: Array<string | null> = [];
983
+ const { relay, currentShell, publications } = yield* makeTestRelay({
984
+ respond: (attempt) => {
985
+ if (!networkUp) throw new TypeError("fetch failed: getaddrinfo EAI_AGAIN");
986
+ delivered.push(publications[attempt - 1]?.state?.phase ?? null);
987
+ return Response.json({ ok: true, deliveries: [] });
988
+ },
989
+ });
990
+ yield* relay.publishThread(THREAD_ID);
991
+ networkUp = false;
992
+ yield* Ref.set(currentShell, shell({ status: "completed" }));
993
+ yield* relay.publishThread(THREAD_ID);
994
+ yield* TestClock.adjust("5 seconds");
995
+ yield* relay.drain;
996
+ for (const delay of [
997
+ "1 second",
998
+ "2 seconds",
999
+ "4 seconds",
1000
+ "8 seconds",
1001
+ "16 seconds",
1002
+ ] as const) {
1003
+ yield* TestClock.adjust(delay);
1004
+ yield* relay.drain;
1005
+ }
1006
+ assert.equal(publications.length, 7);
1007
+ assert.deepEqual(delivered, ["running"]);
1008
+
1009
+ networkUp = true;
1010
+ yield* TestClock.adjust("10 minutes");
1011
+ yield* relay.drain;
1012
+ assert.deepEqual(delivered, ["running", "completed"]);
1013
+ }),
1014
+ );
1015
+
1016
it.effect("keeps settled live work until its awaited monitor finishes", () =>
1017
Effect.gen(function* () {
1018
const { relay, currentShell, publications } = yield* makeTestRelay();
apps/server/src/relay/AgentAwarenessRelay.ts
+11
-5
@@ -205,6 +205,8 @@ function resolveAgentActivityPublishingStartupState(input: {
205
const RELAY_AGENT_ACTIVITY_DETAIL_MAX_LENGTH = 160;
206
const REDACTED_RELAY_AGENT_FAILURE_DETAIL = "The agent run failed.";
207
const RELAY_AGENT_ACTIVITY_RETRY_DELAYS_MS = [1_000, 2_000, 4_000, 8_000, 16_000] as const;
208
+// Nothing else re-queues a thread when the network returns, so a lost terminal state is retried until it lands.
209
+const RELAY_AGENT_ACTIVITY_STEADY_RETRY_DELAY_MS = 60_000;
210
211
function sanitizeRelayAgentActivityState(
212
state: RelayAgentActivityState | null,
@@ -820,11 +822,15 @@ export const make = Effect.gen(function* () {
822
823
schedulePublishRetry = Effect.fnUntraced(function* (threadId: ThreadId) {
824
const attempts = publishRetries.get(threadId)?.attempts ?? 0;
823
- const delayMs = RELAY_AGENT_ACTIVITY_RETRY_DELAYS_MS[attempts];
824
- if (delayMs === undefined) {
825
- // Retain exhausted budgets until activity or success resets them; old timers must not restart retries.
826
- yield* Effect.logWarning("agent activity publish retry budget exhausted", { threadId });
827
- return;
825
+ const delayMs =
826
+ RELAY_AGENT_ACTIVITY_RETRY_DELAYS_MS[attempts] ?? RELAY_AGENT_ACTIVITY_STEADY_RETRY_DELAY_MS;
827
+ if (attempts === RELAY_AGENT_ACTIVITY_RETRY_DELAYS_MS.length) {
828
+ yield* Effect.logWarning(
829
+ "agent activity publish retry budget exhausted; retrying every minute",
830
+ {
831
+ threadId,
832
+ },
833
+ );
834
}
835
const retry = {
836
attempts: attempts + 1,