networks:
  executor-network:
    name: executor-network
    driver: bridge
  claw-control:
    driver: bridge
    internal: true

services:
  executor-tdx:
    restart: always
    image: ritualnetwork/executor-go:7929fd8-0e66c99-amd64@sha256:2ff80a98f0c1e26a0da1f0cc5f2c2d238bc0d47fdde7f028ab030ead68165734
    container_name: executor-tdx-460
    labels:
      - "com.ritual.tee-type=TDX"
      - "com.ritual.executor-index=460"
      - "com.ritual.machine-id=prod-mainnet-http-eemshaven-460"
      - "com.ritual.sidecar-type=executor-http-gcp-mkosi"
      - "com.ritual.deployment-type=gcp-mkosi"
    ports:
      - "3000:3000"
      - "3001:3001"
      - "8082:8082"
    environment:
      - ENVIRONMENT=production
      - HOST=0.0.0.0
      - PORT=3000
      - HEALTH_PORT=3001
      - LOG_LEVEL=DEBUG
      - TEE_TYPE=TDX
      - ENCLAVE=true
      - SERVICE_ENDPOINT=http://34.90.183.59:3000
      - EXECUTOR_INDEX=460
      - PAYMENT_ADDRESS=0x486Ecc40E3dCfB1f970E9Ab956d6b2222FA7D90e
      - CHAIN_ID=784
      - TRUSTED_READ_RPC_URL=https://34.76.33.139
      - TRUSTED_READ_WS_URL=wss://34.76.33.139
      - RPC_CERT_HASH=0x4c4dddd5049e3ac027eaea752da1de68b291a3815e621cc80b2ad22962b4f74e
      - MULTICAST_URLS=http://34.76.33.139:8545,http://35.194.242.142:8545,http://34.150.111.50:8545,http://35.200.82.150:8545,http://34.64.223.253:8545,http://34.126.113.192:8545,http://35.198.109.151:8545,http://8.229.26.0:8545,http://34.24.211.238:8545,http://34.27.58.217:8545,http://34.93.103.8:8545,http://34.7.18.167:8545,http://34.47.187.208:8545,http://34.26.117.85:8545,http://34.179.183.215:8545,http://35.192.225.30:8545,http://8.229.89.134:8545,http://35.190.131.81:8545,http://136.119.186.28:8545,http://35.252.144.186:8545
      - PINATA_API_URL=https://api.pinata.cloud
      - PINATA_GATEWAY_URL=https://gateway.pinata.cloud/ipfs
      - IPFS_API_URL=
      - IPFS_GATEWAY_URL=
      - TEE_SERVICE_REGISTRY_CONTRACT_ADDRESS=0xf4495DC72143D44A93AB0ecE4d6D63a216b27839
      - ASYNC_JOB_TRACKER_CONTRACT_ADDRESS=0xf00385449fD961925A0B125F5f30b29B682D4bFb
      - SECRETS_ACCESS_CONTROL_CONTRACT_ADDRESS=0x0cEae62e2082829226eF5821Bb662483Db17A71F
      - AGENT_HEARTBEAT_CONTRACT_ADDRESS=0xDeeA4Df0C958966ED75570a05430BB0D4844a8cc
      - AGENT_IDENTITY_REGISTRY_CONTRACT_ADDRESS=0x2cbF50F833a3AEfb5c5B27068052cB5585F5c087
      - STREAMING_SUBMISSION=true
      - RESULT_SUBMISSION_INTERVAL=0.1
      - VALIDATOR_PREDICTION_UPDATE_INTERVAL=10
      - SKIP_ENDPOINT_VERIFICATION=false
      - JOB_PUSH_DEBUG=false
      - ALLOW_INSECURE_STREAMING=false
      - PII_ENABLED=true
      - PII_SERVICE_URL=http://pii-service:5002
      - PII_REQUEST_TIMEOUT=30
      - CLAW_SPAWNER_URL=http://claw-spawner:8000
      - CLAW_SPAWNER_API_TOKEN=${CLAW_SPAWNER_API_TOKEN}
      - EXECUTOR_INTERNAL_HOSTNAME=executor-tdx
      - PERSISTENT_AGENT_MAX_INFLIGHT_REQUESTS=4
      - PERSISTENT_AGENT_SPAWN_QUEUE_DEPTH=16
      - PERSISTENT_AGENT_SPAWN_QUEUE_WAIT_TIMEOUT_SECONDS=60
      - PERSISTENT_AGENT_SPAWN_HTTP_TIMEOUT_SECONDS=900
      - SOVEREIGN_AGENT_CONTAINER_MEMORY_LIMIT=3g
      - SOVEREIGN_AGENT_CONTAINER_CPU_LIMIT=1
      - SOVEREIGN_AGENT_MAX_CONCURRENT_ACTIVE=1
    volumes:
      - /dev/tdx_guest:/dev/tdx_guest:rw
      - /sys/kernel/config:/sys/kernel/config:rw
      - /etc/tdx-attest.conf:/etc/tdx-attest.conf:ro
      - /sys/firmware/acpi/tables/data/CCEL:/sys/firmware/acpi/tables/data/CCEL:ro
    devices:
      - /dev/tdx_guest:/dev/tdx_guest
      - /dev/tpm0:/dev/tpm0
      - /dev/tpmrm0:/dev/tpmrm0
    privileged: true
    security_opt:
      - seccomp:unconfined
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://localhost:3001/healthz"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 30s
    networks:
      - executor-network
    depends_on:
      pii-service:
        condition: service_healthy
      claw-spawner:
        condition: service_started

  # PII Redaction Service for sanitizing PII in requests/responses
  # Uses 4 uvicorn workers to handle concurrent requests (spaCy NER is CPU-bound)
  # Handles: http_call_pii, llm_call_pii, long_running_echo_pii
  pii-service:
    restart: always
    logging:
      driver: "json-file"
      options:
        max-size: "50m"
        max-file: "3"
    image: ritualnetwork/ritual-pii:7929fd8-0e66c99-amd64@sha256:7779a257fc54873c2d77f4373163a877f4085ef235c937283647148b64c0edaa
    container_name: pii-service
    command: ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "5002", "--workers", "4"]
    ports:
      - "5002:5002"
    environment:
      - LOG_LEVEL=INFO
    healthcheck:
      test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:5002/health')"]
      interval: 10s
      timeout: 5s
      retries: 3
      start_period: 30s
    networks:
      - executor-network

  docker-socket-proxy:
    image: ritualnetwork/docker-socket-proxy:v0.4.2-2f04313-563c266-amd64@sha256:5c6ece5b10393237ad5ce264a06496d8bc41345be19d61eb6744dbce2cac7994
    container_name: docker-socket-proxy
    restart: unless-stopped
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "1"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      - CONTAINERS=1
      - NETWORKS=1
      - POST=1
      - IMAGES=0
      - VOLUMES=0
      - EXEC=1
      - AUTH=0
      - SECRETS=0
      - SWARM=0
      - BUILD=0
    networks:
      - claw-control

  claw-spawner:
    image: ritualnetwork/claw-spawner:563c266-amd64@sha256:836eae3b994b60b0c08bedd212dfa64d04625e12f87ccf9c1292ccde8316d261
    container_name: claw-spawner
    restart: unless-stopped
    depends_on:
      - docker-socket-proxy
    logging:
      driver: "json-file"
      options:
        max-size: "1g"
        max-file: "1"
    ports:
      # Loopback-only for on-VM operator tooling (scripts/tee/claw_spawner_health_summary.py via SSH); do not expose externally.
      - "127.0.0.1:8123:8000"
    volumes:
      - /var/log/claw-spawner:/var/log/claw-spawner
      # Read-only cgroup v2 view for agent-container OOM diagnostics.
      - /sys/fs/cgroup:/sys/fs/cgroup:ro
    environment:
      - DOCKER_HOST=tcp://docker-socket-proxy:2375
      - SPAWNER_API_TOKEN=${CLAW_SPAWNER_API_TOKEN}
      - PINATA_API_URL=https://api.pinata.cloud
      - PINATA_GATEWAY_URL=https://gateway.pinata.cloud/ipfs
      - IPFS_API_URL=
      - IPFS_GATEWAY_URL=
      - SPAWNER_HOST=0.0.0.0
      - SPAWNER_PORT=8000
      - SPAWNER_INTERNAL_URL=http://claw-spawner:8000
      - OPENCLAW_IMAGE=ritualnetwork/zeroclaw-instance:502b5f2-563c266-amd64@sha256:1d2b2298e72f3503c060ca933f804f0c2d0c92d2a87feb99e90d7f7e14b043d2
      - AGENT_INSTANCE_IMAGE=ritualnetwork/zeroclaw-instance:502b5f2-563c266-amd64@sha256:1d2b2298e72f3503c060ca933f804f0c2d0c92d2a87feb99e90d7f7e14b043d2
      - 'AGENT_RUNTIME_IMAGES={"1":"ritualnetwork/openclaw-instance:563c266-amd64@sha256:06237d4b67195d095959b08bcf06d7ccc72f5b29e82406f716bc7374e01ae856","2":"ritualnetwork/hermes-instance:f90a8c9-563c266-amd64@sha256:eda1412b8cb693daa17b8b9636a47a0f002cac782e87cbd47e8416cce07bee91"}'
      - EXEC_CONTAINER_DEFAULT_IMAGE=ritualnetwork/sovereign-agent:563c266-amd64@sha256:a7e7c0186c8c3569935eba1d94e9b4d50f90e3471333c1ebcacffd050f7f89f1
      - DOCKER_NETWORK=executor-network
      - 'AGENT_INTERNAL_SERVICE_CONTAINERS={}'
      - 'AGENT_EXECUTOR_SERVICE_CONTAINERS={"executor-tdx":"executor-tdx-460"}'
      - PORT_RANGE_START=18790
      - PORT_RANGE_END=18890
      - INSTANCE_RESTART_POLICY=no
      - LOCAL_DEV_MODE=false
      - MAX_EXEC_CONTAINERS=500
      - DA_SYNC_MAX_FILE_BYTES=67108864
      - DA_SYNC_MAX_BYTES=268435456
      - DA_SYNC_MAX_FILES=500
      - DA_SYNC_CRITICAL_FILE_MAX_BYTES=2147483648
      - DA_SYNC_WORKSPACE_MAX_FILES=200
      - DA_SYNC_WORKSPACE_MAX_BYTES=104857600
      - RESTORE_MAX_CONCURRENT_DOWNLOADS=4
      - RESTORE_MAX_MANIFEST_BYTES=4194304
      - AGENT_INSTANCE_MEMORY_RESERVATION=1g
      - AGENT_STARTUP_MEMORY_LIMIT=1280m
      - AGENT_STEADY_MEMORY_LIMIT=1280m
      - AGENT_MEMORY_STABILIZATION_DELAY_SECONDS=60
      - AGENT_MEMORY_TRANSITION_RETRY_DELAY_SECONDS=30
      - AGENT_STEADY_MEMORY_HEADROOM=512m
      - AGENT_SIDECAR_GOMEMLIMIT=1GiB
      - MAX_PERSISTENT_AGENTS_PER_NODE=8
      - MAX_CONCURRENT_AGENT_STARTS=1
      - AGENT_LIMIT_BUDGET=10g
      - AGENT_HOST_MEMORY_RESERVE=2g
      - AGENT_START_QUEUE_TIMEOUT_SECONDS=120
      - AGENT_CAPACITY_RECHECK_INTERVAL_SECONDS=1
      - HERMES_SESSION_RETENTION_DAYS=30
      - DEAD_CONTAINER_LOG_DIR=/var/log/claw-spawner/agent-exits
      - DEAD_CONTAINER_LOG_TAIL_LINES=400
      - AGENT_HEARTBEAT_CONTRACT_ADDRESS=0xDeeA4Df0C958966ED75570a05430BB0D4844a8cc
      - MULTICAST_URLS=http://34.76.33.139:8545,http://35.194.242.142:8545,http://34.150.111.50:8545,http://35.200.82.150:8545,http://34.64.223.253:8545,http://34.126.113.192:8545,http://35.198.109.151:8545,http://8.229.26.0:8545,http://34.24.211.238:8545,http://34.27.58.217:8545,http://34.93.103.8:8545,http://34.7.18.167:8545,http://34.47.187.208:8545,http://34.26.117.85:8545,http://34.179.183.215:8545,http://35.192.225.30:8545,http://8.229.89.134:8545,http://35.190.131.81:8545,http://136.119.186.28:8545,http://35.252.144.186:8545
      - TRUSTED_READ_RPC_URL=https://34.76.33.139
      - TRUSTED_READ_WS_URL=wss://34.76.33.139
      - RPC_CERT_HASH=0x4c4dddd5049e3ac027eaea752da1de68b291a3815e621cc80b2ad22962b4f74e
      - RITUAL_WALLET_CONTRACT_ADDRESS=0xF04076756d8129Baec46Dc0F1c526Baec490C393
    networks:
      - executor-network
      - claw-control

  prepull-runtime-0:
    image: ritualnetwork/hermes-instance:f90a8c9-563c266-amd64@sha256:eda1412b8cb693daa17b8b9636a47a0f002cac782e87cbd47e8416cce07bee91
    restart: "no"
    entrypoint: ["true"]
    network_mode: none

  prepull-runtime-1:
    image: ritualnetwork/openclaw-instance:563c266-amd64@sha256:06237d4b67195d095959b08bcf06d7ccc72f5b29e82406f716bc7374e01ae856
    restart: "no"
    entrypoint: ["true"]
    network_mode: none

  prepull-runtime-2:
    image: ritualnetwork/sovereign-agent:563c266-amd64@sha256:a7e7c0186c8c3569935eba1d94e9b4d50f90e3471333c1ebcacffd050f7f89f1
    restart: "no"
    entrypoint: ["true"]
    network_mode: none

  prepull-runtime-3:
    image: ritualnetwork/zeroclaw-instance:502b5f2-563c266-amd64@sha256:1d2b2298e72f3503c060ca933f804f0c2d0c92d2a87feb99e90d7f7e14b043d2
    restart: "no"
    entrypoint: ["true"]
    network_mode: none
