Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ const AUTO_SETTLE_SETTING_KEYS: ReadonlySet<string> = new Set([
"sidebarAutoSettleOnMerge",
"sidebarAutoSettleAfterDays",
"autoResumeLimitedThreads",
"snoozeLimitedThreads",
]);

function planServerSettingsWrites(
Expand Down
9 changes: 0 additions & 9 deletions apps/mobile/src/features/settings/ThreadSettingsSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export function AutoSettleSettingsRows(props: {
const writeToAll = (
patch: Partial<AutoSettleSettings> & {
autoResumeLimitedThreads?: boolean;
snoozeLimitedThreads?: boolean;
},
) => props.write(patch);

Expand Down Expand Up @@ -142,14 +141,6 @@ export function AutoSettleSettingsRows(props: {
disabled={disabledFor("autoResumeLimitedThreads")}
onValueChange={(value) => writeToAll({ autoResumeLimitedThreads: value })}
/>
<SettingsSwitchRow
icon="clock"
label="Snooze until limits reset"
subtitle="Snooze threads until their usage limits reset. Enable auto-resume to continue the agent after the reset."
value={uniformMobileSetting(displayTargets, "snoozeLimitedThreads")}
disabled={disabledFor("snoozeLimitedThreads")}
onValueChange={(value) => writeToAll({ snoozeLimitedThreads: value })}
/>
</SettingsSection>
) : null}
<SettingsSection title="Auto-settle">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const firstProject = "first-project" as ProjectId;
const secondProject = "second-project" as ProjectId;

describe("mobile usage-limit settings across environments", () => {
it.each(["autoResumeLimitedThreads", "snoozeLimitedThreads"] as const)(
it.each(["autoResumeLimitedThreads"] as const)(
"shows %s as mixed and can enable it everywhere without changing other settings",
(key) => {
const targets = resolveMobileSettingsTargets(
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ const failedThread = (failedAgoMs: number, resetAgoMs: number) => {
};

describe("limitRecoveryCommand arming", () => {
it("does not snooze a thread when a usage limit stops it", () => {
const thread = failedThread(-HOUR_MS, -2 * HOUR_MS);
const asked = limitRecoveryCommand(thread, false, nowMs, true);
assert.isNull(asked);
const armed = limitRecoveryCommand(thread, true, nowMs, true);
assert.equal(armed?.type, "thread.metadata.update");
if (armed?.type === "thread.metadata.update") {
assert.equal(armed.limitRecovery?.snooze, false);
assert.equal(armed.limitRecovery?.autoResume, true);
}
});

it("does not freshly arm a failure whose reset passed days ago", () => {
const thread = failedThread(5 * 24 * HOUR_MS, 4 * 24 * HOUR_MS);
assert.isNull(limitRecoveryCommand(thread, true, nowMs));
Expand Down
18 changes: 8 additions & 10 deletions apps/server/src/orchestration-v2/UsageLimitRecoveryWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export function limitRecoveryCommand(
thread: ProjectionStore.ProjectionLimitRecoveryCandidate,
autoResume: boolean,
nowMs: number,
snooze = false,
// A usage limit no longer snoozes a thread by itself. The flag stays so an older caller
// still compiles; the per-thread "Snooze until reset" button is the only way to hide one.
_snooze = false,
): OrchestrationV2Command | null {
if (
thread.status !== "failed" ||
Expand All @@ -41,7 +43,7 @@ export function limitRecoveryCommand(
const recovery = thread.limitRecovery;
if (recovery?.runId !== thread.latestRunId || recovery.resetAt !== thread.usageLimitResetAt) {
if (nowMs - resetMs > MAX_OVERDUE_ARM_MS) return null;
if (!autoResume && (!snooze || resetMs <= nowMs)) return null;
if (!autoResume) return null;
return {
type: "thread.metadata.update",
commandId: CommandId.make(`limit-arm:${identity}`),
Expand All @@ -50,7 +52,7 @@ export function limitRecoveryCommand(
runId: thread.latestRunId,
resetAt: thread.usageLimitResetAt,
autoResume,
snooze: snooze && resetMs > nowMs,
snooze: false,
},
};
}
Expand Down Expand Up @@ -108,16 +110,12 @@ const makeSweep = Effect.gen(function* () {
const candidates = yield* projections.getLimitRecoveryCandidates({
now,
autoResume: preferences.autoResumeLimitedThreads,
snooze: preferences.snoozeLimitedThreads,
// Saved settings may still say to snooze. A usage limit leaves the thread in the inbox.
snooze: false,
});
let acted = false;
for (const thread of candidates) {
const command = limitRecoveryCommand(
thread,
preferences.autoResumeLimitedThreads,
nowMs,
preferences.snoozeLimitedThreads,
);
const command = limitRecoveryCommand(thread, preferences.autoResumeLimitedThreads, nowMs);
if (command === null) continue;
acted = true;
yield* Effect.gen(function* () {
Expand Down
9 changes: 7 additions & 2 deletions apps/server/src/storageCleanup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ describe("V2 storage cleanup eligibility", () => {
resetIn: -1_000,
idle: true,
},
{ name: "not yet armed by the recovery worker", armed: false, resetIn: DAY_MS, idle: false },
{
name: "not yet armed, and the snooze setting no longer holds it",
armed: false,
resetIn: DAY_MS,
idle: true,
},
{
name: "not yet armed, auto-resume after reset",
armed: false,
Expand Down Expand Up @@ -3684,7 +3689,7 @@ describe("storage cleanup reports and local file policies", () => {
});

describe("settled worktree rechecks", () => {
it.effect.each(["autoResumeLimitedThreads", "snoozeLimitedThreads"] as const)(
it.effect.each(["autoResumeLimitedThreads"] as const)(
"keeps a usage-limited checkout when %s is enabled during measurement",
(preference) =>
runCleanupTest(
Expand Down
3 changes: 2 additions & 1 deletion apps/server/src/storageCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ function heldForLimitRecovery(
now - resetMs > MAX_OVERDUE_ARM_MS
)
return false;
return settings.autoResumeLimitedThreads || (settings.snoozeLimitedThreads && resetMs > now);
// A usage limit no longer snoozes the thread, so that setting does not hold the checkout.
return settings.autoResumeLimitedThreads;
}

/** PR metadata refreshes must not reset the inactivity clock. */
Expand Down
20 changes: 0 additions & 20 deletions apps/web/src/components/settings/SettingsPanels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,6 @@ export function useSettingsRestore(onRestored?: () => void) {
...(settings.autoResumeLimitedThreads !== DEFAULT_UNIFIED_SETTINGS.autoResumeLimitedThreads
? ["Resume after usage limits"]
: []),
...(settings.snoozeLimitedThreads !== DEFAULT_UNIFIED_SETTINGS.snoozeLimitedThreads
? ["Snooze until limits reset"]
: []),
...(!Equal.equals(settings.snoozePresets, DEFAULT_UNIFIED_SETTINGS.snoozePresets)
? ["Snooze options"]
: []),
Expand Down Expand Up @@ -682,7 +679,6 @@ export function useSettingsRestore(onRestored?: () => void) {
sidebarAutoSettleKeepPullRequests: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleKeepPullRequests,
sidebarAutoSettleOnMerge: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge,
autoResumeLimitedThreads: DEFAULT_UNIFIED_SETTINGS.autoResumeLimitedThreads,
snoozeLimitedThreads: DEFAULT_UNIFIED_SETTINGS.snoozeLimitedThreads,
snoozePresets: DEFAULT_UNIFIED_SETTINGS.snoozePresets,
responseStreamingMode: DEFAULT_UNIFIED_SETTINGS.responseStreamingMode,
enableProviderUpdateChecks: DEFAULT_UNIFIED_SETTINGS.enableProviderUpdateChecks,
Expand Down Expand Up @@ -1871,22 +1867,6 @@ export function ThreadsSettingsPanel() {
/>
}
/>
<SettingsRow
serverScoped
{...searchableSetting("snooze-limited-threads")}
description="Snooze threads until their usage limits reset. Enable auto-resume to continue the agent after the reset."
settingKeys={["snoozeLimitedThreads"]}
control={
<ScopedSwitch
settingKeys={["snoozeLimitedThreads"]}
checked={settings.snoozeLimitedThreads}
onCheckedChange={(checked) =>
updateSettings({ snoozeLimitedThreads: Boolean(checked) })
}
aria-label="Snooze until limits reset"
/>
}
/>
</SettingsSection>

{hasServerTargets ? (
Expand Down
6 changes: 0 additions & 6 deletions apps/web/src/components/settings/settingsSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,12 +447,6 @@ export const SETTINGS_SEARCH_ITEMS = [
environmentOnly: true,
scope: "environment-defaults",
},
{
id: "snooze-limited-threads",
title: "Snooze until limits reset",
to: "/settings/threads",
searchTerms: ["usage quota rate limit reset wake recover continue"],
},
{
id: "auto-resume-limited-threads",
title: "Resume after usage limits",
Expand Down
13 changes: 7 additions & 6 deletions docs/user/thread-sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,13 @@ The environment must be running when the reset arrives; it resumes overdue
continuations after a restart. Stopping the thread, sending a new message,
archiving, or settling it prevents a pending continuation from starting.

Choose **Snooze until reset** to hide the thread until its allowance returns.
Snooze and auto-resume are independent: snooze alone wakes the thread without
sending a message; enabling both wakes and continues it. **Wake now** cancels
the snooze. Enable **Snooze until limits reset** in thread behavior settings to
snooze limit stops by default. Providers without a reset time offer manual
retry and the normal snooze choices.
A usage limit leaves the thread in the inbox, marked limited, so it is clear
that the model or provider needs changing. Choose **Snooze until reset** on
that thread to hide it until its allowance returns. Snooze and auto-resume are
independent: snooze alone wakes the thread without sending a message; enabling
both wakes and continues it. **Wake now** cancels the snooze. Nothing snoozes
a limited thread on its own. Providers without a reset time offer manual retry
and the normal snooze choices.

On web and desktop, use **Agents** to follow work delegated to subagents.
On mobile, open a subagent from its conversation card or **Agents**. On iOS
Expand Down
1 change: 0 additions & 1 deletion packages/client-runtime/src/state/sharedSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const SHARED_SERVER_SETTING_KEYS = [
"sidebarAutoSettleAfterDays",
"sidebarAutoSettleOnMerge",
"autoResumeLimitedThreads",
"snoozeLimitedThreads",
"snoozePresets",
"newWorktreesStartFromOrigin",
"sourceControlWritingStyle",
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,9 @@ export const ServerSettings = Schema.Struct({
Schema.withDecodingDefault(Effect.succeed(false)),
),
idleCompaction: Schema.optionalKey(IdleCompactionMode),
// Closura: a usage limit must leave the thread visible. Plans are pooled across providers,
// so hiding the thread until the reset hides the reason to switch models. The per-thread
// "Snooze until reset" button still writes this field's recovery flag.
snoozeLimitedThreads: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
// Closura: a usage limit resets for every thread on the account at once. Resuming them is
// the server's job, so Lead is told only about a thread that does not come back.
Expand Down
Loading