henry3260 opened a new pull request, #74662:
URL: https://github.com/apache/airflow/pull/74662
## Why
`AnthropicBatchAdapter.validate_requests` refuses a batch whose serialized
payload exceeds
Anthropic's 256 MB limit. It measured that payload with
`len(json.dumps(item))`, which counts
the characters of the ASCII-escaped form.
The adapter submits the requests inline
(`messages.batches.create(requests=...)`), so what
travels is httpx's encoding: `ensure_ascii=False`, then UTF-8
(`httpx._content.encode_json`).
A CJK character costs three bytes on the wire but was charged the six of its
`\uXXXX` escape;
a non-BMP character costs four but was charged twelve.
So a non-ASCII batch that is well inside the limit is rejected locally and
never reaches the
API, and the byte count in the error is up to three times the real payload —
which makes the
`.expand()` split the message suggests sized against a number that does not
exist. An English
batch of the same content passes.
`OpenAIBatchAdapter` is not affected: it builds the uploaded JSONL file with
the same
ASCII-escaped defaults it measures, so its estimate matches its own file
byte for byte.
## What
- `providers/common/ai/.../batch/anthropic.py`: measure the payload and the
output directive in
UTF-8 bytes, through a `_utf8_size` helper that follows the convention
`utils/query_results.py::_size` already documents. ASCII-only input is
unaffected.
- `providers/common/ai/tests/.../batch/test_anthropic.py`:
`TestPayloadSizeEstimate` pins the
estimate to the bytes the inline `batches.create` body actually carries,
parametrized over
ASCII / CJK / non-BMP prompts, and checks the reported directive size for
a non-ASCII schema.
The first commit adds them as strict xfail against today's behaviour; the
second drops the
markers with the fix.
Checks run locally: `test_anthropic.py` (29 passed, and the three new
expectations fail without
the source change), `prek run --from-ref upstream/main --stage pre-commit`,
and the same with
`--stage manual` — no hook reported a failure. The breeze provider-test
suites and docs build
that `breeze verify` lists were not run locally; leaving this as a draft for
CI.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: Claude Code (Opus 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]