@devries-cameron20 / t3code-1 / commits / a8603afcf1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): mobile push no longer says "completed" between runs (#24769)

Mobile push said "Thread completed" when a run ended and its continuation started a moment later, then again when the work really finished. Every completion now waits the relay's existing 5s confirm window and is dropped if the thread is live again. A thread that auto-settles during the hold still alerts its completion, then clears its card on a new window. Failed runs publish at once. Follow-up to #24760. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 25, 2026 at 01:55 UTC a8603afcf16623726374bdd44dcdc78a8049622e
2 files changed +150 -2
apps/server/src/relay/AgentAwarenessRelay.test.ts
+111
@@ -392,6 +392,8 @@ describe("AgentAwarenessRelay", () => {
392 const terminal = shell({ status });
393 yield* Ref.set(currentShell, terminal);
394 yield* relay.publishThread(THREAD_ID);
395 + yield* TestClock.adjust("5 seconds");
396 + yield* relay.drain;
397 assert.equal(publications[1]?.state?.phase, status);
398
399 const now = yield* DateTime.now;
@@ -419,6 +421,113 @@ describe("AgentAwarenessRelay", () => {
421 }).pipe(Effect.scoped),
422 );
423
424 + it.effect("holds a completion through a continuation gap, then publishes it once", () =>
425 + Effect.gen(function* () {
426 + const { relay, currentShell, publications } = yield* makeTestRelay();
427 + yield* relay.publishThread(THREAD_ID);
428 + yield* Ref.set(currentShell, shell({ status: "completed" }));
429 + yield* relay.publishThread(THREAD_ID);
430 + yield* Ref.set(currentShell, shell());
431 + yield* relay.publishThread(THREAD_ID);
432 + yield* TestClock.adjust("5 seconds");
433 + yield* relay.drain;
434 + assert.deepEqual(
435 + publications.map((publication) => publication.state?.phase),
436 + ["running"],
437 + );
438 +
439 + yield* Ref.set(currentShell, shell({ status: "completed" }));
440 + yield* relay.publishThread(THREAD_ID);
441 + assert.equal(publications.length, 1);
442 + yield* TestClock.adjust("5 seconds");
443 + yield* relay.drain;
444 + assert.deepEqual(
445 + publications.map((publication) => publication.state?.phase),
446 + ["running", "completed"],
447 + );
448 + }),
449 + );
450 +
451 + it.effect("still publishes a completion when the thread settles during the hold", () =>
452 + Effect.gen(function* () {
453 + const { relay, currentShell, publications } = yield* makeTestRelay();
454 + yield* relay.publishThread(THREAD_ID);
455 + const completed = shell({ status: "completed" });
456 + yield* Ref.set(currentShell, completed);
457 + yield* relay.publishThread(THREAD_ID);
458 + yield* Ref.set(currentShell, {
459 + ...completed,
460 + settledOverride: "settled",
461 + settledAt: yield* DateTime.now,
462 + lastVisitedAt: null,
463 + });
464 + yield* relay.publishThread(THREAD_ID);
465 + yield* TestClock.adjust("5 seconds");
466 + yield* relay.drain;
467 + assert.deepEqual(
468 + publications.map((publication) => publication.state?.phase ?? null),
469 + ["running", "completed"],
470 + );
471 +
472 + yield* TestClock.adjust("5 seconds");
473 + yield* relay.drain;
474 + assert.deepEqual(
475 + publications.map((publication) => publication.state?.phase ?? null),
476 + ["running", "completed", null],
477 + );
478 + }),
479 + );
480 +
481 + it.effect("drops a held completion when a queued continuation hides the thread", () =>
482 + Effect.gen(function* () {
483 + const { relay, currentShell, publications } = yield* makeTestRelay();
484 + yield* relay.publishThread(THREAD_ID);
485 + yield* Ref.set(currentShell, shell({ status: "completed" }));
486 + yield* relay.publishThread(THREAD_ID);
487 + yield* Ref.set(currentShell, shell({ status: "queued" }));
488 + yield* relay.publishThread(THREAD_ID);
489 + yield* TestClock.adjust("5 seconds");
490 + yield* relay.drain;
491 + assert.notInclude(
492 + publications.map((publication) => publication.state?.phase ?? null),
493 + "completed",
494 + );
495 + }),
496 + );
497 +
498 + it.effect("retries a failed completion even after the thread settles", () =>
499 + Effect.gen(function* () {
500 + const { relay, currentShell, publications } = yield* makeTestRelay({
501 + respond: (attempt) =>
502 + attempt === 2
503 + ? new Response("unavailable", { status: 503 })
504 + : Response.json({ ok: true, deliveries: [] }),
505 + });
506 + yield* relay.publishThread(THREAD_ID);
507 + const completed = shell({ status: "completed" });
508 + yield* Ref.set(currentShell, completed);
509 + yield* relay.publishThread(THREAD_ID);
510 + yield* TestClock.adjust("5 seconds");
511 + yield* relay.drain;
512 + yield* Ref.set(currentShell, {
513 + ...completed,
514 + settledOverride: "settled",
515 + settledAt: yield* DateTime.now,
516 + lastVisitedAt: null,
517 + });
518 + yield* TestClock.adjust("1 second");
519 + yield* relay.drain;
520 + assert.deepEqual(
521 + publications.map((publication) => publication.state?.phase ?? null),
522 + ["running", "completed", "completed"],
523 + );
524 +
525 + yield* TestClock.adjust("5 seconds");
526 + yield* relay.drain;
527 + assert.equal(publications.at(-1)?.state ?? null, null);
528 + }),
529 + );
530 +
531 it.effect("keeps settled live work until its awaited monitor finishes", () =>
532 Effect.gen(function* () {
533 const { relay, currentShell, publications } = yield* makeTestRelay();
@@ -595,6 +704,8 @@ describe("AgentAwarenessRelay", () => {
704 yield* deliver(
705 itemEvent("event:held-item:end", item("item:tool", { ...background, status: "completed" })),
706 );
707 + yield* TestClock.adjust("5 seconds");
708 + yield* relay.drain;
709 assert.deepEqual(
710 publications.map((publication) => publication.state?.phase),
711 ["running", "completed"],
apps/server/src/relay/AgentAwarenessRelay.ts
+39 -2
@@ -411,6 +411,8 @@ export const make = Effect.gen(function* () {
411
412 // Confirm through the same worker so tombstones cannot race live updates; recovery clears the deadline.
413 const publishConfirmDeadlines = new Map<ThreadId, number>();
414 + // Threads whose confirmation holds a completion, so a thread that settles during the hold still alerts.
415 + const heldCompletions = new Set<ThreadId>();
416 let schedulePublishConfirm: (threadId: ThreadId) => Effect.Effect<void> = () => Effect.void;
417 const publishRetries = new Map<
418 ThreadId,
@@ -429,6 +431,7 @@ export const make = Effect.gen(function* () {
431 publishedRelayConfig = undefined;
432 cachedRelayClient = undefined;
433 publishConfirmDeadlines.clear();
434 + heldCompletions.clear();
435 yield* Ref.set(publishedStateByThreadRef, new Map());
436 });
437
@@ -542,6 +545,7 @@ export const make = Effect.gen(function* () {
545 if (publishedStateByThread.get(threadId) === publishIdentity) {
546 // Clear moot deadlines so later transient nulls cannot skip their deferral window.
547 publishConfirmDeadlines.delete(threadId);
548 + heldCompletions.delete(threadId);
549 yield* Effect.logDebug("agent activity publish skipped; projected state unchanged", {
550 environmentId,
551 threadId,
@@ -551,12 +555,14 @@ export const make = Effect.gen(function* () {
555 }
556
557 // Confirm tombstones over live state to avoid removing active cards.
554 - // Confirm first-state completion because sessions briefly project completed before their first turn.
558 + // Confirm completion: a run can end moments before its continuation starts, and the relay
559 + // alerts on every move into completed.
560 const requiresConfirmation =
561 (snapshot.state === null &&
562 publishedStateByThread.get(threadId) !== agentAwarenessPublishIdentity(null)) ||
558 - (snapshot.state?.phase === "completed" && !publishedStateByThread.has(threadId));
563 + snapshot.state?.phase === "completed";
564 if (requiresConfirmation) {
565 + if (snapshot.state?.phase === "completed") heldCompletions.add(threadId);
566 const nowMs = (yield* DateTime.now).epochMilliseconds;
567 const deadline = publishConfirmDeadlines.get(threadId);
568 if (deadline === undefined) {
@@ -581,8 +587,38 @@ export const make = Effect.gen(function* () {
587 statePhase: snapshot.state?.phase ?? null,
588 shell: describeThreadShellForAwareness(thread),
589 });
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 =
593 + snapshot.state === null &&
594 + heldCompletions.has(threadId) &&
595 + Option.isSome(thread) &&
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;
606 + yield* publishState({
607 + projectId: unsettled.projectId,
608 + state: completion,
609 + reason: unsettled.reason,
610 + }).pipe(withRelayClientTracing);
611 + heldCompletions.delete(threadId);
612 + publishConfirmDeadlines.set(threadId, nowMs + 5_000);
613 + yield* Ref.update(publishedStateByThreadRef, (publishedStates) =>
614 + new Map(publishedStates).set(threadId, agentAwarenessPublishIdentity(completion)),
615 + );
616 + yield* schedulePublishConfirm(threadId);
617 + return;
618 + }
619 } else {
620 publishConfirmDeadlines.delete(threadId);
621 + heldCompletions.delete(threadId);
622 }
623
624 if (snapshot.reason === "thread-not-found") {
@@ -604,6 +640,7 @@ export const make = Effect.gen(function* () {
640 reason: snapshot.reason,
641 }).pipe(withRelayClientTracing);
642 publishConfirmDeadlines.delete(threadId);
643 + heldCompletions.delete(threadId);
644 yield* Ref.update(publishedStateByThreadRef, (publishedStates) => {
645 const nextPublishedStates = new Map(publishedStates);
646 if (snapshot.state === null) {