Skip to content

Use peek to tell whether a response has a body in the smithy clients - #48

Open
alexey-milovidov wants to merge 1 commit into
ClickHouse/1.11.927from
smithy-response-body-peek
Open

alexey-milovidov wants to merge 1 commit into
ClickHouse/1.11.927from
smithy-response-body-peek

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

ClickHouse gives the SDK a response body that is a stream over the HTTP session: it is only read from, and its tellp does not say whether there is anything in it. The legacy clients (AWSXMLClient, AWSProtocolClient.h) are already patched in this fork to ask peek instead.

The clients that are generated on top of smithy::client::AwsSmithyClientT, such as the ones of Amazon Bedrock, do not go through that code:

  • JsonOutcomeSerializer and XmlOutcomeSerializer took every successful response for an empty one;
  • the error marshallers took every error for one without a body, so its type was guessed from the status code and its message was No response body.

This asks peek there as well: in the two serializers, and in BuildAWSError of JsonErrorMarshaller, XmlErrorMarshaller and RpcV2ErrorMarshaller, which only the smithy clients call.

The clients that ClickHouse has built so far (S3, KMS, Glue) are legacy ones, so nothing changes for them. It is needed for the bedrock provider of the AI agent of clickhouse-client, which is the first use of smithy clients in ClickHouse.

Related: ClickHouse/ClickHouse#137792

🤖 Generated with Claude Code

ClickHouse gives the SDK a response body that is a stream over the HTTP
session: it is only read from, and its `tellp` does not say whether there is
anything in it. The legacy clients (`AWSXMLClient`, `AWSProtocolClient.h`)
already ask `peek` instead. The clients that are generated on top of
`smithy::client::AwsSmithyClientT`, such as the ones of Amazon Bedrock, do not
go through that code: `JsonOutcomeSerializer` and `XmlOutcomeSerializer` took
every successful response for an empty one, and the error marshallers took
every error for one without a body, so its type was guessed from the status
code and its message was `No response body.`

Ask `peek` there as well: in the two serializers, and in `BuildAWSError` of
`JsonErrorMarshaller`, `XmlErrorMarshaller` and `RpcV2ErrorMarshaller`, which
only the smithy clients call.

The clients that ClickHouse has built so far (S3, KMS, Glue) are legacy ones,
so nothing changes for them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
alexey-milovidov added a commit to ClickHouse/ClickHouse that referenced this pull request Dec 5, 2026
… for Amazon Bedrock

The question was whether the provider can reuse the AWS SDK that is already
linked: #137792 (comment)
It can, in two ways.

The requests are sent, signed and retried by `aws-cpp-sdk-core`, which
`contrib/aws-cmake` builds anyway, over the HTTP client of ClickHouse. The
provider of the AI SDK writes and reads the JSON of the Converse API itself
(ClickHouse/ai-sdk-cpp#73), so none of the generated
clients of `bedrock-runtime`, `bedrock` and `sts` is built: only the endpoint
rules of the two services, 6 files instead of 290.

The credentials of AWS are found by `S3::S3CredentialsProviderChain`, the chain
that ClickHouse has for the other services of AWS, and given to the provider.
The default chain of the AWS SDK is not linked for it. It also could not work
here for a web identity token or for a profile with a role: it asks AWS STS
through the HTTP client of the AWS Common Runtime, which ClickHouse builds
without TLS. When there are no credentials, the client says where it has looked
for them and sends nothing, instead of sending a request without a signature.

The stripped `clickhouse` binary (aarch64, a reduced build with the AWS SDK)
grows by 200,016 bytes with the provider instead of 1,465,336, and gets 2 more
static initializers instead of 51.

The mock of `06038_client_ai_bedrock_provider` now checks the signature of every
signed request, the way a service of AWS does: from the path as it has arrived.
It found that the path that was signed was not the path that was sent whenever
the model has a colon, as nearly every model of Bedrock has: the AWS SDK signs
a colon as it is, and `PocoHTTPClient` sends it encoded. It was so with the
generated clients as well. The provider now asks the AWS SDK for the strict
encoding, which is what `PocoHTTPClient` sends. The test also asks a model by
its ARN, which needs the previous commit.

`contrib/aws` is back at the commit of `master`: the patch of
ClickHouse/aws-sdk-cpp#48 was for the generated clients.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant