Skip to content

Commit ede940f

Browse files
Antigravity Agentclaude
andcommitted
fix(cloud): reuse service pool instead of creating new services
The 25 service/day Railway limit was blocking all agent spawns. Now uses round-robin between ubuntu and Agents Anywhere services instead of trying to create agent-{N} services each time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e440560 commit ede940f

1 file changed

Lines changed: 9 additions & 29 deletions

File tree

.github/workflows/agent-spawn.yml

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,18 @@ jobs:
4343
}")
4444
SERVICE_ID=$(echo "$EXISTING" | jq -r ".data.project.services.edges[].node | select(.name == \"${SERVICE_NAME}\") | .id" 2>/dev/null || true)
4545
46+
# Pool of reusable agent services (round-robin by issue number)
47+
POOL_0="acfee27a-74e8-4436-961c-698ae93508ca" # ubuntu
48+
POOL_1="12c2bdf9-d124-4a45-93ad-22921e842d1b" # Agents Anywhere
49+
4650
if [ -n "$SERVICE_ID" ]; then
4751
echo "♻️ Reusing existing service ${SERVICE_NAME} (${SERVICE_ID})"
4852
else
49-
# 1. Create Railway service WITH image source
50-
RESPONSE=$(curl -s -X POST "https://backboard.railway.com/graphql/v2" \
51-
-H "Authorization: Bearer ${RAILWAY_API_TOKEN}" \
52-
-H "Content-Type: application/json" \
53-
-d "{
54-
\"query\": \"mutation(\$input: ServiceCreateInput!) { serviceCreate(input: \$input) { id name } }\",
55-
\"variables\": {
56-
\"input\": {
57-
\"projectId\": \"${RAILWAY_PROJECT_ID}\",
58-
\"name\": \"${SERVICE_NAME}\",
59-
\"source\": { \"image\": \"${AGENT_IMAGE}\" }
60-
}
61-
}
62-
}")
63-
64-
echo "📦 Create response: ${RESPONSE}"
65-
SERVICE_ID=$(echo "$RESPONSE" | jq -r '.data.serviceCreate.id // empty')
66-
if [ -z "$SERVICE_ID" ]; then
67-
echo "❌ Failed to create service — trying to reuse any idle agent service..."
68-
# Fallback: find any idle agent-* service and reuse it
69-
SERVICE_ID=$(echo "$EXISTING" | jq -r '.data.project.services.edges[].node | select(.name | startswith("agent-")) | .id' 2>/dev/null | head -1 || true)
70-
if [ -z "$SERVICE_ID" ]; then
71-
echo "❌ No agent services available to reuse"
72-
exit 1
73-
fi
74-
echo "♻️ Reusing idle agent service (${SERVICE_ID})"
75-
else
76-
echo "✅ Service created: ${SERVICE_ID} (image: ${AGENT_IMAGE})"
77-
fi
53+
# Round-robin: even issues → ubuntu, odd → Agents Anywhere
54+
SLOT=$((ISSUE_NUMBER % 2))
55+
eval "SERVICE_ID=\$POOL_${SLOT}"
56+
POOL_NAME=$([ "$SLOT" -eq 0 ] && echo "ubuntu" || echo "Agents Anywhere")
57+
echo "♻️ No dedicated service — reusing ${POOL_NAME} (${SERVICE_ID}) for issue #${ISSUE_NUMBER}"
7858
fi
7959
8060
# 2. Set environment variables via variableCollectionUpsert (batch)

0 commit comments

Comments
 (0)