From cf2b02f8e949845203eb86f7661353aebe2b003f Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Mon, 27 Jul 2026 16:17:30 -0700 Subject: [PATCH] fix(mobile): name the real reason a snooze was refused; share wake label MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addresses two Bugbot findings on the merge commit. canSnooze refuses for two unrelated reasons — the agent is blocked on the user, or a turn start is still queued — but the alert only described the first. A user whose thread was mid-start went looking for a pending request that didn't exist. Each branch now says what actually happened. snoozeWakeLabel was duplicated almost line-for-line between web's Sidebar.snooze.ts and mobile's threadListV2.ts, so the two platforms could drift on the same thresholds. It now lives in client-runtime beside canSnooze/effectiveSnoozed, which both platforms already import, and both re-export it from where their callers expect. It takes `{ now: string }` like every other function in that module — client-runtime's Effect lint bans `new Date()` — which also makes a malformed clock degrade to "now" rather than NaN. Its tests move to the owning package, keeping mobile's sub-minute case that web's lacked. Co-Authored-By: Claude Opus 5 (1M context) --- apps/mobile/src/features/home/HomeScreen.tsx | 2 +- .../src/features/home/useThreadListActions.ts | 6 ++++- .../threads/ThreadNavigationSidebar.tsx | 4 ++-- .../src/features/threads/threadListV2.test.ts | 17 +------------- .../src/features/threads/threadListV2.ts | 23 ++++--------------- .../web/src/components/Sidebar.snooze.test.ts | 17 ++------------ apps/web/src/components/Sidebar.snooze.ts | 15 ++---------- apps/web/src/components/SidebarV2.tsx | 2 +- .../client-runtime/src/state/threadSettled.ts | 19 +++++++++++++++ .../src/state/threadSnoozed.test.ts | 18 +++++++++++++++ 10 files changed, 55 insertions(+), 68 deletions(-) diff --git a/apps/mobile/src/features/home/HomeScreen.tsx b/apps/mobile/src/features/home/HomeScreen.tsx index 7d253ea7a0..4ec0c4bbbe 100644 --- a/apps/mobile/src/features/home/HomeScreen.tsx +++ b/apps/mobile/src/features/home/HomeScreen.tsx @@ -628,7 +628,7 @@ export function HomeScreen(props: HomeScreenProps) { snoozed={item.snoozed} snoozeWakeLabelText={ item.snoozed && item.thread.snoozedUntil != null - ? snoozeWakeLabel(item.thread.snoozedUntil, new Date(`${nowMinute}:00.000Z`)) + ? snoozeWakeLabel(item.thread.snoozedUntil, { now: `${nowMinute}:00.000Z` }) : undefined } project={ diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts index 3fc41bde3a..64dbbf81fc 100644 --- a/apps/mobile/src/features/home/useThreadListActions.ts +++ b/apps/mobile/src/features/home/useThreadListActions.ts @@ -229,9 +229,13 @@ export function useThreadListActions(): { return false; } if (!canSnooze(thread, { now: new Date().toISOString() })) { + // canSnooze refuses for two unrelated reasons; naming the wrong one + // sends the user looking for a request that isn't there. Alert.alert( "Could not snooze thread", - "This thread is waiting on you. Respond to the pending request before snoozing it.", + thread.hasPendingApprovals || thread.hasPendingUserInput + ? "This thread is waiting on you. Respond to the pending request before snoozing it." + : "This thread is still starting a turn. Try again once it's running.", ); return false; } diff --git a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx index f8cfcd3541..942d3b00ba 100644 --- a/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx +++ b/apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx @@ -535,14 +535,14 @@ function ThreadNavigationSidebarPane( pendingTask, isLast: index === v2PendingTasks.length - 1, })); - const snoozeLabelNow = new Date(`${nowMinute}:00.000Z`); + const snoozeLabelNow = `${nowMinute}:00.000Z`; const threadRows: SidebarListItem[] = threadListV2Layout.items.map((item) => ({ type: "v2-thread" as const, key: scopedThreadKey(item.thread.environmentId, item.thread.id), item, snoozeWakeLabelText: item.snoozed && item.thread.snoozedUntil != null - ? snoozeWakeLabel(item.thread.snoozedUntil, snoozeLabelNow) + ? snoozeWakeLabel(item.thread.snoozedUntil, { now: snoozeLabelNow }) : undefined, })); // The shelf header is a row of its own: collapsed, it IS the shelf, so diff --git a/apps/mobile/src/features/threads/threadListV2.test.ts b/apps/mobile/src/features/threads/threadListV2.test.ts index a295ba7579..b817c90106 100644 --- a/apps/mobile/src/features/threads/threadListV2.test.ts +++ b/apps/mobile/src/features/threads/threadListV2.test.ts @@ -7,7 +7,6 @@ import { resolveThreadListV2SnoozeGateExpiryMs, resolveThreadListV2SwipeActions, resolveThreadListV2Status, - snoozeWakeLabel, sortThreadsForListV2, } from "./threadListV2"; @@ -134,21 +133,7 @@ describe("resolveThreadListV2SwipeActions", () => { }); }); -describe("snoozeWakeLabel", () => { - const now = new Date("2026-06-02T00:00:00.000Z"); - - it("formats remaining time coarsely, rounding up", () => { - expect(snoozeWakeLabel("2026-06-02T00:30:00.000Z", now)).toBe("30m"); - expect(snoozeWakeLabel("2026-06-02T01:30:00.000Z", now)).toBe("2h"); - expect(snoozeWakeLabel("2026-06-03T02:00:00.000Z", now)).toBe("2d"); - }); - - it("never reads zero or negative while still snoozed", () => { - expect(snoozeWakeLabel("2026-06-02T00:00:30.000Z", now)).toBe("1m"); - expect(snoozeWakeLabel("2026-06-01T23:59:59.000Z", now)).toBe("now"); - expect(snoozeWakeLabel("not-a-date", now)).toBe("now"); - }); -}); +// snoozeWakeLabel itself is covered in client-runtime, where it lives. describe("resolveThreadListV2SnoozeGateExpiryMs", () => { it("reports when an unadopted turn's grace window lapses", () => { diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.ts index 483b0e9db0..daa7c532d4 100644 --- a/apps/mobile/src/features/threads/threadListV2.ts +++ b/apps/mobile/src/features/threads/threadListV2.ts @@ -4,6 +4,10 @@ import { hasQueuedTurnStart, QUEUED_TURN_START_GRACE_MS, } from "@t3tools/client-runtime/state/thread-settled"; + +// Wake labels live with the rest of the snooze model so web and mobile can +// never drift; re-exported here because this module is the list's one stop. +export { snoozeWakeLabel } from "@t3tools/client-runtime/state/thread-settled"; import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell"; import type { EnvironmentId, ProjectId } from "@t3tools/contracts"; @@ -45,25 +49,6 @@ export function resolveThreadListV2SwipeActions(input: { }; } -const HOUR_MS = 60 * 60 * 1_000; -const DAY_MS = 24 * HOUR_MS; - -/** - * Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes - * round up so a snooze never reads "0m" while still hidden. Ported from - * web's snoozeWakeLabel (apps/web/src/components/Sidebar.snooze.ts) so both - * platforms describe a wake time identically. - */ -export function snoozeWakeLabel(snoozedUntil: string, now: Date): string { - const wakeMs = Date.parse(snoozedUntil); - if (Number.isNaN(wakeMs)) return "now"; - const remainingMs = wakeMs - now.getTime(); - if (remainingMs <= 0) return "now"; - if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`; - if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`; - return `${Math.ceil(remainingMs / DAY_MS)}d`; -} - /** * When a thread's snooze eligibility can flip on its own, as epoch ms — the * moment the queued-turn-start grace window expires and `canSnooze` starts diff --git a/apps/web/src/components/Sidebar.snooze.test.ts b/apps/web/src/components/Sidebar.snooze.test.ts index 4a4518a259..a72d6fc020 100644 --- a/apps/web/src/components/Sidebar.snooze.test.ts +++ b/apps/web/src/components/Sidebar.snooze.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it } from "vite-plus/test"; -import { resolveSnoozePresets, snoozeWakeDescription, snoozeWakeLabel } from "./Sidebar.snooze"; +import { resolveSnoozePresets, snoozeWakeDescription } from "./Sidebar.snooze"; // Local-time constructor so preset math is timezone-stable in tests. function localDate(year: number, month: number, day: number, hour: number, minute = 0): Date { @@ -64,20 +64,7 @@ describe("resolveSnoozePresets", () => { }); }); -describe("snoozeWakeLabel", () => { - const now = localDate(2026, 4, 8, 10); - - it("formats minutes, hours, and days, rounding up", () => { - expect(snoozeWakeLabel(new Date(now.getTime() + 30 * 60_000).toISOString(), now)).toBe("30m"); - expect(snoozeWakeLabel(new Date(now.getTime() + 90 * 60_000).toISOString(), now)).toBe("2h"); - expect(snoozeWakeLabel(new Date(now.getTime() + 26 * 3_600_000).toISOString(), now)).toBe("2d"); - }); - - it("reports now for past and malformed wake times", () => { - expect(snoozeWakeLabel(new Date(now.getTime() - 1000).toISOString(), now)).toBe("now"); - expect(snoozeWakeLabel("not-a-date", now)).toBe("now"); - }); -}); +// snoozeWakeLabel now lives in client-runtime and is tested there. describe("snoozeWakeDescription", () => { const now = localDate(2026, 4, 8, 10); diff --git a/apps/web/src/components/Sidebar.snooze.ts b/apps/web/src/components/Sidebar.snooze.ts index dd56cec729..7c61afcc2b 100644 --- a/apps/web/src/components/Sidebar.snooze.ts +++ b/apps/web/src/components/Sidebar.snooze.ts @@ -93,19 +93,8 @@ export function resolveSnoozePresets(now: Date): ReadonlyArray { return presets; } -/** - * Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes - * round up so a snooze never reads "0m" while still hidden. - */ -export function snoozeWakeLabel(snoozedUntil: string, now: Date): string { - const wake = parseTimestampDate(snoozedUntil); - if (wake === null) return "now"; - const remainingMs = wake.getTime() - now.getTime(); - if (remainingMs <= 0) return "now"; - if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`; - if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`; - return `${Math.ceil(remainingMs / DAY_MS)}d`; -} +/** Shared with mobile so a wake time never reads differently per platform. */ +export { snoozeWakeLabel } from "@t3tools/client-runtime/state/thread-settled"; /** * Human wake time for menus and toasts: "tomorrow 9:00", "Mon 9:00", diff --git a/apps/web/src/components/SidebarV2.tsx b/apps/web/src/components/SidebarV2.tsx index ed9eadd907..ea970aad3b 100644 --- a/apps/web/src/components/SidebarV2.tsx +++ b/apps/web/src/components/SidebarV2.tsx @@ -2417,7 +2417,7 @@ export default function SidebarV2() { } snoozeWakeLabelText={ section === "snoozed" && thread.snoozedUntil != null - ? snoozeWakeLabel(thread.snoozedUntil, new Date()) + ? snoozeWakeLabel(thread.snoozedUntil, { now: new Date().toISOString() }) : null } // All sections: a woken thread can classify straight diff --git a/packages/client-runtime/src/state/threadSettled.ts b/packages/client-runtime/src/state/threadSettled.ts index 0d077c892b..67b698e9cf 100644 --- a/packages/client-runtime/src/state/threadSettled.ts +++ b/packages/client-runtime/src/state/threadSettled.ts @@ -295,3 +295,22 @@ export function effectiveSettled( Date.parse(lastActivityAt) < Date.parse(options.now) - options.autoSettleAfterDays * DAY_MS ); } + +const HOUR_MS = 60 * 60 * 1_000; + +/** + * Compact "wakes in" label for snoozed rows: "2h", "18h", "3d". Minutes + * round up so a snooze never reads "0m" while still hidden. Shared by web's + * sidebar and the mobile thread list so a wake time never reads differently + * across platforms. + */ +export function snoozeWakeLabel(snoozedUntil: string, options: { readonly now: string }): string { + const wakeMs = Date.parse(snoozedUntil); + const nowMs = Date.parse(options.now); + if (Number.isNaN(wakeMs) || Number.isNaN(nowMs)) return "now"; + const remainingMs = wakeMs - nowMs; + if (remainingMs <= 0) return "now"; + if (remainingMs < HOUR_MS) return `${Math.max(1, Math.ceil(remainingMs / 60_000))}m`; + if (remainingMs < DAY_MS) return `${Math.ceil(remainingMs / HOUR_MS)}h`; + return `${Math.ceil(remainingMs / DAY_MS)}d`; +} diff --git a/packages/client-runtime/src/state/threadSnoozed.test.ts b/packages/client-runtime/src/state/threadSnoozed.test.ts index c26d23e264..dda1940ac7 100644 --- a/packages/client-runtime/src/state/threadSnoozed.test.ts +++ b/packages/client-runtime/src/state/threadSnoozed.test.ts @@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test"; import { canSnooze, effectiveSnoozed, + snoozeWakeLabel, threadRaisedHandWhileSnoozed, threadWokeAt, type ThreadSnoozeShell, @@ -235,3 +236,20 @@ describe("threadWokeAt", () => { ).toBe("2026-04-10T09:30:00.000Z"); }); }); + +describe("snoozeWakeLabel", () => { + const now = "2026-06-02T00:00:00.000Z"; + + it("formats remaining time coarsely, rounding up", () => { + expect(snoozeWakeLabel("2026-06-02T00:30:00.000Z", { now })).toBe("30m"); + expect(snoozeWakeLabel("2026-06-02T01:30:00.000Z", { now })).toBe("2h"); + expect(snoozeWakeLabel("2026-06-03T02:00:00.000Z", { now })).toBe("2d"); + }); + + it("never reads zero or negative while still snoozed", () => { + expect(snoozeWakeLabel("2026-06-02T00:00:30.000Z", { now })).toBe("1m"); + expect(snoozeWakeLabel("2026-06-01T23:59:59.000Z", { now })).toBe("now"); + expect(snoozeWakeLabel("not-a-date", { now })).toBe("now"); + expect(snoozeWakeLabel("2026-06-02T09:00:00.000Z", { now: "bad" })).toBe("now"); + }); +});