From 883ded7ffc1b6c29682f8133e1fdd63b675dc70b Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Sun, 22 Nov 2026 19:38:44 +0000 Subject: [PATCH 1/2] fix(inbox): keep founder sidebars focused and route new threads Model: GPT-6 Task: bugfix Agent: Codex Lane: codex --- apps/server/src/mcp/OrchestratorMcpService.ts | 1 + .../src/orchestration-v2/Orchestrator.ts | 28 +-- .../src/orchestration-v2/ThreadForkService.ts | 2 + .../ThreadLaunchService.test.ts | 21 ++ apps/server/src/peer/linkedSidebar.test.ts | 2 + apps/server/src/peer/linkedSidebar.ts | 1 + apps/server/src/ws.ts | 100 ++++++--- .../Sidebar.founder-inbox.browser.test.tsx | 205 ++++++++++++++++++ apps/web/src/components/Sidebar.tsx | 3 +- .../src/components/bots/botPresence.test.ts | 26 ++- apps/web/src/components/bots/botPresence.ts | 13 +- .../sidebar/SidebarThreadFilterMenu.tsx | 26 +-- .../sidebar/threadListFilter.logic.test.ts | 43 +++- .../sidebar/threadListFilter.logic.ts | 30 ++- apps/web/src/state/linkedSidebar.ts | 6 + .../src/state/linkedSidebar.test.ts | 9 +- .../client-runtime/src/state/linkedSidebar.ts | 1 + packages/contracts/src/linkedSidebar.ts | 2 + packages/contracts/src/orchestratorMcp.ts | 2 + packages/contracts/src/threadInbox.test.ts | 48 +++- packages/contracts/src/threadInbox.ts | 30 +-- 21 files changed, 485 insertions(+), 114 deletions(-) create mode 100644 apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx diff --git a/apps/server/src/mcp/OrchestratorMcpService.ts b/apps/server/src/mcp/OrchestratorMcpService.ts index 78fdc7daa9ec7..a013941c1e366 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.ts @@ -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, diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index e233d8adcef23..d3c5623953a17 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -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, diff --git a/apps/server/src/orchestration-v2/ThreadForkService.ts b/apps/server/src/orchestration-v2/ThreadForkService.ts index 1dc6d1eaf4a54..f1070b794371f 100644 --- a/apps/server/src/orchestration-v2/ThreadForkService.ts +++ b/apps/server/src/orchestration-v2/ThreadForkService.ts @@ -1,5 +1,6 @@ import { ContextTransferId, + makeThreadInbox, OrchestrationV2Actor, OrchestrationV2AppThread, OrchestrationV2ContextSourcePoint, @@ -103,6 +104,7 @@ export const layer: Layer.Layer = 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, diff --git a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts index 6f845be7a5806..7ca428a56ac9f 100644 --- a/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadLaunchService.test.ts @@ -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"); diff --git a/apps/server/src/peer/linkedSidebar.test.ts b/apps/server/src/peer/linkedSidebar.test.ts index 11dc074a60962..7bc9b01055b07 100644 --- a/apps/server/src/peer/linkedSidebar.test.ts +++ b/apps/server/src/peer/linkedSidebar.test.ts @@ -71,6 +71,7 @@ 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)", avatarId: "bolt", accent: "sky" }, threadId: ThreadId.make("thread-eval"), projectId: ProjectId.make("project-eval"), title: "10-model copy eval", @@ -105,6 +106,7 @@ 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?.name).toBe("CoS (Jeff)"); 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", diff --git a/apps/server/src/peer/linkedSidebar.ts b/apps/server/src/peer/linkedSidebar.ts index 6cf869054239c..b1ac8416813a2 100644 --- a/apps/server/src/peer/linkedSidebar.ts +++ b/apps/server/src/peer/linkedSidebar.ts @@ -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, diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts index 0ccf7fb913a3e..486d150741a5e 100644 --- a/apps/server/src/ws.ts +++ b/apps/server/src/ws.ts @@ -36,6 +36,8 @@ import { subscribeChatGptHandoff } from "./provider/CodexChatGptHandoff.ts"; import { AcpRegistryOperationError, CommandId, + founderCreationOrigin, + type InboxActor, authScopeResponse, AuthAccessStreamError, type AuthAccessStreamEvent, @@ -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) => @@ -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()) - ).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()) + ).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( @@ -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 }), diff --git a/apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx b/apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx new file mode 100644 index 0000000000000..8e3cde99498c5 --- /dev/null +++ b/apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx @@ -0,0 +1,205 @@ +import { + DEFAULT_CLIENT_SETTINGS, + EnvironmentId, + ProjectId, + ProviderInstanceId, + ThreadId, + makeThreadInbox, + type Founder, + type LocalApi, + type LinkedSidebarResult, + type LinkedSidebarThread, +} from "@t3tools/contracts"; +import { expect, it, vi } from "vite-plus/test"; +import { page } from "vite-plus/test/browser"; + +import { render } from "../../test/render"; +import { + __resetClientSettingsPersistenceForTests, + ensureClientSettingsHydrated, +} from "../hooks/useSettings"; +import appCss from "../index.css?inline"; +import { AppAtomRegistryProvider, appAtomRegistry } from "../rpc/atomRegistry"; +import { linkedSidebarByHostAtom } from "../state/linkedSidebar"; +import Sidebar from "./Sidebar"; +import { SidebarProvider } from "./ui/sidebar"; + +vi.mock("../localApi", { spy: true }); + +const environments = ["primary-mac-laptop", "primary-r720", "primary-asus", "omarcy-desktop"].map( + (label) => ({ environmentId: EnvironmentId.make(label), label }), +); + +const projectId = ProjectId.make("company"); +const fixtureTime = "2026-11-22T00:00:00.000Z"; + +function standingBot( + name: string, + audience: Founder | "shared" | "agent-only", +): LinkedSidebarThread { + return { + inbox: makeThreadInbox({ + actor: { kind: "agent", id: `standing-${name}` }, + routing: { + owner: audience === "jeff" || audience === "kameron" ? audience : null, + audience, + attentionKind: "background", + }, + }), + standing: { name, accent: "sky", avatarId: "bolt", role: null }, + threadId: ThreadId.make(`standing-${name}`), + projectId, + title: name, + createdBy: "agent", + creationSource: "mcp", + status: "idle", + latestRunId: null, + providerInstanceId: ProviderInstanceId.make("codex"), + model: "gpt-5.4", + runtimeMode: "full-access", + interactionMode: "default", + settled: false, + settledAt: null, + snoozed: false, + snoozedUntil: null, + parentThreadId: null, + relationshipToParent: null, + itemCount: 1, + createdAt: fixtureTime, + updatedAt: fixtureTime, + }; +} + +it.each(["jeff", "kameron"] as const)( + "%s sees their own and Shared Bots, readable filters, and the correct reset", + async (owner) => { + using setup = new DisposableStack(); + __resetClientSettingsPersistenceForTests(); + setup.defer(__resetClientSettingsPersistenceForTests); + const previousLinks = appAtomRegistry.get(linkedSidebarByHostAtom); + setup.defer(() => appAtomRegistry.set(linkedSidebarByHostAtom, previousLinks)); + const style = document.createElement("style"); + style.textContent = appCss; + document.head.append(style); + setup.defer(() => style.remove()); + await page.viewport(1280, 800); + const shared = ["CEO", "CFO", "CTO", "Product Designer", "Growth"]; + const childName = "Delegated CEO research"; + const linkedEnvironments = environments.map((environment, index) => ({ + ...environment, + projects: [ + { + id: projectId, + title: "Company", + workspaceRoot: "/projects/company", + defaultModelSelection: null, + createdAt: fixtureTime, + updatedAt: fixtureTime, + deletedAt: null, + scripts: [], + }, + ], + threads: [ + ...shared + .filter((_, i) => i % environments.length === index) + .map((name) => standingBot(name, "shared")), + ...(index === 0 ? [standingBot("CoS", "kameron")] : []), + ...(index === 3 + ? [standingBot("CoS (Jeff)", "jeff"), standingBot("Personal Finance", "jeff")] + : []), + ...(index === 0 + ? [ + { + ...standingBot(childName, "agent-only"), + parentThreadId: ThreadId.make("standing-CEO"), + }, + ] + : []), + ], + })); + const links: LinkedSidebarResult = { environments: linkedEnvironments }; + appAtomRegistry.set(linkedSidebarByHostAtom, new Map([[EnvironmentId.make("local"), links]])); + const persist = vi + .fn() + .mockResolvedValue(undefined); + using _localApi = vi.spyOn(await import("../localApi"), "ensureLocalApi").mockReturnValue({ + persistence: { + getClientSettings: async () => ({ + ...DEFAULT_CLIENT_SETTINGS, + founderInboxOwner: owner, + founderInboxFilter: [owner], + }), + setClientSettings: persist, + }, + } as unknown as LocalApi); + await ensureClientSettingsHydrated(); + await using screen = await render( + + + + + , + ); + const mine = screen.getByRole("region", { name: "My Bots" }); + const company = screen.getByRole("region", { name: "Shared Bots" }); + const jeff = owner === "jeff"; + for (const name of jeff ? ["CoS (Jeff)", "Personal Finance"] : ["CoS"]) { + await expect.element(mine.getByText(name, { exact: true })).toBeVisible(); + } + for (const name of jeff ? ["CoS"] : ["CoS (Jeff)", "Personal Finance"]) { + await expect.element(screen.getByText(name, { exact: true })).not.toBeInTheDocument(); + } + for (const name of shared) { + await expect.element(company.getByText(name, { exact: true })).toBeVisible(); + } + + const open = () => screen.getByRole("button", { name: /^Filter threads by inbox/ }).click(); + await open(); + const menu = page.getByRole("menu"); + const inboxes = menu.getByRole("group", { name: "Inbox" }); + const agents = inboxes.getByRole("menuitemcheckbox", { name: /^Agents,/ }); + const personal = inboxes.getByRole("menuitemcheckbox", { name: jeff ? /^Jeff,/ : /^Kameron,/ }); + const sharedInbox = inboxes.getByRole("menuitemcheckbox", { name: /^Shared,/ }); + await expect.element(personal).toHaveAttribute("aria-checked", "true"); + await expect.element(sharedInbox).toHaveAttribute("aria-checked", "true"); + await expect.element(agents).toHaveAttribute("aria-checked", "false"); + const labels = [ + "Kameron", + "Kameron's agents", + "Jeff's agents", + "Unknown", + "Shared", + ...environments.map(({ label }) => label), + ]; + for (const width of [1280, 360]) { + await page.viewport(width, 800); + await expect.element(menu).toBeVisible(); + await vi.waitFor(() => { + const popup = menu.element().getBoundingClientRect(); + expect(popup.left).toBeGreaterThanOrEqual(0); + expect(popup.right).toBeLessThanOrEqual(width); + for (const label of labels) { + const matches = menu.getByText(label, { exact: true }).elements(); + expect(matches.length, label).toBeGreaterThan(0); + for (const element of matches) { + expect(element.scrollWidth, label).toBeLessThanOrEqual(element.clientWidth); + } + } + }); + } + await page.viewport(1280, 800); + await agents.click(); + await expect.element(agents).toHaveAttribute("aria-checked", "true"); + await expect.element(mine.getByText(childName, { exact: true })).not.toBeInTheDocument(); + await expect.element(company.getByText(childName, { exact: true })).not.toBeInTheDocument(); + await expect.element(screen.getByText(childName, { exact: true })).toBeVisible(); + await menu.getByRole("menuitem", { name: "Reset to default" }).click(); + await vi.waitFor(() => + expect(persist).toHaveBeenLastCalledWith(expect.objectContaining({ founderInboxFilter: [] })), + ); + await open(); + await expect.element(personal).toHaveAttribute("aria-checked", "true"); + await expect.element(sharedInbox).toHaveAttribute("aria-checked", "true"); + await expect.element(agents).toHaveAttribute("aria-checked", "false"); + }, +); diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 28325237e0e5d..028e34c755a6a 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -1173,6 +1173,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const threads = useSidebarThreadShells(); const promotingDraftThreadKeys = usePromotingDraftThreadKeys(); const threadListFilter = useClientSettings(threadListFilterOf); + const viewingFounder = useClientSettings((settings) => settings.founderInboxOwner); const founderByEnvironmentId = useClientSettings((settings) => settings.founderByEnvironmentId); const machineOwners = resolveMachineOwners(serverConfigs, founderByEnvironmentId); const threadAttributions = resolveThreadAttributions(threads, machineOwners); @@ -1195,7 +1196,7 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve const listFilterApplies = threadSearchQuery.trim().length === 0; const inboxThreads = listFilterApplies ? threads.filter((thread) => - matchesThreadListFilter(thread, threadListFilter, attributionOf(thread)), + matchesThreadListFilter(thread, threadListFilter, attributionOf(thread), viewingFounder), ) : threads; // The same filter over threads servers counted but did not send, for the Settled total. diff --git a/apps/web/src/components/bots/botPresence.test.ts b/apps/web/src/components/bots/botPresence.test.ts index 6174d90925f74..537df3493e718 100644 --- a/apps/web/src/components/bots/botPresence.test.ts +++ b/apps/web/src/components/bots/botPresence.test.ts @@ -1,3 +1,4 @@ +import { ThreadId } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; import { @@ -73,17 +74,28 @@ describe("sortBotThreads", () => { describe("splitStandingThreads", () => { it("sends bots to their own group whatever their pin, settle or snooze state", () => { - const persona = { name: "Ops" }; + const persona = { name: "Ops", role: null, accent: "sky", avatarId: "bolt" } as const; + const lineage = { + parentThreadId: null, + rootThreadId: ThreadId.make("root"), + relationshipToParent: null, + }; const threads = [ - { id: "a", standing: null, pinnedAt: "2026-11-19T00:00:00Z" }, - { id: "b", standing: persona, pinnedAt: "2026-11-19T00:00:00Z" }, - { id: "c", standing: persona, settledOverride: "settled" }, - { id: "d", standing: persona, snoozedAt: "2026-11-19T00:00:00Z" }, - { id: "e", standing: null }, + { id: "a", standing: null, lineage, pinnedAt: "2026-11-19T00:00:00Z" }, + { id: "b", standing: persona, lineage, pinnedAt: "2026-11-19T00:00:00Z" }, + { id: "c", standing: persona, lineage, settledOverride: "settled" }, + { id: "d", standing: persona, lineage, snoozedAt: "2026-11-19T00:00:00Z" }, + { id: "e", standing: null, lineage }, + { id: "f", standing: persona, lineage: { ...lineage, parentThreadId: ThreadId.make("b") } }, + { + id: "g", + standing: persona, + lineage: { ...lineage, relationshipToParent: "subagent" as const }, + }, ]; const { bots, rest } = splitStandingThreads(threads); expect(bots.map((thread) => thread.id)).toEqual(["b", "c", "d"]); - expect(rest.map((thread) => thread.id)).toEqual(["a", "e"]); + expect(rest.map((thread) => thread.id)).toEqual(["a", "e", "f", "g"]); }); }); diff --git a/apps/web/src/components/bots/botPresence.ts b/apps/web/src/components/bots/botPresence.ts index 229aa5987e0f2..522ff79a68899 100644 --- a/apps/web/src/components/bots/botPresence.ts +++ b/apps/web/src/components/bots/botPresence.ts @@ -1,4 +1,5 @@ import type { OrchestrationV2ProviderFailureClass } from "@t3tools/contracts"; +import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models"; import type { ThreadStatusPill } from "../Sidebar.logic"; import type { BotAvatarState } from "./BotAvatar"; @@ -54,12 +55,16 @@ export function sortBotThreads< * Splits standing bots out of the sidebar's thread list. Bots go to their own group whatever * their pin, settle or snooze state; everything else continues to the ordinary sections. */ -export function splitStandingThreads( - threads: readonly T[], -): { readonly bots: T[]; readonly rest: T[] } { +export function splitStandingThreads< + T extends Pick, +>(threads: readonly T[]): { readonly bots: T[]; readonly rest: T[] } { const bots: T[] = []; const rest: T[] = []; - for (const thread of threads) (thread.standing != null ? bots : rest).push(thread); + for (const thread of threads) { + const isChild = + thread.lineage.parentThreadId !== null || thread.lineage.relationshipToParent === "subagent"; + (thread.standing != null && !isChild ? bots : rest).push(thread); + } return { bots, rest }; } diff --git a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx index 29691cb2208b1..e518d74e1b97a 100644 --- a/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx +++ b/apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx @@ -1,9 +1,4 @@ -import { - effectiveInboxFilter, - type EnvironmentId, - type Founder, - type InboxChoice, -} from "@t3tools/contracts"; +import { type EnvironmentId, type Founder, type InboxChoice } from "@t3tools/contracts"; import { THREAD_ATTRIBUTION_LABELS, THREAD_ATTRIBUTIONS, @@ -93,7 +88,7 @@ export function SidebarThreadFilterMenu({ }> 0 && "text-primary")} /> - + ({ {inboxOrder.map((inbox) => { const checked = filter.inboxes.includes(inbox); const isLast = checked && filter.inboxes.length === 1; + const keepsShared = + inbox === "shared" && + owner !== undefined && + filter.inboxes.length === 2 && + filter.inboxes.includes(owner); const count = counts.inboxes.get(inbox) ?? EMPTY_THREAD_LIST_FILTER_BUCKETS; return ( void updateClientSettings({ founderInboxFilter: toggleFilterOption(filter.inboxes, inbox, inboxOrder), @@ -262,7 +262,7 @@ function SidebarThreadFilterOptions({ void updateClientSettings({ - founderInboxFilter: effectiveInboxFilter({ founderInboxOwner: owner }), + founderInboxFilter: [], sidebarHiddenEnvironmentIds: [], sidebarHiddenThreadAttributions: [], }) @@ -297,10 +297,10 @@ function FilterOptionRow({ indicator?: ReactNode; }) { return ( - + {indicator} - {label} - + {label} + {STATE_COUNT_COLUMNS.map(([key, name]) => { const value = count[key]; return ( diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts index caa25638de462..661897008b7ca 100644 --- a/apps/web/src/components/sidebar/threadListFilter.logic.test.ts +++ b/apps/web/src/components/sidebar/threadListFilter.logic.test.ts @@ -29,12 +29,12 @@ const jeff = { kind: "human", id: "jeff" } as const; const bot = { kind: "agent", id: "lead" } as const; describe("thread list filter", () => { - it("shows a founder their own and agent threads, in the environments they keep", () => { + it("shows a founder their own and shared threads, in the environments they keep", () => { const filter = threadListFilterOf({ founderInboxOwner: "kameron" }); const visible = (candidate: ReturnType) => matchesThreadListFilter(candidate, filter); expect(visible(thread(laptop, kameron))).toBe(true); - expect(visible(thread(laptop, bot))).toBe(true); + expect(visible(thread(laptop, bot))).toBe(false); // Shared threads stay visible without opening the filter. expect( visible({ @@ -46,7 +46,9 @@ describe("thread list filter", () => { }), ).toBe(true); // Agent threads from before inbox routing count as Agents. - expect(visible(thread(laptop, null, "agent"))).toBe(true); + expect( + matchesThreadListFilter(thread(laptop, null, "agent"), { ...filter, inboxes: ["agents"] }), + ).toBe(true); expect(visible(thread(laptop, jeff))).toBe(false); expect(visible(thread(laptop, null))).toBe(false); const hidingCrown = { ...filter, hiddenEnvironmentIds: [crown] }; @@ -54,6 +56,35 @@ describe("thread list filter", () => { expect(matchesThreadListFilter(thread(laptop, kameron), hidingCrown)).toBe(true); }); + it.each(["jeff", "kameron"] as const)( + "shows %s their personal and shared standing bots", + (owner) => { + const filter = threadListFilterOf({ founderInboxOwner: owner }); + const all = threadListFilterOf({}); + const visible = (audience: "kameron" | "jeff" | "shared", selected = filter) => + matchesThreadListFilter( + { + ...thread(laptop, bot), + standing: {}, + source: { + inbox: makeThreadInbox({ + actor: bot, + routing: { audience, attentionKind: "background" }, + }), + }, + }, + selected, + undefined, + owner, + ); + const other = owner === "jeff" ? "kameron" : "jeff"; + expect(visible(owner)).toBe(true); + expect(visible("shared")).toBe(true); + expect(visible(other, all)).toBe(false); + expect(visible("shared", { ...filter, inboxes: [owner] })).toBe(false); + }, + ); + it("counts each section within the other sections' selection", () => { const finished = { runtime: { status: "completed" }, latestRun: { status: "completed" } }; const threads = [ @@ -104,7 +135,7 @@ describe("thread list filter", () => { environments: false, from: false, }); - const reordered = { ...unchanged, inboxes: ["agents", "jeff", "shared"] as const }; + const reordered = { ...unchanged, inboxes: ["shared", "jeff"] as const }; expect(changedThreadListFilters(reordered, "jeff", environments).inboxes).toBe(false); // A hidden environment that was since removed is not a visible filter. const removed = { ...unchanged, hiddenEnvironmentIds: [EnvironmentId.make("gone")] }; @@ -120,7 +151,7 @@ describe("thread list filter", () => { it("toggles in menu order and never unchecks the last option", () => { const order = inboxMenuOrder("jeff"); - expect(order).toEqual(["jeff", "agents", "kameron", "shared"]); + expect(order).toEqual(["jeff", "shared", "agents", "kameron"]); expect(toggleFilterOption(["agents"], "jeff", order)).toEqual(["jeff", "agents"]); expect(toggleFilterOption(["jeff", "agents"], "jeff", order)).toEqual(["agents"]); expect(toggleFilterOption(["agents"], "agents", order)).toEqual(["agents"]); @@ -350,7 +381,7 @@ describe("thread list filter", () => { expect(counts.inboxes.get("kameron")?.settled).toBe(1 + 40 + 1); expect(counts.inboxes.get("jeff")?.settled).toBe(7); expect(counts.inboxes.get("agents")?.settled).toBe(3); - expect(counts.environments.get(laptop)?.settled).toBe(1 + 40 + 3); + expect(counts.environments.get(laptop)?.settled).toBe(1 + 40); expect(counts.environments.get(crown)?.settled).toBe(1); expect(counts.unclassified).toBe(5); }); diff --git a/apps/web/src/components/sidebar/threadListFilter.logic.ts b/apps/web/src/components/sidebar/threadListFilter.logic.ts index dd2bc6b3fc368..9940e54aeeddc 100644 --- a/apps/web/src/components/sidebar/threadListFilter.logic.ts +++ b/apps/web/src/components/sidebar/threadListFilter.logic.ts @@ -1,5 +1,6 @@ import { matchesListedInboxes, + matchesThreadListFilter as matchesWorkThreadListFilter, type ThreadListFilter, } from "@t3tools/client-runtime/state/thread-list-filter"; import { @@ -21,13 +22,13 @@ import { import type { ThreadAttribution } from "@t3tools/contracts/settings"; export { - matchesThreadListFilter, threadListFilterOf, type ThreadListFilter, } from "@t3tools/client-runtime/state/thread-list-filter"; interface FilterableThread { readonly environmentId: EnvironmentId; + readonly standing?: unknown; readonly settledOverride?: "settled" | "active" | null; readonly hasPendingApprovals?: boolean; readonly hasPendingUserInput?: boolean; @@ -40,6 +41,27 @@ interface FilterableThread { }; } +function standingInbox(thread: FilterableThread): Founder | "shared" | null { + const audience = thread.standing == null ? undefined : thread.source.inbox?.audience; + return audience === "jeff" || audience === "kameron" || audience === "shared" ? audience : null; +} + +export function matchesThreadListFilter( + thread: FilterableThread, + filter: ThreadListFilter, + attribution?: ThreadAttribution, + viewingFounder?: Founder, +) { + const inbox = standingInbox(thread); + if (inbox === null) return matchesWorkThreadListFilter(thread, filter, attribution); + return ( + (inbox === "shared" || viewingFounder === undefined || inbox === viewingFounder) && + filter.inboxes.includes(inbox) && + !filter.hiddenEnvironmentIds.includes(thread.environmentId) && + (attribution === undefined || !filter.hiddenAttributions.includes(attribution)) + ); +} + const ACTIVE_RUN_STATUSES: ReadonlySet = new Set([ "preparing", "queued", @@ -171,10 +193,10 @@ export function threadListFilterBucket( return null; } -/** The chosen founder's inbox first, then Agents, so the common pair sits together. */ +/** The default pair comes first for a founder. */ export const inboxMenuOrder = (owner: Founder | undefined): ReadonlyArray => { const first = owner ?? Founder.literals[0]; - return [first, "agents", ...Founder.literals.filter((founder) => founder !== first), "shared"]; + return [first, "shared", "agents", ...Founder.literals.filter((founder) => founder !== first)]; }; /** @@ -269,7 +291,7 @@ export function threadListFilterCounts( for (const thread of threads) { tally({ environmentId: thread.environmentId, - inbox: primaryInbox(thread.source.inbox), + inbox: standingInbox(thread) ?? primaryInbox(thread.source.inbox), agentCreated: thread.source.createdBy === "agent", attribution: attributionOf(thread), bucket: threadListFilterBucket(thread, viewingFounder), diff --git a/apps/web/src/state/linkedSidebar.ts b/apps/web/src/state/linkedSidebar.ts index a1a04ce8a75ac..83bc895679386 100644 --- a/apps/web/src/state/linkedSidebar.ts +++ b/apps/web/src/state/linkedSidebar.ts @@ -38,7 +38,13 @@ const sameThread = (left: EnvironmentThreadShell, right: EnvironmentThreadShell) left.snoozedUntil === right.snoozedUntil && left.runtime?.status === right.runtime?.status && left.lastVisitedAt === right.lastVisitedAt && + left.standing?.name === right.standing?.name && + left.standing?.role === right.standing?.role && + left.standing?.avatarId === right.standing?.avatarId && + left.standing?.accent === right.standing?.accent && left.latestRun?.completedAt === right.latestRun?.completedAt && + left.lineage.parentThreadId === right.lineage.parentThreadId && + left.lineage.relationshipToParent === right.lineage.relationshipToParent && left.source.inbox?.owner === right.source.inbox?.owner && left.source.inbox?.audience === right.source.inbox?.audience && left.source.inbox?.attentionKind === right.source.inbox?.attentionKind; diff --git a/packages/client-runtime/src/state/linkedSidebar.test.ts b/packages/client-runtime/src/state/linkedSidebar.test.ts index 21b18f1bb5e53..2931692b5b62b 100644 --- a/packages/client-runtime/src/state/linkedSidebar.test.ts +++ b/packages/client-runtime/src/state/linkedSidebar.test.ts @@ -81,7 +81,9 @@ describe("sidebarFromServerLinks", () => { expect(matchesThreadListFilter(linked, { ...filter, inboxes: ["jeff"] })).toBe(true); }); - it("lists one copy when two hosts report the same server-only link", () => { + it("lists one copy of a standing bot reported by two hosts", () => { + const standing = { name: "CoS (Jeff)", role: null, avatarId: "bolt", accent: "sky" } as const; + const bot = { ...jeffThread, standing }; const listed = sidebarFromServerLinks({ catalogEnvironmentIds: [laptop], environments: [ @@ -89,18 +91,19 @@ describe("sidebarFromServerLinks", () => { environmentId: omarcy, label: "omarcy-desktop", projects: [], - threads: [jeffThread], + threads: [bot], }, { environmentId: omarcy, label: "omarcy-desktop", projects: [], - threads: [jeffThread], + threads: [bot], }, ], }); expect(listed.identities).toEqual([{ environmentId: omarcy, label: "omarcy-desktop" }]); expect(listed.threads.map((thread) => thread.id)).toEqual([threadId]); + expect(listed.threads[0]?.standing).toEqual(standing); expect(listed.projects).toHaveLength(1); }); diff --git a/packages/client-runtime/src/state/linkedSidebar.ts b/packages/client-runtime/src/state/linkedSidebar.ts index 88f9cc75ee048..120172280affd 100644 --- a/packages/client-runtime/src/state/linkedSidebar.ts +++ b/packages/client-runtime/src/state/linkedSidebar.ts @@ -38,6 +38,7 @@ function threadShellFromLinkedThread( try { const shell = decodeShell({ ...(thread.inbox === undefined ? {} : { inbox: thread.inbox }), + ...(thread.standing == null ? {} : { standing: thread.standing }), createdBy: thread.createdBy, creationSource: thread.creationSource, id: thread.threadId, diff --git a/packages/contracts/src/linkedSidebar.ts b/packages/contracts/src/linkedSidebar.ts index 4ff712bd49ca0..39363b722ccc0 100644 --- a/packages/contracts/src/linkedSidebar.ts +++ b/packages/contracts/src/linkedSidebar.ts @@ -14,6 +14,7 @@ import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts"; import { OrchestratorMcpThreadStatus } from "./orchestratorMcp.ts"; import { OrchestrationV2Actor, OrchestrationV2CreationSource } from "./orchestrationV2.ts"; import { ThreadInbox } from "./threadInbox.ts"; +import { StoredThreadStanding } from "./threadStanding.ts"; export const LinkedSidebarInput = Schema.Struct({ catalogEnvironmentIds: Schema.optionalKey(Schema.Array(EnvironmentId)), @@ -22,6 +23,7 @@ export type LinkedSidebarInput = typeof LinkedSidebarInput.Type; export const LinkedSidebarThread = Schema.Struct({ inbox: Schema.optionalKey(ThreadInbox), + standing: Schema.optional(StoredThreadStanding), threadId: ThreadId, projectId: ProjectId, title: Schema.String, diff --git a/packages/contracts/src/orchestratorMcp.ts b/packages/contracts/src/orchestratorMcp.ts index b7278fc9c9984..606f90f881bad 100644 --- a/packages/contracts/src/orchestratorMcp.ts +++ b/packages/contracts/src/orchestratorMcp.ts @@ -1,3 +1,4 @@ +import { StoredThreadStanding } from "./threadStanding.ts"; import * as Effect from "effect/Effect"; import { HostResourcesSnapshot } from "./resourceTelemetry.ts"; import * as Schema from "effect/Schema"; @@ -417,6 +418,7 @@ export type OrchestratorMcpThreadBackgroundTask = typeof OrchestratorMcpThreadBa export const OrchestratorMcpThreadListItem = Schema.Struct({ inbox: Schema.optionalKey(ThreadInbox), + standing: Schema.optional(StoredThreadStanding), threadId: ThreadId, projectId: ProjectId, title: Schema.String, diff --git a/packages/contracts/src/threadInbox.test.ts b/packages/contracts/src/threadInbox.test.ts index 78fdd17d0c4d7..ff364d2fea0b8 100644 --- a/packages/contracts/src/threadInbox.test.ts +++ b/packages/contracts/src/threadInbox.test.ts @@ -10,6 +10,7 @@ import { matchesInboxFilter, effectiveInboxFilter, inboxOriginFor, + founderCreationOrigin, founderInboxLane, staysActiveWhileWorking, compositeThreadKey, @@ -23,6 +24,8 @@ import { withLegacyPeerInboxReason, type ThreadInboxRoutingPatch, } from "./threadInbox.ts"; +const decode = Schema.decodeUnknownSync(ClientSettingsSchema); +const encode = Schema.encodeSync(ClientSettingsSchema); const kameron = { kind: "human", id: "kameron" } as const; const jeff = { kind: "human", id: "jeff" } as const; const bot = { kind: "agent", id: "lead" } as const; @@ -41,9 +44,7 @@ describe("shared fleet organizational inbox", () => { expect(matchesInboxView(j, "all")).toBe(true); expect(matchesInboxView(k, "all")).toBe(true); }); - it("keeps All until a founder is chosen, then defaults to that founder plus Agents and Shared", () => { - const decode = Schema.decodeUnknownSync(ClientSettingsSchema); - const encode = Schema.encodeSync(ClientSettingsSchema); + it("keeps All until a founder is chosen, then defaults to that founder plus Shared", () => { // Settings saved by the single-choice selector still decode; that choice is not carried over. const upgraded = decode({ notificationMode: "off", founderInboxView: "all" }); // Any later settings write saves the whole snapshot; it must not record an unmade choice. @@ -56,9 +57,9 @@ describe("shared fleet organizational inbox", () => { expect(matchesInboxFilter(undefined, effectiveInboxFilter(upgraded))).toBe(true); const jeffClient = decode(encode({ ...upgraded, founderInboxOwner: "jeff" })); const filter = effectiveInboxFilter(jeffClient); - expect(filter).toEqual(["jeff", "agents", "shared"]); + expect(filter).toEqual(["jeff", "shared"]); expect(matchesInboxFilter(makeThreadInbox({ actor: jeff }), filter)).toBe(true); - expect(matchesInboxFilter(makeThreadInbox({ actor: bot }), filter)).toBe(true); + expect(matchesInboxFilter(makeThreadInbox({ actor: bot }), filter)).toBe(false); expect(matchesInboxFilter(makeThreadInbox({ actor: kameron }), filter)).toBe(false); expect( matchesInboxFilter( @@ -95,19 +96,42 @@ describe("shared fleet organizational inbox", () => { }); expect(matchesInboxFilter(filedToKameron, ["kameron"])).toBe(true); expect(matchesInboxFilter(filedToKameron, ["agents"])).toBe(false); - expect(effectiveInboxFilter({ founderInboxOwner: "jeff", founderInboxFilter: [] })).toEqual([ - "jeff", - "agents", - "shared", - ]); + for (const owner of ["jeff", "kameron"] as const) { + expect(effectiveInboxFilter({ founderInboxOwner: owner })).toEqual([owner, "shared"]); + expect(effectiveInboxFilter({ founderInboxOwner: owner, founderInboxFilter: [] })).toEqual([ + owner, + "shared", + ]); + expect( + effectiveInboxFilter( + decode(encode({ ...upgraded, founderInboxOwner: owner, founderInboxFilter: [owner] })), + ), + ).toEqual([owner, "shared"]); + expect( + effectiveInboxFilter({ founderInboxOwner: owner, founderInboxFilter: ["agents"] }), + ).toEqual(["agents"]); + } // Every inbox is All, which keeps unclassified history. const every = ["shared", "jeff", "agents", "kameron"] as const; expect(matchesInboxFilter(undefined, every)).toBe(true); expect(matchesInboxFilter(undefined, every.slice(1))).toBe(false); }); - it("attributes new work only to a chosen founder and leaves unchosen work in All", () => { + it("prefers a session founder over client settings and leaves legacy history discoverable", () => { expect(inboxOriginFor({})).toBeUndefined(); - // The server creates no inbox for a human thread without an origin, like legacy history. + for (const [bound, preference] of [ + [jeff, kameron], + [kameron, jeff], + ] as const) { + expect( + founderCreationOrigin({ founder: bound.id, deviceType: "mobile" }, preference), + ).toEqual(bound); + } + expect(founderCreationOrigin({ founder: null, deviceType: "desktop" }, jeff)).toEqual(jeff); + expect( + founderCreationOrigin({ founder: null, deviceType: "mobile" }, undefined), + ).toBeUndefined(); + expect(founderCreationOrigin({ founder: "jeff", deviceType: "bot" }, bot)).toEqual(bot); + // The current device cannot safely supply a founder for existing unclassified history. for (const view of ["kameron", "jeff", "agents", "shared"] as const) { expect(matchesInboxView(undefined, view)).toBe(false); } diff --git a/packages/contracts/src/threadInbox.ts b/packages/contracts/src/threadInbox.ts index 65b8f2f0a204f..1b49cc957232c 100644 --- a/packages/contracts/src/threadInbox.ts +++ b/packages/contracts/src/threadInbox.ts @@ -369,21 +369,16 @@ export function founderInboxLane(inbox: ThreadInbox | null | undefined, founder: return inbox.reason === "fyi" && inbox.attentionKind === "action" ? "FYI" : inbox.attentionKind; } -/** - * The inboxes the sidebar lists: the chosen ones, else the chosen founder's plus Agents and - * Shared, else every inbox so unclassified history stays visible. Shared is a default so both - * founders see shared bots without opening the filter. - */ +/** Closura: founders default to their own and Shared inboxes. Autonomous work is opt-in. */ export const effectiveInboxFilter = (settings: { readonly founderInboxFilter?: ReadonlyArray | undefined; readonly founderInboxOwner?: Founder | undefined; -}): ReadonlyArray => - // An empty choice, from another client or a hand edit, would blank the list; treat it as unset. - settings.founderInboxFilter !== undefined && settings.founderInboxFilter.length > 0 - ? settings.founderInboxFilter - : settings.founderInboxOwner === undefined - ? InboxChoice.literals - : [settings.founderInboxOwner, "agents", "shared"]; +}): ReadonlyArray => { + const { founderInboxFilter: filter, founderInboxOwner: owner } = settings; + // Older clients could persist the founder alone and silently hide the company desks. + if (filter?.length && !(filter.length === 1 && filter[0] === owner)) return filter; + return owner === undefined ? InboxChoice.literals : [owner, "shared"]; +}; /** Choosing every inbox means All, which also keeps unclassified history. */ const isAllInboxes = (filter: ReadonlyArray) => @@ -424,7 +419,7 @@ export const matchesInboxFilter = ( filter: ReadonlyArray, ) => matchesPrimaryInbox(primaryInbox(inbox), filter); -/** New work is attributed only to a chosen founder; otherwise it stays unclassified (All). */ +/** The founder selected by this client, when one has been chosen. */ export const inboxOriginFor = (settings: { readonly founderInboxOwner?: Founder | undefined; }): InboxActor | undefined => @@ -432,6 +427,15 @@ export const inboxOriginFor = (settings: { ? undefined : { kind: "human", id: settings.founderInboxOwner }; +/** Prefer the destination session's binding over a client preference. */ +export const founderCreationOrigin = ( + sender: { readonly founder: Founder | null; readonly deviceType: string }, + preferred: InboxActor | undefined, +): InboxActor | undefined => + sender.founder !== null && sender.deviceType !== "bot" + ? { kind: "human", id: sender.founder } + : preferred; + /** All deliberately includes every thread, including unclassified history. */ export function matchesInboxView(inbox: ThreadInbox | null | undefined, view: InboxView) { if (view === "all") return true; From 4452a795a005562d25b5a07c09ff296fd891a9d1 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Sun, 22 Nov 2026 19:49:57 +0000 Subject: [PATCH 2/2] fix(inbox): keep unattributed conversations active Model: GPT-6 Task: bugfix Agent: Codex Lane: codex --- .../src/mcp/OrchestratorMcpService.test.ts | 4 +- .../src/orchestration-v2/Orchestrator.ts | 47 ++++++++++--------- .../ThreadSettlementService.test.ts | 4 ++ .../ThreadSettlementService.ts | 2 + apps/server/src/peer/linkedSidebar.test.ts | 14 +++++- .../src/provider/agentContextBudget.json | 2 +- .../Sidebar.founder-inbox.browser.test.tsx | 7 ++- packages/contracts/src/threadInbox.test.ts | 5 +- 8 files changed, 57 insertions(+), 28 deletions(-) diff --git a/apps/server/src/mcp/OrchestratorMcpService.test.ts b/apps/server/src/mcp/OrchestratorMcpService.test.ts index c9a0cb45954eb..b64ecac470b65 100644 --- a/apps/server/src/mcp/OrchestratorMcpService.test.ts +++ b/apps/server/src/mcp/OrchestratorMcpService.test.ts @@ -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), { @@ -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]), [ diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index d3c5623953a17..895362a1d6093 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -7549,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; @@ -7793,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. @@ -7900,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 = @@ -9266,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, diff --git a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts b/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts index 6818c26297c8e..a0cc9913e537b 100644 --- a/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts +++ b/apps/server/src/orchestration-v2/ThreadSettlementService.test.ts @@ -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" }, }); @@ -1077,6 +1080,7 @@ describe("ThreadSettlementServiceV2 worker", () => { asked, idle, already, + unboundHuman, standing, human("kameron"), human("jeff"), diff --git a/apps/server/src/orchestration-v2/ThreadSettlementService.ts b/apps/server/src/orchestration-v2/ThreadSettlementService.ts index 39315fe2af03f..9b868718e62e2 100644 --- a/apps/server/src/orchestration-v2/ThreadSettlementService.ts +++ b/apps/server/src/orchestration-v2/ThreadSettlementService.ts @@ -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); } diff --git a/apps/server/src/peer/linkedSidebar.test.ts b/apps/server/src/peer/linkedSidebar.test.ts index 7bc9b01055b07..1b858c423351b 100644 --- a/apps/server/src/peer/linkedSidebar.test.ts +++ b/apps/server/src/peer/linkedSidebar.test.ts @@ -71,7 +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)", avatarId: "bolt", accent: "sky" }, + 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", @@ -106,7 +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?.name).toBe("CoS (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", diff --git a/apps/server/src/provider/agentContextBudget.json b/apps/server/src/provider/agentContextBudget.json index c2084d57162bb..cbec12124c36f 100644 --- a/apps/server/src/provider/agentContextBudget.json +++ b/apps/server/src/provider/agentContextBudget.json @@ -1,5 +1,5 @@ { "claudeSystemAppendBytes": 5930, "codexAdditionalContextBytes": 7324, - "mcpToolListJsonBytes": 55827 + "mcpToolListJsonBytes": 56852 } diff --git a/apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx b/apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx index 8e3cde99498c5..762d7151cd7bd 100644 --- a/apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx +++ b/apps/web/src/components/Sidebar.founder-inbox.browser.test.tsx @@ -112,6 +112,7 @@ it.each(["jeff", "kameron"] as const)( { ...standingBot(childName, "agent-only"), parentThreadId: ThreadId.make("standing-CEO"), + relationshipToParent: "subagent" as const, }, ] : []), @@ -174,6 +175,7 @@ it.each(["jeff", "kameron"] as const)( for (const width of [1280, 360]) { await page.viewport(width, 800); await expect.element(menu).toBeVisible(); + await vi.waitFor(() => { const popup = menu.element().getBoundingClientRect(); expect(popup.left).toBeGreaterThanOrEqual(0); @@ -188,11 +190,14 @@ it.each(["jeff", "kameron"] as const)( }); } await page.viewport(1280, 800); + await agents.click(); + await expect.element(agents).toHaveAttribute("aria-checked", "true"); + await expect.element(mine.getByText(childName, { exact: true })).not.toBeInTheDocument(); await expect.element(company.getByText(childName, { exact: true })).not.toBeInTheDocument(); - await expect.element(screen.getByText(childName, { exact: true })).toBeVisible(); + await menu.getByRole("menuitem", { name: "Reset to default" }).click(); await vi.waitFor(() => expect(persist).toHaveBeenLastCalledWith(expect.objectContaining({ founderInboxFilter: [] })), diff --git a/packages/contracts/src/threadInbox.test.ts b/packages/contracts/src/threadInbox.test.ts index ff364d2fea0b8..b5be7bd38e836 100644 --- a/packages/contracts/src/threadInbox.test.ts +++ b/packages/contracts/src/threadInbox.test.ts @@ -26,6 +26,7 @@ import { } from "./threadInbox.ts"; const decode = Schema.decodeUnknownSync(ClientSettingsSchema); const encode = Schema.encodeSync(ClientSettingsSchema); +const isDecisionAsk = Schema.is(ThreadDecisionAsk); const kameron = { kind: "human", id: "kameron" } as const; const jeff = { kind: "human", id: "jeff" } as const; const bot = { kind: "agent", id: "lead" } as const; @@ -486,7 +487,7 @@ describe("joint sign-off", () => { question: "Ship it?", } as const; expect( - Schema.is(ThreadDecisionAsk)({ + isDecisionAsk({ ...ask, signOff: [ { founder: "kameron", signed: false }, @@ -495,7 +496,7 @@ describe("joint sign-off", () => { }), ).toBe(true); expect( - Schema.is(ThreadDecisionAsk)({ + isDecisionAsk({ ...ask, signOff: [ { founder: "kameron", signed: false },