Files
agents-marketplace/deploy/mainnet/docker-compose.gateway.yml
david 2f7b0194a5 feat(supplier,gateway,buyer): N-slot chat suppliers + entry-ticket settle mode
Two structural fixes for demo concurrency (3 single-slot suppliers thrashed
under Open WebUI's ~3 conversations per message):

Multi-slot suppliers (MAX_CHAT_SESSIONS, default 1):
- SupplierState is now capacity-aware: a Set of active escrow refs with
  free-until-full status semantics, ref-scoped release(ref) (also fixes the
  latent bug where handler catch-alls released another request's slot), and
  a walletMutex serializing every wallet-spending chain op — Claim, Submit,
  and wallet-health consolidation queue instead of racing the single
  working/collateral UTxO. /status gains active_sessions/max_sessions.

Entry-ticket settle mode (CHAT_SETTLE_MODE=ticket, default full, both sides):
- The buyer's escrow post at session open is the ONLY chain op. The supplier
  verifies the Open escrow as an entry ticket but never Claims/Submits
  (/v1/chat/start → {status:"ticket"}; /v1/chat/end → receipt-less
  {status:"ended"}); no hard-cap timer, so sessions may outlive deliver_by.
  Used tickets can't reopen sessions (records retained; 409 session_exists).
- Buyer SDK: startChat/endChat are settle-mode aware, driven by the
  supplier's response — mixed-mode rollout windows settle correctly.
- Gateway: ticket closes bill cost 0; the sweeper Reclaims Open tickets
  after deliver_by WITHOUT closing live sessions (the conversation and its
  affinity mirror survive their reclaimed ticket), gates reclaims on
  deliver_by, and keeps an in-process settled-refs memory so terminal
  indexer rows aren't retried every sweep forever.

Deployment (kimi-chat trio + gateway): ticket mode, 8 slots per supplier,
idle policy gateway 10 min / supplier 15 min (fixes the inversion where the
supplier idle-closed before the gateway janitor).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-09 20:48:52 +02:00

81 lines
3.1 KiB
YAML

# deploy/mainnet/docker-compose.gateway.yml — OpenAI-compatible Gateway — MAINNET
#
# Multi-tenant, custodial OpenAI gateway. Each API key is its own buyer wallet;
# every request posts an on-chain escrow from that user's wallet. See docs/gateway.md.
#
# Secrets live in gateway/.env (NOT committed):
# GATEWAY_MASTER_KEY=<openssl rand -hex 32> # losing this locks ALL user funds
# Back up BOTH gateway/.env (the master key) AND the gateway-mainnet-data volume
# (the gateway.db holds every user's encrypted wallet key + usage).
name: marketplace-mainnet-gateway
services:
gateway:
build:
context: ../..
dockerfile: gateway/Dockerfile
container_name: marketplace-mainnet-gateway
restart: unless-stopped
env_file:
- path: ../../gateway/.env
required: true
environment:
INDEXER_URL: http://marketplace-mainnet-indexer:8090
OGMIOS_URL: https://ogmios.vector.mainnet.apexfusion.org
LIVE_CHAIN: "1"
NETWORK_ID: "1"
GATEWAY_PORT: "8080"
GATEWAY_DB_DIR: /repo/data/gateway
# Mainnet chain genesis (slot↔wallclock). MUST match buyer/supplier or
# PostEscrow validity bounds land ~51 days off and Ogmios rejects (code 3118).
VECTOR_ZERO_TIME_MS: "1756485600000"
# On-chain reference-script UTxOs (escrow spending validator) used by
# Accept/Reclaim/Submit. Same values the buyer/suppliers use on mainnet.
ESCROW_REF_UTXO: c8d84c6d67ec67a1efe5e9c6c06d53020e05d1bb96d1c55ecb1eb7d5010c4d54#0
ADVERT_REF_UTXO: c8d84c6d67ec67a1efe5e9c6c06d53020e05d1bb96d1c55ecb1eb7d5010c4d54#1
# Browser Origins allowed to call the gateway cross-origin. The buyer
# frontend's "API Keys" page (served from marketplace.vector…) POSTs to
# /signup here. Comma-separated; empty disables CORS entirely.
GATEWAY_CORS_ORIGINS: https://marketplace.vector.apexfusion.org
# Ticket mode: the escrow post at session open is the only chain op;
# the sweeper reclaims Open escrows after deliver_by. Must match the
# kimi-chat suppliers' CHAT_SETTLE_MODE.
CHAT_SETTLE_MODE: ticket
# Demo janitor closes idle sessions BEFORE the suppliers' 15 min
# CHAT_IDLE_TIMEOUT_MS backstop.
DEMO_SESSION_IDLE_MS: "600000"
volumes:
- gateway-mainnet-data:/repo/data/gateway
healthcheck:
test: ["CMD-SHELL", "wget -qO- http://localhost:8080/healthz >/dev/null || exit 1"]
interval: 20s
timeout: 5s
retries: 3
start_period: 15s
networks:
- marketplace-mainnet-net
- traefik-net
labels:
- "traefik.enable=true"
- "traefik.docker.network=traefik-net"
- "traefik.http.routers.mp-gateway-mainnet.entrypoints=web"
- "traefik.http.routers.mp-gateway-mainnet.rule=Host(`api.marketplace.vector.apexfusion.org`)"
- "traefik.http.services.mp-gateway-mainnet.loadbalancer.server.port=8080"
logging:
driver: json-file
options:
max-size: "10m"
max-file: "3"
networks:
marketplace-mainnet-net:
external: true
name: marketplace-mainnet-net
traefik-net:
external: true
name: traefik-net
volumes:
gateway-mainnet-data: