feat(sidebar-v2): thread snoozing #4311
Mergedt3dotgg(GitHub profile, opens in a new tab)merged 15 commits into
main fromrefs/pull/4311/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/components/SidebarV2.tsx line 953OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -761,6 +943,11 @@761943 // strand rows in a tail with no working affordances.762944 const supportsSettlement =763945 serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSettlement === true;946+ const supportsSnooze =947+ serverConfigs.get(thread.environmentId)?.environment.capabilities.threadSnooze === true;764948 const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));765949 const changeRequestState = changeRequestStateByKey.get(threadKey) ?? null;766- if (950+ // Snooze outranks settled classification: an explicitly snoozed thread951+ // belongs to the shelf even if it would also auto-settle (the shelf's952+ // wake time is a stronger statement about when it matters again).953+ if (supportsSnooze && effectiveSnoozed(thread, { now })) {apps/server/src/orchestration/decider.ts line 580Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -510,0 +520,21 @@520+ // snooze state. Reject instead of silently normalizing.521+ if (Date.parse(command.snoozedUntil) <= Date.parse(occurredAt)) {522+ return yield* Effect.fail(523+ new OrchestrationCommandInvariantError({524+ commandType: command.type,525+ detail: `thread ${command.threadId} snooze wake time ${command.snoozedUntil} is not in the future`,526+ }),527+ );528+ }529+ // Blocked-on-you work must not be snoozed away: a pending approval or530+ // user-input request is the agent waiting on the user, and hiding it531+ // defeats the request. (A running session IS snoozable — snooze only532+ // affects visibility, never the agent.)533+ if (hasOpenBlockingRequest(thread)) {534+ return yield* Effect.fail(535+ new OrchestrationCommandInvariantError({536+ commandType: command.type,537+ detail: `thread ${command.threadId} has a pending approval or user-input request and cannot be snoozed`,538+ }),539+ );540+ }
- packages/client-runtime/src/state/threadSettled.ts line 196Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -92,0 +170,21 @@170+ return !threadRaisedHandWhileSnoozed(shell);171+}172+173+/**174+ * When a previously-snoozed thread woke, or null if it never snoozed / is175+ * still snoozed. Used for the "Woke" indicator: the thread reappears in its176+ * original sort position (the inbox sort is deliberately static), so the177+ * wake signal has to carry the weight. Compare against the client's178+ * lastVisitedAt — visiting clears the indicator like it clears unread.179+ *180+ * Timer wakes report the wake time itself; raised-hand wakes report the181+ * triggering timestamp so a visit BEFORE the early wake doesn't suppress182+ * the indicator.183+ */184+export function threadWokeAt(185+ shell: ThreadSnoozeShell,186+ options: { readonly now: string },187+): string | null {188+ if (shell.snoozedUntil == null) return null;189+ if (effectiveSnoozed(shell, options)) return null;190+ const wakeAtMs = Date.parse(shell.snoozedUntil);apps/web/src/components/Sidebar.snooze.ts line 51OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +31,21 @@31+ * Presets for "snooze until", computed against local time. "This evening"32+ * only appears while it is still meaningfully before evening; after that33+ * the list starts at "Tomorrow".34+ */35+export function resolveSnoozePresets(now: Date): ReadonlyArray<SnoozePreset> {36+ const presets: SnoozePreset[] = [37+ {38+ id: "hour",39+ label: "In 1 hour",40+ snoozedUntil: new Date(now.getTime() + HOUR_MS).toISOString(),41+ },42+ ];43+44+ const evening = atHour(now, EVENING_HOUR);45+ // Suppress the evening preset once it is within an hour (or past): it46+ // would duplicate "In 1 hour" or point at the past.47+ if (evening.getTime() - now.getTime() > HOUR_MS) {48+ presets.push({ id: "evening", label: "This evening", snoozedUntil: evening.toISOString() });49+ }50+51+ const tomorrow = atHour(new Date(now.getTime() + DAY_MS), MORNING_HOUR);
- apps/web/src/components/SidebarV2.tsx line 397OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -281,4 +388,10 @@281388 // flag must not light up every historical thread as unread.282389 const isUnread = hasUnseenCompletion({ ...thread, lastVisitedAt });283390 const status = resolveSidebarV2Status(thread);284- const shouldRecede = status === "ready" && !isUnread && !props.isActive && !isSelected;391+ // A woken thread reappears at its original position (the sort is392+ // deliberately static), so the pill has to carry the weight. Snoozing is393+ // an explicit act, so unlike Done, a never-visited woke thread still394+ // shows the pill; visiting clears it.395+ const isWoke =396+ props.wokeAt !== null &&397+ (lastVisitedAt === undefined || Date.parse(lastVisitedAt) < Date.parse(props.wokeAt));
- apps/web/src/components/SidebarV2.tsx line 2091OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1716,0 +2071,21 @@2071+ variantAction={2072+ section === "snoozed"2073+ ? "unsnooze"2074+ : section === "settled"2075+ ? "unsettle"2076+ : "settle"2077+ }2078+ settlementSupported={2079+ serverConfigs.get(thread.environmentId)?.environment.capabilities2080+ .threadSettlement === true2081+ }2082+ snoozeSupported={2083+ serverConfigs.get(thread.environmentId)?.environment.capabilities2084+ .threadSnooze === true2085+ }2086+ snoozeWakeLabelText={2087+ section === "snoozed" && thread.snoozedUntil != null2088+ ? snoozeWakeLabel(thread.snoozedUntil, new Date())2089+ : null2090+ }2091+ wokeAt={isCard ? threadWokeAt(thread, { now: snoozeNow }) : null}
t3dotgg(GitHub profile, opens in a new tab) changed the title
- @@ -962,7 +1167,21 @@9621167 changeRequestStateByKey,9631168 nowMinute,9641169 scopedProject,9651170 serverConfigs,1171+ snoozeWakeTick,9661172 threads,9671173 ]);96811741175+ // Arm a timeout for the earliest upcoming wake so the shelf empties the1176+ // moment a snooze expires instead of on the next minute tick. Sorted1177+ // soonest-first, so entry 0 is the boundary.1178+ useEffect(() => {1179+ const nextWakeAtMs =1180+ snoozedThreads.length > 0 && snoozedThreads[0]?.snoozedUntil != null1181+ ? Date.parse(snoozedThreads[0].snoozedUntil)1182+ : Number.NaN;1183+ if (Number.isNaN(nextWakeAtMs)) return;1184+ const delayMs = Math.max(0, nextWakeAtMs - Date.now()) + 50;1185+ const id = window.setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);1186+ return () => window.clearTimeout(id);1187+ }, [snoozedThreads]);
- apps/server/src/orchestration/decider.ts line 556Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -508,3 +533,21 @@508533 };509534 }510535536+ case "thread.snooze": {537+ const thread = yield* requireThreadNotArchived({538+ readModel,539+ command,540+ threadId: command.threadId,541+ });542+ const occurredAt = yield* nowIso;543+ // A wake time in the past would create a thread that is snoozed and544+ // woken at once — the row would never leave the inbox but still carry545+ // snooze state. Reject instead of silently normalizing.546+ if (Date.parse(command.snoozedUntil) <= Date.parse(occurredAt)) {547+ return yield* Effect.fail(548+ new OrchestrationCommandInvariantError({549+ commandType: command.type,550+ detail: `thread ${command.threadId} snooze wake time ${command.snoozedUntil} is not in the future`,551+ }),552+ );553+ }apps/mobile/src/state/use-thread-selection.ts line 64Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -60,3 +60,5 @@6060 archivedAt: thread.archivedAt,6161 settledOverride: thread.settledOverride,6262 settledAt: thread.settledAt,63+ snoozedUntil: thread.snoozedUntil ?? null,64+ snoozedAt: thread.snoozedAt ?? null,
- apps/mobile/src/features/home/HomeScreen.tsx line 521Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -467,3 +476,4 @@467476 searchQuery: props.searchQuery,468477 changeRequestStateByKey,469478 settlementEnvironmentIds,479+ snoozeEnvironmentIds,
- apps/mobile/src/features/threads/threadListV2.ts line 166Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -130,5 +137,12 @@130137 }131138 if (query.length > 0 && !thread.title.toLocaleLowerCase().includes(query)) continue;132139 const supportsSettlement = input.settlementEnvironmentIds?.has(thread.environmentId) ?? true;140+ const supportsSnooze = input.snoozeEnvironmentIds?.has(thread.environmentId) ?? true;133141 const changeRequestState =134142 input.changeRequestStateByKey?.get(`${thread.environmentId}:${thread.id}`) ?? null;143+ // Visibility parity with web: a snoozed thread leaves the list until it144+ // wakes (or raises its hand — effectiveSnoozed refuses blocked/failed145+ // work). Snooze outranks settled classification, same as web.146+ if (supportsSnooze && effectiveSnoozed(thread, { now })) {147+ snoozedCount += 1;148+ continue;
- apps/web/src/components/SidebarV2.tsx line 640OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -506,3 +621,20 @@506621 },507622 [onUnsettle, threadRef],508623 );624+ const handleUnsnoozeClick = useCallback(625+ (event: ReactMouseEvent) => {626+ event.preventDefault();627+ event.stopPropagation();628+ onUnsnooze(threadRef);629+ },630+ [onUnsnooze, threadRef],631+ );632+ const handleSnoozePreset = useCallback(633+ (preset: SnoozePreset) => {634+ onSnooze(threadRef, preset);635+ },636+ [onSnooze, threadRef],637+ );638+ // While the snooze popover is open the pointer leaves the row, which639+ // would fade the hover actions out from under the open menu; pin them.640+ const [snoozeMenuOpen, setSnoozeMenuOpen] = useState(false);
- apps/mobile/src/features/home/HomeScreen.tsx line 512OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -476,8 +492,21 @@492+ snoozeWakeTick,476493 settledVisibleCount,477494 settlementEnvironmentIds,495+ snoozeEnvironmentIds,478496 props.searchQuery,479497 props.selectedEnvironmentId,480498 props.threads,481499 threadListV2Enabled,482500 v2ScopedProjectGroup,483501 ]);502+ // Re-partition the moment the earliest snooze expires (clamped to the503+ // signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).504+ const nextSnoozeWakeAt = threadListV2Layout.nextSnoozeWakeAt;505+ useEffect(() => {506+ if (nextSnoozeWakeAt === null) return;507+ const wakeAtMs = Date.parse(nextSnoozeWakeAt);508+ if (Number.isNaN(wakeAtMs)) return;509+ const delayMs = Math.min(Math.max(0, wakeAtMs - Date.now()) + 50, 2_147_483_647);510+ const id = setTimeout(() => bumpSnoozeWakeTick((tick) => tick + 1), delayMs);511+ return () => clearTimeout(id);512+ }, [nextSnoozeWakeAt]);
- apps/web/src/components/SidebarV2.tsx line 1476OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1240,3 +1468,9 @@12401468 [],12411469 );124214701471+ // The snoozed shelf is collapsed by default: out of the way, never gone.1472+ // Collapsed threads don't render (and so don't participate in jump1473+ // shortcuts or multi-select), matching the settled tail's paging model.1474+ const [snoozedShelfExpanded, setSnoozedShelfExpanded] = useState(false);1475+ const toggleSnoozedShelf = useCallback(() => setSnoozedShelfExpanded((value) => !value), []);1476+ const visibleSnoozedThreads = snoozedShelfExpanded ? snoozedThreads : [];apps/mobile/src/features/home/HomeScreen.tsx line 872Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -813,8 +845,16 @@813845 // Self-contained: v1's listEmpty keys off projectGroups, which ignores the814846 // v2 project scope, so it can be null (results elsewhere) while this list815847 // is empty. Search outranks the scope — "No results" names the actionable816- // fact when a query is active. Pending tasks render in the header, so the817- // list showing them isn't empty in the user's eyes.848+ // fact when a query is active. Snoozed threads outrank the rest: "No849+ // threads yet" over an inbox that is merely all-snoozed reads as data850+ // loss. Pending tasks render in the header, so the list showing them851+ // isn't empty in the user's eyes.852+ const v2SnoozedCount = threadListV2Layout.snoozedCount;818853 const v2ListEmpty =819854 v2PendingTasks.length > 0 ? null : hasSearchQuery ? (820855 <EmptyState title="No results" detail={`No threads matching "${props.searchQuery}".`} />856+ ) : v2SnoozedCount > 0 ? (857+ <EmptyState858+ title={v2SnoozedCount === 1 ? "1 thread snoozed" : `${v2SnoozedCount} threads snoozed`}859+ detail="Snoozed threads return when their wake time passes."860+ />
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.