From 3f71c601a63be6460798adee834548a4856b1499 Mon Sep 17 00:00:00 2001 From: Ben Davis <45952064+bmdavis419@users.noreply.github.com> Date: Sat, 25 Jul 2026 23:07:29 -0700 Subject: [PATCH] fix: complete Hermes turns on notify, never on finalize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit My previous fix named the wrong culprit. `format_tool_event` is dead code at Hermes 62e07223 — its only caller, `GatewayEventDispatcher` (`gateway/stream_dispatch.py:108`), is referenced solely by upstream tests. The live path is `gateway/run.py:20485+`, which builds the same progress lines and delivers them through `adapter.send` / `adapter.edit_message` with no adapter hook to suppress them. The override is kept as documented-contract defence with a docstring saying so, but it never protected anything. The turn was being closed by `finalize`. Two upstream paths set it: - `gateway/run.py:20777-20780` — the tool-progress loop sets `finalize=True` on every progress-bubble edit when the adapter declares `REQUIRES_EDIT_FINALIZE`, which we did. - `gateway/stream_consumer.py:938-940` — `finalize=(got_done or got_segment_break)`, which fires on every mid-turn segment break *regardless* of that flag. So clearing `REQUIRES_EDIT_FINALIZE` alone would not have fixed it. Ignoring `finalize` in `edit_message` is the load-bearing change; the flag is cleared because declaring it only invites the first path. `notify=True` on `send()` is the real completion signal — the gateway stamps it via `_mark_notify_metadata` (`gateway/platforms/base.py:89`) only on genuine user-visible replies, and the progress path never sets it. Second bug, same class, found while auditing for siblings: the tool hooks' `session_id` is `agent.session_id` (`agent/tool_executor.py:188`) — a timestamped run id like `20260725_143012_ab12cd34` (`gateway/session.py:2388`) — not this plugin's `build_session_key` id (`agent:main:t3:dm:`). The namespaces never intersect, so every tool activity item was silently dropped. `_turn_for_tool_hook` now resolves via the raw id, then `HERMES_SESSION_KEY` from Hermes' session *contextvar* (the concurrency-safe surface; upstream deliberately does not write the process-global env var), then the sole active turn. With two or more concurrent turns and no key it emits nothing rather than misattributing activity to the wrong thread. Also fixes the Build toggle rendering on Hermes threads. Same shape as the `requiresWorkspace` bug: `getProviderInteractionModeToggle` is driver-kind keyed, so it resolves `defaultInstanceIdForDriver("hermes")` — an instance id that never exists, because Hermes ids are user-authored slugs and the registry refuses to synthesize a default. The lookup missed and absent-means-true won. Adds an instance-keyed helper and switches the composer to it, which fixes the wide and compact layouts together. Hiding the toggle is not enough on its own — plan mode stayed reachable three other ways, all now gated: Shift+Tab, the `/plan` and `/default` menu items, and the standalone-message parse (that last one mattered most: typing `/plan` would otherwise swallow the message with no visible effect). Regression tests pin both legs of the finalize bug by replaying the gateway's own `_edit_progress_message` closure, and the interaction-mode test asserts the kind-keyed lookup returns true while the instance-keyed one returns false on a Hermes-shaped provider. COMPATIBILITY.md records the corrected diagnosis and the inverted risk: if `notify` ever stops being stamped, turns would hang instead of truncating. Co-Authored-By: Claude Opus 5 (1M context) --- apps/web/src/components/ChatView.tsx | 7 + apps/web/src/components/chat/ChatComposer.tsx | 52 ++- apps/web/src/providerModels.test.ts | 117 ++++++ apps/web/src/providerModels.ts | 31 ++ .../hermes-t3-gateway/COMPATIBILITY.md | 153 ++++++-- integrations/hermes-t3-gateway/adapter.py | 117 ++++-- .../hermes-t3-gateway/tests/test_adapter.py | 337 +++++++++++++++++- 7 files changed, 733 insertions(+), 81 deletions(-) diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index c5092c0f53..4f9b0e3af6 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -2383,6 +2383,12 @@ function ChatViewContent(props: ChatViewProps) { // synthesized, so a kind-keyed lookup would never find one. Absent means // true, so every provider that predates the flag keeps its directory UI. const providerRequiresWorkspace = activeProviderStatus?.requiresWorkspace !== false; + // Same instance-keyed resolution for the Build/Plan capability. When the + // toggle is hidden the standalone `/plan` and `/default` messages must not be + // intercepted either, otherwise typing one silently swallows the message with + // no visible effect. Absent means true, matching the composer's default. + const providerShowsInteractionModeToggle = + activeProviderStatus?.showInteractionModeToggle !== false; const showComposerContextStrip = isGitRepo && activeProject !== null && providerRequiresWorkspace; const initialDiffPanelGitScope = gitStatusQuery.data?.hasWorkingTreeChanges === true ? "unstaged" : "branch"; @@ -4498,6 +4504,7 @@ function ChatViewContent(props: ChatViewProps) { return; } const standaloneSlashCommand = + providerShowsInteractionModeToggle && composerImages.length === 0 && sendableComposerTerminalContexts.length === 0 && composerElementContexts.length === 0 && diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx index 3209e6bff0..35accb4f5f 100644 --- a/apps/web/src/components/chat/ChatComposer.tsx +++ b/apps/web/src/components/chat/ChatComposer.tsx @@ -174,8 +174,8 @@ import { import { proposedPlanTitle } from "../../proposedPlan"; import { getProviderDisplayName, + getProviderInstanceInteractionModeToggle, getProviderInstanceRequiresWorkspace, - getProviderInteractionModeToggle, } from "../../providerModels"; import { applyProviderInstanceSettings, @@ -945,22 +945,22 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) const selectedPromptEffort = composerProviderState.promptEffort; const selectedModelOptionsForDispatch = composerProviderState.modelOptionsForDispatch; + // Both flags resolve per instance, not per driver kind: the composer already + // knows the exact instance the next turn routes to, and providers whose + // instances are always user-authored (Hermes) have no default instance for a + // kind-keyed lookup to find. const composerProviderControls = useMemo( () => ({ - showInteractionModeToggle: getProviderInteractionModeToggle( + showInteractionModeToggle: getProviderInstanceInteractionModeToggle( providerStatuses, - selectedProvider, + selectedInstanceId, ), - // Resolved per instance, not per driver kind: the composer already - // knows the exact instance the next turn routes to, and providers - // whose instances are always user-authored (Hermes) have no default - // instance for a kind-keyed lookup to find. showRuntimeModeSelector: getProviderInstanceRequiresWorkspace( providerStatuses, selectedInstanceId, ), }), - [providerStatuses, selectedInstanceId, selectedProvider], + [providerStatuses, selectedInstanceId], ); // Only providers with no workspace get an agent button; for everyone else // this stays null and the Build toggle keeps the slot. @@ -1107,14 +1107,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) })); } if (composerTrigger.kind === "slash-command") { - const builtInSlashCommandItems = [ - { - id: "slash:model", - type: "slash-command", - command: "model", - label: "/model", - description: "Switch response model for this thread", - }, + const interactionModeSlashCommandItems = [ { id: "slash:plan", type: "slash-command", @@ -1130,6 +1123,21 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) description: "Switch this thread back to normal build mode", }, ] satisfies ReadonlyArray>; + const builtInSlashCommandItems = [ + { + id: "slash:model", + type: "slash-command", + command: "model", + label: "/model", + description: "Switch response model for this thread", + }, + // Hidden for providers that opt out of the Build/Plan toggle — the + // standalone `/plan` message form is skipped for them too, so the + // command cannot silently swallow a message with no visible effect. + ...(composerProviderControls.showInteractionModeToggle + ? interactionModeSlashCommandItems + : []), + ] satisfies ReadonlyArray>; const providerSlashCommandItems = (selectedProviderStatus?.slashCommands ?? []).map( (command) => ({ id: `provider-slash-command:${selectedProvider}:${command.name}`, @@ -1163,7 +1171,13 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) ); } return []; - }, [composerTrigger, selectedProvider, selectedProviderStatus, workspaceEntries.entries]); + }, [ + composerProviderControls.showInteractionModeToggle, + composerTrigger, + selectedProvider, + selectedProviderStatus, + workspaceEntries.entries, + ]); const composerMenuOpen = Boolean(composerTrigger); const composerMenuSearchKey = composerTrigger @@ -1907,7 +1921,9 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps) key: "ArrowDown" | "ArrowUp" | "Enter" | "Tab", event: KeyboardEvent, ) => { - if (key === "Tab" && event.shiftKey) { + // Providers that opt out of the Build/Plan toggle must not be reachable + // through the shortcut either; fall through to normal Tab handling. + if (key === "Tab" && event.shiftKey && composerProviderControls.showInteractionModeToggle) { toggleInteractionMode(); return true; } diff --git a/apps/web/src/providerModels.test.ts b/apps/web/src/providerModels.test.ts index 9909fb6c48..52fc1b2c00 100644 --- a/apps/web/src/providerModels.test.ts +++ b/apps/web/src/providerModels.test.ts @@ -2,7 +2,9 @@ import { ProviderDriverKind, ProviderInstanceId, type ServerProvider } from "@t3 import { describe, expect, it } from "vite-plus/test"; import { + getProviderInstanceInteractionModeToggle, getProviderInstanceRequiresWorkspace, + getProviderInteractionModeToggle, getProviderRequiresWorkspace, } from "./providerModels"; @@ -10,6 +12,7 @@ function provider(input: { driver: string; instanceId: string; requiresWorkspace?: boolean; + showInteractionModeToggle?: boolean; }): ServerProvider { return { instanceId: ProviderInstanceId.make(input.instanceId), @@ -26,6 +29,9 @@ function provider(input: { ...(input.requiresWorkspace === undefined ? {} : { requiresWorkspace: input.requiresWorkspace }), + ...(input.showInteractionModeToggle === undefined + ? {} + : { showInteractionModeToggle: input.showInteractionModeToggle }), }; } @@ -129,3 +135,114 @@ describe("getProviderInstanceRequiresWorkspace", () => { expect(getProviderInstanceRequiresWorkspace([], hermesInstanceId)).toBe(true); }); }); + +describe("getProviderInteractionModeToggle", () => { + it("treats an absent field as true so existing providers keep the Build/Plan toggle", () => { + expect( + getProviderInteractionModeToggle( + [provider({ driver: "codex", instanceId: "codex" })], + codexKind, + ), + ).toBe(true); + }); + + it("honors an explicit false on the default instance", () => { + expect( + getProviderInteractionModeToggle( + [provider({ driver: "codex", instanceId: "codex", showInteractionModeToggle: false })], + codexKind, + ), + ).toBe(false); + }); + + it("returns true for an unknown driver rather than crashing", () => { + expect( + getProviderInteractionModeToggle( + [provider({ driver: "codex", instanceId: "codex", showInteractionModeToggle: false })], + ProviderDriverKind.make("someForkDriver"), + ), + ).toBe(true); + }); + + it("returns true for an empty providers array", () => { + expect(getProviderInteractionModeToggle([], codexKind)).toBe(true); + }); + + it("ignores non-default instances of the same driver kind", () => { + expect( + getProviderInteractionModeToggle( + [ + provider({ + driver: "codex", + instanceId: "codex_personal", + showInteractionModeToggle: false, + }), + ], + codexKind, + ), + ).toBe(true); + }); +}); + +describe("getProviderInstanceInteractionModeToggle", () => { + const hermesInstanceId = ProviderInstanceId.make("hermes-work-abc123"); + + it("resolves a user-authored Hermes instance that the driver-kind lookup cannot reach", () => { + const providers = [ + provider({ + driver: "hermes", + instanceId: "hermes-work-abc123", + showInteractionModeToggle: false, + }), + ]; + + // The kind-keyed lookup resolves `defaultInstanceIdForDriver("hermes")`, + // which never exists — the absent-means-true fallback wins and the Build + // toggle renders even though the driver opted out. That is the bug. + expect(getProviderInteractionModeToggle(providers, ProviderDriverKind.make("hermes"))).toBe( + true, + ); + // Keyed on the instance the thread is actually bound to, the driver's + // opt-out is honored. + expect(getProviderInstanceInteractionModeToggle(providers, hermesInstanceId)).toBe(false); + }); + + it("treats an absent field as true", () => { + expect( + getProviderInstanceInteractionModeToggle( + [provider({ driver: "codex", instanceId: "codex" })], + ProviderInstanceId.make("codex"), + ), + ).toBe(true); + }); + + it("honors an explicit true", () => { + expect( + getProviderInstanceInteractionModeToggle( + [provider({ driver: "codex", instanceId: "codex", showInteractionModeToggle: true })], + ProviderInstanceId.make("codex"), + ), + ).toBe(true); + }); + + it("returns true for an unknown instance", () => { + expect( + getProviderInstanceInteractionModeToggle( + [provider({ driver: "codex", instanceId: "codex", showInteractionModeToggle: false })], + ProviderInstanceId.make("codex_missing"), + ), + ).toBe(true); + }); + + it("returns true for a null or undefined instance id", () => { + const providers = [ + provider({ driver: "codex", instanceId: "codex", showInteractionModeToggle: false }), + ]; + expect(getProviderInstanceInteractionModeToggle(providers, null)).toBe(true); + expect(getProviderInstanceInteractionModeToggle(providers, undefined)).toBe(true); + }); + + it("returns true for an empty providers array", () => { + expect(getProviderInstanceInteractionModeToggle([], hermesInstanceId)).toBe(true); + }); +}); diff --git a/apps/web/src/providerModels.ts b/apps/web/src/providerModels.ts index 38173d23fd..d106df67c0 100644 --- a/apps/web/src/providerModels.ts +++ b/apps/web/src/providerModels.ts @@ -46,6 +46,21 @@ export function getProviderDisplayName( return snapshot?.displayName?.trim() || formatProviderDriverKindLabel(provider); } +/** + * Whether this driver's default instance offers the Build/Plan interaction-mode + * toggle. + * + * Absent means `true`: every provider that predates the flag is a coding + * provider with a real plan mode. + * + * Driver-kind keyed, so it only ever resolves the *default* instance for the + * kind (`defaultInstanceIdForDriver`). Drivers whose instances are always + * user-authored — Hermes ids look like `hermes-