feat(v2): snooze limited threads until usage resets #12687
Mergedjuliusmarmingemerged 10 commits into
provider-limits/auto-resume fromrefs/pull/12687/headmerged by juliusmarminge 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
juliusmarminge changed the title
- apps/web/src/components/chat/UsageLimitRecoveryCard.tsx lines 26 to 26OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -21,4 +23,4 @@2123 const canSchedule = resetAt !== null && Date.parse(resetAt) > Date.parse(stoppedAt);2224 const scheduled =2325 recovery?.runId === runId && recovery.resetAt === resetAt && recovery.autoResume;24- async function toggle() {26+ const snoozed = resetAt !== null && snoozedUntil === resetAt;apps/web/src/components/settings/SettingsPanels.tsx line 2249OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2244,3 +2244,6 @@22442244 />22452245 }22462246 />2247+ <SettingsRow2248+ serverScoped2249+ title="Snooze limited threads"
- apps/web/src/components/chat/UsageLimitRecoveryCard.tsx line 27OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -21,4 +23,5 @@2123 const canSchedule = resetAt !== null && Date.parse(resetAt) > Date.parse(stoppedAt);2224 const scheduled =2325 recovery?.runId === runId && recovery.resetAt === resetAt && recovery.autoResume;24- async function toggle() {26+ const snoozed =27+ resetAt !== null && snoozedUntil !== null && Date.parse(snoozedUntil) === Date.parse(resetAt);
- apps/server/src/orchestration-v2/Orchestrator.ts lines 2414 to 2431OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2411,3 +2411,21 @@24112411 ? null24122412 : { ...command.limitRecovery, requestId: command.commandId },24132413 }),2414+ ...(command.limitRecovery?.snooze === true &&2415+ Date.parse(command.limitRecovery.resetAt) > DateTime.toEpochMillis(now)2416+ ? {2417+ snoozedUntil: DateTime.makeUnsafe(command.limitRecovery.resetAt),2418+ snoozedAt:2419+ thread.snoozedUntil != null &&2420+ DateTime.toEpochMillis(thread.snoozedUntil) ===2421+ Date.parse(command.limitRecovery.resetAt)2422+ ? (thread.snoozedAt ?? now)2423+ : now,2424+ }2425+ : command.limitRecovery !== undefined &&2426+ thread.limitRecovery?.snooze &&2427+ thread.snoozedUntil != null &&2428+ DateTime.toEpochMillis(thread.snoozedUntil) ===2429+ Date.parse(thread.limitRecovery.resetAt)2430+ ? { snoozedUntil: null, snoozedAt: null }2431+ : {}),
- packages/contracts/src/orchestrationV2.ts line 334Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -331,3 +331,4 @@331331 runId: RunId,332332 resetAt: IsoDateTime,333333 autoResume: Schema.Boolean,334+ snooze: Schema.optional(Schema.Boolean),apps/mobile/src/features/threads/UsageLimitRecoveryCard.tsx line 54OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -36,7 +35,20 @@35+ const snoozed =36+ recovery?.snooze === true &&37+ recovery.runId === runId &&38+ recovery.resetAt === resetAt &&39+ resetAt !== null &&40+ thread.snoozedUntil !== null &&41+ Date.parse(thread.snoozedUntil) === Date.parse(resetAt);42+ async function toggle(action: "resume" | "snooze") {3643 if (!resetAt || !runId || !canSchedule) return;3744 setPending(true);3845 setError(null);3946 try {4047 const result = await updateMetadata({4148 environmentId,42- input: { threadId: thread.id, limitRecovery: { runId, resetAt, autoResume: !scheduled } },49+ input: {50+ threadId: thread.id,51+ limitRecovery: {52+ runId,53+ resetAt,54+ autoResume: action === "resume" ? !scheduled : Boolean(scheduled),
- apps/web/src/components/chat/UsageLimitRecoveryBanner.tsx line 94OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -56,6 +85,10 @@5685 }5786 return (5887 <div className="flex flex-wrap items-center gap-2">59- <Button size="xs" variant="ghost" disabled={pending} onClick={() => void toggle()}>88+ <Button size="xs" variant="ghost" disabled={pending} onClick={() => void toggle("resume")}>6089 {pending ? "Saving..." : scheduled ? "Cancel auto-resume" : "Resume at reset"}6190 </Button>91+ <Button92+ size="xs"93+ variant="ghost"94+ disabled={pending || (!snoozed && Date.parse(resetAt!) <= nowMs)}
- packages/contracts/src/orchestrationV2.ts line 2359Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2339,4 +2349,4 @@23392349 expectedWorktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),23402350 /** Reject unless no message or run has landed on this thread. */23412351 expectedEmpty: Schema.optional(Schema.Boolean),2342- limitRecovery: Schema.optional(Schema.NullOr(OrchestrationV2LimitRecovery)),2352+ limitRecovery: Schema.optional(Schema.NullOr(OrchestrationV2LimitRecoveryUpdate)),
- apps/web/src/components/ChatView.tsx line 6621OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -6614,7 +6614,8 @@66146614 const threadKey = scopedThreadKey(activeThreadRef);66156615 setUnsnoozingThreadKey(threadKey);66166616 try {6617- const result = await unsnoozeThreadMutation({6618- environmentId: activeThreadRef.environmentId,6619- input: { threadId: activeThreadRef.threadId, reason: "user" },6620- });6617+ const recovery = activeThreadShell?.limitRecovery;6618+ const recoveryOwnsSnooze =6619+ recovery?.snooze === true &&6620+ recovery.runId === activeThreadShell?.latestRun?.runId &&6621+ recovery.resetAt === serverRuntime?.usageLimitResetAt &&
- apps/server/src/orchestration-v2/Orchestrator.ts lines 2235 to 2237OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2231,3 +2231,7 @@22312231 const projection = yield* loadProjectionForCommand(command);22322232 const run = projection.runs.at(-1) ?? null;22332233 const failure = latestRootProviderFailure(run, projection.turnItems);2234+ if (2235+ command.limitRecovery.snooze === true &&2236+ Date.parse(command.limitRecovery.resetAt) <= DateTime.toEpochMillis(now)2237+ ) {
- apps/server/src/orchestration-v2/Orchestrator.ts line 2446Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2408,9 +2435,13 @@24082435 ...(command.title === undefined ? {} : { title: command.title }),2409- ...(command.limitRecovery === undefined2410- ? {}2411- : {2412- limitRecovery:2413- command.limitRecovery === null2414- ? null2415- : { ...command.limitRecovery, requestId: command.commandId },2416- }),2436+ ...(command.limitRecovery === undefined ? {} : { limitRecovery }),2437+ ...(command.limitRecovery !== undefined &&2438+ limitRecovery?.snooze === true &&2439+ Date.parse(limitRecovery.resetAt) > DateTime.toEpochMillis(now)2440+ ? {2441+ snoozedUntil: DateTime.makeUnsafe(limitRecovery.resetAt),2442+ // Recovery changes acknowledge the same stopped run; keep its2443+ // metadata timestamp from appearing as a fresh failure wake.2444+ snoozedAt: now,2445+ }2446+ : command.limitRecovery !== undefined &&2447+ thread.limitRecovery?.snooze &&
juliusmarminge merged this58c6559
juliusmarminge closed this
Sign in to join this conversation.



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