You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
bug(server): an AdcpError raised by a pre-validation hook reaches the buyer as INVALID_REQUEST #1278
On 8.0.0, an AdcpError raised by a pre-validation hook reaches the buyer as INVALID_REQUEST. Its code, field, recovery and details are lost, and the original error is stringified into the message.
_apply_pre_validation_hooks (adcp/server/_hooks.py:89-96) wraps any exception in PreValidationHookError. The dispatcher (adcp/server/mcp_tools.py:3163-3172) then turns every PreValidationHookError into Error(code="INVALID_REQUEST", message=str(exc)).
A pre-validation hook is the natural place for request-envelope policy that must run before schema validation, such as requiring an explicit adcp_version. Hooks run before detect_wire_version, so this is also the only point where a seller can reject a request that omits the version, instead of letting it default.
Embedded Sales Agent does exactly this. Buyers that omit adcp_version, or send one ESA doesn't serve, are meant to get VERSION_UNSUPPORTED with field="adcp_version". They get INVALID_REQUEST with no field. A buyer that branches on the error code cannot tell a version-negotiation failure from a malformed request, and so cannot retry with a supported version.
Suggested fix
When the hook's exception is an AdcpError (or ADCPTaskError), re-raise it with its own code, field, recovery and details. Keep the INVALID_REQUEST wrapping for any other exception type, which is a hook bug rather than a deliberate rejection.
Classification: Bug Bucket(s): handlers (no matching label in repo — gap noted) Status: ready-to-implement Milestone: (omitted — none named)
What the experts said:
code-reviewer: Confirmed bug; fix belongs in mcp_tools.pyexcept PreValidationHookError block (inspect exc.__cause__), NOT _hooks.py — that module must remain stdlib-only per its module docstring; also flagged that the existing test must be split.
dx-expert: Confirmed bug and correct API design — AdcpError is the natural signal for policy rejections from hooks; non-AdcpError exceptions should still wrap as INVALID_REQUEST; docs/docstring update needed.
My take: Both experts agree the bug is real and the fix is clear. The correct fix location is src/adcp/server/mcp_tools.py lines 3163–3172 (not _hooks.py, which is constrained to stdlib). The existing AdcpError handler in serve.py will project the structured error correctly once it's no longer swallowed.
Implementation scope:
Fix:src/adcp/server/mcp_tools.py — in except PreValidationHookError as exc block, inspect exc.__cause__; if it is ADCPError (from adcp.exceptions) or a decisioning AdcpError (via the existing _get_decisioning_adcp_error_types() helper in serve.py), re-raise it directly. Both types already have correct projection handlers in serve.py. Keep wrapping all other exception causes as INVALID_REQUEST.
Tests:tests/test_pre_validation_hooks.py — split test_hook_exception_surfaces_as_invalid_request into (a) ValueError/RuntimeError → INVALID_REQUEST (existing path) and (b) AdcpError(code="VERSION_UNSUPPORTED", field="adcp_version") → structured error with code="VERSION_UNSUPPORTED" and field="adcp_version" preserved.
Docstring:src/adcp/server/_hooks.py_apply_pre_validation_hooks docstring says "A hook that raises... is wrapped in PreValidationHookError" — still accurate since AdcpError is re-raised before it reaches the wrap; no change needed there. But add a note that AdcpError/ADCPTaskError raised by hooks propagates unmodified.
Non-breaking rationale: Hooks raising AdcpError were getting incorrect behavior (INVALID_REQUEST); fixing to the intended structured code is a bug fix. Hooks raising any other exception type continue to produce INVALID_REQUEST unchanged.
Activity
bokelley commentedon Oct 2, 2026
Triage
Classification: Bug
Bucket(s): handlers (no matching label in repo — gap noted)
Status: ready-to-implement
Milestone: (omitted — none named)
What the experts said:
mcp_tools.pyexcept PreValidationHookErrorblock (inspectexc.__cause__), NOT_hooks.py— that module must remain stdlib-only per its module docstring; also flagged that the existing test must be split.AdcpErroris the natural signal for policy rejections from hooks; non-AdcpErrorexceptions should still wrap asINVALID_REQUEST; docs/docstring update needed.My take: Both experts agree the bug is real and the fix is clear. The correct fix location is
src/adcp/server/mcp_tools.pylines 3163–3172 (not_hooks.py, which is constrained to stdlib). The existingAdcpErrorhandler inserve.pywill project the structured error correctly once it's no longer swallowed.Implementation scope:
src/adcp/server/mcp_tools.py— inexcept PreValidationHookError as excblock, inspectexc.__cause__; if it isADCPError(fromadcp.exceptions) or a decisioningAdcpError(via the existing_get_decisioning_adcp_error_types()helper inserve.py), re-raise it directly. Both types already have correct projection handlers inserve.py. Keep wrapping all other exception causes asINVALID_REQUEST.tests/test_pre_validation_hooks.py— splittest_hook_exception_surfaces_as_invalid_requestinto (a)ValueError/RuntimeError→INVALID_REQUEST(existing path) and (b)AdcpError(code="VERSION_UNSUPPORTED", field="adcp_version")→ structured error withcode="VERSION_UNSUPPORTED"andfield="adcp_version"preserved.src/adcp/server/_hooks.py_apply_pre_validation_hooksdocstring says "A hook that raises... is wrapped inPreValidationHookError" — still accurate sinceAdcpErroris re-raised before it reaches the wrap; no change needed there. But add a note thatAdcpError/ADCPTaskErrorraised by hooks propagates unmodified.AdcpErrorwere getting incorrect behavior (INVALID_REQUEST); fixing to the intended structured code is a bug fix. Hooks raising any other exception type continue to produce INVALID_REQUEST unchanged.Triaged by Claude Code. Session: https://claude.ai/code/cse_01ELAdnKjNX7GpFeE8Bb975S
Generated by Claude Code