diff --git a/apps/server/src/relay/AgentAwarenessRelay.test.ts b/apps/server/src/relay/AgentAwarenessRelay.test.ts index d7ad9ed1b1746..dacaa9281f459 100644 --- a/apps/server/src/relay/AgentAwarenessRelay.test.ts +++ b/apps/server/src/relay/AgentAwarenessRelay.test.ts @@ -790,7 +790,7 @@ describe("AgentAwarenessRelay", () => { }), ); - it.effect("still publishes a completion when the thread settles during the hold", () => + it.effect("clears instead of alerting when the thread settles during the completion hold", () => Effect.gen(function* () { const { relay, currentShell, publications } = yield* makeTestRelay(); yield* relay.publishThread(THREAD_ID); @@ -808,14 +808,14 @@ describe("AgentAwarenessRelay", () => { yield* relay.drain; assert.deepEqual( publications.map((publication) => publication.state?.phase ?? null), - ["running", "completed"], + ["running", null], ); yield* TestClock.adjust("5 seconds"); yield* relay.drain; assert.deepEqual( publications.map((publication) => publication.state?.phase ?? null), - ["running", "completed", null], + ["running", null], ); }), ); @@ -888,43 +888,45 @@ describe("AgentAwarenessRelay", () => { }), ); - it.effect("alerts a completion settled during its hold after an earlier tombstone", () => - Effect.gen(function* () { - yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe(NOW))); - const { relay, currentShell, publications } = yield* makeTestRelay(); - const settledAt = DateTime.makeUnsafe(NOW); - yield* Ref.set(currentShell, { - ...shell({ status: "completed" }), - settledOverride: "settled", - settledAt, - lastVisitedAt: null, - }); - yield* relay.publishThread(THREAD_ID); - yield* TestClock.adjust("5 seconds"); - yield* relay.drain; + it.effect( + "does not alert when a completion settles during its hold after an earlier tombstone", + () => + Effect.gen(function* () { + yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe(NOW))); + const { relay, currentShell, publications } = yield* makeTestRelay(); + const settledAt = DateTime.makeUnsafe(NOW); + yield* Ref.set(currentShell, { + ...shell({ status: "completed" }), + settledOverride: "settled", + settledAt, + lastVisitedAt: null, + }); + yield* relay.publishThread(THREAD_ID); + yield* TestClock.adjust("5 seconds"); + yield* relay.drain; - const completed = shell({ - status: "completed", - latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T12:00:06.000Z"), - }); - yield* Ref.set(currentShell, completed); - yield* relay.publishThread(THREAD_ID); - yield* Ref.set(currentShell, { - ...completed, - settledOverride: "settled", - settledAt, - lastVisitedAt: null, - }); - yield* relay.publishThread(THREAD_ID); - yield* TestClock.adjust("5 seconds"); - yield* relay.drain; - yield* TestClock.adjust("5 seconds"); - yield* relay.drain; - assert.deepEqual( - publications.map((publication) => publication.state?.phase ?? null), - [null, "completed", null], - ); - }), + const completed = shell({ + status: "completed", + latestRunCompletedAt: DateTime.makeUnsafe("2026-09-04T12:00:06.000Z"), + }); + yield* Ref.set(currentShell, completed); + yield* relay.publishThread(THREAD_ID); + yield* Ref.set(currentShell, { + ...completed, + settledOverride: "settled", + settledAt, + lastVisitedAt: null, + }); + yield* relay.publishThread(THREAD_ID); + yield* TestClock.adjust("5 seconds"); + yield* relay.drain; + yield* TestClock.adjust("5 seconds"); + yield* relay.drain; + assert.deepEqual( + publications.map((publication) => publication.state?.phase ?? null), + [null], + ); + }), ); it.effect("drops a held completion when a queued continuation hides the thread", () => @@ -944,7 +946,7 @@ describe("AgentAwarenessRelay", () => { }), ); - it.effect("retries a failed completion even after the thread settles", () => + it.effect("clears instead of retrying a failed completion after the thread settles", () => Effect.gen(function* () { const { relay, currentShell, publications } = yield* makeTestRelay({ respond: (attempt) => @@ -968,12 +970,12 @@ describe("AgentAwarenessRelay", () => { yield* relay.drain; assert.deepEqual( publications.map((publication) => publication.state?.phase ?? null), - ["running", "completed", "completed"], + ["running", "completed", null], ); yield* TestClock.adjust("5 seconds"); yield* relay.drain; - assert.equal(publications.at(-1)?.state ?? null, null); + assert.equal(publications.length, 3); }), ); diff --git a/apps/server/src/relay/AgentAwarenessRelay.ts b/apps/server/src/relay/AgentAwarenessRelay.ts index 2eed87a8033bd..64edea886fcd5 100644 --- a/apps/server/src/relay/AgentAwarenessRelay.ts +++ b/apps/server/src/relay/AgentAwarenessRelay.ts @@ -478,8 +478,6 @@ export const make = Effect.gen(function* () { // Confirm through the same worker so tombstones cannot race live updates; recovery clears the deadline. const publishConfirmDeadlines = new Map(); - // Threads whose confirmation holds a completion, so a thread that settles during the hold still alerts. - const heldCompletions = new Set(); let schedulePublishConfirm: (threadId: ThreadId) => Effect.Effect = () => Effect.void; const publishRetries = new Map< ThreadId, @@ -499,7 +497,6 @@ export const make = Effect.gen(function* () { publishedRelayConfig = undefined; cachedRelayClient = undefined; publishConfirmDeadlines.clear(); - heldCompletions.clear(); yield* Ref.set(publishedStateByThreadRef, new Map()); }); @@ -611,14 +608,9 @@ export const make = Effect.gen(function* () { ) { if (Option.isNone(thread) || !terminalWorkSinceStart(thread.value, startedAt)) return; } - if ( - publishedStateByThread.get(threadId) === publishIdentity && - // A held completion settled after an earlier clear still has to alert. - !(snapshot.state === null && heldCompletions.has(threadId)) - ) { + if (publishedStateByThread.get(threadId) === publishIdentity) { // Clear moot deadlines so later transient nulls cannot skip their deferral window. publishConfirmDeadlines.delete(threadId); - heldCompletions.delete(threadId); yield* Effect.logDebug("agent activity publish skipped; projected state unchanged", { environmentId, threadId, @@ -632,7 +624,6 @@ export const make = Effect.gen(function* () { // alerts on every move into completed. const requiresConfirmation = snapshot.state === null || snapshot.state?.phase === "completed"; if (requiresConfirmation) { - if (snapshot.state?.phase === "completed") heldCompletions.add(threadId); const nowMs = (yield* DateTime.now).epochMilliseconds; const deadline = publishConfirmDeadlines.get(threadId); if (deadline === undefined) { @@ -657,38 +648,8 @@ export const make = Effect.gen(function* () { statePhase: snapshot.state?.phase ?? null, shell: describeThreadShellForAwareness(thread), }); - // Settled during the hold, not resumed: alert the current completion, then clear the card - // on a new window. Only settlement may hide it; queued or silent runs also project to null. - const unsettled = - snapshot.state === null && - heldCompletions.has(threadId) && - Option.isSome(thread) && - thread.value.settledOverride === "settled" - ? resolveAgentAwarenessRelayPublishSnapshot({ - environmentId, - thread: Option.some({ ...thread.value, settledOverride: null }), - project, - pendingSubagentRequest: null, - }) - : null; - if (unsettled?.state?.phase === "completed") { - const completion = unsettled.state; - yield* publishState({ - projectId: unsettled.projectId, - state: completion, - reason: unsettled.reason, - }).pipe(withRelayClientTracing); - heldCompletions.delete(threadId); - publishConfirmDeadlines.set(threadId, nowMs + 5_000); - yield* Ref.update(publishedStateByThreadRef, (publishedStates) => - new Map(publishedStates).set(threadId, agentAwarenessPublishIdentity(completion)), - ); - yield* schedulePublishConfirm(threadId); - return; - } } else { publishConfirmDeadlines.delete(threadId); - heldCompletions.delete(threadId); } if (snapshot.reason === "thread-not-found") { @@ -721,7 +682,6 @@ export const make = Effect.gen(function* () { childAlertByThread.set(threadId, { requestId: childRequestId, updatedAt: state.updatedAt }); } publishConfirmDeadlines.delete(threadId); - heldCompletions.delete(threadId); yield* Ref.update(publishedStateByThreadRef, (publishedStates) => new Map(publishedStates).set(threadId, publishIdentity), );