Skip to content
Draft
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
4 changes: 3 additions & 1 deletion apps/server/src/mcp/OrchestratorMcpService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4912,8 +4912,9 @@ describe("OrchestratorMcpService thread list", () => {
]
: [],
});
const standing = { name: "Ops", role: "Operations", avatarId: "bolt", accent: "sky" } as const;
const shells = [
shell("thread:a-snoozed", "project:a", true),
{ ...shell("thread:a-snoozed", "project:a", true), standing },
shell("thread:a-awake", "project:a", false),
shell("thread:b-snoozed", "project:b", true, true, true),
{
Expand Down Expand Up @@ -4992,6 +4993,7 @@ describe("OrchestratorMcpService thread list", () => {
listed.threads.map((thread) => thread.pinned),
[false, true],
);
assert.deepStrictEqual(listed.threads[0]?.standing, standing);
assert.deepStrictEqual(
listed.threads.map((thread) => [thread.blockedOnThreadWait, thread.pendingBackgroundTasks]),
[
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ function listItemFromShell(
): OrchestratorMcpThreadListItem {
return {
...(shell.inbox === undefined ? {} : { inbox: shell.inbox }),
...(shell.standing == null ? {} : { standing: shell.standing }),
threadId: shell.id,
projectId: shell.projectId,
title: shell.title,
Expand Down
75 changes: 37 additions & 38 deletions apps/server/src/orchestration-v2/Orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3933,23 +3933,17 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
const now = yield* DateTime.now;
const emitEvent = emit(events, command);
const thread: OrchestrationV2AppThread = {
...(command.inboxOrigin === undefined &&
command.inboxRouting === undefined &&
command.createdBy !== "agent"
? {}
: {
inbox: makeThreadInbox({
actor:
command.inboxOrigin ??
(command.createdBy === "agent" ? { kind: "agent", id: "agent" } : null),
...(command.inboxRouting === undefined ? {} : { routing: command.inboxRouting }),
executorEnvironmentId: yield* Effect.serviceOption(ServerEnvironmentIdentity).pipe(
Effect.flatMap((identity) =>
Option.isSome(identity) ? identity.value.getEnvironmentId : Effect.succeed(null),
),
),
}),
}),
inbox: makeThreadInbox({
actor:
command.inboxOrigin ??
(command.createdBy === "agent" ? { kind: "agent", id: "agent" } : null),
...(command.inboxRouting === undefined ? {} : { routing: command.inboxRouting }),
executorEnvironmentId: yield* Effect.serviceOption(ServerEnvironmentIdentity).pipe(
Effect.flatMap((identity) =>
Option.isSome(identity) ? identity.value.getEnvironmentId : Effect.succeed(null),
),
),
}),
createdBy: command.createdBy,
creationSource: command.creationSource,
id: command.threadId,
Expand Down Expand Up @@ -7555,7 +7549,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
loadProjectionForCommand(command, ["turnItems"], {
turnItemTypes: ["compaction"],
turnItemRunIds: [run.id],
}).pipe(Effect.map(({ turnItems }) => compactionHoldsSteer({ ...projection, turnItems }, run)));
}).pipe(
Effect.map(({ turnItems }) => compactionHoldsSteer({ ...projection, turnItems }, run)),
);
let deferSteer = false;
if (dispatchMode.type === "steer_active" || dispatchMode.type === "restart_active") {
const targetRunId = dispatchMode.targetRunId;
Expand Down Expand Up @@ -7799,7 +7795,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
dispatchMode.type === "start_immediately" ||
dispatchMode.type === "queue_after_active";
// A digest never starts a turn, so on a thread with nothing running it waits for one.
const holdDigest = deliveryClass === "digest" && queueBehindRun === undefined && startsOrQueuesRun;
const holdDigest =
deliveryClass === "digest" && queueBehindRun === undefined && startsOrQueuesRun;
const shouldQueue = (queueBehindRun !== undefined && startsOrQueuesRun) || holdDigest;
// An explicit pick queued ahead reaches the thread only when its run starts. A goal or
// restart command that stops the active run goes first, so nothing queued applies before it.
Expand Down Expand Up @@ -7906,25 +7903,25 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
);
const queuedProviderThread: OrchestrationV2ProviderThread = targetProviderThread ??
queueProviderThread ?? {
id: idAllocator.derive.providerThread({
id: idAllocator.derive.providerThread({
driver: queuedAdapter.driver,
nativeThreadId: `pending:${runId}`,
}),
driver: queuedAdapter.driver,
nativeThreadId: `pending:${runId}`,
}),
driver: queuedAdapter.driver,
providerInstanceId: modelSelection.instanceId,
providerSessionId: null,
appThreadId: command.threadId,
ownerNodeId: null,
nativeThreadRef: null,
nativeConversationHeadRef: null,
status: "not_loaded",
firstRunOrdinal: null,
lastRunOrdinal: null,
handoffIds: [],
forkedFrom: null,
createdAt: now,
updatedAt: now,
};
providerInstanceId: modelSelection.instanceId,
providerSessionId: null,
appThreadId: command.threadId,
ownerNodeId: null,
nativeThreadRef: null,
nativeConversationHeadRef: null,
status: "not_loaded",
firstRunOrdinal: null,
lastRunOrdinal: null,
handoffIds: [],
forkedFrom: null,
createdAt: now,
updatedAt: now,
};
const attemptId = idAllocator.derive.runAttempt({ runId, attemptOrdinal: 1 });
const rootNodeId = idAllocator.derive.rootNode({ runId });
const checkpointScope =
Expand Down Expand Up @@ -9272,7 +9269,9 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
...(continuedTaskId === undefined ? {} : { delegatedTaskId: continuedTaskId }),
...wakeWorkStartedAt(projection, command),
...(command.delivery === undefined ? {} : { delivery: command.delivery }),
...(forkFold === undefined || forkFold.digest.length === 0 ? {} : { digest: forkFold.digest }),
...(forkFold === undefined || forkFold.digest.length === 0
? {}
: { digest: forkFold.digest }),
};
const attempt: OrchestrationV2RunAttempt = {
id: attemptId,
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/orchestration-v2/ThreadForkService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ContextTransferId,
makeThreadInbox,
OrchestrationV2Actor,
OrchestrationV2AppThread,
OrchestrationV2ContextSourcePoint,
Expand Down Expand Up @@ -103,6 +104,7 @@ export const layer: Layer.Layer<ThreadForkServiceV2> = Layer.succeed(
const { delegatedFrom: _delegatedFrom, ...inherited } = input.sourceProjection.thread;
const targetThread: OrchestrationV2AppThread = {
...inherited,
inbox: inherited.inbox ?? makeThreadInbox({ actor: null }),
// PR context follows the conversation; watching remains the source thread's responsibility.
pullRequests: input.sourceProjection.thread.pullRequests?.map(
({ watch: _watch, ...link }) => link,
Expand Down
21 changes: 21 additions & 0 deletions apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3516,6 +3516,27 @@ it.effect(
...launchInput({ command: "inbox-launch", thread: "inbox-thread" }),
inboxOrigin: { kind: "human" as const, id: "jeff" as const },
};
const unrouted = yield* launches.launch(
launchInput({ command: "no-inbox", thread: "no-inbox" }),
);
const shell = yield* threads.getThreadShell(unrouted.threadId);
assert.equal(shell?.inbox?.audience, "agent-only");
assert.equal(shell?.inbox?.origin, null);
for (const founder of ["jeff", "kameron"] as const) {
const own = yield* launches.launch({
...launchInput({ command: `inbox-${founder}`, thread: `inbox-${founder}` }),
inboxOrigin: { kind: "human", id: founder },
});
const inbox = (yield* threads.getThreadShell(own.threadId))?.inbox;
assert.equal(inbox?.owner, founder);
assert.equal(inbox?.audience, founder);
}
const shared = yield* launches.launch({
...launchInput({ command: "shared-inbox", thread: "shared-inbox" }),
inboxOrigin: { kind: "human", id: "jeff" },
inboxRouting: { audience: "shared" },
});
assert.equal((yield* threads.getThreadShell(shared.threadId))?.inbox?.audience, "shared");
const launched = yield* launches.launch(input);
const original = (yield* threads.getThreadProjection(launched.threadId)).thread.inbox;
assert.equal(original?.owner, "jeff");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,9 @@ describe("ThreadSettlementServiceV2 worker", () => {
});
const idle = makeThread("idle-agent", { inbox: agent, status: "idle" });
const already = done("already", "completed", { settledOverride: "settled" });
const unboundHuman = done("unbound-human", "completed", {
inbox: makeThreadInbox({ actor: null }),
});
const standing = done("standing", "completed", {
standing: { name: "Ops", role: null, avatarId: "bolt", accent: "sky" },
});
Expand All @@ -1077,6 +1080,7 @@ describe("ThreadSettlementServiceV2 worker", () => {
asked,
idle,
already,
unboundHuman,
standing,
human("kameron"),
human("jeff"),
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/orchestration-v2/ThreadSettlementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export function settlesFinishedAgentWork(
>,
): boolean {
if (thread.standing != null || thread.inbox?.audience !== "agent-only") return false;
// An unattributed conversation uses Agents for routing without becoming autonomous work.
if (thread.inbox.origin === null) return false;
if (!FINISHED_AGENT_RUN_STATUSES.has(thread.status)) return false;
return !agentBackgroundWorkPending(thread);
}
Expand Down
12 changes: 12 additions & 0 deletions apps/server/src/peer/linkedSidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ it.effect("reads a reachable server-only link and skips catalog and unreachable
threads: [
{
inbox: makeThreadInbox({ actor: { kind: "human", id: "jeff" } }),
standing: {
name: "CoS (Jeff)",
role: "Chief of Staff",
avatarId: "bolt",
accent: "sky",
},
threadId: ThreadId.make("thread-eval"),
projectId: ProjectId.make("project-eval"),
title: "10-model copy eval",
Expand Down Expand Up @@ -105,6 +111,12 @@ it.effect("reads a reachable server-only link and skips catalog and unreachable
"10-model copy eval",
]);
expect(result.environments[0]?.threads[0]?.inbox?.owner).toBe("jeff");
expect(result.environments[0]?.threads[0]?.standing).toEqual({
name: "CoS (Jeff)",
role: "Chief of Staff",
avatarId: "bolt",
accent: "sky",
});
expect(result.environments[0]?.threads[0]?.lastVisitedAt).toBe("2026-11-20T03:59:00.000Z");
expect(result.environments[0]?.threads[0]?.latestRunCompletedAt).toBe(
"2026-11-20T03:58:00.000Z",
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/peer/linkedSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ const slimThread = (
thread: (typeof OrchestratorMcpThreadListResult.Type.threads)[number],
): LinkedSidebarThread => ({
...(thread.inbox === undefined ? {} : { inbox: thread.inbox }),
...(thread.standing == null ? {} : { standing: thread.standing }),
threadId: thread.threadId,
projectId: thread.projectId,
title: thread.title,
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": 5930,
"codexAdditionalContextBytes": 7324,
"mcpToolListJsonBytes": 55827
"mcpToolListJsonBytes": 56852
}
100 changes: 66 additions & 34 deletions apps/server/src/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import { subscribeChatGptHandoff } from "./provider/CodexChatGptHandoff.ts";
import {
AcpRegistryOperationError,
CommandId,
founderCreationOrigin,
type InboxActor,
authScopeResponse,
AuthAccessStreamError,
type AuthAccessStreamEvent,
Expand Down Expand Up @@ -2052,17 +2054,26 @@ export const layerWsRpc = (

// A session names a person only when another client assigned it. A person's unassigned
// client credits this machine's owner; a bot never does, and a null owner stays unnamed.
const messageSender = serverAuth.messageSenderOf(currentSessionId).pipe(
Effect.filterOrElse(
(sentBy) => sentBy.founder !== null || sentBy.deviceType === "bot",
(sentBy) =>
serverSettings.getSettings.pipe(
Effect.map((settings) => creditUnassignedSender(sentBy, settings.ownerFounder)),
// A settings read must not fail the send. Leave the sender unassigned.
Effect.orElseSucceed(() => sentBy),
),
),
);
const sessionSender = serverAuth.messageSenderOf(currentSessionId);
const creditMessageSender = (sender: OrchestrationV2MessageSentBy) =>
sender.founder !== null || sender.deviceType === "bot"
? Effect.succeed(sender)
: serverSettings.getSettings.pipe(
Effect.map((settings) => creditUnassignedSender(sender, settings.ownerFounder)),
Effect.orElseSucceed(() => sender),
);
const messageSender = sessionSender.pipe(Effect.flatMap(creditMessageSender));
const creationOrigin = (
sender: OrchestrationV2MessageSentBy,
preferred: InboxActor | undefined,
) => {
const origin = founderCreationOrigin(sender, preferred);
return origin === undefined
? creditMessageSender(sender).pipe(
Effect.map((credited) => founderCreationOrigin(credited, undefined)),
)
: Effect.succeed(origin);
};

const handlers = ServerWsRpcGroup.of({
[ORCHESTRATION_V2_WS_METHODS.dispatchCommand]: (command) =>
Expand All @@ -2088,26 +2099,41 @@ export const layerWsRpc = (
.enqueueCommand(
(command.type === "prepared-run.retry"
? threadLaunch.retryPreparation(command)
: (command.type === "message.dispatch" ||
command.type === "queued-run.edit" ||
command.type === "runtime-request.respond"
? messageSender.pipe(Effect.asSome)
: Effect.succeed(Option.none<OrchestrationV2MessageSentBy>())
).pipe(
Effect.flatMap((sentBy) =>
ThreadMessageIntake.dispatchCommand(
ThreadManagementService.withCreationProvenance(command, {
createdBy: "user",
creationSource:
"creationSource" in command ? command.creationSource : "web",
...Option.match(sentBy, {
onNone: () => ({}),
onSome: (value) => ({ sentBy: value }),
: command.type === "thread.create"
? sessionSender.pipe(
Effect.flatMap((sender) => creationOrigin(sender, command.inboxOrigin)),
Effect.flatMap((origin) =>
ThreadMessageIntake.dispatchCommand(
ThreadManagementService.withCreationProvenance(
{
...command,
...(origin === undefined ? {} : { inboxOrigin: origin }),
},
{ createdBy: "user", creationSource: command.creationSource },
),
),
),
)
: (command.type === "message.dispatch" ||
command.type === "queued-run.edit" ||
command.type === "runtime-request.respond"
? messageSender.pipe(Effect.asSome)
: Effect.succeed(Option.none<OrchestrationV2MessageSentBy>())
).pipe(
Effect.flatMap((sentBy) =>
ThreadMessageIntake.dispatchCommand(
ThreadManagementService.withCreationProvenance(command, {
createdBy: "user",
creationSource:
"creationSource" in command ? command.creationSource : "web",
...Option.match(sentBy, {
onNone: () => ({}),
onSome: (value) => ({ sentBy: value }),
}),
}),
}),
),
),
),
)
)
).pipe(Effect.provide(intakeContext)),
)
.pipe(
Expand Down Expand Up @@ -2308,14 +2334,20 @@ export const layerWsRpc = (
})
.pipe(
Effect.andThen(
input.initialMessage === undefined ? Effect.undefined : messageSender,
Effect.gen(function* () {
const sender = yield* sessionSender;
const inboxOrigin = yield* creationOrigin(sender, input.inboxOrigin);
const sentBy =
input.initialMessage === undefined
? undefined
: yield* creditMessageSender(sender);
return { inboxOrigin, sentBy };
}),
),
Effect.flatMap((sentBy) =>
Effect.flatMap(({ inboxOrigin, sentBy }) =>
ThreadMessageIntake.launchThread({
commandId: input.commandId,
...(input.inboxOrigin === undefined
? {}
: { inboxOrigin: input.inboxOrigin }),
...(inboxOrigin === undefined ? {} : { inboxOrigin }),
...(input.inboxRouting === undefined
? {}
: { inboxRouting: input.inboxRouting }),
Expand Down
Loading
Loading