Repository navigation
fix(cli): size the sandbox LLM gateway's memory to its capacity - #5080
tale-code-bot wants to merge 2 commits into
Conversation
The gateway's container had a fixed 512m limit whatever capacity the deployment allowed. Its memory grows with the agent sessions that run at once, so a deployment with SANDBOX_MAX_SESSIONS=320 had it OOM-killed about every 40 s from about 80 sessions, and agent starts failed while it was down. The compose builder now takes SANDBOX_LLM_GATEWAY_MEMORY when it is set (a size such as 4g or 4096m, read like the spawner's own sizes, at least 512m) and otherwise gives the gateway 256 MiB plus 12 MiB for each session of SANDBOX_MAX_SESSIONS, at least 512m: 512m for the default 8 sessions, 4096m for 320. An unset capacity counts as the 256 sessions a Docker host may size itself to (3328m), which compose.yml uses as its default because compose cannot derive one variable from another. A malformed value fails the compose generation, before any container is recreated.
The environment reference documents SANDBOX_LLM_GATEWAY_MEMORY and the rule `tale deploy` sizes the gateway by, and the capacity guidance says when to set it: with the shipped compose files above 256 sessions, and on Kubernetes by raising the gateway Deployment's limit. The recovery steps for a gateway killed at boot note the container's current limits and restore them instead of naming a fixed 512m and 2g, which would now lower a larger limit. The Kubernetes and own-compose pages and the gateway's README say the same, in English, German and French.
tale-review-bot
left a comment
There was a problem hiding this comment.
Approved at head ad9233abd91a9f74204de0706df9e32d3f14baaf (base main 9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2).
Scope. The PR does what TALE-229's triage and plan asked, and nothing else:
- The gateway's
mem_limitisSANDBOX_LLM_GATEWAY_MEMORYwhen set; otherwise 256 MiB plus 12 MiB per session ofSANDBOX_MAX_SESSIONS, at least 512m. - An unset capacity gives
3328m, sized for the spawner's 256-session ceiling. compose.ymldefaults to the same value, and a parity test holds the two together..env.example, the gateway README and the EN/DE/FR environment reference, Kubernetes and own-compose pages are swept in. DE and FR carry the same figures as EN.- Restart visibility stays out of scope, as the triage set it.
Correctness.
- Inputs:
loadEnvfolds the project.envintoprocess.envbefore compose generation, as the other builders rely on. The size grammar is the spawner'ssizeEnvregex, byte for byte.sessionCapacitymirrorsnumEnv('SANDBOX_MAX_SESSIONS', 8, { min: 1 }), rounding up, andAUTO_MAX_SESSIONS = 256matches the unset default. - No swap conflict: neither the builder nor
compose.ymlsetsmemswap_limit, so a largermem_limitdoesn't collide with a fixed swap. - Recovery steps: they now note and restore the container's own limits instead of the old
512m/1g, which would have lowered a derived limit.
What I ran at this head (credentials removed; the install's lockfile and manifests are unchanged from main):
bun teston the builder and parity test files: 133 pass, 0 fail.- The same two files against
main's builder: 127 pass, 6 fail, all six of them new. The seventh new test, the 8-session512mcontrol, passes on both.
Checks. All seven CI ready checks passed on this head: Checks 40917140820, SAST 40917141031, Commitlint 40917140838, CLI 40917140990, Build 40917140874, E2E 40917140735 and Security 40917140573. The Checks run includes Format (lint:links), Type check, Knip and Unit (workspaces), which runs the full @tale/cli and @tale/docs suites. There are no review threads.
Not run: a live tale deploy with 80 or more sessions, and the queue-only tier, which the merge queue runs.
Non-blocking:
- The 12 MiB per session rests on one incident. The override variable, which the docs name, is the escape hatch.
- Setting
GOMEMLIMITfrom the limit is a possible follow-up.
|
Not landed yet: its CI must re-run under the new landing rule. (Reviewer
|
|
Reviewer: the CI on this head since the 20:13 UTC reopen can't be used to land it (head It ran the workflows from before
Without a merge queue, those suites never run before landing. So these runs' Next. This PR's merge ref is now based on |
|
Reopened so the checks run again. The 20:13–20:15 UTC reopen started its runs from a test merge into |
|
Landed on |
Task: TALE-229 on the Development board. The plan is the task's plan comment (Coder run
e115d270), and it still holds.What was wrong
tale deploygave the sandbox LLM gateway's container a fixedmem_limit: 512m(tools/cli/src/lib/compose/services/create-sandbox-llm-gateway-service.ts), andcompose.ymldid the same, whatever capacity the deployment allowed. The gateway's memory grows with the agent sessions that run at once. On a deployment withSANDBOX_MAX_SESSIONS=320, the kernel OOM-killed it about every 40 s from about 80 sessions, and agent starts failed while it was down. Its health check passed between the kills, so nothing reported them.What changed (two commits)
fix(cli): size the sandbox LLM gateway's memory to its capacitySANDBOX_LLM_GATEWAY_MEMORYsets the limit when it is present. It takes a size such as4gor4096m, parsed the way the spawner parses its own sizes (sizeEnvinservices/sandbox/src/config.ts). It must be at least512mand is emitted as whole MiB.SANDBOX_MAX_SESSIONS, parsed the way the spawner'snumEnvparses it: 256 MiB plus 12 MiB per session, at least 512 MiB.512m.1216m.4096m, the value that fixed the reported deployment.3328m.tale deploy,tale dev) before any container is recreated.compose.ymlnow readsmem_limit: ${SANDBOX_LLM_GATEWAY_MEMORY:-3328m}, because compose interpolation cannot derive one variable from another. A parity test pins this default to the builder's default for an unset capacity..env.exampledocuments the variable.docs: explain how the model gateway's memory scales with sessionsSANDBOX_LLM_GATEWAY_MEMORY;SANDBOX_MAX_SESSIONS.2gand512m, which would now lower a larger limit.limits.memoryby the same rule; the manifest keeps512Mifor 8 sessions), the own-compose page and the gateway's README.{#sandbox-agent-turns}id, because the new links point there. No page linked to the old FR slug.Why 12 MiB per session.
GOMEMLIMIT, so Go's collector lets the heap grow to about twice what is live.Why provider concurrency is not in the formula.
SANDBOX_LLM_GATEWAY_[CUSTOM_]PROVIDER_CONCURRENCYsizes the worker pool of each provider record.Checklist
bun run checkpasses, in CI on this head. In Checks run 40917140820, these lanes pass: Format, Lint, Knip, Type check, Unit (platform 1/2), Unit (platform 2/2) and Unit (workspaces). The workspaces lane'sturbo run testcovers@tale/cliand@tale/docs, with 16 of 16 tasks successful. The UI and browser lanes skip on pull requests and run in the merge queue. It was not run as one command on the authoring worker (see What was not tested).bun run lint:sastpasses, in CI on this head: Opengrep passed in SAST run 40917141031. It was not run locally, because opengrep is not cached on the worker and the pre-commit scan skipped.docs/{en,de,fr}/: the environment reference, Kubernetes and own-compose pages, in all three locales.README.md/README.de.md/README.fr.md: N/A. The root READMEs do not cover gateway memory orSANDBOX_MAX_SESSIONS; the gateway's own README (services/sandbox-llm-gateway/README.md) is updated.How it was tested
Every command ran on the Coder's worker with the GitHub credentials removed from the environment, at head
ad9233abd91a9f74204de0706df9e32d3f14baaf, which is the head of this pull request.main.bun test src/lib/compose/services/create-sandbox-llm-gateway-service.test.ts src/lib/compose/services/compose-parity.test.ts(intools/cli): 133 pass, 0 fail.main9be5cadacb5f59cd6b2cc67c7840e3c0101bdde2swapped back in: 127 pass, 6 fail. The failures are the six new tests:compose.ymlparity.docker compose -f compose.yml config(Compose v5.6.0) resolves the gateway'smem_limitto:3489660928bytes (3328 MiB);4gand4096m:4294967296bytes.bun run --filter @tale/docs test: 38 files, 716 tests passed.bun run lint:links: every link lands (502 pages).bun run --filter @tale/docs lint: passes.bun run --filter @tale/cli typecheckpasses afterbun run --filter @tale/cli generate.bun run --filter @tale/cli lint: passes.bun run --filter @tale/cli test: 3827 pass, 35 skip, 9 fail. The nine failures are explained under What was not tested.oxfmt --check: all 8615 matched files use the correct format.bun run lint:conflicts: passes.@tale/clisuite and the@tale/docstests.What was not tested
The full
bun run check, as one command on the authoring worker. The worker fails 9@tale/clitests whatever the change, all in files that touch no compose code:git archive --mtime, which the worker's git 2.39.5 lacks.scripts/action-archive.test.tshits the worker's 512 MiB file-size limit (SIGXFSZ).tests/smoke-fixture.test.tspasses onceCLAUDECODEis unset.In CI, the full
@tale/clisuite passes on this head (Unit (workspaces) above). The other workspaces' lint, typecheck and tests ran only in CI.The UI, browser and e2e lanes. They skip on pull requests and run in the merge queue. This change touches no UI.
ruff format --check.uvxis not installed on the worker. No Python file changed.Opengrep, locally. See the checklist.
A live deployment. Nobody ran
tale deployagainst a Docker host or measured the gateway under 80+ sessions.Out of scope, per triage: showing gateway restarts on the Sandboxes page or the health endpoint (the issue's optional item).
Possible follow-up: setting
GOMEMLIMITfrom the container's limit, so the collector respects the cap.Closes #5074