Skip to content

Commit f780dc2

Browse files
feat: pause every thread queue in an environment with one switch
While threadQueuesPaused is on, a run under way finishes but no queued message starts. Lifting the pause starts the queues that waited. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f0e4b62 commit f780dc2

7 files changed

Lines changed: 90 additions & 0 deletions

File tree

‎apps/server/src/mcp/toolkits/environment/handlers.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function preferences(settings: ServerSettings) {
1515
enableProviderUpdateChecks,
1616
switchAccountAtUsageLimit,
1717
scheduledTasksPaused,
18+
threadQueuesPaused,
1819
backgroundActivity,
1920
sourceControlWritingStyle,
2021
} = settings;
@@ -25,6 +26,7 @@ export function preferences(settings: ServerSettings) {
2526
enableProviderUpdateChecks,
2627
switchAccountAtUsageLimit,
2728
scheduledTasksPaused,
29+
threadQueuesPaused,
2830
backgroundActivity: { profile: backgroundActivity.profile },
2931
sourceControlWritingStyle: {
3032
...sourceControlWritingStyle,

‎apps/server/src/mcp/toolkits/environment/tools.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const PreferenceFields = {
2020
enableProviderUpdateChecks: ServerSettings.fields.enableProviderUpdateChecks,
2121
switchAccountAtUsageLimit: ServerSettings.fields.switchAccountAtUsageLimit,
2222
scheduledTasksPaused: ServerSettings.fields.scheduledTasksPaused,
23+
threadQueuesPaused: ServerSettings.fields.threadQueuesPaused,
2324
backgroundActivity: Schema.Struct({ profile: BackgroundActivityProfileSelection }),
2425
sourceControlWritingStyle: Schema.Struct({
2526
mode: Schema.String,
@@ -63,6 +64,7 @@ const EnvironmentPreferencesTool = Tool.make("t3_environment_preferences_update"
6364
enableProviderUpdateChecks: ServerSettingsPatch.fields.enableProviderUpdateChecks,
6465
switchAccountAtUsageLimit: ServerSettingsPatch.fields.switchAccountAtUsageLimit,
6566
scheduledTasksPaused: ServerSettingsPatch.fields.scheduledTasksPaused,
67+
threadQueuesPaused: ServerSettingsPatch.fields.threadQueuesPaused,
6668
backgroundActivity: Schema.optionalKey(Schema.Struct({ profile: BackgroundActivityProfile })),
6769
sourceControlWritingStyle: ServerSettingsPatch.fields.sourceControlWritingStyle,
6870
}),

‎apps/server/src/orchestration-v2/Orchestrator.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
derivePendingBackgroundWork,
6666
pendingBackgroundTurnItems,
6767
} from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
68+
import * as ServerSettings from "../serverSettings.ts";
6869
import * as Context from "effect/Context";
6970
import * as DateTime from "effect/DateTime";
7071
import * as Effect from "effect/Effect";
@@ -809,6 +810,16 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
809810
const idAllocator = yield* IdAllocator.IdAllocatorV2;
810811
const projects = yield* ProjectStore.ProjectStoreV2;
811812
const projectionStore = yield* ProjectionStoreV2;
813+
// Optional, so harnesses that build the orchestrator without settings still work.
814+
const queueSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
815+
// The environment-wide queue pause. Starting a queued run is the one place
816+
// every queue passes through, so the pause is read here and nowhere else.
817+
const threadQueuesPaused = Option.isNone(queueSettings)
818+
? Effect.succeed(false)
819+
: queueSettings.value.getSettings.pipe(
820+
Effect.map((settings) => settings.threadQueuesPaused),
821+
Effect.orElseSucceed(() => false),
822+
);
812823
const effectOutbox = yield* EffectOutbox.EffectOutboxV2;
813824
const nextTurnItemOrdinal = (
814825
projection: Pick<OrchestrationV2ThreadProjection, "thread"> &
@@ -1274,6 +1285,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
12741285
options?: { readonly failedRunId?: RunId; readonly endedRunId?: RunId },
12751286
) =>
12761287
Effect.gen(function* () {
1288+
if (yield* threadQueuesPaused) return;
12771289
// Every terminal run checks the queue. Only a deliverable queued run
12781290
// needs the transcript for provider handoff and legacy import context.
12791291
if (!(yield* projectionStore.canStartQueuedRun(threadId))) return;

‎apps/server/src/orchestration-v2/ThreadManagementService.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import * as Duration from "effect/Duration";
3737
import * as Effect from "effect/Effect";
3838
import * as Layer from "effect/Layer";
3939
import * as Option from "effect/Option";
40+
import * as Ref from "effect/Ref";
4041
import * as Schema from "effect/Schema";
4142
import * as Stream from "effect/Stream";
4243

@@ -459,6 +460,32 @@ const make = Effect.gen(function* () {
459460
// Optional, so harnesses that build this service without providers still work.
460461
const serverSettings = yield* Effect.serviceOption(ServerSettings.ServerSettingsService);
461462
const providerRegistry = yield* Effect.serviceOption(ProviderRegistry.ProviderRegistry);
463+
// Lifting the environment-wide queue pause must start the queues that
464+
// waited: nothing else would, because a queue only moves when a run ends.
465+
if (Option.isSome(serverSettings)) {
466+
const wasPaused = yield* Ref.make(
467+
yield* serverSettings.value.getSettings.pipe(
468+
Effect.map((settings) => settings.threadQueuesPaused),
469+
Effect.orElseSucceed(() => false),
470+
),
471+
);
472+
yield* Stream.runForEach(serverSettings.value.streamChanges, (settings) =>
473+
Ref.getAndSet(wasPaused, settings.threadQueuesPaused).pipe(
474+
Effect.flatMap((before) =>
475+
before && !settings.threadQueuesPaused
476+
? orchestrator.resumeQueuedRuns.pipe(
477+
Effect.tap((resumed) =>
478+
Effect.logInfo("Thread queues resumed", { threads: resumed }),
479+
),
480+
Effect.catch((cause) =>
481+
Effect.logWarning("Could not resume thread queues", { cause }),
482+
),
483+
)
484+
: Effect.void,
485+
),
486+
),
487+
).pipe(Effect.forkIn(layerScope));
488+
}
462489

463490
const ensureLegacyTranscript = Effect.fn(
464491
"orchestrationV2.threadManagement.ensureLegacyTranscript",

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ export function useSettingsRestore(onRestored?: () => void) {
650650
...(settings.switchAccountAtUsageLimit !== DEFAULT_UNIFIED_SETTINGS.switchAccountAtUsageLimit
651651
? ["Switch account at usage limit"]
652652
: []),
653+
...(settings.threadQueuesPaused !== DEFAULT_UNIFIED_SETTINGS.threadQueuesPaused
654+
? ["Pause all queues"]
655+
: []),
653656
...(settings.continueThreadsAfterServerUpdate !==
654657
DEFAULT_UNIFIED_SETTINGS.continueThreadsAfterServerUpdate
655658
? ["Continue threads after restarts"]
@@ -727,6 +730,7 @@ export function useSettingsRestore(onRestored?: () => void) {
727730
settings.persistComposerContextStrip,
728731
settings.enableProviderUpdateChecks,
729732
settings.switchAccountAtUsageLimit,
733+
settings.threadQueuesPaused,
730734
settings.continueThreadsAfterServerUpdate,
731735
settings.sidebarAutoSettleAfterDays,
732736
settings.sidebarAutoSettleOnMerge,
@@ -848,6 +852,7 @@ export function useSettingsRestore(onRestored?: () => void) {
848852
responseStreamingMode: DEFAULT_UNIFIED_SETTINGS.responseStreamingMode,
849853
enableProviderUpdateChecks: DEFAULT_UNIFIED_SETTINGS.enableProviderUpdateChecks,
850854
switchAccountAtUsageLimit: DEFAULT_UNIFIED_SETTINGS.switchAccountAtUsageLimit,
855+
threadQueuesPaused: DEFAULT_UNIFIED_SETTINGS.threadQueuesPaused,
851856
continueThreadsAfterServerUpdate: DEFAULT_UNIFIED_SETTINGS.continueThreadsAfterServerUpdate,
852857
backgroundActivity: DEFAULT_UNIFIED_SETTINGS.backgroundActivity,
853858
backgroundActivityProfile: DEFAULT_UNIFIED_SETTINGS.backgroundActivityProfile,
@@ -3060,6 +3065,35 @@ export function GeneralSettingsPanel() {
30603065
}
30613066
/>
30623067

3068+
<SettingsRow
3069+
serverScoped
3070+
settingKeys={["threadQueuesPaused"]}
3071+
{...searchableSetting("pause-all-queues")}
3072+
description="Hold every thread's queue. Runs under way finish; queued messages wait until you turn this off."
3073+
resetAction={
3074+
settings.threadQueuesPaused !== DEFAULT_UNIFIED_SETTINGS.threadQueuesPaused ? (
3075+
<SettingResetButton
3076+
label="pause all queues"
3077+
onClick={() =>
3078+
updateSettings({
3079+
threadQueuesPaused: DEFAULT_UNIFIED_SETTINGS.threadQueuesPaused,
3080+
})
3081+
}
3082+
/>
3083+
) : null
3084+
}
3085+
control={
3086+
<ScopedSwitch
3087+
settingKeys={["threadQueuesPaused"]}
3088+
checked={settings.threadQueuesPaused}
3089+
onCheckedChange={(checked) =>
3090+
updateSettings({ threadQueuesPaused: Boolean(checked) })
3091+
}
3092+
aria-label="Pause all queues"
3093+
/>
3094+
}
3095+
/>
3096+
30633097
<SettingsRow
30643098
{...searchableSetting("continue-threads-after-server-update")}
30653099
serverScoped

‎apps/web/src/components/settings/settingsSearch.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,12 @@ export const SETTINGS_SEARCH_ITEMS = [
494494
to: "/settings/general",
495495
searchTerms: ["quota limit credits second account subscription automatic fallback weekly"],
496496
},
497+
{
498+
id: "pause-all-queues",
499+
title: "Pause all queues",
500+
to: "/settings/general",
501+
searchTerms: ["queue hold stop waiting messages global pause queued automation"],
502+
},
497503
{
498504
id: "continue-threads-after-server-update",
499505
title: "Continue threads after restarts",

‎packages/contracts/src/settings.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,12 @@ export const ServerSettings = Schema.Struct({
11281128
* its own enabled state, so resuming restores exactly what was running.
11291129
*/
11301130
scheduledTasksPaused: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
1131+
/**
1132+
* Holds every thread's queue in this environment: a run that is under way
1133+
* finishes, but no queued message starts until this is turned off again.
1134+
* Messages can still be queued, edited and removed meanwhile.
1135+
*/
1136+
threadQueuesPaused: Schema.Boolean.pipe(Schema.withDecodingDefault(Effect.succeed(false))),
11311137
// Retain the update-era key; recovery now needs an environment-owned opt-in.
11321138
continueThreadsAfterServerUpdate: Schema.Boolean.pipe(
11331139
Schema.withDecodingDefault(Effect.succeed(false)),
@@ -1481,6 +1487,7 @@ export const ServerSettingsPatch = Schema.Struct({
14811487
enableProviderUpdateChecks: Schema.optionalKey(Schema.Boolean),
14821488
switchAccountAtUsageLimit: Schema.optionalKey(Schema.Boolean),
14831489
scheduledTasksPaused: Schema.optionalKey(Schema.Boolean),
1490+
threadQueuesPaused: Schema.optionalKey(Schema.Boolean),
14841491
continueThreadsAfterServerUpdate: Schema.optionalKey(Schema.Boolean),
14851492
enableAgentBrowserAccess: Schema.optionalKey(Schema.Boolean),
14861493
projectAgentBrowserAccessOverrides: Schema.optionalKey(

0 commit comments

Comments
 (0)