Skip to content

Commit 9c3a1b9

Browse files
StiensWoutclaude
andcommitted
fix(acp): sign-in failures show the agent's reason
ACP Registry sign-in replaced the agent's JSON-RPC error with a generic "The ACP agent could not complete sign-in." For agents that sign in themselves, such as Mistral Vibe's browser-auth, that error is the only explanation of what went wrong. Append the agent's own error message (bounded, single line) to the sign-in failure detail when the error came back from the agent over the wire. Local and transport failures keep their existing text. Refs #15118 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5a4e998 commit 9c3a1b9

4 files changed

Lines changed: 146 additions & 1 deletion

File tree

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ const advertisedAuthMethodId = process.env.T3_ACP_AUTH_METHOD_ID?.trim();
110110
const initializeAuthMethodId =
111111
advertisedAuthMethodId ?? (supportsSessionLifecycle ? "test" : undefined);
112112
const requiresAuthentication = process.env.T3_ACP_REQUIRE_AUTH === "1";
113+
// Agents that sign in themselves (method type "agent") report a failed login as
114+
// a JSON-RPC error on `authenticate`, as Mistral Vibe does when its browser
115+
// sign-in status poll fails.
116+
const authenticateErrorMessage = process.env.T3_ACP_AUTHENTICATE_ERROR_MESSAGE;
113117
const commandAdvertisementDelayMs = Number(
114118
process.env.T3_ACP_COMMAND_ADVERTISEMENT_DELAY_MS ?? "-1",
115119
);
@@ -549,6 +553,9 @@ const program = Effect.gen(function* () {
549553
`Unknown mock authentication method: ${request.methodId}`,
550554
);
551555
}
556+
if (authenticateErrorMessage) {
557+
return yield* AcpError.AcpRequestError.internalError(authenticateErrorMessage);
558+
}
552559
authenticated = true;
553560
return {};
554561
}),
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// @effect-diagnostics nodeBuiltinImport:off
2+
import * as NodePath from "node:path";
3+
import * as NodeURL from "node:url";
4+
5+
import * as NodeServices from "@effect/platform-node/NodeServices";
6+
import { ProviderInstanceId, type ProviderAuthState } from "@t3tools/contracts";
7+
import { AcpRegistrySettings } from "@t3tools/provider-acp-registry/settings";
8+
import { makeAcpRegistryAuth } from "@t3tools/provider-acp-registry/testing";
9+
import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";
10+
import { describe, expect, it } from "@effect/vitest";
11+
import * as Effect from "effect/Effect";
12+
import * as Option from "effect/Option";
13+
import * as Schema from "effect/Schema";
14+
import * as Stream from "effect/Stream";
15+
16+
const instanceId = ProviderInstanceId.make("acpRegistry_mock");
17+
const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
18+
const mockAgentPath = NodePath.join(__dirname, "../../scripts/acp-mock-agent.ts");
19+
const decodeSettings = Schema.decodeSync(AcpRegistrySettings);
20+
21+
/** Signs in to the mock ACP agent over its real stdio wire, like the provider settings row. */
22+
const signIn = (agentEnvironment: Record<string, string>) =>
23+
Effect.gen(function* () {
24+
const changed: Array<boolean> = [];
25+
const controller = yield* makeAcpRegistryAuth({
26+
instanceId,
27+
settings: decodeSettings({ agentId: "mock-agent" }),
28+
cwd: process.cwd(),
29+
environment: process.env,
30+
onChanged: (authenticated) =>
31+
Effect.sync(() => {
32+
changed.push(authenticated);
33+
}),
34+
}).pipe(
35+
Effect.provideService(
36+
AcpRegistrySupport.AcpRegistryCatalog,
37+
AcpRegistrySupport.AcpRegistryCatalog.of({
38+
search: () => Effect.die("unused search"),
39+
prepare: () => Effect.die("unused prepare"),
40+
uninstallManagedBinary: () => Effect.die("unused uninstall"),
41+
inspect: () =>
42+
Effect.succeed({
43+
status: "ready",
44+
agentId: "mock-agent",
45+
version: "1.0.0",
46+
distribution: "npx",
47+
}),
48+
resolve: () =>
49+
Effect.succeed({
50+
agent: {
51+
id: "mock-agent",
52+
name: "Mock Agent",
53+
version: "1.0.0",
54+
description: "ACP sign-in test agent",
55+
distribution: { npx: { package: "[email protected]" } },
56+
},
57+
distribution: "npx" as const,
58+
spawn: {
59+
command: "node",
60+
args: [mockAgentPath],
61+
env: {
62+
...process.env,
63+
T3_ACP_AUTH_METHOD_ID: "mock-login",
64+
T3_ACP_REQUIRE_AUTH: "1",
65+
...agentEnvironment,
66+
},
67+
},
68+
}),
69+
}),
70+
),
71+
);
72+
const settled = (phase: ProviderAuthState["phase"]) =>
73+
controller.subscribe("owner").pipe(
74+
Stream.filter((state) => state.phase === phase || state.phase === "failed"),
75+
Stream.runHead,
76+
Effect.map(Option.getOrThrow),
77+
);
78+
yield* controller.subscribe("owner").pipe(
79+
Stream.filter((state) => (state.methods?.length ?? 0) > 0),
80+
Stream.runHead,
81+
);
82+
yield* controller.start("owner", Effect.void, "mock-login");
83+
return { changed, settled };
84+
});
85+
86+
describe("ACP Registry sign-in", () => {
87+
it.effect("signs in through an agent-handled method and verifies a session", () =>
88+
Effect.gen(function* () {
89+
const { changed, settled } = yield* signIn({});
90+
expect(yield* settled("succeeded")).toMatchObject({
91+
phase: "succeeded",
92+
message: "Sign-in complete.",
93+
});
94+
expect(changed).toEqual([true]);
95+
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
96+
);
97+
98+
it.effect("shows the agent's reason when its own sign-in fails", () =>
99+
Effect.gen(function* () {
100+
const { changed, settled } = yield* signIn({
101+
T3_ACP_AUTHENTICATE_ERROR_MESSAGE: "Browser sign-in status could not be retrieved.",
102+
});
103+
expect(yield* settled("succeeded")).toMatchObject({
104+
phase: "failed",
105+
message:
106+
"The ACP agent could not complete sign-in: Browser sign-in status could not be retrieved.",
107+
});
108+
expect(changed).toEqual([]);
109+
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
110+
);
111+
});

‎packages/provider-acp-registry/src/server/auth.ts‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import * as Exit from "effect/Exit";
1111
import * as Layer from "effect/Layer";
1212
import * as Option from "effect/Option";
1313
import * as Queue from "effect/Queue";
14+
import * as Schema from "effect/Schema";
1415
import * as Scope from "effect/Scope";
1516
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
1617
import type * as AcpSchema from "effect-acp/compat";
18+
import * as EffectAcpErrors from "effect-acp/errors";
1719

1820
import * as PtyAdapter from "@t3tools/shared/PtyAdapter";
1921
import * as ProviderAuthFlow from "@t3tools/provider-core/server/providerAuthFlow";
@@ -27,6 +29,25 @@ type Runtime = Pick<
2729
"initialize" | "authenticate" | "start" | "handleElicitation" | "logout"
2830
>;
2931

32+
const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);
33+
const MAX_AGENT_REASON_LENGTH = 300;
34+
35+
/**
36+
* Appends the agent's own JSON-RPC error message to a sign-in failure. Agents
37+
* that sign in themselves (method type "agent") explain failures only there,
38+
* for example Mistral Vibe's "Browser sign-in status could not be retrieved."
39+
*/
40+
function withAgentReason(detail: string, cause: unknown) {
41+
if (!isAcpRequestError(cause) || cause.operation !== "receive-response") return detail;
42+
const reason = cause.errorMessage.replace(/\s+/gu, " ").trim();
43+
if (!reason) return detail;
44+
const bounded =
45+
reason.length > MAX_AGENT_REASON_LENGTH
46+
? `${reason.slice(0, MAX_AGENT_REASON_LENGTH - 1)}…`
47+
: reason;
48+
return `${detail.replace(/\.$/u, "")}: ${bounded}`;
49+
}
50+
3051
/** ACP credentials stay in the agent's own store, using the same launch environment as chat. */
3152
export const makeAcpRegistryAuth = Effect.fn("makeAcpRegistryAuth")(function* (options: {
3253
readonly instanceId: ProviderInstanceId;
@@ -48,7 +69,12 @@ export const makeAcpRegistryAuth = Effect.fn("makeAcpRegistryAuth")(function* (o
4869
const agentKey =
4970
options.settings.source === "local" ? `local:${options.instanceId}` : options.settings.agentId;
5071
const failure = (operation: string, detail: string, cause?: unknown) =>
51-
new ProviderSetupError({ instanceId: options.instanceId, operation, detail, cause });
72+
new ProviderSetupError({
73+
instanceId: options.instanceId,
74+
operation,
75+
detail: withAgentReason(detail, cause),
76+
cause,
77+
});
5278
const resolve = catalog
5379
.resolve(options.settings, options.cwd, options.environment)
5480
.pipe(

‎packages/provider-acp-registry/src/testing.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export {
1616
normalizeDevinSessionUpdate,
1717
normalizeDevinToolCall,
1818
} from "./server/devinAcp.ts";
19+
export { makeAcpRegistryAuth } from "./server/auth.ts";
1920
export { extractCopilotSubagentUpdate, makeCopilotSubagentRouting } from "./server/copilotAcp.ts";
2021
export {
2122
acpRegistryProbeFailure,

0 commit comments

Comments
 (0)