Cocoon is Telegram's confidential-compute network for AI: a proxy receives requests from clients and hands them to workers that run the models inside trusted hardware. We run a worker there and pay for inference through it, so we read the proxy code closely. This is what we found and what we sent upstream as pull request #84.
The problem
ProxyRunner chooses the worker connection with the lowest running_queries() * average_query_time(). The idea is
right: a busy worker with slow answers should receive less. But when workers are idle, or answer faster than the timing
window can register, every weight is 0. The strict < comparison then keeps the first connection in the map, and that
connection receives every request. A worker that joins later never gets traffic — and because it never gets traffic, it
never builds the timing history that would let it compete. Idle time, which is most of the time on a young network,
freezes the ranking.
The change
Two files, +16/−2 lines.
- When loads are equal, the request goes to the connection with fewer queries in the last ten minutes. The proxy already
keeps this amortised counter (
total_queries_); the change exposes it asrecent_queries()and uses it as the tie-break. - A connection without timing history counts each in-flight query as one second (
avg > 0 ? avg : 1.0), so a new worker is not seen as idle while it is busy.
Selection is unchanged when loads differ; the coefficient and the max_active_requests checks are untouched.
The measurement
On a Cocoon network on TON testnet — one proxy, two workers serving the same model with coefficient 0, both with
allow queries YES — we sent 24 parallel chat completions through the client.
| worker 1 | worker 2 | |
|---|---|---|
| before the change (measured twice) | 24 | 0 |
| after the change | 12 | 12 |
The branch builds and passes the repository's local network smoke test. The pull request is open; whether and how it lands is the maintainers' call, and we will update this post when it does.
Why it matters to us
MINIMAL AI pays for inference per request and issues a signed receipt for every answer. Fair scheduling between workers is what turns a network of volunteers into a market: a new worker must be able to earn from its first minute. The same idea runs through everything we build — identity on the agent's own key, payment per request, a receipt anyone can check at ai.minimalcult.org/check.