Repository navigation
fix(agents): cap container CPU limit at the Docker host's CPU count (#2318) - #3184
Conversation
…2318) Docker rejects NanoCpus above the host's CPU count with a 400. The trinity-system template asks for 4 CPUs, so on any 2-CPU host (a t3a.large, the AWS Marketplace default) the system agent was never created, failing again on every backend start. A user agent configured above the host's CPUs failed the same way. containers_run, the one seam every agent create and recreate goes through, now caps nano_cpus at docker info's NCPU and logs a warning. The trinity.cpu label keeps the requested value: the resource drift check compares it with the DB setting, and a capped label would recreate the agent on every start. If the host count can't be read, the request passes through unchanged. Verified on a 2-vCPU EC2 instance: with this file in place, trinity-system was created and runs with NanoCpus=2e9, label trinity.cpu=4. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Regression details (head_sha: `0292f04d26bad918fd521d2ecc2f1acd6115735c`)Seed Backend unit-suite regression diffPer-XML totals
❌ New failures introduced by HEAD (1)Tests failing under HEAD that did not fail under BASE in any seed:
Legend: [F] = assertion failure, [E] = collection or fixture error. Seed Backend unit-suite regression diffPer-XML totals
❌ New failures introduced by HEAD (1)Tests failing under HEAD that did not fail under BASE in any seed:
Legend: [F] = assertion failure, [E] = collection or fixture error. Seed Backend unit-suite regression diffPer-XML totals
❌ New failures introduced by HEAD (1)Tests failing under HEAD that did not fail under BASE in any seed:
Legend: [F] = assertion failure, [E] = collection or fixture error. Reproduce locally: |
test_2318_cpu_capped_to_host imported get_docker_utils from test_docker_utils by bare name, but tests/unit is not on sys.path, so the file failed at collection and 'regression diff' went red on the PR's own test. Add the path preamble the other sibling-importing unit tests use (test_2392, test_3185). Mechanical, per the merge-train note on the PR. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
merge-train (2026-10-04): on today's train. Two commits pushed to this branch, both mechanical:
Checked before pushing:
It merges once Tier 1 is green on the new head. |
Pre-release for the AWS Marketplace AMI (#3004). Supersedes 1.0.0-aws.1 and carries the AMI cleanup fix (#3182) and the CPU cap at the host's count (#3184), without which the system agent never starts on a 2-vCPU instance. The DigitalOcean installer default moves with VERSION (trinity#2380). Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Closes #2318.
Problem
Docker refuses to create a container whose CPU limit exceeds the host's CPU count (
range of CPUs is from 0.01 to 2.00, as there are only 2 CPUs available). Thetrinity-systemtemplate asks for 4 CPUs, so on any 2-CPU host the system agent is never created, and creation fails again on every backend start. A 2-vCPU t3a.large is the default instance type for the AWS Marketplace listing (#3004). A user agent set above the host's CPUs fails the same way.Fix
services/docker_utils.containers_run— the single seam every agent create and recreate goes through (system agent,crud.py,lifecycle.py) — capsnano_cpusatdocker info'sNCPUand logs a warning when it does.Deliberately not capped: the
trinity.cpulabel.helpers.py's resource drift check compares that label with the DB setting; a capped label would mismatch a DB value of 4 and recreate the agent on every start. The issue suggested capping the label too; this is why it doesn't.If the host CPU count can't be read, the request passes through unchanged (Docker decides, as before).
Verification
tests/unit/test_2318_cpu_capped_to_host.py: 4→2 on 2 CPUs, unchanged when it fits, odd host count (8→3), no limit untouched, unreadable host count passes through. Failed before the fix on the two capping cases; passes after. Existingtest_docker_utils.pypasses.v1.0.0-aws.1) the backend logged the 400 above. With this file in place and the backend restarted:[#2318] CPU limit 4 exceeds the host's 2 CPUs; capping to 2, thenSystem agent: created; containerNanoCpus=2000000000, labeltrinity.cpu=4.dev), from a local Python 3.11 environment; CI runs 3.13.🤖 Generated with Claude Code