From 2501681651c5255a4442a375c28b791f3fda4598 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Wed, 18 Nov 2026 10:34:29 +0000 Subject: [PATCH 1/2] feat(inbox): agent-launched threads file into Agents unless the agent picks an inbox t3_thread_launch and create_threads copied the calling thread's inbox routing, so any thread an agent started from a founder's thread landed in that founder's action inbox. Both tools now take an `inbox` choice (kameron, jeff, shared, agents) that defaults to agents. Explicit `inboxRouting` still wins. The thread menu and agent launches share one routing table, and delegated launches send the resolved routing so older linked environments file them the same way. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/OrchestratorMcpService.ts | 7 ++-- .../src/mcp/toolkits/project/handlers.test.ts | 33 +++++++++++++++++++ .../src/mcp/toolkits/project/handlers.ts | 10 +++--- apps/server/src/mcp/toolkits/project/tools.ts | 2 ++ .../src/provider/agentContextBudget.json | 2 +- .../src/components/threadActionMenu.logic.ts | 26 +++++++-------- packages/contracts/src/orchestratorMcp.ts | 3 +- packages/contracts/src/threadInbox.test.ts | 19 +++++++++++ packages/contracts/src/threadInbox.ts | 31 +++++++++++++++++ 9 files changed, 107 insertions(+), 26 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 3a2c917c83e27..eb394388218d7 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -66,6 +66,7 @@ import { latestProviderTurnForAttempt, resolveProjectProviderInstanceEnabled, SECRET_REQUEST_UNSAVED_NOTE, + agentLaunchInboxRouting, } from "@t3tools/contracts"; import { getProviderOptionCurrentValue, withLegacyUltracodeEffort } from "@t3tools/shared/model"; import { backgroundWorkHoldsCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork"; @@ -3216,11 +3217,7 @@ const make = Effect.gen(function* () { .dispatch({ type: "thread.create", inboxOrigin: { kind: "agent", id: parent.thread.id }, - ...(request.inboxRouting !== undefined - ? { inboxRouting: request.inboxRouting } - : parent.thread.inbox === undefined - ? {} - : { inboxRouting: parent.thread.inbox }), + inboxRouting: agentLaunchInboxRouting(request), createdBy: "agent", creationSource: "mcp", commandId, diff --git a/apps/server/src/mcp/toolkits/project/handlers.test.ts b/apps/server/src/mcp/toolkits/project/handlers.test.ts index c95fadd9096e2..79df1ca9e2bd4 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.test.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.test.ts @@ -416,6 +416,39 @@ it.effect("a launch with a model its provider does not advertise creates no thre }), ); +it.effect("a launch is filed in Agents unless the agent picks an inbox", () => + Effect.gen(function* () { + const launched: Array = []; + const { projectId, dependencies } = clientLaunchHarness({ + runtimeModeCeiling: "auto", + launched, + }); + const toolkit = yield* ProjectToolkit.pipe( + Effect.provide( + McpToolAccess.HandlersLayer.layer(ProjectHandlers.layer).pipe(Layer.provide(dependencies)), + ), + ); + const launch = (inbox?: "kameron" | "shared") => + toolkit + .handle("t3_thread_launch", { + title: "Fix", + projectId, + ...(inbox === undefined ? {} : { inbox }), + }) + .pipe(Stream.unwrap, Stream.runCollect, Effect.provide(dependencies)); + + yield* launch(); + yield* launch("kameron"); + yield* launch("shared"); + expect(launched.map((input) => input.inboxRouting?.audience)).toEqual([ + "agent-only", + "kameron", + "shared", + ]); + expect(launched[1]?.inboxRouting?.assignee).toEqual({ kind: "human", id: "kameron" }); + }), +); + it.effect("a launch retried with the same clientRequestId replays the first one", () => Effect.gen(function* () { const launched: Array = []; diff --git a/apps/server/src/mcp/toolkits/project/handlers.ts b/apps/server/src/mcp/toolkits/project/handlers.ts index 7361cfd7e9d69..57a7c7952061b 100644 --- a/apps/server/src/mcp/toolkits/project/handlers.ts +++ b/apps/server/src/mcp/toolkits/project/handlers.ts @@ -1,4 +1,5 @@ import { + agentLaunchInboxRouting, CommandId, type EnvironmentId, isProviderAvailable, @@ -155,6 +156,7 @@ const launchPlacedThere = Effect.fn("mcp.launchPlacedThere")(function* ( placement: _placement, delegatedFrom: _delegatedFrom, workspaceStrategy: _requested, + inbox: _inbox, ...params } = input; const launched = yield* delegation.value.launch(scope, { @@ -165,6 +167,8 @@ const launchPlacedThere = Effect.fn("mcp.launchPlacedThere")(function* ( // The workspace and modes it was admitted with go explicitly, so nothing there changes them. params: { ...params, + // Resolved here: a linked environment on an older release knows only inboxRouting. + inboxRouting: agentLaunchInboxRouting(input), modelSelection, ...(local.strategy === undefined ? {} : { workspaceStrategy: local.strategy }), runtimeMode: local.runtimeMode, @@ -404,11 +408,7 @@ export const layer = McpToolAccess.toLayer(ProjectToolkit, { } const result = yield* ThreadMessageIntake.launchThread({ inboxOrigin: { kind: "agent", id: caller?.id ?? "agent" }, - ...(input.inboxRouting !== undefined - ? { inboxRouting: input.inboxRouting } - : caller?.inbox === undefined - ? {} - : { inboxRouting: caller.inbox }), + inboxRouting: agentLaunchInboxRouting(input), commandId, threadId, projectId, diff --git a/apps/server/src/mcp/toolkits/project/tools.ts b/apps/server/src/mcp/toolkits/project/tools.ts index ac9b2a8ef67b8..1a052a1ba75ae 100644 --- a/apps/server/src/mcp/toolkits/project/tools.ts +++ b/apps/server/src/mcp/toolkits/project/tools.ts @@ -1,6 +1,7 @@ import { McpAttachmentInput } from "../attachment/input.ts"; import { clampedPositiveInt, + InboxChoiceParameter, ThreadInboxRoutingPatch, NonNegativeInt, ModelSelection, @@ -141,6 +142,7 @@ const ThreadLaunchTool = Tool.make("t3_thread_launch", { "No project: a new Scratch folder. Not with `projectId` or `workspaceStrategy`.", }), ), + inbox: Schema.optional(InboxChoiceParameter), inboxRouting: Schema.optional(ThreadInboxRoutingPatch), title: TrimmedNonEmptyString, modelSelection: Schema.optional(ModelSelection), diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index 0051813371e5b..a7986073b4b0c 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 49736 + "mcpToolListJsonBytes": 52497 } diff --git a/apps/web/src/components/threadActionMenu.logic.ts b/apps/web/src/components/threadActionMenu.logic.ts index 4882857251d44..9f3cc4b150a99 100644 --- a/apps/web/src/components/threadActionMenu.logic.ts +++ b/apps/web/src/components/threadActionMenu.logic.ts @@ -1,4 +1,8 @@ -import type { ThreadInboxRoutingPatch } from "@t3tools/contracts"; +import { + inboxRoutingFor, + type InboxChoice, + type ThreadInboxRoutingPatch, +} from "@t3tools/contracts"; import type { ContextMenuItem } from "@t3tools/contracts"; import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled"; @@ -298,19 +302,13 @@ export function buildThreadActionMenuItems( } export function threadRoutingUpdateFromMenuAction(action: string): ThreadInboxRoutingPatch | null { - if (action === "inbox:kameron" || action === "inbox:jeff") { - const founder = action === "inbox:kameron" ? "kameron" : "jeff"; - return { - owner: founder, - assignee: { kind: "human", id: founder }, - audience: founder, - attentionKind: "action", - }; - } - if (action === "inbox:shared") - return { owner: null, assignee: null, audience: "shared", attentionKind: "FYI" }; - if (action === "inbox:agents") - return { owner: null, assignee: null, audience: "agent-only", attentionKind: "background" }; + if ( + action === "inbox:kameron" || + action === "inbox:jeff" || + action === "inbox:shared" || + action === "inbox:agents" + ) + return inboxRoutingFor(action.slice("inbox:".length) as InboxChoice); if (action === "attention:action") return { attentionKind: "action" }; if (action === "attention:FYI") return { attentionKind: "FYI" }; if (action === "attention:background") return { attentionKind: "background" }; diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index e7b3827987b8b..afd1ab215cd6a 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -279,9 +279,10 @@ export const OrchestratorMcpTaskCancelResult = Schema.Struct({ }); export type OrchestratorMcpTaskCancelResult = typeof OrchestratorMcpTaskCancelResult.Type; -import { ThreadInbox, ThreadInboxRoutingPatch } from "./threadInbox.ts"; +import { InboxChoiceParameter, ThreadInbox, ThreadInboxRoutingPatch } from "./threadInbox.ts"; export const OrchestratorMcpCreateThreadRequest = Schema.Struct({ + inbox: Schema.optional(InboxChoiceParameter), inboxRouting: Schema.optional(ThreadInboxRoutingPatch), prompt: Schema.optional(OrchestratorMcpPrompt), title: Schema.optional(OrchestratorMcpTitle), diff --git a/packages/contracts/src/threadInbox.test.ts b/packages/contracts/src/threadInbox.test.ts index bde1cf4ca7dd8..83ca89705ba40 100644 --- a/packages/contracts/src/threadInbox.test.ts +++ b/packages/contracts/src/threadInbox.test.ts @@ -10,6 +10,7 @@ import { inboxOriginFor, founderInboxLane, compositeThreadKey, + agentLaunchInboxRouting, } from "./threadInbox.ts"; const kameron = { kind: "human", id: "kameron" } as const; const jeff = { kind: "human", id: "jeff" } as const; @@ -66,6 +67,24 @@ describe("shared fleet organizational inbox", () => { false, ]); }); + it("files agent launches in Agents unless the agent picks an inbox", () => { + // A launch from a thread in Kameron's inbox no longer copies that routing. + const launched = (choice: Parameters[0]) => + makeThreadInbox({ actor: bot, routing: agentLaunchInboxRouting(choice) }); + const views = ["kameron", "jeff", "shared", "agents"] as const; + const visibleIn = (inbox: ReturnType) => + views.filter((view) => matchesInboxView(inbox, view)); + expect(visibleIn(launched({}))).toEqual(["agents"]); + expect(visibleIn(launched({ inbox: "kameron" }))).toEqual(["kameron", "agents"]); + expect(visibleIn(launched({ inbox: "jeff" }))).toEqual(["jeff", "agents"]); + expect(visibleIn(launched({ inbox: "shared" }))).toEqual(["shared", "agents"]); + expect(launched({ inbox: "kameron" }).origin).toEqual(bot); + const explicit = launched({ + inbox: "kameron", + inboxRouting: { assignee: { kind: "human", id: "jeff" } }, + }); + expect(visibleIn(explicit)).toEqual(["jeff", "agents"]); + }); it("hides bot-only work by default while All and Agents retain it", () => { const inbox = makeThreadInbox({ actor: bot }); expect(matchesInboxView(inbox, "kameron")).toBe(false); diff --git a/packages/contracts/src/threadInbox.ts b/packages/contracts/src/threadInbox.ts index d9bc3b9b7eb87..a537990bd281b 100644 --- a/packages/contracts/src/threadInbox.ts +++ b/packages/contracts/src/threadInbox.ts @@ -34,6 +34,37 @@ export type ThreadInbox = typeof ThreadInbox.Type; export const INBOX_CAPABILITY = "closura-founder-inbox-v2" as const; export const InboxView = Schema.Literals(["kameron", "jeff", "shared", "agents", "all"]); export type InboxView = typeof InboxView.Type; +/** An inbox a thread can be filed into: every view except All. */ +export const InboxChoice = Schema.Literals(["kameron", "jeff", "shared", "agents"]); +export type InboxChoice = typeof InboxChoice.Type; + +/** The routing that files a thread into one inbox, shared by the thread menu and agent launches. */ +export function inboxRoutingFor(inbox: InboxChoice): ThreadInboxRouting { + if (inbox === "shared") + return { owner: null, assignee: null, audience: "shared", attentionKind: "FYI" }; + if (inbox === "agents") + return { owner: null, assignee: null, audience: "agent-only", attentionKind: "background" }; + return { + owner: inbox, + assignee: { kind: "human", id: inbox }, + audience: inbox, + attentionKind: "action", + }; +} + +/** + * Where an agent-launched top-level thread is filed. Explicit routing wins, then the + * chosen inbox; otherwise Agents, so agent work never lands in a founder's inbox by default. + */ +export const agentLaunchInboxRouting = (input: { + readonly inbox?: InboxChoice | undefined; + readonly inboxRouting?: ThreadInboxRoutingPatch | undefined; +}): ThreadInboxRoutingPatch => input.inboxRouting ?? inboxRoutingFor(input.inbox ?? "agents"); + +export const InboxChoiceParameter = InboxChoice.annotate({ + description: + "Sidebar inbox for the new thread. Default 'agents'. Pick 'kameron' or 'jeff' only when that founder asked for it or must act on it; 'shared' for both. `inboxRouting` overrides it.", +}); export const compositeThreadKey = (environmentId: string, threadId: string) => JSON.stringify([environmentId, threadId]); export const InboxThreadRef = Schema.Struct({ environmentId: EnvironmentId, threadId: ThreadId }); From 5628057864b39c36e7019e2ec6718a9c7d31eac2 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Wed, 18 Nov 2026 11:16:34 +0000 Subject: [PATCH 2/2] fix(inbox): inboxRouting adjusts the chosen launch inbox instead of replacing it An agent that sent `inbox:"kameron"` with a partial `inboxRouting` such as `{attentionKind:"FYI"}` lost the inbox choice and the thread landed only in Agents. The patch now applies over the chosen inbox. The `inbox` description points the agent at its thread's `inbox.owner`, and the thread menu checks its inbox action with the shared InboxChoice schema instead of a cast. Co-Authored-By: Claude Opus 5.5 --- .../src/provider/agentContextBudget.json | 2 +- .../src/components/threadActionMenu.logic.ts | 18 ++++++------------ packages/contracts/src/threadInbox.test.ts | 3 +++ packages/contracts/src/threadInbox.ts | 11 +++++++---- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index a7986073b4b0c..ab49f2b6c830d 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 52497 + "mcpToolListJsonBytes": 52637 } diff --git a/apps/web/src/components/threadActionMenu.logic.ts b/apps/web/src/components/threadActionMenu.logic.ts index 9f3cc4b150a99..328c99930d0bb 100644 --- a/apps/web/src/components/threadActionMenu.logic.ts +++ b/apps/web/src/components/threadActionMenu.logic.ts @@ -1,8 +1,5 @@ -import { - inboxRoutingFor, - type InboxChoice, - type ThreadInboxRoutingPatch, -} from "@t3tools/contracts"; +import * as Schema from "effect/Schema"; +import { InboxChoice, inboxRoutingFor, type ThreadInboxRoutingPatch } from "@t3tools/contracts"; import type { ContextMenuItem } from "@t3tools/contracts"; import type { SnoozePreset } from "@t3tools/client-runtime/state/thread-settled"; @@ -301,14 +298,11 @@ export function buildThreadActionMenuItems( ); } +const isInboxChoice = Schema.is(InboxChoice); + export function threadRoutingUpdateFromMenuAction(action: string): ThreadInboxRoutingPatch | null { - if ( - action === "inbox:kameron" || - action === "inbox:jeff" || - action === "inbox:shared" || - action === "inbox:agents" - ) - return inboxRoutingFor(action.slice("inbox:".length) as InboxChoice); + const inbox = action.startsWith("inbox:") ? action.slice("inbox:".length) : undefined; + if (isInboxChoice(inbox)) return inboxRoutingFor(inbox); if (action === "attention:action") return { attentionKind: "action" }; if (action === "attention:FYI") return { attentionKind: "FYI" }; if (action === "attention:background") return { attentionKind: "background" }; diff --git a/packages/contracts/src/threadInbox.test.ts b/packages/contracts/src/threadInbox.test.ts index 83ca89705ba40..c52ba992dd605 100644 --- a/packages/contracts/src/threadInbox.test.ts +++ b/packages/contracts/src/threadInbox.test.ts @@ -84,6 +84,9 @@ describe("shared fleet organizational inbox", () => { inboxRouting: { assignee: { kind: "human", id: "jeff" } }, }); expect(visibleIn(explicit)).toEqual(["jeff", "agents"]); + const quieter = launched({ inbox: "kameron", inboxRouting: { attentionKind: "FYI" } }); + expect(visibleIn(quieter)).toEqual(["kameron", "agents"]); + expect(quieter.attentionKind).toBe("FYI"); }); it("hides bot-only work by default while All and Agents retain it", () => { const inbox = makeThreadInbox({ actor: bot }); diff --git a/packages/contracts/src/threadInbox.ts b/packages/contracts/src/threadInbox.ts index a537990bd281b..2ac7787b190f5 100644 --- a/packages/contracts/src/threadInbox.ts +++ b/packages/contracts/src/threadInbox.ts @@ -53,17 +53,20 @@ export function inboxRoutingFor(inbox: InboxChoice): ThreadInboxRouting { } /** - * Where an agent-launched top-level thread is filed. Explicit routing wins, then the - * chosen inbox; otherwise Agents, so agent work never lands in a founder's inbox by default. + * Where an agent-launched top-level thread is filed: the chosen inbox, else Agents, so agent + * work never lands in a founder's inbox by default. `inboxRouting` adjusts the chosen inbox. */ export const agentLaunchInboxRouting = (input: { readonly inbox?: InboxChoice | undefined; readonly inboxRouting?: ThreadInboxRoutingPatch | undefined; -}): ThreadInboxRoutingPatch => input.inboxRouting ?? inboxRoutingFor(input.inbox ?? "agents"); +}): ThreadInboxRoutingPatch => + input.inbox === undefined + ? (input.inboxRouting ?? inboxRoutingFor("agents")) + : { ...inboxRoutingFor(input.inbox), ...input.inboxRouting }; export const InboxChoiceParameter = InboxChoice.annotate({ description: - "Sidebar inbox for the new thread. Default 'agents'. Pick 'kameron' or 'jeff' only when that founder asked for it or must act on it; 'shared' for both. `inboxRouting` overrides it.", + "Sidebar inbox for the new thread. Default 'agents'. Pick 'kameron' or 'jeff' only when that founder asked for it or must act on it (your thread's `inbox.owner` in t3_thread_read); 'shared' for both. `inboxRouting` adjusts fields of the chosen inbox.", }); export const compositeThreadKey = (environmentId: string, threadId: string) => JSON.stringify([environmentId, threadId]);