FORGE-79: autoscale the Cloudflare executor from waiting jobs #694

Merged
gmackie merged 1 commit from FORGE-79-executor-pool into main 2026-10-12 04:20:13 +00:00
Owner

Issue: https://tasks.gmac.io/gmacko/issue/FORGE-79 · plan phase 3 · follows #686

What

  • CiExecutorPool Durable Object (singleton) with an alarm loop every POOL_POLL_SECONDS (20). Each tick:
    • asks Forgejo for waiting jobs the cloudflare label can run, via GET /api/v1/repos/gmackie/ForgeGraph/actions/runners/jobs?labels=cloudflare, with a read-only token (read:repository; writes return 403);
    • starts containers for tasks not yet claimed, as computed by planLaunches.
  • planLaunches (pure, src/plan.ts): launches from the last 90s count as already claiming, so a slow claim doesn't start a second container, and at most POOL_MAX_IN_FLIGHT (6) starts are in flight. Six node:test cases cover it (pnpm --filter @forgegraph/ci-executor test).
  • A cron * * * * * acts only as a keep-alive that restarts the alarm loop. GET /pool (admin bearer) shows recent launches and the last tick.
  • max_instances goes 4 → 8. The container also receives RUNNER_LABEL.

Why the Forgejo API

It needs no SSH or psql against the busy Forgejo host, and it is one small API call per poll. When FORGE-67's control plane serves the same job search, or pushes to the pool, only the URL or trigger changes.

Verified live (deployed from this branch)

/pool showed pending: 0 while idle. After dispatching cf-executor-smoke, the next tick (9s later) saw pending: 1 and started one container, which claimed the job. Run #3434 passed in 10s, with no manual /run.

Not in this PR

Phase 4 (routing light ci.yml jobs to cloudflare) follows separately.

🤖 Generated with Claude Code

Issue: https://tasks.gmac.io/gmacko/issue/FORGE-79 · plan phase 3 · follows #686 ## What - **`CiExecutorPool`** Durable Object (singleton) with an alarm loop every `POOL_POLL_SECONDS` (20). Each tick: - asks Forgejo for waiting jobs the `cloudflare` label can run, via `GET /api/v1/repos/gmackie/ForgeGraph/actions/runners/jobs?labels=cloudflare`, with a **read-only** token (`read:repository`; writes return 403); - starts containers for tasks not yet claimed, as computed by `planLaunches`. - **`planLaunches`** (pure, `src/plan.ts`): launches from the last 90s count as already claiming, so a slow claim doesn't start a second container, and at most `POOL_MAX_IN_FLIGHT` (6) starts are in flight. Six `node:test` cases cover it (`pnpm --filter @forgegraph/ci-executor test`). - A **cron** `* * * * *` acts only as a keep-alive that restarts the alarm loop. **`GET /pool`** (admin bearer) shows recent launches and the last tick. - `max_instances` goes 4 → 8. The container also receives `RUNNER_LABEL`. ## Why the Forgejo API It needs no SSH or psql against the busy Forgejo host, and it is one small API call per poll. When FORGE-67's control plane serves the same job search, or pushes to the pool, only the URL or trigger changes. ## Verified live (deployed from this branch) `/pool` showed `pending: 0` while idle. After dispatching `cf-executor-smoke`, the next tick (9s later) saw `pending: 1` and started one container, which claimed the job. **Run #3434 passed in 10s**, with no manual `/run`. ## Not in this PR Phase 4 (routing light `ci.yml` jobs to `cloudflare`) follows separately. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(ci): autoscale the Cloudflare executor from waiting jobs (FORGE-79)
All checks were successful
CF executor smoke / smoke (pull_request) Successful in 14s
CI / gitleaks (pull_request) Successful in 7s
CI / storybook (pull_request) Successful in 1m52s
CI / unit-api (pull_request) Successful in 2m40s
CI / web-build (pull_request) Successful in 4m2s
CI / checks (pull_request) Successful in 4m9s
CI / go (pull_request) Successful in 1m21s
CI / database (pull_request) Successful in 3m4s
CI / unit-web (pull_request) Successful in 3m35s
forgegraph/ci CI passed
CI / ci (pull_request) Successful in 11s
da2cce31d7
CiExecutorPool, a singleton Durable Object, polls Forgejo's runner job
search (GET /repos/{repo}/actions/runners/jobs?labels=cloudflare) every
20s with a read-only token. It starts one container per waiting task.
Launches from the last 90s count as already claiming, so a slow claim
does not double up, and at most 6 starts are in flight. A per-minute
cron restarts the alarm loop if it ever stops. GET /pool (admin) shows
the last tick.

It uses Forgejo's public API, not its database, so the loop needs no
SSH or psql and can follow FORGE-67's control plane once that serves the
same query or pushes. The planner is a pure function with node:test
coverage. max_instances goes to 8.

Verified live: a dispatched cf-executor-smoke run was seen as pending,
a container was started without a manual /run, and run #3434 passed in
10s.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Author
Owner

Preview environment is live: https://pr-694-forgegraph.forgegraf.com

Deployed da2cce31 with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.

Preview environment is live: https://pr-694-forgegraph.forgegraf.com Deployed `da2cce31` with the beta stage's environment. It redeploys on every push and is destroyed when this PR closes.
Sign in to join this conversation.
No description provided.