Skip to content
Open
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
74 changes: 74 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5636,6 +5636,80 @@ describe("OrchestratorMcpService thread lookup", () => {
}),
);

// Closura: an actionable assignment to an idle agent thread starts a turn. A digest never
// starts one, which is how two repair orders sat queued on idle writers on 2026-12-01 (CLO-1316).
it.effect("starts a turn for an actionable send to an idle agent thread", () =>
Effect.gen(function* () {
const target = liveThreadShell(ThreadId.make("thread:writer"));
const caller = liveThreadShell(ThreadId.make("thread:caller"));
const asThread = (threadId: ThreadId): McpInvocationScope => ({
...client,
thread: {
threadId,
providerSessionId: "session:test",
providerInstanceId: ProviderInstanceId.make("codex"),
},
requestNamespace: `client:${threadId}`,
});
const capture = (scope: McpInvocationScope, extra: Record<string, unknown> = {}) =>
Effect.gen(function* () {
const inputs: Array<ThreadManagementService.ThreadManagementSendInput> = [];
const sent = yield* Ref.make(0);
const result = yield* Effect.gen(function* () {
const mcp = yield* OrchestratorMcpService.OrchestratorMcpService;
return yield* mcp.sendToThread(scope, {
threadId: target.id,
message: "repair head 7925c479",
...extra,
});
}).pipe(
Effect.provide(
service([target, caller], sent, {
// The lookup receives { projectId, threadId }, so the caller's thread is chosen by
// the thread id inside it. Comparing the object itself with caller.id is always false.
getProjectThreadRecords: (input) =>
Effect.succeed(
idleThreadProjection(input.threadId === caller.id ? caller : target),
),
getThreadRecords: (threadId) =>
Effect.succeed(idleThreadProjection(threadId === caller.id ? caller : target)),
sendToThread: (input) => {
inputs.push(input);
return Effect.succeed({
run: { id: RunId.make("run:sent"), status: "running" },
delivery: "started",
} as never);
},
}),
),
);
return { input: inputs[0], result };
});

// A child of the caller, idle and agent-owned: the assignment starts a turn.
const child = yield* capture(asThread(caller.id));
assert.strictEqual(child.input?.delivery, undefined);
assert.isUndefined(child.result.deliveryClass);

// A worker reached through a link, with no thread on this machine: the same.
const linked = yield* capture({
...client,
client: { sessionId: "link-a", label: "A", access: "full-access", linked: true },
});
assert.strictEqual(linked.input?.delivery, undefined);
assert.isUndefined(linked.result.deliveryClass);

// An FYI keeps the digest, and the result names the downgrade instead of hiding it.
const fyi = yield* capture(asThread(caller.id), { digestCategory: "fyi" });
assert.strictEqual(fyi.input?.delivery?.class, "digest");
assert.strictEqual(fyi.result.deliveryClass, "digest");

// A class the sender names is kept, digest included.
const named = yield* capture(asThread(caller.id), { deliveryClass: "digest" });
assert.strictEqual(named.input?.delivery?.class, "digest");
}),
);

it.effect("retries a failed worktree setup when a send is held behind it", () =>
Effect.gen(function* () {
const target = liveThreadShell(ThreadId.make("thread:held"));
Expand Down
11 changes: 5 additions & 6 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3982,14 +3982,13 @@ const make = Effect.gen(function* () {
}

const mode = input.mode ?? "auto";
// A message to another thread rides in that thread's next digest unless the sender
// names a class. A message to the sender's own thread keeps the mode it asked for.
// Closura: an assignment to an idle agent thread starts a turn (CLO-1316). Only an FYI, which
// names a digest category, stays a digest, and the result names that downgrade. A named class
// is kept. A send to the sender's own thread keeps the mode it asked for.
const crossThread = parent === undefined || parent.thread.id !== target.thread.id;
const deliveryClass =
input.deliveryClass ??
(input.digestCategory !== undefined ||
(parent !== undefined && parent.thread.id !== target.thread.id)
? "digest"
: undefined);
(input.digestCategory !== undefined && crossThread ? "digest" : undefined);
if (
deliveryClass === undefined &&
(input.coalesceKey !== undefined || input.expiresAt !== undefined)
Expand Down