@devries-cameron20 / t3code Mirror · read-only / commits / cb5fac907a
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, 12:00 UTC

fix(server): mark unread no longer brings back a dismissed wake (#24080)

Co-authored-by: maria-rcks <maria@kuuro.net>

fixfon committed Oct 29, 2026 at 21:06 UTC cb5fac907a21576e1e4b4da24aa70e0e2ea2e8d9
4 files changed +147 -3
apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts
+114
@@ -260,6 +260,120 @@ it.effect("marks a never-visited thread's first completion unread", () =>
260 }).pipe(Effect.provide(layerTest)),
261 );
262
263 +const completeAndSnoozeThread = Effect.fn("test.completeAndSnoozeThread")(function* (
264 + name: string,
265 + snoozeMinutes: number,
266 +) {
267 + const orchestrator = yield* Orchestrator.OrchestratorV2;
268 + const projections = yield* ProjectionStore.ProjectionStoreV2;
269 + const threadId = ThreadId.make(`thread:${name}`);
270 + yield* orchestrator.dispatch({
271 + type: "thread.create",
272 + commandId: CommandId.make(`create-${name}`),
273 + threadId,
274 + projectId: ProjectId.make(`project:${name}`),
275 + title: "Snoozed completion",
276 + modelSelection,
277 + runtimeMode: "full-access",
278 + interactionMode: "default",
279 + branch: null,
280 + worktreePath: null,
281 + createdBy: "user",
282 + creationSource: "web",
283 + });
284 + yield* orchestrator.dispatch({
285 + type: "message.dispatch",
286 + commandId: CommandId.make(`dispatch-${name}`),
287 + threadId,
288 + messageId: MessageId.make(`dispatch-${name}`),
289 + text: "Run in the background",
290 + attachments: [],
291 + dispatchMode: { type: "defer_start" },
292 + createdBy: "agent",
293 + creationSource: "mcp",
294 + });
295 + yield* orchestrator.dispatch({
296 + type: "run.interrupt",
297 + commandId: CommandId.make(`interrupt-${name}`),
298 + threadId,
299 + runId: (yield* projections.getThreadProjection(threadId)).runs[0]!.id,
300 + });
301 + const completedAt = (yield* projections.getThreadProjection(threadId)).runs.at(-1)?.completedAt;
302 + assert.ok(completedAt);
303 + yield* TestClock.adjust("1 second");
304 + const snoozedUntil = DateTime.add(yield* DateTime.now, { minutes: snoozeMinutes });
305 + yield* orchestrator.dispatch({
306 + type: "thread.snooze",
307 + commandId: CommandId.make(`snooze-${name}`),
308 + threadId,
309 + snoozedUntil: DateTime.formatIso(snoozedUntil),
310 + });
311 + return { threadId, completedAt, snoozedUntil };
312 +});
313 +
314 +it.effect("mark unread retires an expired snooze so a dismissed wake stays dismissed", () =>
315 + Effect.gen(function* () {
316 + const orchestrator = yield* Orchestrator.OrchestratorV2;
317 + const projections = yield* ProjectionStore.ProjectionStoreV2;
318 + const { threadId, completedAt, snoozedUntil } = yield* completeAndSnoozeThread(
319 + "mark-unread-expired-snooze",
320 + 1,
321 + );
322 + yield* TestClock.adjust("2 minutes");
323 + yield* orchestrator.dispatch({
324 + type: "thread.visit",
325 + commandId: CommandId.make("dismiss-woke"),
326 + threadId,
327 + visitedAt: DateTime.formatIso(snoozedUntil),
328 + });
329 + const dismissed = yield* projections.getThread(threadId);
330 + assert.deepEqual(dismissed.lastVisitedAt, snoozedUntil);
331 +
332 + yield* orchestrator.dispatch({
333 + type: "thread.mark-unread",
334 + commandId: CommandId.make("mark-unread-expired-snooze"),
335 + threadId,
336 + });
337 + assert.deepEqual(yield* projections.getThread(threadId), {
338 + ...dismissed,
339 + lastVisitedAt: DateTime.subtract(completedAt, { milliseconds: 1 }),
340 + snoozedUntil: null,
341 + snoozedAt: null,
342 + lastSnoozeWakeAt: snoozedUntil,
343 + });
344 + }).pipe(Effect.provide(layerTest)),
345 +);
346 +
347 +it.effect("mark unread leaves a future snooze untouched", () =>
348 + Effect.gen(function* () {
349 + const orchestrator = yield* Orchestrator.OrchestratorV2;
350 + const projections = yield* ProjectionStore.ProjectionStoreV2;
351 + const { threadId, completedAt } = yield* completeAndSnoozeThread(
352 + "mark-unread-future-snooze",
353 + 60,
354 + );
355 + yield* TestClock.adjust("1 minute");
356 + yield* orchestrator.dispatch({
357 + type: "thread.visit",
358 + commandId: CommandId.make("visit-snoozed"),
359 + threadId,
360 + visitedAt: DateTime.formatIso(yield* DateTime.now),
361 + });
362 + const visited = yield* projections.getThread(threadId);
363 + assert.isNotNull(visited.snoozedUntil);
364 +
365 + yield* orchestrator.dispatch({
366 + type: "thread.mark-unread",
367 + commandId: CommandId.make("mark-unread-future-snooze"),
368 + threadId,
369 + });
370 + assert.deepEqual(yield* projections.getThread(threadId), {
371 + ...visited,
372 + lastVisitedAt: DateTime.subtract(completedAt, { milliseconds: 1 }),
373 + });
374 + }).pipe(Effect.provide(layerTest)),
375 +);
376 +
377 it.effect(
378 "dispatches metadata, queue resume and request controls without hydrating unrelated history",
379 () =>
apps/server/src/orchestration-v2/Orchestrator.ts
+13 -2
@@ -3360,8 +3360,19 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
3360 updatedAt: thread.updatedAt,
3361 };
3362 }
3363 - case "thread.mark-unread":
3364 - return { ...thread, lastVisitedAt: markUnreadVisitedAt };
3363 + case "thread.mark-unread": {
3364 + // Retire the wake before rewinding the visit, preserving its settlement timer.
3365 + const snoozeExpired =
3366 + thread.snoozedUntil != null &&
3367 + DateTime.toEpochMillis(thread.snoozedUntil) <= DateTime.toEpochMillis(now);
3368 + return {
3369 + ...thread,
3370 + lastVisitedAt: markUnreadVisitedAt,
3371 + ...(snoozeExpired
3372 + ? { snoozedUntil: null, snoozedAt: null, lastSnoozeWakeAt: thread.snoozedUntil }
3373 + : {}),
3374 + };
3375 + }
3376 case "thread.metadata.update": {
3377 const previousRecovery =
3378 thread.limitRecovery?.runId === command.limitRecovery?.runId &&
packages/client-runtime/src/state/threadVisits.test.ts
+18
@@ -111,6 +111,24 @@ it("keeps a mark-unread on the open thread until new activity lands", () => {
111 expect(t.visits.slice(1)).toEqual([{ threadId: t.ref.threadId, visitedAt: at(30) }]);
112 });
113
114 +it("keeps mark unread sticky after an expired wake is retired", () => {
115 + using t = setup("thread-unread-retired-wake", {
116 + updatedAt: at(10),
117 + lastVisitedAt: at(0),
118 + latestRun: { completedAt: at(9) },
119 + wokeAt: at(15),
120 + });
121 + t.mount();
122 + expect(t.visits).toEqual([{ threadId: t.ref.threadId, visitedAt: at(15), opened: true }]);
123 + t.update({ lastVisitedAt: at(15) });
124 + t.update({ lastVisitedAt: at(8), wokeAt: null });
125 + vi.advanceTimersByTime(VISIT_DISPATCH_THROTTLE_MS);
126 + expect(t.visits).toHaveLength(1);
127 +
128 + t.update({ updatedAt: at(30) });
129 + expect(t.visits.slice(1)).toEqual([{ threadId: t.ref.threadId, visitedAt: at(30) }]);
130 +});
131 +
132 it("waits for the shell and records local visits for servers without tracking", () => {
133 using t = setup("thread-local", null);
134 t.mount();
packages/client-runtime/src/state/threadVisits.ts
+2 -1
@@ -115,7 +115,8 @@ export function createThreadVisitTracker(options: ThreadVisitTrackerOptions) {
115 }
116 const lastVisitedAtMs = shell.lastVisitedAt ? Date.parse(shell.lastVisitedAt) : NaN;
117 if (!Number.isNaN(lastVisitedAtMs) && lastVisitedAtMs >= updatedAtMs) return;
118 - if (lastDispatchedUpdatedAt === visitedAt) return;
118 + if (lastDispatchedUpdatedAt !== null && Date.parse(lastDispatchedUpdatedAt) >= updatedAtMs)
119 + return;
120
121 const completedAtMs = shell.latestRun?.completedAt
122 ? Date.parse(shell.latestRun.completedAt)