Skip to content

Local development

voxix edited this page Nov 4, 2026 · 15 revisions

Local development

Python services

uv sync
cp .env.example .env
docker compose up -d --wait db
uv run --env-file .env alembic upgrade head
uv run --env-file .env pytest
uv run --env-file .env uvicorn agent.server:app --port 8001 &   # the fake agent, AGENT_URL in .env
uv run --env-file .env uvicorn api.main:app --reload            # http://localhost:8000

Or run the API and one agent in containers next to the database: podman compose up -d --build api (also on localhost:8000; it applies the migrations on start). Docker works the same.

.env has two Context API settings. CONTEXT_TOKEN_SECRET signs the agent's tokens (at least 32 characters, for example openssl rand -hex 32); compose refuses to start the API without it. CONTEXT_API_URL is where the agent reaches the API (http://localhost:8000; compose sets http://api:8000). Leave it empty and the agent gets no Context API and works from the task text. The API on the host cannot be reached from the actors on kind, so deploy/local/compose.yaml leaves it empty there.

Ports taken? API_PORT moves the API for compose and pnpm dev. DB_PORT moves Postgres; change the port in .env too. /health says the process is up; /ready also checks the database, and is what the compose healthcheck uses.

Tests create and drop their own database on TEST_DATABASE_URL. Without the env file the database tests are skipped.

Web app

See apps/web/README.md. pnpm dev serves on localhost:5173 and proxies /api/** to the API on localhost:8000. pnpm e2e runs the Playwright tests against that API (CI runs them against the compose api service). The fake agent takes 10 s a round, so they run in parallel and take about two minutes. They are timing sensitive: don't build images at the same time.

Auth

Use the Firebase Auth Emulator for local accounts:

firebase emulators:start --only auth --project demo-justpass

In .env: FIREBASE_PROJECT_ID=demo-justpass, FIREBASE_AUTH_EMULATOR_HOST=localhost:9099. The API refuses emulator mode with a non-demo-* project ID.

Substrate on kind

Agents run as Substrate actors on a local kind cluster (rootless podman works).

source deploy/local/env.sh
  • env.sh sets KUBECONFIG=~/.kube/substrate-kind.yaml (never ~/.kube/config) and ATE_INGRESS_ALLOWED_SPIFFE_IDS, the clients the atenet router accepts.
  • Machine-specific settings (container runtime, Go location) go in deploy/local/env.local.sh, which is not committed.
  • Build the cluster with Substrate's quickstart (hack/create-kind-cluster.sh in the Substrate repo). Images go to the local registry at localhost:5001.
  • Only Substrate and the agents run on the cluster. The API and Postgres run in podman next to it, as production has them on Cloud Run and Cloud SQL.
  • deploy/local/deploy.sh builds the agent image, applies the worker pool with kubectl apply -k deploy/local, creates the atespace, access policy and actor template in ate-api with uv run python -m api.substrate_sync, and starts the API with compose.yaml plus deploy/local/compose.yaml. Run it again after a change: each agent image or size gets a new template, because templates are immutable, and the unchanged parts stay as they are. Set CONTAINER_TOOL=podman in env.local.sh with rootless podman. kubectl ate must be on PATH (~/go/bin) for e2e.sh.
  • Agent sizing: the worker pool (deploy/substrate/agent-pool.yaml, a kustomize base) and the template (deploy/substrate/agents.yaml, which also holds the atespace and access policy) are plain files, with no templating. The sandbox must fit inside its worker, and a unit test fails if the two drift apart. The local overlay deploy/local/kustomization.yaml only sets the worker image to a tag in the local registry: Substrate accepts any non-empty workerImage.
  • substrate_sync needs an owner: creating an atespace takes global owner, and its access policy atespace owner, while the API's own identity is only an editor. deploy.sh mints a 10-minute token for ate-client, a bootstrap owner of the kind cluster, and deletes it afterwards. A changed access policy is replaced (with the stored uid and version as preconditions); a template is never changed. In production this would run in CI as an identity in ate-api's bootstrap owners; that is not built yet.
  • deploy/local/identity.sh gives the API the identity homework/api with no pod: a service account token for ate-api, and a client certificate for the router from a PodCertificateRequest. They last 24 hours; rerun it after that, and the API picks them up without a restart. The files, with a private key, stay in the git-ignored deploy/local/.identity/.
  • deploy/local/forward.sh keeps port-forwards to ate-api (8443) and the router (9443) up, on 127.0.0.1 only. deploy.sh starts it. The API uses the host network to reach them, and binds to 127.0.0.1 itself, so nothing reaches the LAN.
  • deploy/local/e2e.sh sends jobs through the API and checks each job's actor: 10 s to the answer, suspended, feedback wakes it, accepted deletes it, and four jobs at once on two workers.
  • The router only accepts mTLS. deploy/local/router-client.yaml runs a debug pod with the API's identity (spiffe://cluster.local/ns/homework/sa/api); its header shows the curl to call an actor.
  • Actor commands: kubectl ate create actor ..., kubectl ate suspend actor ... --mode=sync; the next request resumes it.
  • On Linux, if Envoy crashes on inotify, raise fs.inotify.max_user_instances=1024 and fs.inotify.max_user_watches=524288.
  • After a host reboot, start the registry, the kind node and the buildx builder containers again. Pods get new IPs but workers keep the ones they registered, so every request to an actor fails with a 503 and UF,URX in the router's Envoy log. Recreate the workers: kubectl -n justpass-agents delete pod -l ate.dev/worker-pool=agent.

Clone this wiki locally