fix: Hermes turns ended at the first tool call
A Hermes turn stopped as soon as the agent used a tool. The transcript kept
the tool-progress chrome ("📚 Reading skill hermes-agent 🔍 Searching the web
for …") as the assistant's entire answer, and the gateway logged
`Send failed: no active T3 turn — trying plain-text fallback` for everything
Hermes produced afterwards. The real answer was never delivered.
`BasePlatformAdapter.format_tool_event` renders each tool call as an emoji
progress line and the gateway delivers it through the ordinary reply path.
The gateway marks user-visible replies `notify=True`, and this plugin's
`send()` treats `notify` as "this turn is finished" — it calls
`_complete_turn`. So the first tool call closed the turn mid-flight.
Overriding `format_tool_event` to return `None` is the documented way for an
adapter that cannot render tool chrome to drop the event
(`gateway/stream_dispatch.py:108` — "None == adapter chose to eat this
event"). T3 loses nothing: it already renders tool calls as typed
`item.started` / `item.completed` activity from the tool hooks, which is a
richer surface than the text line it duplicated.
Also fixes duplicate React keys in the sidebar. `visibleSidebarSections`
concatenated the Projects and Agents lists, but grouping can collapse an agent
row onto the same logical `projectKey` as a workspace row — and threads are
looked up per section by that key, so the same threads were emitted twice.
That surfaced as "two children with the same key" from the thread prewarmer
and double-counted threads in jump/traversal ordering. Deduped at the section
list, and again in `getSidebarThreadIdsToPrewarm` since each id there becomes a
React key and the invariant belongs to the thing that depends on it.
COMPATIBILITY.md records both new upstream surfaces, verified present at the
audited commit 62e07223, and the exact shape this regresses into if a future
Hermes stops routing tool chrome through `format_tool_event`.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
26e3c308f4
commit
6a76a011b6
6 files changed
+117
-5
No files matched your search
@@ -326,6 +326,14 @@ describe("getSidebarThreadIdsToPrewarm", () => {
|
||||
it("returns no thread ids when the limit is zero", () => {
|
||||
expect(getSidebarThreadIdsToPrewarm(["t1", "t2"], 0)).toEqual([]);
|
||||
});
|
||||
|
||||
it("drops repeats so every prewarmed id can be a unique React key", () => {
|
||||
expect(getSidebarThreadIdsToPrewarm(["t1", "t2", "t1", "t3"], 10)).toEqual(["t1", "t2", "t3"]);
|
||||
});
|
||||
|
||||
it("dedupes before applying the limit so a repeat cannot displace a distinct thread", () => {
|
||||
expect(getSidebarThreadIdsToPrewarm(["t1", "t1", "t2"], 2)).toEqual(["t1", "t2"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldClearThreadSelectionOnMouseDown", () => {
|
||||
|
||||
@@ -296,11 +296,30 @@ export function getVisibleSidebarThreadIds<TThreadId>(
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The prewarm slice, de-duplicated.
|
||||
*
|
||||
* Each id becomes a React `key` on a prewarmer element, so a repeat is a
|
||||
* render-time error, not a cosmetic one. Callers should not emit duplicates —
|
||||
* but a section list that collapses two rows onto one logical project key
|
||||
* silently produces them, so this is deduped here as well: the invariant
|
||||
* belongs to the thing that depends on it.
|
||||
*
|
||||
* Dedupe runs before the limit so a duplicate cannot displace a distinct
|
||||
* thread that would otherwise have been prewarmed.
|
||||
*/
|
||||
export function getSidebarThreadIdsToPrewarm<TThreadId>(
|
||||
visibleThreadIds: readonly TThreadId[],
|
||||
limit = SIDEBAR_THREAD_PREWARM_LIMIT,
|
||||
): TThreadId[] {
|
||||
return visibleThreadIds.slice(0, Math.max(0, limit));
|
||||
const unique: TThreadId[] = [];
|
||||
const seen = new Set<TThreadId>();
|
||||
for (const threadId of visibleThreadIds) {
|
||||
if (seen.has(threadId)) continue;
|
||||
seen.add(threadId);
|
||||
unique.push(threadId);
|
||||
}
|
||||
return unique.slice(0, Math.max(0, limit));
|
||||
}
|
||||
|
||||
export function resolveAdjacentThreadId<T>(input: {
|
||||
|
||||
@@ -3555,10 +3555,22 @@ export default function Sidebar() {
|
||||
// Agent rows render after the Projects group, so their threads continue the
|
||||
// same visible ordering: thread-jump shortcuts and prev/next traversal reach
|
||||
// an agent's threads exactly as they reach a project's.
|
||||
const visibleSidebarSections = useMemo(
|
||||
() => [...sortedProjects, ...agentEntries.map((agent) => agent.project)],
|
||||
[agentEntries, sortedProjects],
|
||||
);
|
||||
const visibleSidebarSections = useMemo(() => {
|
||||
// De-duplicate by `projectKey`. Threads are looked up per section via
|
||||
// `threadsByProjectKey`, so a key appearing twice yields the same threads
|
||||
// twice — which surfaces as duplicate React keys in the thread prewarmer
|
||||
// and double-counts every thread in jump/traversal ordering. Grouping can
|
||||
// legitimately collapse an agent row onto the same logical key as a
|
||||
// workspace row, so this cannot be assumed away.
|
||||
const seen = new Set<string>();
|
||||
const sections: SidebarProjectSnapshot[] = [];
|
||||
for (const project of [...sortedProjects, ...agentEntries.map((agent) => agent.project)]) {
|
||||
if (seen.has(project.projectKey)) continue;
|
||||
seen.add(project.projectKey);
|
||||
sections.push(project);
|
||||
}
|
||||
return sections;
|
||||
}, [agentEntries, sortedProjects]);
|
||||
const visibleSidebarThreadKeys = useMemo(
|
||||
() =>
|
||||
visibleSidebarSections.flatMap((project) => {
|
||||
|
||||
@@ -15,6 +15,8 @@ Audited surfaces, all present at that commit:
|
||||
| `resolve_gateway_approval` | `tools/approval.py:2073` |
|
||||
| `resolve_gateway_clarify` | `tools/clarify_gateway.py:160` |
|
||||
| `register_platform` (`**entry_kwargs`) | `hermes_cli/plugins.py:931` |
|
||||
| `format_tool_event` (override hook) | `gateway/platforms/base.py:2740` |
|
||||
| Tool-chrome dispatch (`None` == eat) | `gateway/stream_dispatch.py:108` |
|
||||
| `/steer` active-run handler | `gateway/run.py:11280` |
|
||||
| Home-channel notice text | `gateway/run.py:13780` |
|
||||
| Active-command inline dispatch | `gateway/platforms/base.py:4926` |
|
||||
@@ -151,3 +153,28 @@ older server/plugin pairs are rejected during the handshake.
|
||||
`protocol.error` path.
|
||||
- Attachments are not accepted. They are the first planned post-stability
|
||||
feature; the capability is reserved and fixed to `false` in protocol v2.
|
||||
|
||||
## Tool-progress chrome is dropped, not rendered
|
||||
|
||||
`BasePlatformAdapter.format_tool_event` renders each tool call as an emoji
|
||||
progress line ("📚 skill_view: …") and the gateway delivers it through the
|
||||
ordinary reply path. The plugin overrides it to return `None`, which
|
||||
`gateway/stream_dispatch.py:108` documents as "adapter chose to eat this event".
|
||||
|
||||
Two reasons, the second severe:
|
||||
|
||||
1. T3 already renders tool calls as typed `item.started` / `item.completed`
|
||||
activity from the `pre_tool_call` / `post_tool_call` hooks. The text line is
|
||||
a strictly poorer duplicate of a surface T3 already has.
|
||||
2. The gateway marks user-visible replies `notify=True`
|
||||
(`_mark_notify_metadata`, `gateway/platforms/base.py:89`), and this plugin's
|
||||
`send()` treats `notify` as "this turn is finished" — it calls
|
||||
`_complete_turn`. So the **first tool call ended the T3 turn while Hermes was
|
||||
still working**: the transcript kept the progress chrome as the assistant's
|
||||
entire answer, and every subsequent send failed with "no active T3 turn"
|
||||
(visible in the gateway log as `Send failed: no active T3 turn — trying
|
||||
plain-text fallback`). The real answer never arrived.
|
||||
|
||||
If a future Hermes stops routing tool chrome through `format_tool_event`, this
|
||||
regresses silently and in exactly that shape: turns that end early, at the first
|
||||
tool call, with progress text as the answer.
|
||||
@@ -249,6 +249,31 @@ class T3PlatformAdapter(BasePlatformAdapter):
|
||||
async def get_chat_info(self, chat_id: str) -> dict[str, Any]:
|
||||
return {"name": f"T3 thread {chat_id}", "type": "dm"}
|
||||
|
||||
def format_tool_event(
|
||||
self, event: Any, *, mode: str = "all", preview_max_len: int = 40
|
||||
) -> str | None:
|
||||
"""Drop Hermes' textual tool-progress chrome.
|
||||
|
||||
The base implementation renders each tool call as an emoji progress
|
||||
line ("📚 skill_view: …") and delivers it through the ordinary reply
|
||||
path. Two things go wrong when that reaches T3:
|
||||
|
||||
1. T3 already renders tool calls as typed `item.started` /
|
||||
`item.completed` activity from the `pre_tool_call` / `post_tool_call`
|
||||
hooks, so the text is a duplicate of a richer surface.
|
||||
2. Worse, it is delivered as a *user-visible reply*, and the gateway
|
||||
marks user-visible replies `notify=True`. `send()` treats `notify`
|
||||
as "this turn is finished" and calls `_complete_turn`, so the first
|
||||
tool call ended the T3 turn while Hermes was still working. Every
|
||||
later send failed with "no active T3 turn" and the answer was lost.
|
||||
|
||||
Returning None is the documented way for an adapter that cannot render
|
||||
this chrome to drop the event, and it is what the base class's own
|
||||
docstring prescribes.
|
||||
"""
|
||||
del event, mode, preview_max_len
|
||||
return None
|
||||
|
||||
async def send_typing(
|
||||
self, chat_id: str, metadata: dict[str, Any] | None = None
|
||||
) -> None:
|
||||
|
||||
@@ -1178,6 +1178,27 @@ class AdapterTests(unittest.IsolatedAsyncioTestCase):
|
||||
[message["type"] for message in self.connection.messages],
|
||||
)
|
||||
|
||||
def test_tool_progress_chrome_is_dropped(self):
|
||||
"""Tool chrome must never reach T3 as a user-visible reply.
|
||||
|
||||
The gateway marks user-visible replies `notify=True`, and `send()`
|
||||
treats `notify` as "turn finished". Rendering tool chrome therefore
|
||||
ended the T3 turn on the first tool call, and everything Hermes did
|
||||
afterwards failed with "no active T3 turn". T3 already renders tool
|
||||
calls as typed activity items, so the text is redundant regardless.
|
||||
"""
|
||||
|
||||
class _ToolCallChunk:
|
||||
tool_name = "skill_view"
|
||||
preview = "hermes-agent"
|
||||
args = {"name": "hermes-agent"}
|
||||
|
||||
for mode in ("all", "new", "verbose"):
|
||||
with self.subTest(mode=mode):
|
||||
self.assertIsNone(
|
||||
self.adapter.format_tool_event(_ToolCallChunk(), mode=mode)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user