2.5 KiB
Agent Focus: Den Service + Polar Gate
This guide explains how agents should operate, test, and troubleshoot the Den service.
What this service does
- Handles auth (
/api/auth/*) and session lookup (/v1/me). - Creates workers (
/v1/workers) and provisions cloud workers on Render or Daytona. - Optionally enforces a Polar paywall for cloud worker creation.
Core flows to test
1) Auth flow
POST /api/auth/sign-up/emailGET /v1/meusing cookie sessionGET /v1/meusing Bearer token from sign-up response
Expected: all succeed with 200.
2) Cloud worker flow (no paywall)
Set POLAR_FEATURE_GATE_ENABLED=false.
POST /v1/workerswithdestination="cloud"- Confirm
instance.providermatches the configured cloud provisioner (renderordaytona) - Poll
instance.url + "/health"
Expected: worker creation 202, worker health 200 after async provisioning finishes.
3) Cloud worker flow (paywall enabled)
Set all Polar env vars and POLAR_FEATURE_GATE_ENABLED=true.
For a user without entitlement:
POST /v1/workerswithdestination="cloud"
Expected:
402 payment_required- response contains
polar.checkoutUrl
For an entitled user (has the required Polar benefit):
POST /v1/workerswithdestination="cloud"
Expected: worker creation 202 with a healthy cloud-backed instance once provisioning completes.
Required env vars (summary)
- Base:
DATABASE_URL,BETTER_AUTH_SECRET,BETTER_AUTH_URL - Optional social auth:
GITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET,GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET - Render:
PROVISIONER_MODE=render,RENDER_API_KEY,RENDER_OWNER_ID, andRENDER_WORKER_* - Daytona:
PROVISIONER_MODE=daytona,DAYTONA_API_KEY, and optionalDAYTONA_*sizing/mount settings - Polar gate:
POLAR_FEATURE_GATE_ENABLEDPOLAR_ACCESS_TOKENPOLAR_PRODUCT_IDPOLAR_BENEFIT_IDPOLAR_SUCCESS_URLPOLAR_RETURN_URL
Deployment behavior
dev is the production branch for this service. Workflow:
.github/workflows/deploy-den.yml
It updates Render env vars and triggers a deploy for the configured service ID. Release snapshot publishing now calls it after a successful Daytona snapshot push so Den picks up the new DAYTONA_SNAPSHOT value.
Common failure modes
provisioning_failed: Render deploy failed, Daytona sandbox boot failed, or worker health check timed out.payment_required: Polar gate is enabled and user does not have the required benefit.- startup error: paywall enabled but missing Polar env vars.