[codex] Structure ACP transport errors #3251
main fromrefs/pull/3251/head·merged by juliusmarminge View on GitHubSummary#
- attach transport operation and RPC method context while preserving original RPC, stream, process, and SchemaError causes
- keep messages stable instead of copying cause-derived diagnostics
- summarize schema failures with issue count, issue kinds, and maximum path depth; raw invalid payload values are never copied into direct fields or JSON-RPC data
- normalize core and extension notification SchemaErrors through one payload-safe structural mapper
- represent a clean ACP input-stream end as its own error rather than inventing a cause
- centralize reusable error transformations on the error classes
Validation#
- vp test run packages/effect-acp/src/errors.test.ts packages/effect-acp/src/protocol.test.ts packages/effect-acp/src/agent.test.ts packages/effect-acp/src/client.test.ts (25 tests)
- vp check (0 errors; 20 pre-existing warnings)
- vp run typecheck
Note
Medium Risk Error shapes and user-visible messages change across the ACP client/agent stack, which may break callers that match on message text; the changes are security-motivated (avoid leaking payload/cause details) and are covered by new and updated tests.
Overview
Restructures ACP transport, protocol parse, and request errors so public message strings are fixed templates with optional operation and method fields, while the original cause (RPC, stream, SchemaError, etc.) is preserved on the error object.
Schema validation failures no longer embed formatted issue text or raw invalid values in messages, logs, or JSON-RPC data. Instead they attach summarized diagnostics (issueCount, issueKinds, maximumPathDepth) via shared helpers on AcpProtocolParseError and AcpRequestError, with full details only on the SchemaError cause.
Protocol and RPC plumbing passes RPC method names into callRpc, maps handler failures through fromCoreHandlerError / fromExtensionHandlerError, logs decode failures with operation metadata only, uses stable RpcClient defect messages for termination and send failures, and treats a clean stdin end as AcpInputStreamEndedError instead of a synthetic transport error.
API cleanup: removes makeTerminal; the agent builds terminal handles as plain AcpTerminal-shaped objects. Adds errors.test.ts and extends protocol/client tests for the new error behavior.
Note
Structure ACP transport, request, and protocol parse errors with operation and method context#
- Replaces free-form
detailstrings onAcpTransportError,AcpProtocolParseError, andAcpRequestErrorwith structuredoperationandmethodfields, standardizing all user-facing error messages. - Adds
schemaIssueDiagnosticsto aggregate schema issue counts, kinds, and path depth into error metadata without leaking raw payload values. - Introduces
AcpInputStreamEndedErroras a distinct error type for end-of-input conditions, replacing ad-hocAcpTransportErrorconstruction. - Removes
makeTerminalfrom terminal.ts and thenormalizeToRequestError/toRpcClientErrorhelpers from protocol.ts; callers must construct terminal objects directly. - Risk: all public-facing error messages change, and
callRpcnow requires an explicit method string as its first argument — call sites in agent.ts and client.ts are updated accordingly.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Approved
Refactoring of ACP transport error handling to use structured fields instead of free-form strings. No behavioral changes beyond error message formatting, with added benefit of preventing sensitive values from leaking into error messages. Comprehensive test coverage included.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Core handlers get extension errors
- Replaced the misuse of fromHandlerError in runHandler with inline logic that produces core-appropriate error message ('ACP request handler failed') and operation tag ('handle-request') instead of the extension-specific wording.
Or push these changes by commenting:
@cursor push f1de956242You can send follow-ups to the cloud agent here. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e545938c70c990e374a6148742f5b80f647e165d. Configure [here](https://www.cursor.com/dashboard/bugbot).Preview (pingdotgg/t3code@f1de956242)
diff --git a/packages/effect-acp/src/_internal/shared.ts b/packages/effect-acp/src/_internal/shared.ts --- a/packages/effect-acp/src/_internal/shared.ts +++ b/packages/effect-acp/src/_internal/shared.ts @@ -35,9 +35,17 @@ return yield* Effect.fail(AcpError.AcpRequestError.methodNotFound(method).toProtocolError()); } return yield* handler(payload).pipe( - Effect.mapError((error) => - AcpError.AcpRequestError.fromHandlerError(error, method).toProtocolError(), - ), + Effect.mapError((error) => { + const requestError = + error._tag === "AcpRequestError" + ? error + : AcpError.AcpRequestError.internalError( + `ACP request handler failed for method '${method}'`, + undefined, + { method, operation: "handle-request", cause: error }, + ); + return requestError.toProtocolError(); + }), ); }); diff --git a/packages/effect-acp/src/errors.test.ts b/packages/effect-acp/src/errors.test.ts --- a/packages/effect-acp/src/errors.test.ts +++ b/packages/effect-acp/src/errors.test.ts @@ -96,7 +96,7 @@ expect(error).toMatchObject({ code: -32603, - message: "ACP extension request handler failed for method 'fs/read_text_file'", + message: "ACP request handler failed for method 'fs/read_text_file'", }); expect(error.message).not.toContain(cause.message); }); diff --git a/packages/effect-acp/src/errors.ts b/packages/effect-acp/src/errors.ts --- a/packages/effect-acp/src/errors.ts +++ b/packages/effect-acp/src/errors.ts @@ -6,6 +6,7 @@ export const AcpRequestOperation = Schema.Literals([ "decode-extension-request-payload", "handle-extension-request", + "handle-request", ]); export type AcpRequestOperation = typeof AcpRequestOperation.Type;packages/effect-acp/src/_internal/shared.ts line 40Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -37,4 +36,3 @@3736 }3837 return yield* handler(payload).pipe(3938 Effect.mapError((error) =>40- isAcpRequestError(error)Core handlers get extension errors#
Medium Severity
runHandlernow maps every non-AcpRequestErrorfailure throughfromHandlerError, which always emits the JSON-RPC messageACP extension request handler failed for method '…'and tagshandle-extension-request. That helper is only appropriate for extension RPC paths;runHandleris wired exclusively to core agent and client methods (for examplesession/promptandfs/read_text_file), so peers see misleading extension wording instead of a core-handler failure.Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e545938c70c990e374a6148742f5b80f647e165d. Configure [here](https://www.cursor.com/dashboard/bugbot).Additional Locations (1)
- ✅ Fixed: Core handlers get extension errors
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this4c16c66
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
d6cbc5df-e4c2-4611-aaf0-6851e78bbea4You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.