@devries-cameron20 / t3code-1 / commits / 404c6e712e
Fork 0

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

fix(server): settling a finished thread removes it from the Live Activity (#18604)

Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

alcpereira committed Oct 20, 2026 at 02:57 UTC 404c6e712e3f6a548e301abd2c9817364c656299
4 files changed +124 -1
apps/server/src/relay/AgentAwarenessRelay.test.ts
+111
@@ -11,6 +11,7 @@ import {
11 ProjectId,
12 ProviderInstanceId,
13 RunId,
14 + RuntimeRequestId,
15 ThreadId,
16 TurnItemId,
17 } from "@t3tools/contracts";
@@ -771,6 +772,116 @@ describe("AgentAwarenessRelay", () => {
772 }),
773 );
774
775 + it.effect.each(["completed", "failed"] as const)(
776 + "settling a %s thread publishes a tombstone without re-alerting on unsettle",
777 + (status) =>
778 + Effect.gen(function* () {
779 + const events = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
780 + const pulls = yield* Queue.unbounded<void>();
781 + const { relay, currentShell, publications } = yield* makeTestRelay({
782 + domainEvents: Stream.fromEffectRepeat(
783 + Queue.offer(pulls, undefined).pipe(Effect.andThen(Queue.take(events))),
784 + ),
785 + });
786 + yield* relay.start();
787 + yield* Queue.take(pulls);
788 + const finished = shell({
789 + status,
790 + latestRunCompletedAt: DateTime.add(yield* DateTime.now, { seconds: 1 }),
791 + });
792 + yield* Ref.set(currentShell, finished);
793 + yield* relay.publishThread(THREAD_ID);
794 + yield* TestClock.adjust("5 seconds");
795 + yield* relay.drain;
796 + assert.deepEqual(
797 + publications.map(({ state }) => state?.phase),
798 + [status],
799 + );
800 +
801 + for (const type of ["thread.settled", "thread.unsettled"] as const) {
802 + const updated = {
803 + ...finished,
804 + settledOverride: type === "thread.settled" ? ("settled" as const) : ("active" as const),
805 + updatedAt: yield* DateTime.now,
806 + };
807 + yield* Ref.set(currentShell, updated);
808 + yield* Queue.offer(events, {
809 + id: EventId.make(type),
810 + type,
811 + threadId: THREAD_ID,
812 + occurredAt: updated.updatedAt,
813 + payload: { ...updated, lastVisitedAt: updated.lastVisitedAt ?? null },
814 + });
815 + yield* Queue.take(pulls);
816 + yield* relay.drain;
817 + yield* TestClock.adjust("5 seconds");
818 + yield* relay.drain;
819 + assert.deepEqual(
820 + publications.map(({ state }) => state?.phase ?? null),
821 + [status, null],
822 + );
823 + }
824 + }).pipe(Effect.scoped),
825 + );
826 +
827 + it.effect.each([
828 + { work: "running", status: "running", phase: "running" },
829 + { work: "user input", status: "completed", phase: "waiting_for_input" },
830 + { work: "monitor", status: "completed", phase: "running" },
831 + { work: "monitor", status: "failed", phase: "failed" },
832 + ] as const)(
833 + "keeps settled $work visible until it finishes ($status run)",
834 + ({ work, status, phase }) =>
835 + Effect.gen(function* () {
836 + const { relay, currentShell, publications } = yield* makeTestRelay();
837 + const active = shell({
838 + status,
839 + latestRunCompletedAt: DateTime.add(yield* DateTime.now, { seconds: 1 }),
840 + pendingRuntimeRequest:
841 + work === "user input"
842 + ? {
843 + id: RuntimeRequestId.make("waiting"),
844 + kind: "user_input",
845 + createdAt: yield* DateTime.now,
846 + }
847 + : null,
848 + pendingBackgroundTasks: work === "monitor" ? [{ taskId: "watch", kind: "monitor" }] : [],
849 + });
850 + yield* Ref.set(currentShell, active);
851 + yield* relay.publishThread(THREAD_ID);
852 + yield* TestClock.adjust("5 seconds");
853 + yield* relay.drain;
854 + assert.deepEqual(
855 + publications.map(({ state }) => state?.phase),
856 + [phase],
857 + );
858 +
859 + yield* Ref.set(currentShell, { ...active, settledOverride: "settled" });
860 + yield* relay.publishThread(THREAD_ID);
861 + yield* TestClock.adjust("5 seconds");
862 + yield* relay.drain;
863 + assert.deepEqual(
864 + publications.map(({ state }) => state?.phase),
865 + [phase],
866 + );
867 +
868 + yield* Ref.set(currentShell, {
869 + ...active,
870 + settledOverride: "settled",
871 + status: status === "running" ? "completed" : status,
872 + pendingRuntimeRequest: null,
873 + pendingBackgroundTasks: [],
874 + });
875 + yield* relay.publishThread(THREAD_ID);
876 + yield* TestClock.adjust("5 seconds");
877 + yield* relay.drain;
878 + assert.deepEqual(
879 + publications.map(({ state }) => state?.phase ?? null),
880 + [phase, null],
881 + );
882 + }),
883 + );
884 +
885 it.effect("confirms a first completed state and respects disabling during confirmation", () =>
886 Effect.gen(function* () {
887 const { relay, secrets, currentShell, publications } = yield* makeTestRelay();
apps/server/src/relay/AgentAwarenessRelay.ts
+2 -1
@@ -93,6 +93,7 @@ export function shouldPublishAgentAwarenessEvent(
93 case "thread.metadata-updated":
94 case "thread.pull-request-link-updated":
95 case "thread.pull-request-synced":
96 + case "thread.settled":
97 case "thread.model-selection-updated":
98 case "thread.provider-switched":
99 case "run.created":
@@ -101,7 +102,7 @@ export function shouldPublishAgentAwarenessEvent(
102 case "subagent.updated":
103 case "provider-thread.updated":
104 return true;
104 - case "thread.settled":
105 + // Unsettling must not re-alert a dismissed result.
106 case "thread.unsettled":
107 case "thread.snoozed":
108 case "thread.unsnoozed":
packages/shared/src/agentAwareness.test.ts
+2
@@ -28,6 +28,7 @@ describe("projectThreadAwarenessV2", () => {
28 | "pendingBackgroundTasks"
29 | "pendingRuntimeRequest"
30 | "lineage"
31 + | "settledOverride"
32 >
33 > = {},
34 ) => ({
@@ -41,6 +42,7 @@ describe("projectThreadAwarenessV2", () => {
42 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
43 status: "running" as const,
44 pendingRuntimeRequest: null,
45 + settledOverride: null,
46 updatedAt,
47 ...overrides,
48 });
packages/shared/src/agentAwareness.ts
+9
@@ -48,6 +48,7 @@ export interface ProjectThreadAwarenessV2Input {
48 | "modelSelection"
49 | "pendingBackgroundTasks"
50 | "pendingRuntimeRequest"
51 + | "settledOverride"
52 | "status"
53 | "title"
54 | "updatedAt"
@@ -63,6 +64,14 @@ export function projectThreadAwarenessV2(
64 if (phase === null) {
65 return null;
66 }
67 + // Resolve the phase first so live or waiting work stays visible after settlement.
68 + if (
69 + thread.settledOverride === "settled" &&
70 + (phase === "completed" || phase === "failed") &&
71 + !backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])
72 + ) {
73 + return null;
74 + }
75 const detail =
76 phase === "completed"
77 ? "Review the completed task."