@devries-cameron20 / t3code Mirror · read-only / commits / 961233137d
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

fix(server): Hermes Agent's reply after a background process finishes reaches the thread (#38615)

Julius Marminge committed Nov 18, 2026 at 06:00 UTC 961233137d1b64b90e36403d9e02aa7b21909386
2 files changed +93 -3
apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
+84 -3
@@ -20,6 +20,7 @@ import * as Fiber from "effect/Fiber";
20 import * as DateTime from "effect/DateTime";
21 import * as Queue from "effect/Queue";
22 import * as Stream from "effect/Stream";
23 +import * as TestClock from "effect/testing/TestClock";
24 import * as Effect from "effect/Effect";
25 import * as FileSystem from "effect/FileSystem";
26 import * as Layer from "effect/Layer";
@@ -209,7 +210,7 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* (
210 entries: ReadonlyArray<unknown>,
211 replayGate?: ProviderReplayGate,
212 continuationEnabled = true,
212 - agentId = "claude-acp",
213 + agentId: string | Record<string, unknown> = "claude-acp",
214 ) {
215 const fileSystem = yield* FileSystem.FileSystem;
216 const path = yield* Path.Path;
@@ -251,7 +252,9 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* (
252 const adapterOptions = {
253 selfInvocation: yield* resolveSelfInvocation(),
254 instanceId,
254 - settings: yield* decodeAcpRegistryAdapterSettings({ agentId }),
255 + settings: yield* decodeAcpRegistryAdapterSettings(
256 + typeof agentId === "string" ? { agentId } : agentId,
257 + ),
258 environment: {},
259 ...(continuationEnabled ? { continuationRequests } : {}),
260 makeRuntime: (runtimeInput: Parameters<typeof replayRuntime>[0]) => {
@@ -287,7 +290,7 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* (
290 runtimePolicy,
291 });
292 yield* Effect.addFinalizer(() => Effect.sync(() => replayGate?.releaseAll()));
290 - if (continuationEnabled) {
293 + if (continuationEnabled && agentId === "claude-acp") {
294 assert.isDefined(
295 runtime.hasPendingBackgroundWork,
296 "Claude ACP v2 must report background work after foreground idle",
@@ -1997,6 +2000,84 @@ describe("AcpRegistryAdapterV2", () => {
2000 }).pipe(Effect.provide(layerTest)),
2001 );
2002
2003 + // regression: #38599 Hermes replies on its own when a background process it started exits
2004 + it.effect("does not drop Hermes' reply after a background process finishes", () =>
2005 + Effect.gen(function* () {
2006 + const gate = makeProviderReplayGate(["process-exit"]);
2007 + const sessionId = "hermes-session";
2008 + const update = (sessionUpdate: Record<string, unknown>) =>
2009 + claudeFrames.update(sessionId, sessionUpdate);
2010 + const session = yield* openClaudeReplaySession(
2011 + [
2012 + {
2013 + type: "expect_outbound",
2014 + frame: { kind: "request", method: "initialize", params: "<any>" },
2015 + },
2016 + {
2017 + type: "emit_inbound",
2018 + frame: {
2019 + kind: "response",
2020 + method: "initialize",
2021 + result: {
2022 + protocolVersion: 1,
2023 + agentInfo: { name: "hermes-agent", version: "0.23.1" },
2024 + agentCapabilities: { loadSession: true },
2025 + authMethods: [],
2026 + },
2027 + },
2028 + },
2029 + {
2030 + type: "expect_outbound",
2031 + frame: { kind: "request", method: "session/new", params: "<any>" },
2032 + },
2033 + {
2034 + type: "emit_inbound",
2035 + frame: { kind: "response", method: "session/new", result: { sessionId } },
2036 + },
2037 + {
2038 + type: "expect_outbound",
2039 + frame: { kind: "request", method: "session/prompt", params: "<any>" },
2040 + },
2041 + update({
2042 + sessionUpdate: "agent_message_chunk",
2043 + content: { type: "text", text: "Started it in the background." },
2044 + }),
2045 + {
2046 + type: "emit_inbound",
2047 + frame: {
2048 + kind: "response",
2049 + method: "session/prompt",
2050 + result: { stopReason: "end_turn" },
2051 + },
2052 + },
2053 + {
2054 + ...update({
2055 + sessionUpdate: "agent_message_chunk",
2056 + content: { type: "text", text: "The background command printed DONE" },
2057 + }),
2058 + label: "process-exit",
2059 + },
2060 + update({ sessionUpdate: "session_info_update", title: "after completion reply" }),
2061 + ],
2062 + gate,
2063 + true,
2064 + { source: "local", commandPath: "hermes", commandArgs: ["acp"] },
2065 + );
2066 + yield* session.runtime.startTurn(session.turnInput(1));
2067 + const foreground = yield* session.until((event) => event.type === "turn.terminal");
2068 + assert.include(JSON.stringify(foreground.at(-1)), '"status":"completed"');
2069 + gate.release("process-exit");
2070 + yield* Queue.take(session.offered);
2071 + yield* session.throughMarker("after completion reply");
2072 + yield* session.offers[0]!.dispatchIfCurrent!(Effect.void);
2073 + yield* session.runtime.startTurn(session.turnInput(2, { continuation: true }));
2074 + yield* TestClock.adjust("10 seconds");
2075 + const continuation = yield* session.until((event) => event.type === "turn.terminal");
2076 + assert.include(JSON.stringify(continuation), "printed DONE");
2077 + assert.include(JSON.stringify(continuation.at(-1)), '"status":"completed"');
2078 + }).pipe(Effect.provide(layerTest)),
2079 + );
2080 +
2081 // Copilot flattens MCP titles and reports kind "read" for MCP calls and glob ("other" for rg);
2082 // its native tool.execution_start event carries the real identity.
2083 it.effect.each(["glob", "rg"])("keeps Copilot's MCP and %s identity", (toolName) =>
packages/provider-acp-registry/src/server/adapter.ts
+9
@@ -211,6 +211,10 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
211 registryAgentId === "kimi-code" ||
212 (options.settings.source === "local" &&
213 /^kimi(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? ""));
214 + // Hermes Agent is not in the public registry; local installs run `hermes acp`.
215 + const isHermes =
216 + options.settings.source === "local" &&
217 + /^hermes(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? "");
218 const isClaude =
219 registryAgentId === "claude-acp" ||
220 (options.settings.source === "local" &&
@@ -269,6 +273,11 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu
273 extractSubagentSessionEvent: extractClaudeSubagentSessionEvent,
274 }
275 : {}),
276 + // Hermes replies on the root session when a background process it started exits; no
277 + // prompt response follows, so the continuation ends on the deferred-finalize debounce.
278 + ...(isHermes
279 + ? { enablePostSettleContinuation: true, deferFinalizeForBackgroundWork: true }
280 + : {}),
281 ...(isDevin
282 ? {
283 clientCapabilitiesMeta: {