{"slug":"architecture/TWIN_DEPLOYMENT_STATUS","title":"Twin + OpenRouter Deployment Status","section":"architecture","sectionLabel":"Architecture","status":"unclassified","type":"document","path":"architecture/TWIN_DEPLOYMENT_STATUS.mdx","bytes":6624,"description":null,"updated":null,"source":"integratewise/Integratewise-docs-wiki","content":"\n**Date:** 2026-06-09\n**Status:** ✅ Ready for Deployment\n\n---\n\n## Configuration Verification\n\n### ✅ Intelligence Worker\n\n**File:** `services/intelligence/wrangler.toml`\n\n```toml\nname = \"intelligence\"\naccount_id = \"a1bbbb12a32cdbb68dd170b09fe8b5f3\"  ✅\nroute = { pattern = \"intelligence.dev.integratewise.ai\", custom_domain = true }  ✅\n\n[[secrets_store_secrets]]\nbinding = \"OPENROUTER_API_KEY\"  ✅\nstore_id = \"1fd83fc5881e4cd296ae3c2fbe80693c\"\nsecret_name = \"OPENROUTER_API_KEY\"\n```\n\n**Env Interface:** ✅ Fixed (added `OPENROUTER_API_KEY: string`)\n\n**Endpoint:** `POST /v1/ai/agent` ✅\n\n---\n\n### ✅ Twin Orchestrator\n\n**File:** `services/twin-orchestrator/wrangler.toml`\n\n```toml\nname = \"twin-orchestrator\"\naccount_id = \"a1bbbb12a32cdbb68dd170b09fe8b5f3\"  ✅ (just added)\nroute = { pattern = \"twin.dev.integratewise.ai\", custom_domain = true }  ✅\n\n[triggers]\ncrons = [\"*/5 * * * *\"]  ✅ Every 5 minutes\n\n[[services]]\nbinding = \"INTELLIGENCE\"\nservice = \"intelligence\"  ✅\n\n[[d1_databases]]\nbinding = \"D1\"\ndatabase_name = \"integratewise-spine-cache\"  ✅\ndatabase_id = \"ed1f534a-df1e-4783-8a74-8d6d70d067ff\"\n\n[[kv_namespaces]]\nbinding = \"CACHE\"\nid = \"18aa20dfeb304f0ba592d9070964dd31\"  ✅\n```\n\n---\n\n## Fixes Applied\n\n1. ✅ Added `OPENROUTER_API_KEY: string` to intelligence Env interface\n2. ✅ Added `account_id = \"a1bbbb12a32cdbb68dd170b09fe8b5f3\"` to twin-orchestrator\n\n---\n\n## Deploy Commands\n\n```bash\n# 1. Deploy Intelligence Worker\ncd services/intelligence\nunset CLOUDFLARE_API_TOKEN\nwrangler deploy --env dev\n\n# 2. Deploy Twin Orchestrator\ncd ../twin-orchestrator\nunset CLOUDFLARE_API_TOKEN\nwrangler deploy --env dev\n```\n\n---\n\n## Post-Deployment Verification\n\n### 1. Check Intelligence Worker\n\n```bash\n# Health check\ncurl https://intelligence.dev.integratewise.ai/health\n\n# Expected response:\n{\n  \"status\": \"ok\",\n  \"service\": \"intelligence\",\n  \"components\": [\"think\", \"act\", \"govern\", \"agents\", \"ai-router\"],\n  \"ai\": {\n    \"workers_ai\": \"available\",\n    \"openrouter\": \"configured\",  ← Should show \"configured\"\n    \"gateway\": \"...\"\n  }\n}\n```\n\n### 2. Check Twin Orchestrator\n\n```bash\n# Health check\ncurl https://twin.dev.integratewise.ai/health\n\n# Expected response:\n{\n  \"status\": \"ok\",\n  \"service\": \"twin-orchestrator\",\n  \"role\": \"cognitive-orchestrator\",\n  \"capabilities\": [\"observe\", \"reason\", \"propose\", \"coordinate\", \"learn\"],\n  \"infrastructure\": {\n    \"mcp_connector\": \"bound\",\n    \"intelligence\": \"bound\",  ← Should show \"bound\"\n    \"pipeline\": \"bound\",\n    \"knowledge\": \"bound\",\n    \"continuity\": \"bound\"\n  }\n}\n```\n\n### 3. Test Twin Observe Loop\n\n```bash\n# Manual trigger (don't wait for cron)\ncurl -X POST https://twin.dev.integratewise.ai/v1/twin/observe \\\n  -H \"x-tenant-id: iw-customer-zero\" \\\n  -H \"Content-Type: application/json\"\n\n# Expected response structure:\n{\n  \"success\": true,\n  \"data\": {\n    \"context\": {\n      \"memory\": {...},\n      \"signals\": {...},\n      \"proposals\": {...},\n      \"operations\": {...},\n      \"time\": {...}\n    },\n    \"reasoning\": {\n      \"timestamp\": \"...\",\n      \"context_summary\": \"...\",\n      \"observations\": [...],\n      \"concerns\": [...],\n      \"opportunities\": [...],\n      \"suggested_actions\": [...]\n    },\n    \"proposals\": [...]\n  }\n}\n```\n\n### 4. Monitor Cron Execution\n\n```bash\n# Watch Twin logs\nwrangler tail twin-orchestrator --env dev\n\n# Look for (every 5 minutes):\n[Twin Orchestrator] Scheduled trigger: */5 * * * *\n[Twin] Context built: { memory_items: X, signals: Y, proposals: Z }\n[Twin] Reasoning complete: { observations: N, concerns: M, suggested_actions: P }\n[Twin] Proposals created: X\n[Twin] Observe loop complete\n```\n\n### 5. Check OpenRouter Usage\n\n```bash\n# Intelligence worker logs\nwrangler tail intelligence --env dev\n\n# Look for:\nPOST /v1/ai/agent\nOpenRouter agent response: { model: \"...\", provider: \"openrouter-agent\", usage: {...} }\n```\n\n---\n\n## Routing Architecture\n\n```\nUser/System\n    │\n    ├─→ https://twin.dev.integratewise.ai\n    │   ├─ GET  /health\n    │   └─ POST /v1/twin/observe\n    │\n    └─→ https://intelligence.dev.integratewise.ai\n        ├─ GET  /health\n        └─ POST /v1/ai/agent  ← OpenRouter Agents endpoint\n```\n\n**Service Binding (Internal):**\n\n```\nTwin Orchestrator\n    ↓ (env.INTELLIGENCE)\nIntelligence Worker\n    ↓ (HTTPS)\nOpenRouter API\n    ↓ (ecosystem agent)\nMultiple Models (coordinated)\n```\n\n---\n\n## Custom Domains Status\n\nAll custom domains configured:\n\n- ✅ `intelligence.dev.integratewise.ai` → intelligence worker\n- ✅ `twin.dev.integratewise.ai` → twin-orchestrator worker\n- ✅ `gateway.dev.integratewise.ai` → gateway worker\n\n**Test environments:**\n\n- `intelligence.test.integratewise.ai`\n- `twin.test.integratewise.ai`\n\n**Production:**\n\n- `intelligence.integratewise.ai`\n- `twin.integratewise.ai`\n\n---\n\n## Known Good Configuration\n\nBased on working workers (gateway, pipeline, mcp-connector):\n\n```toml\nname = \"worker-name\"\naccount_id = \"a1bbbb12a32cdbb68dd170b09fe8b5f3\"  ← Required\nmain = \"src/index.ts\"\ncompatibility_date = \"2026-06-09\"\ncompatibility_flags = [\"nodejs_compat\"]\n\nroute = { pattern = \"subdomain.dev.integratewise.ai\", custom_domain = true }\n```\n\nBoth intelligence and twin-orchestrator now match this pattern ✅\n\n---\n\n## What Could Go Wrong\n\n### Issue: \"Worker not found\"\n\n**Cause:** Missing `account_id`\n**Fix:** ✅ Added to twin-orchestrator\n\n### Issue: \"Route already exists\"\n\n**Cause:** Multiple workers claiming same route\n**Check:**\n\n```bash\nwrangler deployments list --name intelligence\nwrangler deployments list --name twin-orchestrator\n```\n\n### Issue: \"Service binding failed\"\n\n**Cause:** Intelligence worker not deployed yet\n**Fix:** Deploy intelligence first, then twin-orchestrator\n\n### Issue: \"OPENROUTER_API_KEY undefined\"\n\n**Cause:** Secret not created in Secrets Store\n**Check:**\n\n```bash\n# List secrets\nwrangler secret list --name intelligence\n\n# Should show:\nOPENROUTER_API_KEY\n```\n\nIf missing, add it:\n\n```bash\ncd services/intelligence\nwrangler secret put OPENROUTER_API_KEY\n# Paste key when prompted\n```\n\n---\n\n## Deployment Order\n\n**IMPORTANT:** Deploy in this order to avoid service binding errors:\n\n1. ✅ Intelligence worker (provides `/v1/ai/agent` endpoint)\n2. ✅ Twin orchestrator (depends on intelligence via service binding)\n\n---\n\n## Next: Deploy\n\n```bash\ncd /Users/nirmal/Github/integratewise-live\n\n# 1. Intelligence\ncd services/intelligence\nunset CLOUDFLARE_API_TOKEN\nwrangler deploy --env dev\n\n# 2. Twin\ncd ../twin-orchestrator\nunset CLOUDFLARE_API_TOKEN\nwrangler deploy --env dev\n```\n\nThen verify with health checks above.\n\n**Ready to deploy!** ✅\n"}