Repository navigation
Local development
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.
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.
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.
Agents run as Substrate actors on a local kind cluster (rootless podman works).
source deploy/local/env.sh
-
env.shsetsKUBECONFIG=~/.kube/substrate-kind.yaml(never~/.kube/config) andATE_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.shin the Substrate repo). Images go to the local registry atlocalhost: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.shbuilds the agent image, applies the worker pool withkubectl apply -k deploy/local, creates the atespace, access policy and actor template in ate-api withuv run python -m api.substrate_sync, and starts the API withcompose.yamlplusdeploy/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. SetCONTAINER_TOOL=podmaninenv.local.shwith rootless podman.kubectl atemust be onPATH(~/go/bin) fore2e.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 overlaydeploy/local/kustomization.yamlonly sets the worker image to a tag in the local registry: Substrate accepts any non-emptyworkerImage. -
substrate_syncneeds 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.shmints a 10-minute token forate-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.shgives the API the identityhomework/apiwith 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-ignoreddeploy/local/.identity/. -
deploy/local/forward.shkeeps port-forwards to ate-api (8443) and the router (9443) up, on127.0.0.1only.deploy.shstarts it. The API uses the host network to reach them, and binds to127.0.0.1itself, so nothing reaches the LAN. -
deploy/local/e2e.shsends 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.yamlruns 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=1024andfs.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,URXin the router's Envoy log. Recreate the workers:kubectl -n justpass-agents delete pod -l ate.dev/worker-pool=agent.