Skip to content

Commit ef80d2e

Browse files
fix(server): detect the self-contained runtime with node:sea for the ACP bridge
Path equality between execPath and argv[1] is an accident of how Node fixes up argv for a single-executable, not the signal. Ask node:sea directly, leave T3_ACP_MCP_ENTRYPOINT unset in that runtime, and teach the terminal fallback instruction to omit the entrypoint when the variable is missing, so agents running under the packaged binary can still reach acp-mcp-call. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent c723f31 commit ef80d2e

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import {
77
import * as NodeChildProcess from "node:child_process";
88
import * as NodeFS from "node:fs";
99
import * as NodePath from "node:path";
10+
import * as NodeSea from "node:sea";
1011

1112
import * as NodeServices from "@effect/platform-node/NodeServices";
1213
import { assert, describe, it } from "@effect/vitest";
14+
import { vi } from "vite-plus/test";
1315
import {
1416
CheckpointId,
1517
GrokSettings,
@@ -91,6 +93,11 @@ import {
9193

9294
import { makeGrokAdapterV2 } from "./GrokAdapterV2.ts";
9395

96+
vi.mock("node:sea", async (importOriginal) => {
97+
const sea = await importOriginal<typeof import("node:sea")>();
98+
return { ...sea, isSea: vi.fn(sea.isSea) };
99+
});
100+
94101
const DEFAULT_GROK_SETTINGS = Schema.decodeSync(GrokSettings)({});
95102

96103
const serverConfigLayer = ServerConfig.layerTest(process.cwd(), {
@@ -568,8 +575,7 @@ describe("AcpAdapterV2", () => {
568575
const mockAgentPath = yield* path.fromFileUrl(
569576
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
570577
);
571-
const originalEntrypoint = process.argv[1];
572-
process.argv[1] = process.execPath;
578+
vi.mocked(NodeSea.isSea).mockReturnValue(true);
573579

574580
const instanceId = ProviderInstanceId.make("acp-test-self-contained-mcp-bridge");
575581
const threadId = ThreadId.make("thread-acp-self-contained-mcp-bridge");
@@ -585,8 +591,7 @@ describe("AcpAdapterV2", () => {
585591
yield* Effect.addFinalizer(() =>
586592
Effect.sync(() => {
587593
McpProviderSession.clearMcpProviderSession(threadId);
588-
if (originalEntrypoint === undefined) process.argv.splice(1, 1);
589-
else process.argv[1] = originalEntrypoint;
594+
vi.mocked(NodeSea.isSea).mockReset();
590595
}),
591596
);
592597

@@ -626,6 +631,8 @@ describe("AcpAdapterV2", () => {
626631
}
627632
assert.equal(mcpServer.command, process.execPath);
628633
assert.deepEqual(mcpServer.args, ["acp-mcp-bridge"]);
634+
assert.equal(runtimeInput?.processEnvironment?.T3_ACP_MCP_NODE, process.execPath);
635+
assert.equal(runtimeInput?.processEnvironment?.T3_ACP_MCP_ENTRYPOINT, undefined);
629636
}).pipe(Effect.provide(testLayer), Effect.scoped),
630637
);
631638

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @effect-diagnostics nodeBuiltinImport:off
22
import * as NodePath from "node:path";
3+
import * as NodeSea from "node:sea";
34

45
import {
56
type ChatAttachment,
@@ -624,18 +625,23 @@ function acpMcpContext(threadId: ThreadId | null): AcpMcpContext {
624625
// forwards JSON-RPC to T3's authenticated MCP endpoint. The credential
625626
// travels via environment variables, never the command line.
626627
// The agent spawns the bridge from its own working directory, so the server
627-
// entrypoint must be an absolute path.
628-
const serverEntrypoint = process.argv[1] === undefined ? "t3" : NodePath.resolve(process.argv[1]);
629-
const bridgeArgs =
630-
NodePath.resolve(process.execPath) === serverEntrypoint
631-
? ["acp-mcp-bridge"]
632-
: [serverEntrypoint, "acp-mcp-bridge"];
628+
// entrypoint must be an absolute path. The single-executable has no
629+
// entrypoint script: Node repeats the binary at argv[1], and the executable
630+
// dispatches subcommands from argv[2], so it is invoked with none.
631+
const serverEntrypoint = NodeSea.isSea()
632+
? undefined
633+
: process.argv[1] === undefined
634+
? "t3"
635+
: NodePath.resolve(process.argv[1]);
633636
return {
634637
servers: [
635638
{
636639
name: "t3-code",
637640
command: process.execPath,
638-
args: bridgeArgs,
641+
args:
642+
serverEntrypoint === undefined
643+
? ["acp-mcp-bridge"]
644+
: [serverEntrypoint, "acp-mcp-bridge"],
639645
env: [
640646
{ name: "ELECTRON_RUN_AS_NODE", value: "1" },
641647
{ name: "T3_ACP_MCP_ENDPOINT", value: session.endpoint },
@@ -650,7 +656,7 @@ function acpMcpContext(threadId: ThreadId | null): AcpMcpContext {
650656
T3_ACP_MCP_ENDPOINT: session.endpoint,
651657
T3_ACP_MCP_AUTHORIZATION: session.authorizationHeader,
652658
T3_ACP_MCP_NODE: process.execPath,
653-
T3_ACP_MCP_ENTRYPOINT: serverEntrypoint,
659+
...(serverEntrypoint === undefined ? {} : { T3_ACP_MCP_ENTRYPOINT: serverEntrypoint }),
654660
},
655661
};
656662
}

‎apps/server/src/provider/T3OrchestrationInstructions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ For stacked work, set \`baseRef\` to the intended parent branch and \`startFromO
2626
2727
Tool names may include a harness-normalized MCP prefix, such as \`mcp__t3_code__delegate_task\`; the semantics are the same. Some harnesses attach optional MCP servers lazily: if an initial tool-catalog scan does not show T3 tools, do not conclude that cross-provider delegation is unavailable. Make one bounded direct attempt using the known T3 tool name on the next tool step. In Codex code mode, for example, call \`tools.mcp__t3_code__orchestrator_capabilities({})\` before reporting that the capability is absent. Keep polling/wait loops bounded, do not duplicate active work, and use stable \`clientRequestId\` values when retrying tools that accept them.
2828
29-
ACP fallback: some ACP agents accept the injected MCP server but fail to expose its tools. When the T3 tools are absent and \`T3_ACP_MCP_NODE\` plus \`T3_ACP_MCP_ENTRYPOINT\` are present, call the same tools through the terminal: \`ELECTRON_RUN_AS_NODE=1 "$T3_ACP_MCP_NODE" "$T3_ACP_MCP_ENTRYPOINT" acp-mcp-call orchestrator_capabilities '{}'\`. Delegate with \`acp-mcp-call delegate_task '{"task":"...","target":{"providerInstanceId":"...","model":"..."},"mode":"async","clientRequestId":"..."}'\`. This is the supported T3 transport fallback, not an ordinary shell-based substitute for delegation.
29+
ACP fallback: some ACP agents accept the injected MCP server but fail to expose its tools. When the T3 tools are absent and \`T3_ACP_MCP_NODE\` is present, call the same tools through the terminal: \`ELECTRON_RUN_AS_NODE=1 "$T3_ACP_MCP_NODE" \${T3_ACP_MCP_ENTRYPOINT:+"$T3_ACP_MCP_ENTRYPOINT"} acp-mcp-call orchestrator_capabilities '{}'\` (\`T3_ACP_MCP_ENTRYPOINT\` is unset when T3 runs as a standalone executable). Delegate with \`acp-mcp-call delegate_task '{"task":"...","target":{"providerInstanceId":"...","model":"..."},"mode":"async","clientRequestId":"..."}'\`. This is the supported T3 transport fallback, not an ordinary shell-based substitute for delegation.
3030
`;
3131

3232
export const T3_CODE_BROWSER_TOOL_INSTRUCTIONS = `

0 commit comments

Comments
 (0)