Skip to content

Commit 8ba03a9

Browse files
t3dotggclaude
andcommitted
fix(server): a settled completion alerts with the current run
The settle replay sent the snapshot held from the first confirmation, which can describe an earlier run. It now publishes the thread's current completion, read as if it were not settled, so the hold only needs to remember which threads hold a completion. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent b2a418b commit 8ba03a9

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

‎apps/server/src/relay/AgentAwarenessRelay.ts‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,8 @@ export const make = Effect.gen(function* () {
411411

412412
// Confirm through the same worker so tombstones cannot race live updates; recovery clears the deadline.
413413
const publishConfirmDeadlines = new Map<ThreadId, number>();
414-
// The completion a confirmation holds, so a thread that settles during the hold still alerts.
415-
const heldCompletions = new Map<
416-
ThreadId,
417-
ReturnType<typeof resolveAgentAwarenessRelayPublishSnapshot>
418-
>();
414+
// Threads whose confirmation holds a completion, so a thread that settles during the hold still alerts.
415+
const heldCompletions = new Set<ThreadId>();
419416
let schedulePublishConfirm: (threadId: ThreadId) => Effect.Effect<void> = () => Effect.void;
420417
const publishRetries = new Map<
421418
ThreadId,
@@ -565,7 +562,7 @@ export const make = Effect.gen(function* () {
565562
publishedStateByThread.get(threadId) !== agentAwarenessPublishIdentity(null)) ||
566563
snapshot.state?.phase === "completed";
567564
if (requiresConfirmation) {
568-
if (snapshot.state?.phase === "completed") heldCompletions.set(threadId, snapshot);
565+
if (snapshot.state?.phase === "completed") heldCompletions.add(threadId);
569566
const nowMs = (yield* DateTime.now).epochMilliseconds;
570567
const deadline = publishConfirmDeadlines.get(threadId);
571568
if (deadline === undefined) {
@@ -590,28 +587,31 @@ export const make = Effect.gen(function* () {
590587
statePhase: snapshot.state?.phase ?? null,
591588
shell: describeThreadShellForAwareness(thread),
592589
});
593-
const held = heldCompletions.get(threadId);
594-
// Settled during the hold, not resumed: alert the completion, then clear the card on a new window.
595-
const hiddenOnlyBySettlement =
590+
// Settled during the hold, not resumed: alert the current completion, then clear the card
591+
// on a new window. Only settlement may hide it; queued or silent runs also project to null.
592+
const unsettled =
596593
snapshot.state === null &&
594+
heldCompletions.has(threadId) &&
597595
Option.isSome(thread) &&
598-
thread.value.settledOverride === "settled" &&
599-
resolveAgentAwarenessRelayPublishSnapshot({
600-
environmentId,
601-
threadId,
602-
thread: Option.some({ ...thread.value, settledOverride: null }),
603-
project,
604-
}).state?.phase === "completed";
605-
if (hiddenOnlyBySettlement && held?.state != null) {
596+
thread.value.settledOverride === "settled"
597+
? resolveAgentAwarenessRelayPublishSnapshot({
598+
environmentId,
599+
threadId,
600+
thread: Option.some({ ...thread.value, settledOverride: null }),
601+
project,
602+
})
603+
: null;
604+
if (unsettled?.state?.phase === "completed") {
605+
const completion = unsettled.state;
606606
yield* publishState({
607-
projectId: held.projectId,
608-
state: held.state,
609-
reason: held.reason,
607+
projectId: unsettled.projectId,
608+
state: completion,
609+
reason: unsettled.reason,
610610
}).pipe(withRelayClientTracing);
611611
heldCompletions.delete(threadId);
612612
publishConfirmDeadlines.set(threadId, nowMs + 5_000);
613613
yield* Ref.update(publishedStateByThreadRef, (publishedStates) =>
614-
new Map(publishedStates).set(threadId, agentAwarenessPublishIdentity(held.state)),
614+
new Map(publishedStates).set(threadId, agentAwarenessPublishIdentity(completion)),
615615
);
616616
yield* schedulePublishConfirm(threadId);
617617
return;

0 commit comments

Comments
 (0)