feat: snooze running threads until done #13196
Closedjakeleventhal(GitHub profile, opens in a new tab)wants to merge 2 commits into
t3code/codex-turn-mapping fromrefs/pull/13196/headopened 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:L
- apps/web/src/components/Sidebar.logic.ts line 380OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -342,10 +342,11 @@342342 | "activeOrderKey"343343 | "snoozedAt"344344 | "snoozedUntil"345+ | "snoozeWakeOn"345346 | "settledAt"346347 | "settledOverride"347348 | "unsettledAt"348349 >,349350 >(thread: T, section: "pinned" | "active" | "settled", now: string, orderKey?: string): T {350351 const wasSettled = thread.settledOverride === "settled";351- const awake = { ...thread, snoozedAt: null, snoozedUntil: null };352+ const awake = { ...thread, snoozedAt: null, snoozedUntil: null, snoozeWakeOn: null };
- packages/contracts/src/orchestration.ts lines 1806 to 1809OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1790,4 +1803,7 @@1790180317911804 export const ThreadSnoozedPayload = Schema.Struct({17921805 threadId: ThreadId,1793- snoozedUntil: IsoDateTime,1806+ // Null only for condition-only snoozes. Optional wakeOn keeps events1807+ // persisted before wake conditions decoding.1808+ snoozedUntil: Schema.NullOr(IsoDateTime),1809+ wakeOn: Schema.optional(Schema.NullOr(ThreadSnoozeWakeCondition)),
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/mobile/src/features/threads/thread-list-v2-items.tsx line 655OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -640,3 +647,4 @@640647 snoozable: canSnooze(thread, { now: new Date().toISOString() }),641648 snoozed: snoozedRow,642649 });650+ const untilDone = props.snoozeUntilDoneSupported && isThreadRunInProgress(thread);packages/client-runtime/src/state/threadCommands.ts line 431OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -425,7 +416,14 @@425- snoozedAt:426- thread.snoozedUntil != null &&427- DateTime.formatIso(thread.snoozedUntil) === input.snoozedUntil428- ? (thread.snoozedAt ?? now)429- : now,430- },431- ),416+ snooze: optimistic.wrap(commands.snooze, (thread, input, now, accepted) => {417+ if (418+ (!accepted &&419+ (thread.pendingRuntimeRequest !== null ||420+ ["preparing", "queued", "starting"].includes(thread.status))) ||421+ (input.snoozedUntil === undefined && input.wakeOn === undefined) ||422+ (input.snoozedUntil !== undefined &&423+ !(Date.parse(input.snoozedUntil) > DateTime.toEpochMillis(now)))424+ ) {425+ return thread;426+ }427+ // Mirrors the server: "Until done" binds to the run in progress.428+ let snoozeWakeOn: OrchestrationV2SnoozeWakeOn | null = null;429+ if (input.wakeOn === "run-end") {
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- packages/client-runtime/src/state/threadSettled.ts lines 153 to 154OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -135,3 +143,12 @@135143 return false;136144 }137145146+/**147+ * An "Until done" snooze's run has ended, however it ended: the run stopped,148+ * or a newer run replaced it. Binding to the run keeps a stale condition from149+ * re-hiding the thread when a later run starts.150+ */151+function snoozedRunEnded(shell: ThreadSnoozeShell): boolean {152+ if (shell.snoozeWakeOn?.type !== "run-end") return false;153+ const latestRun = shell.latestRun ?? null;154+ return latestRun?.runId !== shell.snoozeWakeOn.runId || !isThreadRunInProgress(shell);
- packages/client-runtime/src/state/threadSettled.ts lines 156 to 147OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -135,3 +144,4 @@135144 return false;136145 }137146147+/**
- apps/server/src/orchestration-v2/Orchestrator.ts lines 2485 to 2492OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -2463,7 +2472,21 @@2472+ (Option.isNone(parsedSnoozedUntil) ||2473+ DateTime.toEpochMillis(parsedSnoozedUntil.value) <= DateTime.toEpochMillis(now))24632474 ) {24642475 return yield* new OrchestratorDispatchError({24652476 commandId: command.commandId,24662477 commandType: command.type,24672478 cause: `Thread ${command.threadId} snooze wake time ${command.snoozedUntil} is not in the future.`,24682479 });24692480 }2481+ if (command.wakeOn === "run-end") {2482+ // With no run in progress the condition has already fired, so the2483+ // snooze would wake at once. Bind to the run so a later one cannot2484+ // re-hide the thread.2485+ const run = projection.runs.at(-1);2486+ if (2487+ run === undefined ||2488+ (run.status !== "preparing" &&2489+ run.status !== "starting" &&2490+ run.status !== "running" &&2491+ run.status !== "waiting")2492+ ) {
juliusmarminge closed this
Sign in to join this conversation.




macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed