Skip to content

Commit 7762b8b

Browse files
StiensWoutclaude
andcommitted
fix(acp): sign-in failures use fixed text for the agent's reason
The failed sign-in state no longer copies the agent's error message. A received "Browser sign-in status could not be retrieved." maps to fixed canonical text; any other agent text stays only in cause. The test resolves the mock agent through Effect Path, so it no longer needs the nodeBuiltinImport suppression. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 9c3a1b9 commit 7762b8b

2 files changed

Lines changed: 35 additions & 27 deletions

File tree

‎apps/server/src/provider/AcpRegistryAuth.test.ts‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
// @effect-diagnostics nodeBuiltinImport:off
2-
import * as NodePath from "node:path";
3-
import * as NodeURL from "node:url";
4-
51
import * as NodeServices from "@effect/platform-node/NodeServices";
62
import { ProviderInstanceId, type ProviderAuthState } from "@t3tools/contracts";
73
import { AcpRegistrySettings } from "@t3tools/provider-acp-registry/settings";
@@ -10,17 +6,20 @@ import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRe
106
import { describe, expect, it } from "@effect/vitest";
117
import * as Effect from "effect/Effect";
128
import * as Option from "effect/Option";
9+
import * as Path from "effect/Path";
1310
import * as Schema from "effect/Schema";
1411
import * as Stream from "effect/Stream";
1512

1613
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");
1914
const decodeSettings = Schema.decodeSync(AcpRegistrySettings);
2015

2116
/** Signs in to the mock ACP agent over its real stdio wire, like the provider settings row. */
2217
const signIn = (agentEnvironment: Record<string, string>) =>
2318
Effect.gen(function* () {
19+
const path = yield* Path.Path;
20+
const mockAgentPath = yield* path.fromFileUrl(
21+
new URL("../../scripts/acp-mock-agent.ts", import.meta.url),
22+
);
2423
const changed: Array<boolean> = [];
2524
const controller = yield* makeAcpRegistryAuth({
2625
instanceId,
@@ -95,17 +94,28 @@ describe("ACP Registry sign-in", () => {
9594
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
9695
);
9796

98-
it.effect("shows the agent's reason when its own sign-in fails", () =>
97+
it.effect("names a recognized agent sign-in failure without copying the agent's text", () =>
9998
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:
99+
const secret = "https://console.example.test/callback?code=sk-secret-123";
100+
for (const [agentMessage, message] of [
101+
[
102+
"Browser sign-in status could not be retrieved.",
106103
"The ACP agent could not complete sign-in: Browser sign-in status could not be retrieved.",
107-
});
108-
expect(changed).toEqual([]);
104+
],
105+
[
106+
`Browser sign-in status could not be retrieved. Last poll: ${secret}`,
107+
"The ACP agent could not complete sign-in: Browser sign-in status could not be retrieved.",
108+
],
109+
[`Sign-in failed at ${secret}`, "The ACP agent could not complete sign-in."],
110+
] as const) {
111+
const { changed, settled } = yield* signIn({
112+
T3_ACP_AUTHENTICATE_ERROR_MESSAGE: agentMessage,
113+
});
114+
const state = yield* settled("succeeded");
115+
expect(state).toMatchObject({ phase: "failed", message });
116+
expect(JSON.stringify(state)).not.toContain("sk-secret-123");
117+
expect(changed).toEqual([]);
118+
}
109119
}).pipe(Effect.provide(NodeServices.layer), Effect.scoped),
110120
);
111121
});

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,20 @@ type Runtime = Pick<
3030
>;
3131

3232
const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);
33-
const MAX_AGENT_REASON_LENGTH = 300;
33+
// Mistral Vibe's JSON-RPC error message when its own browser sign-in status poll
34+
// fails (`POLL_FAILED` in vibe/setup/auth/http_browser_sign_in_gateway.py, #15118).
35+
const BROWSER_SIGN_IN_POLL_FAILED = "Browser sign-in status could not be retrieved.";
3436

3537
/**
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."
38+
* Adds canonical text for a recognized sign-in failure an agent sent. The
39+
* agent's own message is never copied and stays in `cause`.
3940
*/
4041
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}`;
42+
return isAcpRequestError(cause) &&
43+
cause.operation === "receive-response" &&
44+
cause.errorMessage.includes(BROWSER_SIGN_IN_POLL_FAILED)
45+
? `${detail.replace(/\.$/u, "")}: ${BROWSER_SIGN_IN_POLL_FAILED}`
46+
: detail;
4947
}
5048

5149
/** ACP credentials stay in the agent's own store, using the same launch environment as chat. */

0 commit comments

Comments
 (0)