@devries-cameron20 / t3code-1 / commits / b15f772ebe
Fork 0

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

fix(provider-acp-registry): surface agent error message on sign-in failure (#30295)

Nico committed Nov 6, 2026 at 05:23 UTC b15f772ebee6bab65950cb2b3404736d480eec0d
2 files changed +165 -3
packages/provider-acp-registry/src/server/auth.test.ts
+136 -2
@@ -5,6 +5,7 @@ import { assert, it } from "@effect/vitest";
5 import { ProviderInstanceId, type ProviderAuthState } from "@t3tools/contracts";
6 import { AcpRegistrySettings } from "../settings.ts";
7 import * as Deferred from "effect/Deferred";
8 +import * as Cause from "effect/Cause";
9 import * as Effect from "effect/Effect";
10 import * as Option from "effect/Option";
11 import * as Schema from "effect/Schema";
@@ -13,7 +14,7 @@ import type * as AcpSchema from "effect-acp/compat";
14 import { AcpRequestError } from "effect-acp/errors";
15
16 import * as PtyAdapter from "@t3tools/shared/PtyAdapter";
16 -import { makeAcpRegistryAuth } from "./auth.ts";
17 +import { formatFailureDetail, makeAcpRegistryAuth } from "./auth.ts";
18 import * as AcpRegistrySupport from "./AcpRegistrySupport.ts";
19 import type * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
20
@@ -61,6 +62,7 @@ const makeHarness = (
62 failVerification = false,
63 settings = decodeSettings({ agentId: "test-agent" }),
64 providerInstanceId = instanceId,
65 + authenticateError?: AcpRequestError,
66 ) =>
67 Effect.gen(function* () {
68 const verify = yield* Deferred.make<void>();
@@ -111,6 +113,9 @@ const makeHarness = (
113 authenticate: (methodId) =>
114 Effect.gen(function* () {
115 authenticated.push(methodId);
116 + if (authenticateError !== undefined) {
117 + return yield* authenticateError;
118 + }
119 if (elicitation)
120 yield* elicitation(
121 {
@@ -342,8 +347,137 @@ it.effect("does not report authentication when post-login verification fails", (
347 h.exit(0);
348 yield* h.phase("verifying");
349 yield* Deferred.succeed(h.verify, undefined);
345 - yield* h.phase("failed");
350 + const failed = yield* h.phase("failed");
351 assert.deepEqual(h.changed, []);
352 assert.isTrue(h.killed());
353 + assert.strictEqual(
354 + failed.message,
355 + "The provider could not create a session after terminal sign-in. Authentication required",
356 + );
357 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
358 +);
359 +
360 +it.effect("surfaces the agent error message when authenticate fails with AcpRequestError", () =>
361 + Effect.gen(function* () {
362 + const error = new AcpRequestError({
363 + method: "authenticate",
364 + code: -32000,
365 + errorMessage: "Connect to the VPN, then sign in again.",
366 + });
367 + const h = yield* makeHarness(
368 + browserMethod,
369 + false,
370 + decodeSettings({ agentId: "test-agent" }),
371 + instanceId,
372 + error,
373 + );
374 + yield* h.controller.start("owner", Effect.void, "browser");
375 + const failed = yield* h.phase("failed");
376 + assert.strictEqual(
377 + failed.message,
378 + "The ACP agent could not complete sign-in. Connect to the VPN, then sign in again.",
379 + );
380 + assert.deepEqual(h.changed, []);
381 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
382 );
383 +
384 +it.effect(
385 + "surfaces the agent error message when post-sign-in verification fails for agent auth",
386 + () =>
387 + Effect.gen(function* () {
388 + const h = yield* makeHarness(browserMethod, true);
389 + const flow = yield* h.controller.start("owner", Effect.void, "browser");
390 + yield* h.phase("waiting");
391 + yield* h.controller.respond!("owner", {
392 + instanceId,
393 + flowId: flow.flowId!,
394 + interactionId: "consent",
395 + response: { type: "browser", action: "accept" },
396 + });
397 + yield* h.phase("verifying");
398 + yield* Deferred.succeed(h.verify, undefined);
399 + const failed = yield* h.phase("failed");
400 + assert.strictEqual(
401 + failed.message,
402 + "The provider could not create a session after sign-in. Authentication required",
403 + );
404 + assert.deepEqual(h.changed, []);
405 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
406 +);
407 +
408 +it("formatFailureDetail handles all cause types and formatting edge cases cleanly", () => {
409 + const baseWithPeriod = "The ACP agent could not complete sign-in.";
410 + const baseWithoutPeriod = "The ACP agent could not complete sign-in";
411 +
412 + // 1. undefined or null cause
413 + assert.strictEqual(formatFailureDetail(baseWithPeriod, undefined), baseWithPeriod);
414 + assert.strictEqual(formatFailureDetail(baseWithPeriod, null), baseWithPeriod);
415 +
416 + // 2. plain Error object, string, number, or object defect
417 + assert.strictEqual(
418 + formatFailureDetail(baseWithPeriod, new Error("Something broke")),
419 + baseWithPeriod,
420 + );
421 + assert.strictEqual(formatFailureDetail(baseWithPeriod, "string error"), baseWithPeriod);
422 + assert.strictEqual(formatFailureDetail(baseWithPeriod, { foo: "bar" }), baseWithPeriod);
423 +
424 + // 3. AcpRequestError with empty or whitespace-only errorMessage
425 + const emptyError = new AcpRequestError({
426 + method: "authenticate",
427 + code: -32000,
428 + errorMessage: "",
429 + });
430 + const whitespaceError = new AcpRequestError({
431 + method: "authenticate",
432 + code: -32000,
433 + errorMessage: " \t\n ",
434 + });
435 + assert.strictEqual(formatFailureDetail(baseWithPeriod, emptyError), baseWithPeriod);
436 + assert.strictEqual(formatFailureDetail(baseWithPeriod, whitespaceError), baseWithPeriod);
437 +
438 + // 4. AcpRequestError with valid message: ensure no double periods, clean separation
439 + const validError = new AcpRequestError({
440 + method: "authenticate",
441 + code: -32000,
442 + errorMessage: "Connect to the VPN, then sign in again.",
443 + });
444 + assert.strictEqual(
445 + formatFailureDetail(baseWithPeriod, validError),
446 + "The ACP agent could not complete sign-in. Connect to the VPN, then sign in again.",
447 + );
448 + assert.strictEqual(
449 + formatFailureDetail(baseWithoutPeriod, validError),
450 + "The ACP agent could not complete sign-in. Connect to the VPN, then sign in again.",
451 + );
452 +
453 + // 5. AcpRequestError with trimmed message and message without ending period
454 + const unpunctError = new AcpRequestError({
455 + method: "authenticate",
456 + code: -32000,
457 + errorMessage: " Invalid credentials ",
458 + });
459 + assert.strictEqual(
460 + formatFailureDetail(baseWithPeriod, unpunctError),
461 + "The ACP agent could not complete sign-in. Invalid credentials",
462 + );
463 +
464 + // 6. Nested Cause (e.g. Cause.fail or Cause.die wrapping AcpRequestError)
465 + assert.strictEqual(
466 + formatFailureDetail(baseWithPeriod, Cause.fail(validError)),
467 + "The ACP agent could not complete sign-in. Connect to the VPN, then sign in again.",
468 + );
469 + assert.strictEqual(
470 + formatFailureDetail(baseWithPeriod, Cause.die(validError)),
471 + "The ACP agent could not complete sign-in. Connect to the VPN, then sign in again.",
472 + );
473 +
474 + // 7. Extremely long error message: truncates to 500 characters with ellipsis
475 + const longText = "A".repeat(600);
476 + const longError = new AcpRequestError({
477 + method: "authenticate",
478 + code: -32000,
479 + errorMessage: longText,
480 + });
481 + const expectedLong = `The ACP agent could not complete sign-in. ${"A".repeat(500)}…`;
482 + assert.strictEqual(formatFailureDetail(baseWithPeriod, longError), expectedLong);
483 +});
packages/provider-acp-registry/src/server/auth.ts
+29 -1
@@ -5,6 +5,7 @@ import {
5 } from "@t3tools/contracts";
6 import type { AcpRegistrySettings } from "../settings.ts";
7 import * as SecureRandom from "effect/crypto/SecureRandom";
8 +import * as Cause from "effect/Cause";
9 import * as Deferred from "effect/Deferred";
10 import * as Effect from "effect/Effect";
11 import * as Exit from "effect/Exit";
@@ -13,7 +14,9 @@ import * as Option from "effect/Option";
14 import * as Queue from "effect/Queue";
15 import * as Scope from "effect/Scope";
16 import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
17 +import * as Schema from "effect/Schema";
18 import type * as AcpSchema from "effect-acp/compat";
19 +import * as EffectAcpErrors from "effect-acp/errors";
20
21 import * as PtyAdapter from "@t3tools/shared/PtyAdapter";
22 import * as ProviderAuthFlow from "@t3tools/provider-core/server/providerAuthFlow";
@@ -22,6 +25,26 @@ import * as AcpRegistrySupport from "./AcpRegistrySupport.ts";
25 import * as AcpRegistryRuntimeCoordinator from "./AcpRegistryRuntimeCoordinator.ts";
26 import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
27
28 +const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError);
29 +
30 +const MAX_ERROR_MESSAGE_LENGTH = 500;
31 +
32 +export const formatFailureDetail = (detail: string, cause?: unknown): string => {
33 + const unwrapped = Cause.isCause(cause) ? Cause.squash(cause) : cause;
34 + if (isAcpRequestError(unwrapped)) {
35 + let message = unwrapped.errorMessage.trim();
36 + if (message.length > MAX_ERROR_MESSAGE_LENGTH) {
37 + message = `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH).trimEnd()}…`;
38 + }
39 + if (message.length > 0) {
40 + const trimmed = detail.trimEnd();
41 + const prefix = trimmed.endsWith(".") ? `${trimmed} ` : `${trimmed}. `;
42 + return `${prefix}${message}`;
43 + }
44 + }
45 + return detail;
46 +};
47 +
48 type Runtime = Pick<
49 AcpSessionRuntime.AcpSessionRuntime["Service"],
50 "initialize" | "authenticate" | "start" | "handleElicitation" | "logout"
@@ -47,7 +70,12 @@ export const makeAcpRegistryAuth = Effect.fn("makeAcpRegistryAuth")(function* (o
70 const agentKey =
71 options.settings.source === "local" ? `local:${options.instanceId}` : options.settings.agentId;
72 const failure = (operation: string, detail: string, cause?: unknown) =>
50 - new ProviderSetupError({ instanceId: options.instanceId, operation, detail, cause });
73 + new ProviderSetupError({
74 + instanceId: options.instanceId,
75 + operation,
76 + detail: formatFailureDetail(detail, cause),
77 + cause,
78 + });
79 const resolve = catalog
80 .resolve(options.settings, options.cwd, options.environment)
81 .pipe(