@devries-cameron20 / t3code Mirror · read-only / commits / 4741dc563f
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 20:45 UTC

fix(web): silence notifications when stopping a watch (#22615)

Yash Singh committed Oct 20, 2026 at 21:35 UTC 4741dc563f5df538babe02421dca513f2458e577
6 files changed +101 -1
apps/server/src/orchestration-v2/ProjectionStore.ts
+22
@@ -1058,6 +1058,7 @@ type ShellThreadRow = {
1058 readonly latest_run_requested_at: string | null;
1059 readonly latest_run_started_at: string | null;
1060 readonly latest_run_completed_at: string | null;
1061 + readonly latest_run_stop_requested: number;
1062 readonly active_run_id: string | null;
1063 readonly active_run_status: string | null;
1064 readonly activity_run_status: string | null;
@@ -1068,6 +1069,7 @@ type ShellThreadRow = {
1069 readonly blocking_run_requested_at: string | null;
1070 readonly blocking_run_started_at: string | null;
1071 readonly blocking_run_completed_at: string | null;
1072 + readonly blocking_run_stop_requested: number;
1073 readonly blocking_failure_payload_json: string | null;
1074 readonly pending_request_payload_json: string | null;
1075 readonly pending_secret_request_payload_json: string | null;
@@ -1598,6 +1600,11 @@ export function threadShellFromProjection(
1600 latestRunRequestedAt: latestRun?.requestedAt ?? null,
1601 latestRunStartedAt: latestRun?.startedAt ?? null,
1602 latestRunCompletedAt: latestRun?.completedAt ?? null,
1603 + latestRunStopRequested:
1604 + latestRun != null &&
1605 + projection.turnItems.some(
1606 + (item) => item.runId === latestRun.id && item.type === "run_interrupt_request",
1607 + ),
1608 activeRunId: activeRun?.id ?? null,
1609 blockedOnThreadWait: deriveBlockedOnThreadWait({ activeRun, turnItems: projection.turnItems }),
1610 activityRunStatus: activityRun?.status ?? null,
@@ -1697,6 +1704,7 @@ type ShellThreadState = {
1704 readonly latestRunRequestedAt: DateTime.Utc | null;
1705 readonly latestRunStartedAt: DateTime.Utc | null;
1706 readonly latestRunCompletedAt: DateTime.Utc | null;
1707 + readonly latestRunStopRequested: boolean;
1708 readonly activeRunId: RunId | null;
1709 readonly blockedOnThreadWait: boolean;
1710 readonly activityRunStatus: ShellActivityRunStatus | null;
@@ -1850,6 +1858,7 @@ function shellFromState(input: {
1858 latestRunRequestedAt: input.state.latestRunRequestedAt,
1859 latestRunStartedAt: input.state.latestRunStartedAt,
1860 latestRunCompletedAt: input.state.latestRunCompletedAt,
1861 + latestRunStopRequested: input.state.latestRunStopRequested,
1862 activeRunId: input.state.activeRunId,
1863 blockedOnThreadWait: input.state.blockedOnThreadWait,
1864 activityRunStatus: input.state.activityRunStatus,
@@ -5638,6 +5647,11 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5647 presented.requested_at AS latest_run_requested_at,
5648 json_extract(presented.payload_json, '$.startedAt') AS latest_run_started_at,
5649 presented.completed_at AS latest_run_completed_at,
5650 + EXISTS (
5651 + SELECT 1 FROM orchestration_v2_projection_turn_items stop_request
5652 + WHERE stop_request.thread_id = t.thread_id AND stop_request.run_id = presented.run_id
5653 + AND stop_request.type = 'run_interrupt_request'
5654 + ) AS latest_run_stop_requested,
5655 active.run_id AS active_run_id,
5656 active.status AS active_run_status,
5657 (
@@ -5688,6 +5702,11 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
5702 blocked.requested_at AS blocking_run_requested_at,
5703 json_extract(blocked.payload_json, '$.startedAt') AS blocking_run_started_at,
5704 blocked.completed_at AS blocking_run_completed_at,
5705 + EXISTS (
5706 + SELECT 1 FROM orchestration_v2_projection_turn_items stop_request
5707 + WHERE stop_request.thread_id = t.thread_id AND stop_request.run_id = blocked.run_id
5708 + AND stop_request.type = 'run_interrupt_request'
5709 + ) AS blocking_run_stop_requested,
5710 (
5711 SELECT item.payload_json
5712 FROM orchestration_v2_projection_turn_items item
@@ -6160,6 +6179,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6179 row.latest_run_completed_at === null
6180 ? null
6181 : DateTime.makeUnsafe(row.latest_run_completed_at);
6182 + let latestRunStopRequested = row.latest_run_stop_requested === 1;
6183 if (row.blocking_run_id !== null && row.blocking_failure_payload_json !== null) {
6184 const blockingFailure = yield* decodeTurnItemPayload(
6185 row.blocking_failure_payload_json,
@@ -6172,6 +6192,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6192 if (blocksQueue && blockingFailure !== null) {
6193 terminalFailureItem = blockingFailure;
6194 latestRunId = RunId.make(row.blocking_run_id);
6195 + latestRunStopRequested = row.blocking_run_stop_requested === 1;
6196 latestRunStatus = "failed";
6197 latestRunRequestedAt =
6198 row.blocking_run_requested_at === null
@@ -6211,6 +6232,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
6232 latestRunRequestedAt,
6233 latestRunStartedAt,
6234 latestRunCompletedAt,
6235 + latestRunStopRequested,
6236 activeRunId: row.active_run_id === null ? null : RunId.make(row.active_run_id),
6237 blockedOnThreadWait: deriveBlockedOnThreadWait({
6238 activeRun:
apps/server/src/orchestration-v2/ThreadStop.test.ts
+57
@@ -10,6 +10,7 @@ import {
10 ProviderDriverKind,
11 ProviderInstanceId,
12 ProviderSessionId,
13 + ProviderThreadId,
14 ProviderTurnId,
15 RuntimeRequestId,
16 ScheduledTaskId,
@@ -726,6 +727,62 @@ it.effect(
727 }).pipe(Effect.provide(layerTest)),
728 );
729
730 +it.effect.each([false, true])(
731 + "a completed watch records whether it ended through Stop (%s)",
732 + (stopped) =>
733 + Effect.gen(function* () {
734 + const orchestrator = yield* Orchestrator.OrchestratorV2;
735 + const projections = yield* ProjectionStore.ProjectionStoreV2;
736 + const threadId = ThreadId.make(`thread:watch-completion:${stopped}`);
737 + yield* createWatchingThread(threadId, 7);
738 + yield* send(threadId, "watch", "start_immediately");
739 + const run = (yield* orchestrator.getThreadProjection(threadId)).runs[0]!;
740 + const now = yield* DateTime.now;
741 + const completedRun = {
742 + ...run,
743 + providerThreadId: run.providerThreadId ?? ProviderThreadId.make("provider-thread:watch"),
744 + status: "completed" as const,
745 + startedAt: now,
746 + completedAt: now,
747 + };
748 + yield* projections.apply({
749 + id: EventId.make("event:watch-completed"),
750 + type: "run.updated",
751 + threadId,
752 + occurredAt: now,
753 + payload: completedRun,
754 + });
755 + assert.isFalse((yield* projections.getThreadShell(threadId))?.latestRunStopRequested);
756 +
757 + yield* orchestrator.dispatch(
758 + stopped
759 + ? { type: "thread.stop", commandId: CommandId.make("stop-watch"), threadId }
760 + : {
761 + type: "thread.pull-request.watch",
762 + commandId: CommandId.make("finish-watch"),
763 + threadId,
764 + ...pullRequest(7),
765 + watching: false,
766 + },
767 + );
768 + const shell = yield* projections.getThreadShell(threadId);
769 + const snapshot = (yield* projections.getShellSnapshot()).threads.find(
770 + (thread) => thread.id === threadId,
771 + );
772 + const memoryShell = ProjectionStore.threadShellFromProjection(
773 + yield* orchestrator.getThreadProjection(threadId),
774 + );
775 + for (const result of [shell, snapshot, memoryShell]) {
776 + assert.equal(result?.status, "completed");
777 + assert.isEmpty(result?.pendingBackgroundTasks ?? []);
778 + assert.equal(result?.latestRunStopRequested, stopped);
779 + }
780 +
781 + yield* send(threadId, "next", "start_immediately");
782 + assert.isFalse((yield* projections.getThreadShell(threadId))?.latestRunStopRequested);
783 + }).pipe(Effect.provide(layerTest)),
784 +);
785 +
786 it.effect("a run Stop reached cannot delegate or start a watch, even after it ends", () =>
787 Effect.gen(function* () {
788 const orchestrator = yield* Orchestrator.OrchestratorV2;
apps/web/src/components/ThreadNotificationCoordinator.tsx
+3 -1
@@ -154,7 +154,9 @@ function EnvironmentNotifications({
154 const kind =
155 attention && attention !== prior.attention
156 ? "input"
157 - : completion !== null && (prior.completion === null || completion > prior.completion)
157 + : !rawThread.latestRunStopRequested &&
158 + completion !== null &&
159 + (prior.completion === null || completion > prior.completion)
160 ? "completion"
161 : null;
162 if (!kind) continue;
packages/contracts/src/orchestrationV2.ts
+1
@@ -1825,6 +1825,7 @@ export const OrchestrationV2ThreadShell = Schema.Struct({
1825 latestRunRequestedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)),
1826 latestRunStartedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)),
1827 latestRunCompletedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)),
1828 + latestRunStopRequested: Schema.optional(Schema.Boolean),
1829 activeRunId: Schema.NullOr(RunId),
1830 activityRunStartedAt: Schema.optional(Schema.NullOr(Schema.DateTimeUtc)),
1831 activityRunStatus: Schema.optional(
packages/shared/src/agentAwareness.test.ts
+16
@@ -24,6 +24,7 @@ describe("projectThreadAwarenessV2", () => {
24 Pick<
25 OrchestrationV2ThreadShell,
26 | "activityRunStatus"
27 + | "latestRunStopRequested"
28 | "status"
29 | "pendingBackgroundTasks"
30 | "pendingRuntimeRequest"
@@ -47,6 +48,21 @@ describe("projectThreadAwarenessV2", () => {
48 ...overrides,
49 });
50
51 + it("does not announce completion after a manual stop", () => {
52 + const input = {
53 + environmentId: "env-1" as EnvironmentId,
54 + project,
55 + thread: v2Thread({ status: "completed" }),
56 + };
57 + expect(projectThreadAwarenessV2(input)?.phase).toBe("completed");
58 + expect(
59 + projectThreadAwarenessV2({
60 + ...input,
61 + thread: { ...input.thread, latestRunStopRequested: true },
62 + }),
63 + ).toBeNull();
64 + });
65 +
66 it.each(["running", "completed", "failed"] as const)(
67 "does not publish %s subagent activity",
68 (status) => {
packages/shared/src/agentAwareness.ts
+2
@@ -45,6 +45,7 @@ export interface ProjectThreadAwarenessV2Input {
45 | "activityRunStatus"
46 | "id"
47 | "lineage"
48 + | "latestRunStopRequested"
49 | "modelSelection"
50 | "pendingBackgroundTasks"
51 | "pendingRuntimeRequest"
@@ -64,6 +65,7 @@ export function projectThreadAwarenessV2(
65 if (phase === null) {
66 return null;
67 }
68 + if (phase === "completed" && thread.latestRunStopRequested === true) return null;
69 // Resolve the phase first so live or waiting work stays visible after settlement.
70 if (
71 thread.settledOverride === "settled" &&