The test measured the proxy's memory per byte of body with an image as
base64, and called that the costliest shape. A code review of this
branch measured more for text in several bytes per character, and the
reference box agrees, two runs of 24 MiB each: 3.97 times for base64,
6.73 for Chinese and 9.98 for emoji, as the reasoning_effort rewrite
writes the body again with every such character escaped (5.64 and 7.06
when it writes UTF-8). 2G holds the body budget for media, the shape of
the largest legitimate bodies, not 384 MiB of multibyte text, which no
context window takes and only a key holder can send. The docstring
says so; writing the body as UTF-8 and sizing the ceiling on the
costliest shape is the next step.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BODY_BUDGET_BYTES (384 MiB) bounds the bytes of the bodies in flight,
but a body costs the proxy about four times its bytes while the guards
work on it: the reasoning_effort route parses it and writes it again.
Measured on the reference box (aarch64, Python 3.12), on the proxy as a
process with the shape tests/test_proxy_memory_ceiling.py sends (an
image as base64, reasoning_effort "lean"), three runs each: 3.99 times
a 24 MiB body, 4.01 times a 250 MiB one; one body of 250 MiB, under
MAX_BODY_BYTES, took the proxy from 31 to 1033 MiB, past the unit's
MemoryMax=1G with MemorySwapMax=0, where the kernel kills the proxy
with every stream in flight (seen in a cloud container under systemd
255; the client got an empty reply). The proxy of v1.36.2 measured the
same. MemoryMax is 2G now, which holds the budget at that rate with a
tenth to spare; the limits clients see are unchanged.
tests/test_proxy_memory_ceiling.py measures the rate on the machine it
runs on and fails when the idle proxy plus the budget at that rate is
over nine tenths of MemoryMax. The ceiling test of v1.22.13 asks for 2G,
and the two comments that gave 1G as the current ceiling say it was 1G
then.
Found in a cloud review of v1.36.1 (pull request #52). On the reference
box the unit rendered from this commit holds MemoryMax=2147483648 and
MemorySwapMax=0 with the sandbox of the commit before, and every client
above answered through it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>