Skip to content

P6: add a Docker Compose deployment for a quick, no-root dev-machine trial (supervisor + relay + redis) #342

Closed

Description

@pdettori

Summary

P6 already has a production deployment story with no Kubernetes: deploy/vm/setup-vm.sh installs sh-supervisor and sh-relay as systemd units (bare node --import tsx processes) with Redis and the sandbox containers run via podman alongside them (deploy/vm/README.md:1-11). That path requires root, systemd, a harness system user, and a built checkout on the target machine — reasonable for a dedicated VM or bare metal, wrong for "let me try this on my laptop in five minutes."

This issue adds a second, additive deployment path — deploy/compose/ — that runs the same three long-running components (supervisor, relay, redis) via Docker Compose, fronted by a curl | sh-style bootstrap script, for the dev-machine trial case described in the RA1 rearchitecture design (docs/specs/2026-09-24-ra1-density-cutover-and-repo-rearchitecture-design.md). It does not replace or modify deploy/vm/, which remains the production path.

Compose is the right tool here specifically because P6 is already "no Kubernetes" and substrate-neutral below the process-manager line (P6 spec §2.1) — this issue containerizes processes that already run as bare processes (or podman, for Redis) in deploy/vm/, it does not re-architect anything.

The one hard constraint — read before writing the compose file

sh-supervisor spawns its worker pool with child_process.fork() (packages/supervisor/src/main.ts:58, packages/supervisor/src/pool.ts:145,327). fork() creates a child of the calling process, in the same PID namespace — it cannot create a process in a different container. This is also why ADR-0034 describes accepted-socket handoff as IPC between supervisor and worker, not a network call.

Consequence: the supervisor and its entire worker pool (SH_WORKERS processes) must run inside one container. Do not attempt "one worker per container," a sidecar-per-worker pattern, or anything that tries to scale W by adding containers — W is scaled via SH_WORKERS inside the single supervisor container, exactly as it is today on the VM path. If more throughput is wanted than one container's CPU allocation supports, scale by running additional replicas of the whole supervisor container (each an independent supervisor with its own worker pool, its own port, behind whatever fronts them), not by decomposing one supervisor's pool.

This depends softly on #341 (fixing SH_WORKERS's cgroup-blind default) — until that lands, operators must set SH_WORKERS explicitly in the compose file rather than relying on the auto-detected default to respect deploy.resources.limits.cpus. Not a hard blocker; just don't assume the default is container-aware yet.

Deliverables

  • deploy/compose/docker-compose.yml with three services:
    • redis (official image, matching whatever deploy/vm/setup-vm.sh's start_redis() pins)
    • sandbox-relay (from packages/sandbox-relay), env mirroring deploy/vm/env/relay.env.example (SH_RELAY_PORT, REDIS_URL, SH_RELAY_TOKEN)
    • supervisor (from packages/supervisor), env mirroring deploy/vm/env/supervisor.env.example (SH_WORKERS, SH_TURNS_PER_WORKER, SH_ROUTING_POLICY, SH_SANDBOX_DISCOVERY=records, SH_REMOTE_SANDBOX=1, SH_RELAY_ADDR, REDIS_URL, KAGENTI_SANDBOX_POOL_SELECTOR, KAGENTI_SANDBOX_CAP) — note SH_RELAY_ADDR must point at the sandbox-relay service name, not 127.0.0.1, since these are now separate containers on a compose network
    • SH_RELAY_PORT (relay's bind port) and the supervisor's SH_RELAY_ADDR port must still agree, same footgun the relay.env.example comment already flags for the VM path
  • A Dockerfile (or a multi-stage Dockerfile with per-package targets) building packages/sandbox-relay and packages/supervisor — needs pi-fork built first per the existing prerequisite (deploy/vm/README.md's "Prerequisites"); decide at implementation time whether the image build does this or requires a pre-built context
  • deploy/compose/install.sh: a curl -fsSL .../install.sh | sh-style bootstrap that fetches the compose file + a generated .env (prompting for/generating SH_RELAY_TOKEN, since relay token validation is fail-closed per relay.env.example) and runs docker compose up -d
  • deploy/compose/README.md documenting the trial flow, explicitly cross-linking to deploy/vm/README.md as "the production path" so the two don't get confused

Test plan (write these first, mirroring deploy/vm/tests/setup-vm.test.sh's approach)

  1. A mocked test for install.sh in the same style as setup-vm.test.sh: mock docker/docker compose onto PATH, source or run the script, assert on recorded argv and generated .env/compose file content — in particular assert SH_RELAY_TOKEN is passed by env/file, never appears in argv (same secret-handling check setup-vm.test.sh does for SANDBOX_TOKEN via MOCK_ENV_LOG)
  2. A static check on docker-compose.yml that there is exactly one service definition owning the supervisor's worker pool (i.e., the compose file itself can't regress into a per-worker-container topology) — e.g. assert there's one supervisor service and no per-worker replica count applied to it that the fork()-based pool doesn't itself manage
  3. If Docker is available in CI/dev sandbox: an end-to-end smoke test — docker compose up -d, poll the supervisor's health/admin port, confirm it reports workers > 0, confirm a trivial turn reaches the relay and Redis, docker compose down. Gate this behind an env var the way M3_LIVE_SMOKE gates other live tests (per this repo's Testing conventions), since it needs Docker on the runner.

Acceptance

  • deploy/vm/ is untouched
  • deploy/compose/docker-compose.yml runs supervisor+worker-pool as one service/container; no per-worker container scheme
  • Env surface mirrors deploy/vm/env/*.env.example var-for-var, with only the addressing changed (service names instead of 127.0.0.1)
  • install.sh never puts SH_RELAY_TOKEN on a process argv; mocked test proves it
  • deploy/compose/README.md cross-links deploy/vm/README.md and states which path is for production vs. trial
  • A real docker compose up (manual or gated smoke test) reaches a working /turn against a stub sandbox

Out of scope

Related: P6 spec (docs/specs/2026-09-08-p6-vm-process-manager-design.md), ADR-0034, deploy/vm/README.md, RA1 design (docs/specs/2026-09-24-ra1-density-cutover-and-repo-rearchitecture-design.md), #341.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions