fix: Home threads showed another provider's composer controls

A Hermes Home thread rendered "Enable a provider in Settings to send a
message" alongside a Full access selector and a Build toggle — controls
Hermes explicitly opts out of, on a thread whose provider was connected.

One root cause. `deriveLockedProvider` reads `session.providerName` first,
but a Home thread never opens a session (deliveries bypass the turn
machinery), so it fell through to `modelSelection.instanceId`. That value is
an instance id, and `isProviderDriverKind` validates slug *shape* rather than
registry membership — so `hermes-siva-local-c9cc` satisfied it and came back
as a "driver kind" matching no driver. The composer then failed to resolve
the bound instance, and both `requiresWorkspace` and
`showInteractionModeToggle` fell through to their absent-means-true defaults.
That default is where the two stray controls came from; neither is
special-cased away, they simply stop applying once the instance resolves.

The registry lookup now runs before the shape check.

Home also gets the treatment its fixed binding deserves: the model chip is a
static label rather than a picker (the instance and model slug are fixed at
`thread.create` and Hermes sets `requiresNewThreadForModelChange`, so a
picker would offer a choice that cannot be taken), and the placeholder names
the agent it is addressed to.

Proactive deliveries now render as arrivals rather than as replies: a header
carrying source and time over a hairline rule, with room above. The timestamp
is always visible, unlike the hover-revealed one on an ordinary assistant
message — a reply is dated by the act of asking for it, but a delivery lands
while you are elsewhere. Agent-authored bodies routinely open with an H1
restating the header ("Cronjob Response: …"), so headings inside a delivery
are demoted one step via a scoped class; the markdown itself is untouched, so
nothing can be parsed away. Keyed on notification provenance rather than on
the thread being Home, so a `/handoff` into an ordinary thread reads the same.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Ben DavisandClaude Opus 5 committed 2026-07-26 19:48:28 -07:00
1 parent 288fe5d29d
commit 52035b9be7
9 files changed
+364 -61

No files matched your search

@@ -2,6 +2,7 @@ import {
EnvironmentId,
MessageId,
ProjectId,
ProviderDriverKind,
ProviderInstanceId,
ThreadId,
TurnId,
@@ -17,6 +18,7 @@ import {
buildThreadTurnInterruptInput,
createLocalDispatchSnapshot,
deriveComposerSendState,
deriveLockedProvider,
dismissBranchMismatchForSession,
getStartedThreadModelChangeBlockReason,
hasServerAcknowledgedLocalDispatch,
@@ -599,3 +601,99 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
expect(hasServerAcknowledgedLocalDispatch({ ...common, threadError: "failed" })).toBe(true);
});
});
describe("deriveLockedProvider", () => {
const hermesInstanceId = ProviderInstanceId.make("hermes-siva-local-c9cc");
const providers = [
{ instanceId: hermesInstanceId, driver: ProviderDriverKind.make("hermes") },
{ instanceId: ProviderInstanceId.make("codex"), driver: ProviderDriverKind.make("codex") },
];
it("leaves an unstarted thread unlocked", () => {
expect(
deriveLockedProvider({
thread: makeThread(),
selectedProvider: null,
threadProvider: "codex",
providers,
}),
).toBe(null);
});
it("follows the open session's driver kind when there is one", () => {
expect(
deriveLockedProvider({
thread: makeThread({ session: readySession }),
selectedProvider: null,
threadProvider: null,
providers,
}),
).toBe("codex");
});
it("resolves a sessionless thread's instance id back to its driver kind", () => {
// A Hermes home thread never opens a session — deliveries bypass the turn
// machinery — so `modelSelection.instanceId` is the only binding left.
// Before this resolved, the composer fell through to the unknown-instance
// defaults and showed a runtime mode selector Hermes opts out of.
expect(
deriveLockedProvider({
thread: makeThread({
session: null,
messages: [
{
id: MessageId.make("message-1"),
role: "assistant",
text: "Gateway online",
turnId: null,
streaming: false,
createdAt: now,
updatedAt: now,
},
],
modelSelection: { instanceId: hermesInstanceId, model: "hermes" },
}),
selectedProvider: null,
threadProvider: hermesInstanceId,
providers,
}),
).toBe("hermes");
});
it("prefers the registry over the slug shape for an instance id", () => {
// `isProviderDriverKind` validates slug *shape*, not membership, so an
// instance id passes it. Checking shape first would hand back
// `hermes-siva-local-c9cc` as a driver kind matching no driver — which is
// exactly how a home thread ended up with another provider's composer
// controls.
expect(
deriveLockedProvider({
thread: makeThread({ latestTurn: completedTurn }),
selectedProvider: null,
threadProvider: hermesInstanceId,
providers,
}),
).toBe("hermes");
});
it("stays unlocked when the thread carries no usable binding", () => {
expect(
deriveLockedProvider({
thread: makeThread({ latestTurn: completedTurn }),
selectedProvider: null,
threadProvider: null,
providers,
}),
).toBe(null);
});
it("degrades to slug-only matching when no snapshots are supplied", () => {
expect(
deriveLockedProvider({
thread: makeThread({ latestTurn: completedTurn }),
selectedProvider: null,
threadProvider: "codex",
}),
).toBe("codex");
});
});
+27 -14
View File
@@ -342,15 +342,19 @@ export function threadHasStarted(thread: Thread | null | undefined): boolean {
//
// `selectedProvider` takes the same open-string shape because the composer
// now tracks the picker selection as a `ProviderInstanceId` (e.g.
// `codex_personal`). Custom instance ids that don't directly match a
// registered driver resolve to `null` here, which matches the existing
// "unknown driver -> unlocked" semantics. Callers that want the lock to track
// a custom instance's underlying driver kind should resolve the instance id
// upstream and pass the correlated kind.
// `codex_personal`). Such an id is not itself a driver-kind slug, so
// `providers` is consulted to map it back to its owning kind; without that
// lookup a thread bound to a user-authored instance reads as unlocked.
export function deriveLockedProvider(input: {
thread: Thread | null | undefined;
selectedProvider: string | null;
threadProvider: string | null;
/**
* Instance snapshots used to resolve a `ProviderInstanceId` to its driver
* kind. Optional so callers that already hold a kind can omit it; absent (or
* not yet streamed) it degrades to the previous slug-only matching.
*/
providers?: ReadonlyArray<Pick<ServerProvider, "instanceId" | "driver">>;
}): ProviderDriverKind | null {
if (!threadHasStarted(input.thread)) {
return null;
@@ -359,15 +363,24 @@ export function deriveLockedProvider(input: {
if (sessionProvider && isProviderDriverKind(sessionProvider)) {
return sessionProvider;
}
const narrowedThreadProvider =
input.threadProvider && isProviderDriverKind(input.threadProvider)
? input.threadProvider
: null;
const narrowedSelectedProvider =
input.selectedProvider && isProviderDriverKind(input.selectedProvider)
? input.selectedProvider
: null;
return narrowedThreadProvider ?? narrowedSelectedProvider ?? null;
// A Hermes home thread never opens a session (deliveries bypass the turn
// machinery), so `providerName` is absent and the only binding left is the
// instance id on `modelSelection`. Resolving it through the snapshots is
// what keeps the composer on the thread's own instance instead of falling
// through to the unknown-instance defaults, which show a workspace runtime
// mode selector and a plan toggle that Hermes explicitly opts out of.
//
// The registry lookup must come FIRST. `isProviderDriverKind` validates slug
// *shape*, not membership, so an instance id like `hermes-siva-local-c9cc`
// satisfies it and would otherwise be returned as a driver kind that matches
// no driver — locking the thread to a provider that does not exist.
const narrow = (candidate: string | null): ProviderDriverKind | null => {
if (!candidate) return null;
const resolved = input.providers?.find((entry) => entry.instanceId === candidate)?.driver;
if (resolved) return resolved;
return isProviderDriverKind(candidate) ? candidate : null;
};
return narrow(input.threadProvider) ?? narrow(input.selectedProvider) ?? null;
}
export function getStartedThreadModelChangeBlockReason(input: {
+6 -5
View File
@@ -1799,16 +1799,17 @@ function ChatViewContent(props: ChatViewProps) {
activeThread?.modelSelection.instanceId ??
activeProject?.defaultModelSelection?.instanceId ??
null;
const lockedProvider = deriveLockedProvider({
thread: activeThread,
selectedProvider: selectedProviderByThreadId,
threadProvider,
});
// Once a thread selects an environment, never substitute the primary
// environment's config while the selected environment is still loading.
const serverConfig = activeThread
? (activeEnvironment?.serverConfig ?? null)
: (primaryEnvironment?.serverConfig ?? null);
const lockedProvider = deriveLockedProvider({
thread: activeThread,
selectedProvider: selectedProviderByThreadId,
threadProvider,
providers: serverConfig?.providers ?? EMPTY_PROVIDERS,
});
const versionMismatch = resolveServerConfigVersionMismatch(serverConfig);
const versionMismatchDismissKey =
versionMismatch && activeThread
+18 -3
View File
@@ -187,6 +187,7 @@ import {
sortProviderInstanceEntries,
type ProviderInstanceEntry,
} from "../../providerInstances";
import { homeThreadComposerPlaceholder, isHomeThreadId } from "../../homeThreads";
import { type AppModelOption, getAppModelOptionsForInstance } from "../../modelSelection";
import type { UnifiedSettings } from "@t3tools/contracts/settings";
import type { SessionPhase, Thread } from "../../types";
@@ -401,7 +402,7 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
render={
<Button
variant="ghost"
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 sm:px-3"
className="shrink-0 whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80"
size="sm"
type="button"
onClick={props.onOpenAgent}
@@ -409,8 +410,10 @@ const ComposerFooterModeControls = memo(function ComposerFooterModeControls(prop
/>
}
>
{/* The mark alone. `aria-label` on the trigger and the tooltip below
both still say "Open agent details", so dropping the visible
word costs nothing to a screen reader. */}
<HermesIcon />
<span className="sr-only sm:not-sr-only">Agent</span>
</TooltipTrigger>
<TooltipPopup side="top">Open agent details</TooltipPopup>
</Tooltip>
@@ -902,6 +905,15 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
selectedProviderEntry?.driverKind ?? requestedDriverKind;
const allowHermesSteering = phase === "running" && selectedProvider === "hermes";
// A Home thread is permanently bound to one instance and one model slug —
// `thread.create` fixes both, and Hermes sets
// `requiresNewThreadForModelChange`. A picker there would offer a choice
// that cannot be taken, so the chip renders as a static label instead.
const isHomeThread = useMemo(
() => isHomeThreadId(providerStatuses, activeThread?.id),
[activeThread?.id, providerStatuses],
);
const { modelOptions: composerModelOptions, selectedModel } = useEffectiveComposerModelState({
threadRef: composerDraftTarget,
providers: providerStatuses,
@@ -2699,7 +2711,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
? providerUnavailableMessage
: phase === "disconnected"
? "Ask for follow-up changes or attach images"
: "Ask anything, @tag files/folders, $use skills, or / for commands"
: isHomeThread
? homeThreadComposerPlaceholder(selectedProviderEntry?.displayName)
: "Ask anything, @tag files/folders, $use skills, or / for commands"
}
disabled={isConnecting || isComposerApprovalState || projectSelectionRequired}
/>
@@ -2771,6 +2785,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
compact={isComposerFooterCompact}
activeInstanceId={selectedInstanceId}
model={selectedModelForPickerWithCustomFallback}
staticLabel={isHomeThread}
lockedProvider={lockedProvider}
lockedContinuationGroupKey={lockedContinuationGroupKey}
instanceEntries={providerInstanceEntries}
@@ -1021,25 +1021,45 @@ function TurnFoldTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "turn-
}
/**
* Provenance chip above a proactive agent delivery.
* Header for a proactive agent delivery: provenance on the left, arrival time
* on the right, a hairline rule under both.
*
* Deliberately not a status pill: it is inline, unpadded on the left, and
* sits in the message's own column so the body below reads as the same
* assistant message it would have been without it.
* The timestamp is always visible here, unlike the hover-revealed one on an
* ordinary assistant message. A reply is dated by the act of asking for it —
* you were there. A delivery arrives while you are not, so "when" is part of
* reading it at all.
*/
function NotificationBadge({ badge }: { badge: NotificationBadgePresentation }) {
function NotificationHeader({
badge,
timestamp,
timestampTooltip,
}: {
badge: NotificationBadgePresentation;
timestamp: string;
timestampTooltip: string;
}) {
return (
<div
className={cn(
"mb-1 inline-flex items-center gap-1 rounded-sm px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide",
badge.muted
? "bg-muted/50 text-muted-foreground/80"
: "bg-accent/60 text-accent-foreground",
)}
className="mb-2 flex items-baseline gap-2 border-b border-border/60 pb-1.5"
data-notification-badge
>
<BellIcon className="size-3 opacity-70" />
<span className="min-w-0 truncate normal-case tracking-normal">{badge.label}</span>
<span
className={cn(
"flex min-w-0 items-center gap-1.5 text-sm font-semibold",
badge.muted ? "text-muted-foreground" : "text-foreground",
)}
>
<BellIcon className="size-3.5 shrink-0 self-center opacity-70" />
<span className="min-w-0 truncate">{badge.label}</span>
</span>
<Tooltip>
<TooltipTrigger
render={<p className="ml-auto shrink-0 text-xs tabular-nums text-muted-foreground/80" />}
>
{timestamp}
</TooltipTrigger>
<TooltipPopup>{timestampTooltip}</TooltipPopup>
</Tooltip>
</div>
);
}
@@ -1051,14 +1071,35 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
return (
<>
<div className="relative min-w-0 px-1 py-0.5">
{notificationBadge ? <NotificationBadge badge={notificationBadge} /> : null}
<div
className={cn(
"relative min-w-0 px-1 py-0.5",
// A delivery interrupts rather than continues, so it gets room to
// read as its own arrival instead of running into the message above.
notificationBadge ? "mt-5 first:mt-1" : null,
)}
>
{notificationBadge ? (
<NotificationHeader
badge={notificationBadge}
timestamp={formatShortTimestamp(row.message.updatedAt, ctx.timestampFormat)}
timestampTooltip={formatChatTimestampTooltip(
row.message.updatedAt,
ctx.timestampFormat,
)}
/>
) : null}
<ChatMarkdown
text={messageText}
cwd={ctx.markdownCwd}
threadRef={ctx.threadRef ?? undefined}
isStreaming={Boolean(row.message.streaming)}
skills={ctx.skills}
// The delivery's own header is the heading. Agent-authored bodies
// routinely open with an H1 restating it ("Cronjob Response: …"),
// which would otherwise out-shout the real one; demoting the scale
// keeps that text intact but subordinate.
{...(notificationBadge ? { className: "chat-markdown-notification-body" } : {})}
/>
<AssistantChangedFilesSection
turnSummary={row.assistantTurnDiffSummary}
@@ -1069,7 +1110,8 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
{row.showAssistantMeta ? (
<div className="mt-1.5 flex items-center gap-2 text-xs tabular-nums opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover/assistant:opacity-100">
<AssistantCopyButton row={row} />
{!row.message.streaming && (
{/* A delivery's header already carries the time, permanently. */}
{!row.message.streaming && !notificationBadge && (
<Tooltip>
<TooltipTrigger
render={<p className="text-muted-foreground text-xs tabular-nums" />}
@@ -35,6 +35,15 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
activeProviderIconClassName?: string;
compact?: boolean;
disabled?: boolean;
/**
* Render the trigger as a plain label — no caret, no popover, not focusable.
*
* For threads whose instance and model are fixed at creation and cannot be
* reassigned (a Hermes Home channel). `disabled` is the wrong control here:
* it styles the chip as a broken affordance, when the truth is there is no
* choice to offer.
*/
staticLabel?: boolean;
terminalOpen?: boolean;
open?: boolean;
triggerVariant?: VariantProps<typeof buttonVariants>["variant"];
@@ -132,6 +141,48 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
setIsMenuOpen(false);
};
const triggerContents = (
<span className="flex min-w-0 flex-1 items-center gap-2">
{activeEntry ? (
<ProviderInstanceIcon
driverKind={activeEntry.driverKind}
displayName={activeEntry.displayName}
accentColor={activeEntry.accentColor}
showBadge={showInstanceBadge}
className={showInstanceBadge ? "size-5" : "size-4"}
iconClassName={cn("size-4", props.activeProviderIconClassName)}
indicatorBackground="var(--input)"
badgeClassName={cn(
"right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3",
"px-0.5 text-[7px]",
)}
/>
) : null}
<Tooltip>
<TooltipTrigger render={<span className="min-w-0 flex-1 overflow-hidden truncate" />}>
{triggerTitle}
</TooltipTrigger>
<TooltipPopup side="top">{triggerLabel}</TooltipPopup>
</Tooltip>
</span>
);
if (props.staticLabel) {
return (
<span
data-chat-provider-model-picker="true"
data-static="true"
className={cn(
"flex h-8 min-w-0 items-center whitespace-nowrap px-2 text-sm text-muted-foreground/70",
props.compact ? "max-w-42 shrink-0" : "max-w-48 shrink sm:max-w-56 sm:px-3",
props.triggerClassName,
)}
>
{triggerContents}
</span>
);
}
return (
<Popover
open={isMenuOpen}
@@ -158,29 +209,7 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
/>
}
>
<span className="flex min-w-0 flex-1 items-center gap-2">
{activeEntry ? (
<ProviderInstanceIcon
driverKind={activeEntry.driverKind}
displayName={activeEntry.displayName}
accentColor={activeEntry.accentColor}
showBadge={showInstanceBadge}
className={showInstanceBadge ? "size-5" : "size-4"}
iconClassName={cn("size-4", props.activeProviderIconClassName)}
indicatorBackground="var(--input)"
badgeClassName={cn(
"right-[-0.125rem] bottom-[-0.125rem] h-3 min-w-3",
"px-0.5 text-[7px]",
)}
/>
) : null}
<Tooltip>
<TooltipTrigger render={<span className="min-w-0 flex-1 overflow-hidden truncate" />}>
{triggerTitle}
</TooltipTrigger>
<TooltipPopup side="top">{triggerLabel}</TooltipPopup>
</Tooltip>
</span>
{triggerContents}
<span aria-hidden="true" className="flex items-center">
<ChevronDownIcon aria-hidden="true" className="!ms-0 !-me-1 size-3 shrink-0 opacity-60" />
</span>
+45
View File
@@ -0,0 +1,45 @@
import { ThreadId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { homeThreadComposerPlaceholder, isHomeThreadId } from "./homeThreads";
const homeThreadId = ThreadId.make("thread-home");
const otherThreadId = ThreadId.make("thread-other");
const providers = [{ homeThreadId: undefined }, { homeThreadId }] as Parameters<
typeof isHomeThreadId
>[0];
describe("isHomeThreadId", () => {
it("recognizes the designated home thread", () => {
expect(isHomeThreadId(providers, homeThreadId)).toBe(true);
});
it("does not claim an ordinary thread in the same project", () => {
expect(isHomeThreadId(providers, otherThreadId)).toBe(false);
});
it("is false for a draft thread with no id yet", () => {
// A draft must not inherit Home's fixed-binding composer treatment.
expect(isHomeThreadId(providers, null)).toBe(false);
expect(isHomeThreadId(providers, undefined)).toBe(false);
});
it("is false when no instance has designated one", () => {
// Every non-Hermes driver, and a Hermes instance pre-handshake. An
// `undefined` designation must never match an absent thread id.
expect(isHomeThreadId([{ homeThreadId: undefined }], undefined)).toBe(false);
expect(isHomeThreadId([], homeThreadId)).toBe(false);
});
});
describe("homeThreadComposerPlaceholder", () => {
it("addresses the agent by name", () => {
expect(homeThreadComposerPlaceholder("Hermes Siva Local")).toBe("Message Hermes Siva Local");
});
it("falls back before the instance snapshot arrives", () => {
expect(homeThreadComposerPlaceholder(undefined)).toBe("Message Hermes");
expect(homeThreadComposerPlaceholder(" ")).toBe("Message Hermes");
});
});
+31
View File
@@ -0,0 +1,31 @@
import type { ServerProvider, ThreadId } from "@t3tools/contracts";
/**
* Whether a thread is some instance's designated Home channel.
*
* Read off the streamed provider snapshots rather than off the thread itself:
* the designation lives in the instance's settings blob, is re-emitted on
* every status tick, and a thread row carries no flag of its own. A thread
* that is Home for *any* instance is Home — instances cannot share one.
*/
export function isHomeThreadId(
providers: ReadonlyArray<Pick<ServerProvider, "homeThreadId">>,
threadId: ThreadId | string | null | undefined,
): boolean {
if (!threadId) return false;
return providers.some((provider) => provider.homeThreadId === threadId);
}
/**
* Composer placeholder for a Home thread.
*
* Home is the agent's own channel rather than a workspace thread, and naming
* the agent is the cue for that: the box you type in is addressed to a
* specific process, not to whatever provider the picker happens to hold.
* Falls back to a bare "Message Hermes" when the instance snapshot has not
* streamed yet, which is preferable to a flash of the generic prompt.
*/
export function homeThreadComposerPlaceholder(displayName: string | undefined): string {
const trimmed = displayName?.trim();
return trimmed ? `Message ${trimmed}` : "Message Hermes";
}
+29
View File
@@ -1130,6 +1130,35 @@ label:has(> select#reasoning-effort) select {
color: var(--muted-foreground);
}
/*
* Body of a proactive delivery (cron result, agent-initiated message).
*
* The delivery renders its own header — source and arrival time — and agent
* authored bodies routinely open with an H1 restating it. Demoting the whole
* heading scale by one step keeps that text and its internal hierarchy intact
* while leaving the real heading the largest thing in the block. The first
* heading also loses its top margin, since the header rule above it is
* already the separation.
*/
.chat-markdown-notification-body h1 {
font-size: 1.0625rem;
}
.chat-markdown-notification-body h2 {
font-size: 1rem;
}
.chat-markdown-notification-body h3,
.chat-markdown-notification-body h4,
.chat-markdown-notification-body h5,
.chat-markdown-notification-body h6 {
font-size: 0.875rem;
}
.chat-markdown-notification-body > :first-child {
margin-top: 0;
}
.chat-markdown ul {
padding-left: 1.25rem;
list-style-type: disc;