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, 22:00 UTC
fix(threads): snoozed threads stay hidden through background wakes (#22202)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 20, 2026 at 01:19 UTC
d2fb83a973b53edcca1ab0677f99dac7e2d302ce
10 files changed
+122
-104
apps/server/src/mcp/toolkits/orchestrator/tools.ts
+1
-1
@@ -192,7 +192,7 @@ export const CreateThreadsTool = Tool.make("create_threads", {
192
193
const ThreadListTool = Tool.make("t3_thread_list", {
194
description:
195
- "List T3 threads in a project, newest first. Omit projectId for the calling thread's project. Filter by durable run status, title, or settled state (settled=true lists threads the user or auto-settlement moved out of the active list), or snoozed state, and paginate with the returned cursor. A snoozed thread wakes early when it asks for something, fails after snoozing, or completes a run requested after snoozing. pullRequests lists every pull request linked to each thread; linkedPullRequest is a legacy single link and can be null while pullRequests still has entries. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",
195
+ "List T3 threads in a project, newest first. Omit projectId for the calling thread's project. Filter by durable run status, title, or settled state (settled=true lists threads the user or auto-settlement moved out of the active list), or snoozed state, and paginate with the returned cursor. A snoozed thread wakes early only when it asks for something or fails after snoozing; completed runs and background wakes keep it snoozed. pullRequests lists every pull request linked to each thread; linkedPullRequest is a legacy single link and can be null while pullRequests still has entries. To link a thread for the user, write `[title](t3-thread://v1/<threadId>)` with the threadId exactly as returned, not URL-encoded; T3 Code shows the thread's current title.",
196
parameters: OrchestratorMcpThreadListInput,
197
success: OrchestratorMcpThreadListResult,
198
failure: OrchestratorMcpFailure,
apps/server/src/orchestration-v2/Orchestrator.ts
+5
-1
@@ -4922,7 +4922,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
4922
});
4923
projection = yield* getProjectionWithPendingEvents(command.threadId, events);
4924
}
4925
- if (projection.thread.snoozedUntil != null) {
4925
+ // Background wakes and delegated completions continue work the user already snoozed, so
4926
+ // only a message someone actually sent ends the snooze.
4927
+ const automaticWake =
4928
+ command.notification !== undefined || command.delegatedCompletion !== undefined;
4929
+ if (projection.thread.snoozedUntil != null && !automaticWake) {
4930
const now = yield* DateTime.now;
4931
const thread: OrchestrationV2AppThread = {
4932
...projection.thread,
apps/server/src/orchestration-v2/ProjectionSettlement.test.ts
+1
-1
@@ -216,7 +216,7 @@ it.effect.each([
216
snoozedUntil: DateTime.add(now, { days: 1 }),
217
snoozedAt: DateTime.subtract(old, { days: 1 }),
218
});
219
- yield* createRun(woke);
219
+ yield* createRun(woke, "failed");
220
const background = yield* createThread("idle-background");
221
yield* createItem(background, yield* createRun(background), "idle");
222
const persistent = yield* createThread("persistent-monitor");
apps/server/src/orchestration-v2/ThreadSettlementService.test.ts
+21
-29
@@ -1405,35 +1405,27 @@ describe("ThreadSettlementServiceV2 single-thread sweeps", () => {
1405
1406
describe("isSnoozed", () => {
1407
const snoozed = { snoozedAt: at(-2 * DAY_MS), snoozedUntil: at(DAY_MS) };
1408
- it.each([
1409
- { boundary: "before snooze", requestedAt: at(-2 * DAY_MS - 1), snoozed: true },
1410
- { boundary: "at snooze", requestedAt: snoozed.snoozedAt, snoozed: true },
1411
- { boundary: "unknown", requestedAt: null, snoozed: true },
1412
- { boundary: "after snooze", requestedAt: at(-2 * DAY_MS + 1), snoozed: false },
1413
- ])(
1414
- "agrees on snooze and settlement with completed request time $boundary",
1415
- ({ requestedAt, snoozed: parked }) => {
1416
- const thread = shell({
1417
- ...snoozed,
1418
- status: "completed",
1419
- latestRunRequestedAt: requestedAt,
1420
- latestRunStartedAt: at(-DAY_MS - 1),
1421
- latestRunCompletedAt: at(-DAY_MS),
1422
- });
1423
-
1424
- expect(ThreadSettlementService.isSnoozed(thread, NOW_MS)).toBe(parked);
1425
- expect(ThreadSettlementService.isAutoSettlementCandidate(thread, NOW_MS)).toBe(!parked);
1426
- expect(
1427
- ThreadSettlementService.resolveAutoSettlementAt({
1428
- thread,
1429
- pullRequest: { state: "merged", mergedAt: DateTime.formatIso(at(-1)) },
1430
- nowMs: NOW_MS,
1431
- autoSettleAfterDays: null,
1432
- autoSettleOnMerge: true,
1433
- }),
1434
- ).toEqual(parked ? null : at(-DAY_MS));
1435
- },
1436
- );
1408
+ it("keeps a run requested and completed after snoozing parked until the timer", () => {
1409
+ const thread = shell({
1410
+ ...snoozed,
1411
+ status: "completed",
1412
+ latestRunRequestedAt: at(-2 * DAY_MS + 1),
1413
+ latestRunStartedAt: at(-DAY_MS - 1),
1414
+ latestRunCompletedAt: at(-DAY_MS),
1415
+ });
1416
+
1417
+ expect(ThreadSettlementService.isSnoozed(thread, NOW_MS)).toBe(true);
1418
+ expect(ThreadSettlementService.isAutoSettlementCandidate(thread, NOW_MS)).toBe(false);
1419
+ expect(
1420
+ ThreadSettlementService.resolveAutoSettlementAt({
1421
+ thread,
1422
+ pullRequest: { state: "merged", mergedAt: DateTime.formatIso(at(-1)) },
1423
+ nowMs: NOW_MS,
1424
+ autoSettleAfterDays: null,
1425
+ autoSettleOnMerge: true,
1426
+ }),
1427
+ ).toBeNull();
1428
+ });
1429
1430
it("keeps quiet and interrupted threads snoozed until the timer expires", () => {
1431
expect(ThreadSettlementService.isSnoozed(shell(snoozed), NOW_MS)).toBe(true);
apps/server/src/orchestration-v2/ThreadSettlementService.ts
+2
-15
@@ -177,12 +177,7 @@ export function isAutoSettlementCandidate(
177
export function isSnoozed(
178
thread: Pick<
179
ProjectionStore.ProjectionSettlementCandidate,
180
- | "snoozedUntil"
181
- | "snoozedAt"
182
- | "latestRunRequestedAt"
183
- | "latestRunCompletedAt"
184
- | "status"
185
- | "pendingRuntimeRequest"
180
+ "snoozedUntil" | "snoozedAt" | "latestRunCompletedAt" | "status" | "pendingRuntimeRequest"
181
>,
182
nowMs: number,
183
): boolean {
@@ -190,19 +185,11 @@ export function isSnoozed(
185
if (snoozedUntilMs === null || snoozedUntilMs <= nowMs) return false;
186
if (thread.pendingRuntimeRequest !== null) return false;
187
const snoozedAtMs = toMillis(thread.snoozedAt);
193
- const requestedAtMs = toMillis(thread.latestRunRequestedAt);
188
const completedAtMs = toMillis(thread.latestRunCompletedAt);
189
const wokeOnError =
190
thread.status === "failed" &&
191
(snoozedAtMs === null || (completedAtMs !== null && completedAtMs > snoozedAtMs));
198
- const wokeOnCompletion =
199
- thread.status === "completed" &&
200
- snoozedAtMs !== null &&
201
- requestedAtMs !== null &&
202
- requestedAtMs > snoozedAtMs &&
203
- completedAtMs !== null &&
204
- completedAtMs > snoozedAtMs;
205
- return !wokeOnError && !wokeOnCompletion;
192
+ return !wokeOnError;
193
}
194
195
export function resolveAutoSettlementAt(input: {
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+57
@@ -5812,6 +5812,63 @@ it.layer(layerTest)("snooze queued runs", (it) => {
5812
}
5813
}),
5814
);
5815
+
5816
+ it.effect.each(["notification", "user"] as const)(
5817
+ "a %s message on a snoozed thread keeps the snooze only when automatic",
5818
+ (kind) =>
5819
+ Effect.gen(function* () {
5820
+ const orchestrator = yield* Orchestrator.OrchestratorV2;
5821
+ const threadId = ThreadId.make(`snooze-wake:${kind}`);
5822
+ const snoozedUntil = "2099-07-25T09:00:00.000Z";
5823
+ yield* orchestrator.dispatch({
5824
+ type: "thread.create",
5825
+ commandId: CommandId.make(`create:${threadId}`),
5826
+ threadId,
5827
+ projectId: ProjectId.make("snooze-wake-project"),
5828
+ title: "Snoozed long-running thread",
5829
+ modelSelection,
5830
+ runtimeMode: "full-access",
5831
+ interactionMode: "default",
5832
+ branch: null,
5833
+ worktreePath: "/tmp/snooze-wake",
5834
+ createdBy: "user",
5835
+ creationSource: "web",
5836
+ });
5837
+ yield* orchestrator.dispatch({
5838
+ type: "thread.snooze",
5839
+ commandId: CommandId.make(`snooze:${threadId}`),
5840
+ threadId,
5841
+ snoozedUntil,
5842
+ });
5843
+ yield* orchestrator.dispatch({
5844
+ type: "message.dispatch",
5845
+ commandId: CommandId.make(`wake:${threadId}`),
5846
+ threadId,
5847
+ messageId: MessageId.make(`wake:${threadId}`),
5848
+ text: "Continue",
5849
+ attachments: [],
5850
+ modelSelection,
5851
+ dispatchMode: { type: "queue_after_active" },
5852
+ createdBy: kind === "user" ? "user" : "agent",
5853
+ creationSource: kind === "user" ? "web" : "provider",
5854
+ ...(kind === "notification"
5855
+ ? {
5856
+ notification: {
5857
+ source: { kind: "background_task" as const },
5858
+ outcome: "updated" as const,
5859
+ summary: "Background activity updated",
5860
+ },
5861
+ }
5862
+ : {}),
5863
+ });
5864
+ const thread = (yield* orchestrator.getThreadProjection(threadId)).thread;
5865
+ if (kind === "user") {
5866
+ assert.isNull(thread.snoozedUntil);
5867
+ } else {
5868
+ assert.equal(DateTime.formatIso(thread.snoozedUntil!), snoozedUntil);
5869
+ }
5870
+ }),
5871
+ );
5872
});
5873
5874
it.layer(layerSharedApplicationDataPlaneTest)("snooze projection", (it) => {
docs/orchestration-v2/orchestrator-mcp-server.md
+2
-2
@@ -391,8 +391,8 @@ relabels local matches; cross-environment links can retain the written label.
391
List and read results report `snoozed` and `snoozedUntil`, and
392
`t3_thread_list` filters on `snoozed`. The server's `isSnoozed` follows the
393
client's `effectiveSnoozed`, so agents and the sidebar agree: a snoozed thread
394
-wakes early when it has a pending request, fails after snoozing, or completes a
395
-run requested after snoozing.
394
+wakes early only when it has a pending request or fails after snoozing. Completed
395
+runs, background wakes, and delegated completions keep it snoozed.
396
397
### `t3_thread_update`
398
docs/user/thread-sidebar.md
+3
@@ -233,3 +233,6 @@ Choose **Snooze → Custom…** from a thread's menu to pick a date and time in
233
local time zone, or a duration in minutes, hours, or days. Durations start when
234
you confirm; one day means 24 hours. On web and desktop, you can also snooze
235
several selected threads together. Choose **Wake thread** to bring a thread back early.
236
+A snoozed thread keeps working and stays hidden until its wake time, even while
237
+its agent wakes itself for background work. It comes back early only when it needs
238
+an approval or answer from you, when a run fails, or when you send it a message.
packages/client-runtime/src/state/threadSettled.ts
+7
-23
@@ -79,35 +79,21 @@ export interface ThreadSnoozeShell extends QueuedThreadShell {
79
readonly pendingSubagentRequest?: PendingSubagentRequest | null;
80
}
81
82
+/**
83
+ * Only a request for the user or a fresh failure ends a snooze early. Completed runs never do:
84
+ * a snoozed long-running thread keeps waking itself for background work and stays hidden
85
+ * until its timer.
86
+ */
87
export function threadRaisedHandWhileSnoozed(shell: ThreadSnoozeShell): boolean {
88
if (shell.hasPendingApprovals || shell.hasPendingUserInput) return true;
89
if (shell.source?.pendingRuntimeRequest != null) return true;
90
if (shell.pendingSubagentRequest != null) return true;
91
const failedAt = failureEdgeAt(shell);
87
- if (
92
+ return (
93
failedAt !== undefined &&
94
(shell.snoozedAt == null ||
95
(failedAt != null && Date.parse(failedAt) > Date.parse(shell.snoozedAt)))
91
- ) {
92
- return true;
93
- }
94
- return completionWakeAt(shell) !== null;
95
-}
96
-
97
-/** A snooze acknowledges the run already requested, including its eventual result. */
98
-function completionWakeAt(shell: ThreadSnoozeShell): string | null {
99
- const latestRun = shell.latestRun ?? shell.latestTurn ?? null;
100
- if (
101
- shell.snoozedAt != null &&
102
- (latestRun?.state === "completed" || latestRun?.status === "completed") &&
103
- latestRun.requestedAt != null &&
104
- Date.parse(latestRun.requestedAt) > Date.parse(shell.snoozedAt) &&
105
- latestRun.completedAt != null &&
106
- Date.parse(latestRun.completedAt) > Date.parse(shell.snoozedAt)
107
- ) {
108
- return latestRun.completedAt;
109
- }
110
- return null;
96
+ );
97
}
98
99
// V2 runtime.updatedAt includes metadata writes; prefer the failed run's completion.
@@ -168,8 +154,6 @@ export function threadWokeAt(
154
// indicator the user already cleared by visiting (snoozedUntil is newer
155
// than that visit's lastVisitedAt).
156
if (threadRaisedHandWhileSnoozed(shell)) {
171
- const completedAt = completionWakeAt(shell);
172
- if (completedAt !== null) return completedAt;
157
// An old failure must not replace the activity time of an approval or input wake.
158
const failedAt = failureEdgeAt(shell);
159
if (
packages/client-runtime/src/state/threadSnoozed.test.ts
+23
-32
@@ -168,29 +168,20 @@ describe("effectiveSnoozed", () => {
168
).toBe(true);
169
});
170
171
- it.each([
172
- { boundary: "before snooze", requestedAt: "2026-04-10T08:59:59.999Z", snoozed: true },
173
- { boundary: "at snooze", requestedAt: SNOOZED_AT, snoozed: true },
174
- { boundary: "unknown", requestedAt: null, snoozed: true },
175
- { boundary: "after snooze", requestedAt: "2026-04-10T09:00:00.001Z", snoozed: false },
176
- ])(
177
- "classifies completion and its wake time with request time $boundary",
178
- ({ requestedAt, snoozed }) => {
179
- const completedAt = "2026-04-10T10:30:00.000Z";
180
- const shell = {
181
- ...makeShell({ snoozedUntil: FUTURE_WAKE }),
182
- latestRun: {
183
- status: "completed",
184
- requestedAt,
185
- startedAt: "2026-04-10T09:15:00.000Z",
186
- completedAt,
187
- },
188
- };
171
+ it("stays snoozed when a run requested after the snooze completes", () => {
172
+ const shell = {
173
+ ...makeShell({ snoozedUntil: FUTURE_WAKE }),
174
+ latestRun: {
175
+ status: "completed",
176
+ requestedAt: "2026-04-10T09:00:00.001Z",
177
+ startedAt: "2026-04-10T09:15:00.000Z",
178
+ completedAt: "2026-04-10T10:30:00.000Z",
179
+ },
180
+ };
181
190
- expect(effectiveSnoozed(shell, { now: NOW })).toBe(snoozed);
191
- expect(threadWokeAt(shell, { now: NOW })).toBe(snoozed ? null : completedAt);
192
- },
193
- );
182
+ expect(effectiveSnoozed(shell, { now: NOW })).toBe(true);
183
+ expect(threadWokeAt(shell, { now: NOW })).toBe(null);
184
+ });
185
186
it("ignores runs that completed before the snooze — the user saw that result", () => {
187
expect(
@@ -347,16 +338,16 @@ describe("threadWokeAt", () => {
338
});
339
340
it("keeps the early wake authoritative after the scheduled time passes", () => {
350
- expect(
351
- threadWokeAt(
352
- makeShell({
353
- snoozedUntil: PAST_WAKE,
354
- turnRequestedAt: "2026-04-10T09:15:00.000Z",
355
- turnCompletedAt: "2026-04-10T09:30:00.000Z",
356
- }),
357
- { now: NOW },
358
- ),
359
- ).toBe("2026-04-10T09:30:00.000Z");
341
+ const shell: ThreadSnoozeShell = {
342
+ ...makeShell({ snoozedUntil: PAST_WAKE }),
343
+ runtime: { status: "failed", updatedAt: "2026-04-10T11:00:00.000Z" },
344
+ latestRun: {
345
+ status: "failed",
346
+ requestedAt: "2026-04-10T09:15:00.000Z",
347
+ completedAt: "2026-04-10T09:30:00.000Z",
348
+ },
349
+ };
350
+ expect(threadWokeAt(shell, { now: NOW })).toBe("2026-04-10T09:30:00.000Z");
351
});
352
});
353