diff --git a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts index 1931b1a87b0d2..7de5357aa76e8 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts @@ -20,6 +20,7 @@ import * as Fiber from "effect/Fiber"; import * as DateTime from "effect/DateTime"; import * as Queue from "effect/Queue"; import * as Stream from "effect/Stream"; +import * as TestClock from "effect/testing/TestClock"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; @@ -209,7 +210,7 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* ( entries: ReadonlyArray, replayGate?: ProviderReplayGate, continuationEnabled = true, - agentId = "claude-acp", + agentId: string | Record = "claude-acp", ) { const fileSystem = yield* FileSystem.FileSystem; const path = yield* Path.Path; @@ -251,7 +252,9 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* ( const adapterOptions = { selfInvocation: yield* resolveSelfInvocation(), instanceId, - settings: yield* decodeAcpRegistryAdapterSettings({ agentId }), + settings: yield* decodeAcpRegistryAdapterSettings( + typeof agentId === "string" ? { agentId } : agentId, + ), environment: {}, ...(continuationEnabled ? { continuationRequests } : {}), makeRuntime: (runtimeInput: Parameters[0]) => { @@ -287,7 +290,7 @@ const openClaudeReplaySession = Effect.fn("openClaudeReplaySession")(function* ( runtimePolicy, }); yield* Effect.addFinalizer(() => Effect.sync(() => replayGate?.releaseAll())); - if (continuationEnabled) { + if (continuationEnabled && agentId === "claude-acp") { assert.isDefined( runtime.hasPendingBackgroundWork, "Claude ACP v2 must report background work after foreground idle", @@ -1997,6 +2000,84 @@ describe("AcpRegistryAdapterV2", () => { }).pipe(Effect.provide(layerTest)), ); + // regression: #38599 Hermes replies on its own when a background process it started exits + it.effect("does not drop Hermes' reply after a background process finishes", () => + Effect.gen(function* () { + const gate = makeProviderReplayGate(["process-exit"]); + const sessionId = "hermes-session"; + const update = (sessionUpdate: Record) => + claudeFrames.update(sessionId, sessionUpdate); + const session = yield* openClaudeReplaySession( + [ + { + type: "expect_outbound", + frame: { kind: "request", method: "initialize", params: "" }, + }, + { + type: "emit_inbound", + frame: { + kind: "response", + method: "initialize", + result: { + protocolVersion: 1, + agentInfo: { name: "hermes-agent", version: "0.23.1" }, + agentCapabilities: { loadSession: true }, + authMethods: [], + }, + }, + }, + { + type: "expect_outbound", + frame: { kind: "request", method: "session/new", params: "" }, + }, + { + type: "emit_inbound", + frame: { kind: "response", method: "session/new", result: { sessionId } }, + }, + { + type: "expect_outbound", + frame: { kind: "request", method: "session/prompt", params: "" }, + }, + update({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "Started it in the background." }, + }), + { + type: "emit_inbound", + frame: { + kind: "response", + method: "session/prompt", + result: { stopReason: "end_turn" }, + }, + }, + { + ...update({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "The background command printed DONE" }, + }), + label: "process-exit", + }, + update({ sessionUpdate: "session_info_update", title: "after completion reply" }), + ], + gate, + true, + { source: "local", commandPath: "hermes", commandArgs: ["acp"] }, + ); + yield* session.runtime.startTurn(session.turnInput(1)); + const foreground = yield* session.until((event) => event.type === "turn.terminal"); + assert.include(JSON.stringify(foreground.at(-1)), '"status":"completed"'); + gate.release("process-exit"); + yield* Queue.take(session.offered); + yield* session.throughMarker("after completion reply"); + yield* session.offers[0]!.dispatchIfCurrent!(Effect.void); + yield* session.runtime.startTurn(session.turnInput(2, { continuation: true })); + yield* TestClock.adjust("10 seconds"); + const continuation = yield* session.until((event) => event.type === "turn.terminal"); + assert.include(JSON.stringify(continuation), "printed DONE"); + assert.include(JSON.stringify(continuation.at(-1)), '"status":"completed"'); + }).pipe(Effect.provide(layerTest)), + ); + // Copilot flattens MCP titles and reports kind "read" for MCP calls and glob ("other" for rg); // its native tool.execution_start event carries the real identity. it.effect.each(["glob", "rg"])("keeps Copilot's MCP and %s identity", (toolName) => diff --git a/packages/provider-acp-registry/src/server/adapter.ts b/packages/provider-acp-registry/src/server/adapter.ts index 105778db7e876..837d296773933 100644 --- a/packages/provider-acp-registry/src/server/adapter.ts +++ b/packages/provider-acp-registry/src/server/adapter.ts @@ -211,6 +211,10 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu registryAgentId === "kimi-code" || (options.settings.source === "local" && /^kimi(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? "")); + // Hermes Agent is not in the public registry; local installs run `hermes acp`. + const isHermes = + options.settings.source === "local" && + /^hermes(\.exe|\.cmd)?$/i.test(options.settings.commandPath.split(/[\\/]/).pop() ?? ""); const isClaude = registryAgentId === "claude-acp" || (options.settings.source === "local" && @@ -269,6 +273,11 @@ export const makeAcpRegistryAdapterV2 = Effect.fn("makeAcpRegistryAdapterV2")(fu extractSubagentSessionEvent: extractClaudeSubagentSessionEvent, } : {}), + // Hermes replies on the root session when a background process it started exits; no + // prompt response follows, so the continuation ends on the deferred-finalize debounce. + ...(isHermes + ? { enablePostSettleContinuation: true, deferFinalizeForBackgroundWork: true } + : {}), ...(isDevin ? { clientCapabilitiesMeta: {