ci-local.sh runs the six jobs side by side on one machine, and three of
them run the same test files. Eleven files took a port number out of a
socket they then closed, to start a proxy on it or to have a port where
nothing listens. Anyone could be handed that port before the server bound
it: a stranger could then answer in its place, and a dead port could come
alive. run_suite.py ran those files one at a time, which kept them apart
inside the suite job and not from the other jobs (code review,
2026-10-28, never seen in three runs).
tests/localports.py gives three answers. held() keeps a port bound and
never listening: a connection to it is refused and no other program can
bind it. serve() starts a server of the test's process on a held port,
beside the socket that keeps it (SO_REUSEPORT), so an engine that stops
and starts again keeps its port in between. spawn() starts a proxy in a
process of its own and keeps it once the socket listening on its port is
its own, read in /proc, else starts it again on another port. The
certificate test passes port 0, since nobody connects to a proxy that
refuses to start, and now checks that the refusal is the certificate's.
test_localports.py proves each answer on the machine, and fails on a test
file that takes a port the old way: on the tree before this commit it
names the eleven. With none left, the suite runs them four at a time.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test measured the proxy's cost on one body shape, an image as base64.
It now measures three, each 24 MiB, sent as UTF-8 as clients send them,
each on a proxy of its own (its peak only grows): base64, Chinese text
and emoji, and holds the unit to the costliest. On the reference box
(2026-10-24, three runs each), v6.45 cost 3.98, 5.65 and 7.98 times the
body, so 384 MiB of emoji needed 3,101 MiB against nine tenths of the 2G
the unit holds, and the test fails on it; v6.46 costs 3.99, 3.98 and
3.99, and passes. MemoryMax and the body budget stay as they are.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>