fix(schema): coerce string protocolVersion in InitializeRequest#92
Open
WeeeeeKdY wants to merge 1 commit intoagentclientprotocol:mainfrom
Open
fix(schema): coerce string protocolVersion in InitializeRequest#92WeeeeeKdY wants to merge 1 commit intoagentclientprotocol:mainfrom
WeeeeeKdY wants to merge 1 commit intoagentclientprotocol:mainfrom
Conversation
Some ACP clients (notably Zed) send a date string like "2024-11-05" as the protocolVersion instead of an integer. The Rust SDK already handles this gracefully — its Deserialize impl maps any string to V0 with the comment "Old versions used strings". The Python SDK rejected strings outright, causing the agent process to crash on the very first handshake. Changes: - Add `_coerce_protocol_version` field_validator to `InitializeRequest` in `src/acp/schema.py` that maps non-integer values to 1 (current stable version), mirroring the Rust SDK's lenient behaviour. - Add `CLASS_VALIDATOR_INJECTIONS` table and `_inject_field_validators` post-processing step to `scripts/gen_schema.py` so the validator is re-applied automatically on future schema regenerations. - Add `_ensure_pydantic_import` helper used by the injection step to add `field_validator` to the generated pydantic import line. Ref: https://github.com/agentclientprotocol/rust-sdk/blob/main/crates/agent-client-protocol-schema/src/version.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Some ACP clients send a date string like
"2024-11-05"asprotocolVersioninstead of an integer. Zed is a known example — itsagent_serversimplementation can emit the MCP-style date format during the ACP handshake.The current Python SDK rejects this outright with a pydantic validation error, causing the agent process to crash immediately after the client connects:
Root cause
The Rust SDK (
agent-client-protocol-schema) already handles this gracefully with an explicit comment in the source:The Python SDK's generated
schema.pyuses a strict pydanticinttype with no equivalent fallback.Fix
field_validator("protocol_version", mode="before")toInitializeRequestinsrc/acp/schema.pythat coerces non-integer values to1(current stable version), mirroring the Rust SDK's lenient behaviour. Strings that look like integers (e.g."1") are parsed normally; arbitrary strings (e.g."2024-11-05") fall back to1.CLASS_VALIDATOR_INJECTIONStable and_inject_field_validatorspost-processing step toscripts/gen_schema.pyso the validator is automatically re-injected on future schema regenerations._ensure_pydantic_importhelper to addfield_validatorto the generated pydantic import line when needed.References