Skip to content
Open
40 changes: 40 additions & 0 deletions apps/server/src/mcp/toolkits/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,46 @@ it.effect("a read-only client reads threads and is refused every write before it
);
const dispatched: Array<string> = [];

it.effect("an agent turns a thread's auto-settle off and back on", () => {
const commands: Array<unknown> = [];
return Effect.gen(function* () {
const server = yield* McpServer.McpServer;
for (const action of ["disable_auto_settle", "enable_auto_settle"]) {
const result = yield* server
.callTool({ name: "t3_thread_organize", arguments: { action } })
.pipe(
Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
Effect.provideService(McpSchema.McpServerClient, client),
);
expect(result.isError).toBe(false);
}
expect(commands).toMatchObject([
{ type: "thread.auto-settle.set", threadId, enabled: false },
{ type: "thread.auto-settle.set", threadId, enabled: true },
]);
}).pipe(
Effect.provide(
layerThreadToolkit.pipe(
Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
Layer.provide(NodeCrypto.layer),
Layer.provide(
Layer.mock(ThreadManagement.ThreadManagementService)({
getThreadShell: (id) => Effect.succeed(McpToolAccessTestkit.liveThreadShell(id)),
getProjectThreadRecords: ({ threadId: id }) =>
Effect.succeed(
McpToolAccessTestkit.idleThreadProjection(McpToolAccessTestkit.liveThreadShell(id)),
),
dispatch: (command) => {
commands.push(command);
return Effect.succeed({ sequence: 1 } as never);
},
}),
),
),
),
);
});

it.effect("hides act-as-caller tools from a client caller", () =>
Effect.gen(function* () {
const server = yield* McpServer.McpServer;
Expand Down
8 changes: 8 additions & 0 deletions apps/server/src/mcp/toolkits/thread/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ export const layer = McpToolAccess.toLayer(ThreadToolkit, {
command = { ...common, type: "thread.pin", ...(orderKey ? { orderKey } : {}) };
break;
}
case "disable_auto_settle":
case "enable_auto_settle":
command = {
...common,
type: "thread.auto-settle.set",
enabled: input.action === "enable_auto_settle",
};
break;
default:
command = { ...common, type: `thread.${input.action}` };
}
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/mcp/toolkits/thread/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import * as McpInvocationContext from "../../McpInvocationContext.ts";

const ThreadOrganizeTool = Tool.make("t3_thread_organize", {
description:
"Pin, snooze, settle, archive, or mark a thread unread. Omit `threadId` for this thread. `snooze` needs `snoozedUntil`. Settling this thread applies at turn end. A failed turn or queued message leaves it active.",
"Pin, snooze, settle, archive, or mark a thread unread. Omit `threadId` for this thread. `snooze` needs `snoozedUntil`. Settling this thread applies at turn end. A failed turn or queued message leaves it active. `disable_auto_settle` stops the thread settling itself, such as after its PR merges, until `enable_auto_settle`.",
parameters: Schema.Struct({
environmentId: OrchestratorMcpEnvironmentTarget,
threadId: Schema.optional(ThreadId),
Expand All @@ -46,6 +46,8 @@ const ThreadOrganizeTool = Tool.make("t3_thread_organize", {
"archive",
"unarchive",
"mark_unread",
"disable_auto_settle",
"enable_auto_settle",
]),
snoozedUntil: Schema.optional(IsoDateTime),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,47 @@ const layerTest = Layer.mergeAll(
),
);

it.effect("a same-millisecond auto-settle disable rejects an in-flight settlement", () =>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fold the race assertion into the lifecycle test

apps/server/src/orchestration-v2/runtimeLayer.test.ts's existing applies lifecycle commands idempotently... case already exercises thread.auto-settle dispatch with stale snapshots and overrides, so the same-millisecond disable assertion fits there; fold it into that case instead of adding another it to follow the repo's extend-before-add test rule.

AGENTS.md reference: AGENTS.md:L107-L107

Useful? React with 👍 / 👎.

Effect.gen(function* () {
const orchestrator = yield* Orchestrator.OrchestratorV2;
const projections = yield* ProjectionStore.ProjectionStoreV2;
const threadId = ThreadId.make("thread:auto-settle-disable-race");
yield* orchestrator.dispatch({
type: "thread.create",
commandId: CommandId.make("create-auto-settle-disable-race"),
threadId,
projectId: ProjectId.make("project:auto-settle-disable-race"),
title: "Follow-up work",
modelSelection,
runtimeMode: "full-access",
interactionMode: "default",
branch: null,
worktreePath: null,
createdBy: "user",
creationSource: "web",
});
const snapshotAt = (yield* projections.getThread(threadId)).updatedAt;
yield* orchestrator.dispatch({
type: "thread.auto-settle.set",
commandId: CommandId.make("disable-auto-settle-race"),
threadId,
enabled: false,
});
const disabled = yield* projections.getThread(threadId);
assert.equal(DateTime.toEpochMillis(disabled.updatedAt), DateTime.toEpochMillis(snapshotAt));
const settlement = yield* Effect.exit(
orchestrator.dispatch({
type: "thread.auto-settle",
commandId: CommandId.make("in-flight-auto-settle-race"),
threadId,
snapshotAt,
}),
);
assert.equal(settlement._tag, "Failure");
assert.equal((yield* projections.getThread(threadId)).settledOverride, null);
}).pipe(Effect.provide(layerTest)),
);

it.effect.each(
(["provider.switch", "thread.model-selection.set"] as const).flatMap((type) =>
[
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/orchestration-v2/Orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15557,6 +15557,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
);
if (
thread.settledOverride !== null ||
thread.autoSettleDisabledAt != null ||
DateTime.toEpochMillis(thread.updatedAt) > DateTime.toEpochMillis(command.snapshotAt)
) {
return yield* new OrchestratorDispatchError({
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 6245,
"codexAdditionalContextBytes": 7639,
"mcpToolListJsonBytes": 58399
"mcpToolListJsonBytes": 58555
}
4 changes: 3 additions & 1 deletion docs/user/thread-sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ To keep one thread out of the settled shelf no matter how long it sits idle, ope
choose **Auto-settle behavior**, and pick **Never**. The current option is checked. Pick
**Follow settings** to return to the rules in **Settings → Threads**. While those rules are off,
a thread on **Follow settings** does not settle automatically either. Manual settle, snooze, and
archive still work while it is set to **Never**.
archive still work while it is set to **Never**. An agent can switch a thread between **Never** and
**Follow settings** too, for example to keep a thread whose pull request merged open while it
finishes follow-up work.

Change these rules in **Settings → Threads**.
They continue to run when your apps are closed. On web and desktop, choose an environment at the
Expand Down
Loading
Loading