Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions .agents/repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,6 @@ default means deleting the override and fixing what surfaces:
backfill was shipped (the `0093`/`0098` external-key precedent). Paying it down means a
forward-only migration that canonicalises `app.folders.name` where no twin exists and detaches
or renames the loser where one does, documented like `0098_external_keys_canonical_twins.sql`.
- **A long OpenCode or Pi turn books only its later calls' tokens** — every drain window
re-parses the exec from the start of runnerd's replay buffer (`resumeSinceSeq: 0` in
`drainHarnessWindow`, `backend/core/chat/external_turn_shared.ts`), and the buffer keeps only
the last 256 KB of output (`RUNNERD_RING_BUFFER_BYTES`). A CLI that reports its own turn totals
(Claude Code, Codex, Gemini, Qwen Code, OpenClaw) books them whole, but the OpenCode and Pi
parsers sum the model calls they see, so a turn whose output outgrew the buffer books the
tokens of the calls still in it (2026-09). Cost is unaffected: it comes from the turn's gateway
key. Paying it down means counting each call's usage once by stream position across windows
(the drain passing line seqs, the op row keeping the last counted seq and the running totals),
or reading the turn's token counts from the gateway as its cost is read.
- **No usage or cost on a run** — `GET …/runs/{runId}` carries no `usage` block: an `llm`
node's spend is not metered at all (`backend/core/automations/llm_call.ts` → `model_call.ts`
parses no usage and writes no ledger row), and an `agent` node's cents settle on
Expand Down
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ TALE_AUDIT_PEPPER=9c1e5b7d3a2f8064e1c7a9d5b3f2e8c604a7d1b9e5c3f8a2d6b0e4c7a1f9d3
# How long a session that no turn or run holds stays up once idle, in ms (agent
# sessions with Docker inside keep the full idle window).
# SANDBOX_SESSION_RELEASED_IDLE_MS=300000
# Workloads allowed to start inner Docker when DinD is enabled. Unset keeps
# project,workflow; project leaves workflow agents lightweight; none disables
# it for both. Applies to newly created sessions; existing compute is retained.
# SANDBOX_DOCKER_WORKLOADS=project
# Per-agent resource limits, applied to newly created sandbox sessions.
# Leave memory unset for 4g normally or 8g with Docker inside the sandbox.
# SANDBOX_AGENT_CPUS=2
Expand Down
1 change: 1 addition & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ services:
# runc/gvisor); set SANDBOX_DOCKER_IN_CONTAINER=true/false (or the
# deployment.json sandboxRuntime section) to force it.
SANDBOX_DOCKER_IN_CONTAINER: ${SANDBOX_DOCKER_IN_CONTAINER:-}
SANDBOX_DOCKER_WORKLOADS: ${SANDBOX_DOCKER_WORKLOADS:-}
SANDBOX_DIND_INNER_POOL: ${SANDBOX_DIND_INNER_POOL:-}
SANDBOX_RUNTIME_IMAGE: ${SANDBOX_RUNTIME_IMAGE:-tale-sandbox-runtime:latest}
# Shared cross-session docker build cache. Unset here so the spawner applies
Expand Down
5 changes: 5 additions & 0 deletions docs/de/self-hosted/configuration/environment-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ Der Sandbox-Spawner liest die folgenden Einstellungen. Übergib sie seiner Umgeb
| `SANDBOX_MAX_SESSIONS` | auf einem lokalen Docker-Host nach dem Host-Speicher bemessen (mindestens `8`, höchstens `256`); sonst `8` | Höchstzahl laufender und startender Sessions aller Organisationen auf dem Docker-Host oder im Kubernetes-Namespace, einschließlich weiterlaufender Container im Leerlauf. Die Kapazität reserviert weder CPU noch Arbeitsspeicher. Fehlt die Variable auf einem Docker-Host, dessen Speicher der Spawner lesen kann, bemisst er sie nach diesem Speicher: eine Session je 768 MiB, die nach `SANDBOX_MIN_FREE_MEMORY` übrig bleiben, oder je 1,5 GiB, wenn Agent-Sessions Docker in der Sandbox betreiben. Lässt sich der Speicher beim Start nicht lesen, bleibt die Kapazität bei `8`, bis er lesbar ist. Ein expliziter Wert legt sie fest. Gleichzeitige Kubernetes-Replikate setzen sie nach bestem Bemühen durch; harte Ressourcengrenzen im Namespace setzt du mit ResourceQuota. |
| `SANDBOX_MIN_FREE_MEMORY` | ein Zehntel des Host-Speichers, mindestens `1g` | Speicher, den eine neue Session auf einem lokalen Docker-Host frei lassen muss, neben dem, was noch startende und eben gestartete Sessions gleich belegen werden. Würde ein Start weniger übrig lassen, stoppt der Spawner zuerst eine freigegebene Session im Leerlauf; reicht der Speicher dann immer noch nicht, antwortet er mit „beschäftigt“, und die Arbeit wartet, bis laufende Sessions Speicher freigeben. Akzeptiert Größen wie `2g` oder `1536m`. Wirkt nicht unter Kubernetes oder mit einem entfernten Docker-Daemon. |
| `SANDBOX_MIN_FREE_DISK` | ein Zwanzigstel des Datenträgers, mindestens `2g`, höchstens `20g` | Speicherplatz, den eine neue Session auf einem lokalen Docker-Host auf dem Datenträger mit den Arbeitsverzeichnissen der Sessions frei lassen muss. Darunter antwortet der Spawner mit „beschäftigt“, und die Arbeit wartet, bis Platz frei wird; Sessions im Leerlauf zu stoppen hilft hier nicht, denn ihre Arbeitsverzeichnisse bleiben für die Wiederaufnahme erhalten. Währenddessen entfernt der Spawner die Build-Caches von Organisationen, deren Build-Cache-Hilfscontainer alle gestoppt sind und die keine Session nutzen kann, die am längsten gestoppten zuerst und höchstens drei pro Minute; gibt eine Entfernung auf diesem Datenträger nichts frei, pausiert er sechs Stunden. Akzeptiert Größen wie `10g` oder `4096m`; `0` schaltet die Prüfung ab. Wirkt nicht unter Kubernetes, wo das Arbeitsverzeichnis jeder Session ein Volume fester Größe ist. |
| `SANDBOX_DOCKER_WORKLOADS` | `project,workflow` | Workloads, die Docker in ihrer Sandbox nutzen dürfen, wenn es für das Deployment aktiviert ist. Mit `project` starten Workflow-Agenten ohne Docker, mit `workflow` gilt das für Projektagenten und mit `none` für beide. Die Einstellung gilt für neu erstellte Sessions; bestehende behalten ihre Fähigkeiten. Eine Session-Anfrage kann Docker mit `docker: false` abwählen, aber weder diese Liste noch die Deployment-Einstellung erweitern. |
| `SANDBOX_AGENT_CPUS` | `2` | CPU-Grenze je Agent-Session. Berücksichtige bei der Session-Anzahl gleichzeitig laufende Builds und andere Aufgaben auf dem Host. |
| `SANDBOX_AGENT_MEMORY` | `4g`; `8g` mit Docker in der Sandbox | Speichergrenze je Agent-Session, die auch für ihren inneren Docker-Daemon und dessen Container gilt. Ein expliziter Wert ersetzt beide Standardwerte und gilt für neu erstellte Sessions. |
| `SANDBOX_BUILDKITD_CPUS` | `SANDBOX_AGENT_CPUS` | CPU-Grenze des Build-Cache-Hilfscontainers einer Organisation, der die Image-Builds all ihrer Agent-Sessions ausführt, wenn Docker in der Sandbox läuft. Laufende Hilfscontainer übernehmen einen neuen Wert sofort. |
Expand All @@ -260,6 +261,10 @@ Der Sandbox-Spawner liest die folgenden Einstellungen. Übergib sie seiner Umgeb
| `SANDBOX_DIND_INNER_POOL` | nicht gesetzt (automatisch) | Optionaler Adresspool für den inneren Docker-Daemon in Agent-Sessions auf Docker oder Kubernetes. Verwende ein kanonisches privates IPv4-`/16` nach RFC1918 außerhalb deiner Pod-, Service- und VPC-Netze. Die Runtime lehnt Überschneidungen mit erkannten Netzen und Adressen ab. |
| `SANDBOX_EGRESS_MAX_CLIENTS` | `2000` | **Vom Dienst `sandbox-egress` gelesen**, nicht vom Spawner: Erstelle diesen Dienst nach einer Änderung neu. Verbindungen, die der Egress-Proxy für alle Sessions zusammen gleichzeitig bedient; mit transparentem Egress läuft jede ausgehende Verbindung einer Session, ihrer Builds und ihrer Paketinstallationen über ihn. Jenseits der Grenze lehnt der Proxy neue Verbindungen ab, und Installationen und Seitenaufrufe brechen mit zurückgesetzten Verbindungen ab. Jede Verbindung belegt einen Thread und zwei offene Dateien, deshalb bemessen die mitgelieferten Compose-Dateien die Prozess- und Dateigrenzen des Proxys für den Default; ein höherer Wert braucht auch höhere Grenzen, und der Proxy warnt beim Start, wenn seine Grenze für offene Dateien zu niedrig ist. Beim Start hebt der Proxy seine Grenze für offene Dateien auf das an, was die Verbindungen brauchen, so weit die harte Grenze des Containers es erlaubt. Unter Kubernetes setzt du ihn am Egress-Deployment; eine Pod-Spezifikation setzt keine Prozessgrenze, daher muss das `podPidsLimit` des Nodes Platz für einen Thread je Verbindung lassen. |

Die Reaktivierung einer freigegebenen Session durchläuft dieselbe Speicherprüfung auf dem lokalen Host wie eine neue Session. Eine bereits aktive Generation wird nicht erneut angerechnet. Ein Workflow ohne inneres Docker behält die Identität und Werkzeuge seines Agenten, startet aber keinen Docker-Daemon und hält keine Build-Cache-Hilfscontainer aktiv. Als Speichergrenze gilt weiterhin das konfigurierte Agentenlimit des Deployments. Es ist eine Obergrenze, kein reservierter Arbeitsspeicher.

Die Vorbereitung des gemeinsamen Build-Caches darf den Start höchstens 15 Sekunden verzögern, bei einem kürzeren Bereitschafts-Timeout des Runners höchstens ein Viertel davon. Danach startet die Session mit ihrem lokalen Builder. Die weiterhin verwaltete Einrichtung des gemeinsamen Caches läuft für spätere Sessions zu Ende. Die Registry-Mirrors werden parallel vorbereitet. Der gemeinsame Builder führt höchstens vier Build-Schritte gleichzeitig aus; seine CPU- und Speichergrenzen gelten weiterhin.

Bei voller Kapazität kann der Spawner eine freigegebene, nicht angepinnte Session im Leerlauf schon vor Ablauf des Leerlauffensters stoppen, um neue Arbeit zuzulassen, zuerst die am längsten untätige. Der Daemon muss bestätigen, dass keine Arbeit läuft; beschäftigte Sessions und Sessions mit unbekanntem Zustand bleiben geschützt. Das dauerhafte Arbeitsverzeichnis oder Volume bleibt beim Stoppen erhalten. Lässt sich keine Session sicher freigeben, blockiert die Kapazitätsgrenze weiterhin neue Starts. Dasselbe gilt, wenn der freie Speicher des Hosts unter `SANDBOX_MIN_FREE_MEMORY` fallen würde. Solange der Datenträger mit den Arbeitsverzeichnissen der Sessions unter `SANDBOX_MIN_FREE_DISK` liegt, wartet neue Arbeit, ohne dass Sessions im Leerlauf gestoppt werden: Eine gestoppte Session behält ihr Arbeitsverzeichnis.

### Session-Kapazität bemessen
Expand Down
5 changes: 5 additions & 0 deletions docs/en/self-hosted/configuration/environment-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ The sandbox spawner reads the settings below. Pass them into its environment and
| `SANDBOX_MAX_SESSIONS` | sized from host memory on a local Docker host (at least `8`, at most `256`); `8` elsewhere | Maximum running and starting sessions across all organizations on the Docker host or in the Kubernetes namespace, including idle containers kept for reuse. This capacity does not reserve CPU or memory. Unset on a Docker host whose memory the spawner can read, it is sized from that memory: one session per 768 MiB left after `SANDBOX_MIN_FREE_MEMORY`, or per 1.5 GiB where agent sessions run Docker inside the sandbox. If the memory cannot be read at start, the capacity stays `8` until it can. An explicit value fixes it. Concurrent Kubernetes replicas enforce it on a best-effort basis; use ResourceQuota for hard namespace resource bounds. |
| `SANDBOX_MIN_FREE_MEMORY` | a tenth of host memory, at least `1g` | Memory a new session must leave free on a local Docker host, beside what the sessions still starting or just started are about to use. A create that would leave less first stops a released idle session; if memory is still short, the spawner answers busy and the work waits until running sessions free some. Accepts sizes such as `2g` or `1536m`. Has no effect on Kubernetes or with a remote Docker daemon. |
| `SANDBOX_MIN_FREE_DISK` | a twentieth of the disk, at least `2g`, at most `20g` | Free space a new session must leave on the disk that holds the session workspaces on a local Docker host. Below it, the spawner answers busy and the work waits until space is freed; stopping idle sessions would not help, since their workspaces stay for their resume. Meanwhile the spawner removes the build caches of organizations whose build-cache helpers are all stopped and that no session may use, the longest-stopped first and at most three a minute, and pauses for six hours if a removal frees nothing on that disk. Accepts sizes such as `10g` or `4096m`; `0` turns the check off. Has no effect on Kubernetes, where each session's workspace is a volume of a fixed size. |
| `SANDBOX_DOCKER_WORKLOADS` | `project,workflow` | Workloads allowed to use inner Docker when it is enabled for the deployment. Set `project` to keep workflow agents lightweight, `workflow` for the reverse, or `none` to disable both. Applies to newly created sessions; existing sessions keep their capabilities. A session request can opt out with `docker: false`, but cannot enable Docker beyond this allowlist or the deployment setting. |
| `SANDBOX_AGENT_CPUS` | `2` | CPU limit per agent session. Account for overlapping builds and other host workloads when choosing the session count. |
| `SANDBOX_AGENT_MEMORY` | `4g`; `8g` with Docker inside the sandbox | Memory limit per agent session, shared with its inner Docker daemon and nested containers. An explicit value overrides either default and applies to newly created sessions. |
| `SANDBOX_BUILDKITD_CPUS` | `SANDBOX_AGENT_CPUS` | CPU limit of an organization's build-cache helper, which runs the image builds of all its agent sessions when Docker runs inside the sandbox. A running helper takes a new value at once. |
Expand All @@ -260,6 +261,10 @@ The sandbox spawner reads the settings below. Pass them into its environment and
| `SANDBOX_DIND_INNER_POOL` | unset (automatic) | Optional inner Docker address pool for agent sessions on Docker or Kubernetes. Use a canonical RFC1918 IPv4 `/16` outside your Pod, Service and VPC networks. The runtime rejects overlaps with networks and addresses it discovers. |
| `SANDBOX_EGRESS_MAX_CLIENTS` | `2000` | **Read by the `sandbox-egress` service**, not the spawner: recreate that service after a change. Connections the egress proxy serves at once for all sessions together; with transparent egress, every outbound connection of a session, its builds and its package installs goes through it. Past the limit the proxy refuses new connections, and installs and page loads fail with connection resets. Each connection takes a thread and two open files, so the shipped compose files size the proxy's process and open-file limits for the default; a higher value needs them raised too, and the proxy warns at start when its open-file limit is too low. At start the proxy raises its open-file limit to what the connections need, as far as the container's hard limit allows. On Kubernetes, set it on the egress Deployment; a Pod spec sets no process limit, so the node's `podPidsLimit` must leave room for one thread per connection. |

Reactivating a released session uses the same local-host memory admission as creating one. An already active generation is not charged again. A workflow without inner Docker keeps its agent identity and tools, but starts no Docker daemon and does not keep build-cache helpers alive. The memory limit remains the deployment’s configured agent limit; it is a ceiling, not reserved RAM.

Shared build-cache preparation waits at most 15 seconds, or one quarter of the runner readiness timeout if shorter. After that, the session starts with its local builder while the tracked shared setup finishes for later sessions. Registry mirrors are prepared concurrently. The shared builder runs at most four build steps at once; its CPU and memory limits still apply.

At full capacity, the spawner can stop a released, unpinned idle session before the idle timeout to admit new work, starting with the one idle longest. The daemon must confirm that no work is in progress; busy sessions and sessions with unknown state are protected. Stopping compute preserves the persistent workspace directory or volume. If no safe session can be reclaimed, admission remains blocked by the deployment capacity. The same applies when the host's free memory would drop below `SANDBOX_MIN_FREE_MEMORY`. While the disk that holds the session workspaces is below `SANDBOX_MIN_FREE_DISK`, new work waits without stopping idle sessions: a stopped session keeps its workspace.

### Size session capacity
Expand Down
Loading