Repository navigation
feat(sandbox): Sandbox page, scale-to-zero and capacity cap for the Kubernetes backend - #791
Open
thecorporatetractor wants to merge 6 commits into
Open
thecorporatetractor wants to merge 6 commits into
thecorporatetractor wants to merge 6 commits into
Conversation
ARTEX_RUNNER_BACKEND=kubernetes runs each task in a worker pod behind its own egress-proxy pod, created through the Kubernetes API with no container runtime socket. Per-task NetworkPolicies are applied before the pods and removed after them; the runner waits until they are in effect before the first command, runs commands through pods/exec under env -i and artex-exec-wrap, and re-adopts task pods after a restart. Unit tests run against a fake API server; a live test (TestKubeSandboxE2E) drives a deployed runner.
deploy/helm/artex deploys the panel, PostgreSQL and artex-runner with a namespace-scoped Role, default-deny NetworkPolicies and a values schema. A volume-permissions init container restores root ownership of /app/data and /app/keys, fixing the isolation self-test failure on world-writable volumes (BaaRai#620). scripts/k3d-e2e.sh and the kubernetes CI job test it live on k3d.
…ew API The runner gains GET /v1/tasks (same bearer auth) backed by an optional StatusReporter interface, implemented for the Kubernetes backend (one label-selected pod list) and the Docker backend (list + inspect). sandbox.Client gains Tasks(). The panel exposes GET /api/sandbox/overview: sandbox mode, runner health, the runner task list, and per task a bounded tail of the egress audit log. Audit reads go through os.Root, refuse symlinked task directories and log files, and cap the bytes, line length and entry count. The panel still talks to the cluster only through the runner. ValidateTaskID no longer trims: " 42" was accepted by the runner and became a different task from "42". Ids are checked as given; the runner answers 400 and the client refuses before sending.
…rnetes backend The runner scales an idle task to zero after ARTEX_KUBE_IDLE_TIMEOUT: its worker and proxy pods are deleted, the proxy Service, NetworkPolicies and workspace stay, and the next command starts the pods again. ARTEX_KUBE_MAX_ACTIVE caps the tasks with pods: at the cap the least recently used idle task is scaled to zero, otherwise the command waits in arrival order for ARTEX_KUBE_QUEUE_TIMEOUT and fails with 429 sandbox at capacity. Capacity slots: a deleted task holds its slot until its pods are gone, and a start that fails after creating pods deletes them, frees the slot and records a scale_up_failed event. A pod still unschedulable at the ready timeout (a cluster autoscaler adding a node) fails with ErrCapacity (429, the task is not paused) and keeps its pods and slot; the next command reuses pending or ready pods instead of recreating them. If no command comes, the idle reaper removes the pods, and for a start that never succeeded also its Service and policies. GET /v1/tasks and /api/sandbox/overview report per-task scaling state, health, the scope last applied to the proxy NetworkPolicy for tasks scaled to zero (scope_known, scope_source), a summary, the last 100 scale events, totals and cold start p50/p95. With ARTEX_KUBE_STATE_DIR (chart: runner-state on the data volume) events, totals and cold-start samples survive a runner restart. The overview honours ARTEX_AUDIT_ROOT. Chart: sandbox.scaling.*, worker requests, sandbox.nodeSelector, tolerations, priorityClassName, postgres nodeSelector/tolerations and podAnnotations. scripts/capd-autoscaler-e2e.sh tests the official cluster-autoscaler on a Cluster API (CAPD) cluster; the chart README documents the measured timings and recommended values.
System > Sandbox shows the panel, the runner, each task with its worker and egress proxy, and the internet, from /api/sandbox/overview every 3 s. The graph view (xyflow) can be panned and zoomed; links move while a command runs or traffic passes, refused egress goes to a Blocked node, and scaled-to-zero tasks are dimmed. The list view is an operator table with per-task health, scope, policies and recent egress, and is what phones get. Every node and row opens a details drawer. The Scaling section shows capacity against the cap, cold start p50/p95 and trend, per-task idle countdowns and the scale event timeline. The page also fits the Docker backend (which does not scale) and a runner that is down. The topology and summary logic lives in lib/sandbox-topology.ts with node tests (test:sandbox-topology, added to CI). The mock backend serves Kubernetes and Docker overviews, and ?tasks=N for a crowded graph. Strings are translated for tr, vi, zh-CN and pt-BR.
… tech An axe-core audit of System > Sandbox (graph and list, light and dark) found its only violations in the shared shell: the preferences button had no accessible name, the account menu trigger was a span carrying aria-expanded (not allowed on it) without a name, the sidebar logo's alt repeated the product name next to it, and the sidebar content sat outside any landmark. The trigger is now a named button, the settings button is labelled Preferences, the logo is decorative, and the sidebar is a named navigation landmark. The page now has no axe violations.
This was referenced Dec 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
With the Kubernetes backend and the chart, operators cannot see what the sandbox is doing: which tasks have pods, which scope each proxy enforces, what egress was allowed or refused. Every task also keeps its two pods until it is deleted, so an idle task holds node resources forever and nothing bounds how many tasks run at once.
Change
Runner status API and panel overview (
feat(sandbox): read-only task status ...):GET /v1/tasks(same bearer auth), for the Kubernetes backend (one label-selected pod list) and the Docker backend (list + inspect).sandbox.Client.Tasks().GET /api/sandbox/overview: sandbox mode, runner health, the runner's task list, and per task a bounded tail of the egress audit log. Audit reads go throughos.Root, refuse symlinks and cap bytes, line length and entries. The panel still talks to the cluster only through the runner.ValidateTaskIDno longer trims:" 42"was accepted and became a different task from"42".Kubernetes scaling (
feat(sandbox): scale-to-zero, capacity cap and placement ...):sandbox.scaling.idleTimeout(ARTEX_KUBE_IDLE_TIMEOUT, default 15m). Pods are deleted; Service, NetworkPolicies and workspace stay. The next command starts the pods again through the normal readiness and network checks.sandbox.scaling.maxActive(ARTEX_KUBE_MAX_ACTIVE, default 10): the least recently used idle task is scaled to zero, otherwise the command waits in FIFO order forqueueTimeoutand fails with HTTP 429sandbox at capacity(the panel does not pause the task).scale_up_failed.Unschedulableatsandbox.podReadyTimeoutfails with 429 instead of 500. Its pods and slot are kept, and the next command reuses pending or ready pods instead of recreating them. Without a retry, the idle reaper removes them, and for a start that never succeeded also its Service and policies.health,scope_known/scope_source(liveorlast_appliedfrom the proxy NetworkPolicy of a task scaled to zero), asummary, the last 100 scale events, totals, cold start p50/p95.ARTEX_KUBE_STATE_DIR(chart:runner-stateon the data volume) events, totals and cold-start samples survive a runner restart (scaling.json, versioned, atomic, debounced). The overview honoursARTEX_AUDIT_ROOT.sandbox.scaling.*, worker CPU/memory requests,sandbox.nodeSelector/tolerations/priorityClassName, PostgreSQLnodeSelector/tolerations,podAnnotationsfor panel, runner and PostgreSQL (values always quoted).scripts/capd-autoscaler-e2e.sh: the official cluster-autoscaler on a Cluster API (CAPD) cluster with Calico and NFS. The chart README documents the measured timings and recommended values.Sandbox page (
feat(web): Sandbox page under System):lib/sandbox-topology.tswith node tests (test:sandbox-topology, added to CI). Mock data for Kubernetes, Docker, and?tasks=Nfor a crowded graph.App shell a11y (
fix(web): name the app shell's icon buttons ...): an axe-core audit of the page found violations only in the shared shell (unnamed preferences button, account trigger as a span witharia-expanded, redundant logo alt, sidebar outside a landmark). Fixed; the page has no axe violations.Depends on
Depends on #783 (Helm chart), which depends on #780. The diff includes their commits until they merge. Review the last 4 commits.
Tests
Run on this branch before the last rebase onto the updated chart PR. The rebase changed nothing in this PR's own diff except the CHANGELOG context; after it,
go build ./...,go vet ./..., gofmt, andgo test -p 1 ./sandbox ./server ./db ./cmd/...with PostgreSQL were rerun and pass (the new base brings #775 and #779 inserver/db).go build ./...,go vet ./..., gofmt clean, cross-builds for darwin/arm64, darwin/amd64, windows/amd64: OK.go test -race -count=1 ./sandbox ./server ./cmd/...: all OK.go test -p 1 ./...against a throwaway PostgreSQL 16 container: 25 packages OK, 0 failures.biome ci,tsc --noEmit, all 18test:*scripts (including the newtest:sandbox-topology, 46 tests, andtest:i18nwith pt-BR),build:static: all pass.helm lint --strict, chart render tests (placement values, scaling values,runner-statemount),shellcheck -S warningonscripts/k3d-e2e.shandscripts/capd-autoscaler-e2e.sh: clean.-race: FIFO queue, eviction, cap never exceeded under churn, Delete holding its slot until the pods are gone, every failed-start mode releasing its slot, persisted state. A mutation check of the scaling code (27 mutations,go test -race -count=2): 21 killed, 5 survive (late in-flight count, evicting busy or starting tasks, a brief slot release in Delete, a Delete that won the task lock), 1 no longer applies.TestKubeCapacityFailureKeepsPendingPodsAndSlot(pods still unschedulable at the ready timeout keep their slot; the retry reuses them; the reaper removes an abandoned first start with its Service and policies; a queued task can evict them; Delete frees the slot once the pods are gone).TestKubeRetryKeepsPendingPodsandTestKubeFailedStartCleanupFailureKeepsSlotcover the rest.RUNNER_ONLY=1 ARTEX_E2E_INTERNET=1 scripts/k3d-e2e.sh:TestKubeSandboxE2Epassed, 12/12 subtests in 142 s. Scaled to zero 33 s after the last command (idle timeout 30 s), resume cold start 3.6 s, queued exec waited 12.1 s for a slot atmaxActive=2.helm testSucceeded, isolation self-test passed,TestKubeSandboxE2E12/12 in 140 s.runner-state/scaling.jsonwas written on the data volume.kubectl rollout restart(state-persist-across-runner-restart.txt).GET /v1/tasks(docker-v1-tasks.json): scaling reported as unsupported.scripts/capd-autoscaler-e2e.sh: helm test andTestKubeSandboxE2E12/12 on Calico; a burst of 6 tasks scaled a tainted task pool from 0 to 3 nodes, 6/6 commands ran (cold start p50 111.6 s, p95 113.1 s); task pods gone 63 s after the burst (idle timeout 60 s), pool back to 0 machines after 186 s; resume from a zero-node pool kept the workspace and isolation (106 s); withReadWriteOncethe autoscaler did not scale up and 3 of 5 commands got HTTP 429. A task scaled to zero reports its last-applied scope after a runner restart. These runs used the runner before the slot-accounting merge; the merged behaviour for unschedulable pods (pods and slot kept, retry reuses them) is the one those runs exercised.Screenshots
Kubernetes, graph view:
List view:
Scaling section and details drawer:
Phone:
Docker backend:
Runner down:
Notes
DELETE /v1/tasks/{id}still answers 500 onmainbecause the worker container stays attached to the task network. This PR does not include a fix: fix(sandbox): remove the worker container in Delete #778 (and fix(sandbox): remove workers on failed execs and task deletion #764) fix it.sidequestionhas a pre-existing flaky test that also fails onmain; it is not touched here.ReadWriteOncedata volume every task pod is pinned to the runner's node, so a cluster autoscaler cannot help. UseReadWriteManyon autoscaled clusters (documented).Part of #781.