Skip to content

Commit 4a4c0d4

Browse files
author
ben
authored
ci(headless-runner): deploy the runner to celld on dev pushes (#5825)
* docs(cells): require bucket durability on temporary disks * ci(headless-runner): deploy the runner to celld on dev pushes
1 parent 13f038d commit 4a4c0d4

5 files changed

Lines changed: 265 additions & 1 deletion

File tree

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
name: Deploy runner to celld
2+
3+
# The production headless runner runs on a celld fleet (Render service headless-cells, bucket openwork-celld/fleet).
4+
# celld nodes don't build from the repo: a new runner exists only after `celld deploy` writes it to the bucket. This
5+
# workflow does that on every dev push that changes the runner or a package bundled into it, so the runner never
6+
# falls behind Workbot and den-api (which Render deploys from the same push).
7+
#
8+
# Each run first deploys the bundle to a throwaway bucket prefix, starts a local node on it and runs a real turn;
9+
# only then does it deploy to the fleet and wait until every node has adopted the new version. See
10+
# ee/apps/headless-runner/OWNER-CELLS.md.
11+
12+
on:
13+
push:
14+
branches:
15+
- dev
16+
paths:
17+
- "ee/apps/headless-runner/**"
18+
- "ee/packages/headless-protocol/**"
19+
- "ee/packages/headless-computer/**"
20+
- "packages/sandbox-daytona/**"
21+
- "pnpm-lock.yaml"
22+
- ".github/workflows/celld-runner-deploy.yml"
23+
workflow_dispatch:
24+
25+
permissions:
26+
contents: read
27+
28+
concurrency:
29+
group: celld-runner-deploy
30+
cancel-in-progress: false
31+
32+
jobs:
33+
deploy:
34+
name: Deploy runner to celld
35+
if: github.repository == 'different-ai/openwork'
36+
runs-on: blacksmith-4vcpu-ubuntu-2404
37+
environment: celld-production
38+
timeout-minutes: 30
39+
40+
env:
41+
CELLD_VERSION: v0.6.2
42+
AWS_ACCESS_KEY_ID: ${{ secrets.CELLD_R2_ACCESS_KEY_ID }}
43+
AWS_SECRET_ACCESS_KEY: ${{ secrets.CELLD_R2_SECRET_ACCESS_KEY }}
44+
AWS_REGION: auto
45+
S3_ENDPOINT: https://5abbcca46f2a1399566cab3a8f8bd2c6.r2.cloudflarestorage.com
46+
FLEET_BUCKET: s3://openwork-celld/fleet
47+
PREFLIGHT_BUCKET: s3://openwork-celld/ci/${{ github.run_id }}-${{ github.run_attempt }}
48+
RUNNER_VARS: ${{ secrets.CELLD_RUNNER_VARS }}
49+
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
50+
RENDER_OWNER_ID: tea-cspud29u0jms7384itk0
51+
RENDER_SERVICE_ID: srv-db3upfjbc2fs73c1ii70
52+
53+
steps:
54+
- name: Verify secrets are configured
55+
run: |
56+
set -euo pipefail
57+
missing=""
58+
for name in AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY RUNNER_VARS RENDER_API_KEY; do
59+
[ -z "${!name}" ] && missing="$missing $name"
60+
done
61+
if [ -n "$missing" ]; then
62+
echo "::error::Missing celld-production secrets:$missing (CELLD_R2_ACCESS_KEY_ID, CELLD_R2_SECRET_ACCESS_KEY, CELLD_RUNNER_VARS, RENDER_API_KEY)."
63+
exit 1
64+
fi
65+
66+
- name: Checkout
67+
uses: actions/checkout@v6
68+
69+
- name: Setup Node
70+
uses: actions/setup-node@v6
71+
with:
72+
node-version: 24
73+
74+
- name: Setup pnpm
75+
uses: pnpm/action-setup@v4
76+
with:
77+
version: 11.4.0
78+
79+
- name: Install and build the runner's packages
80+
run: |
81+
pnpm install --filter "@openwork-ee/headless-runner..." --frozen-lockfile
82+
pnpm --filter "@openwork-ee/headless-runner^..." --if-present run build
83+
84+
- name: Install celld
85+
run: |
86+
set -euo pipefail
87+
curl -fsSL https://celld.dev/install.sh | sh
88+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
89+
"$HOME/.local/bin/celld" --version
90+
91+
# CELLD_RUNNER_VARS is one JSON object of the runner's HEADLESS_* settings (secrets included). Mask every value:
92+
# GitHub masks the whole secret, not the values inside it.
93+
- name: Bundle the runner
94+
run: |
95+
set -euo pipefail
96+
umask 077
97+
printf '%s' "$RUNNER_VARS" > "$RUNNER_TEMP/vars.json"
98+
jq -r '.[]' "$RUNNER_TEMP/vars.json" | while IFS= read -r value; do [ -n "$value" ] && echo "::add-mask::$value"; done
99+
cd ee/apps/headless-runner
100+
pnpm exec tsx scripts/celld-bundle.ts "$RUNNER_TEMP/celld" "$RUNNER_TEMP/vars.json"
101+
echo "CELLD_ESBUILD=$PWD/node_modules/.bin/esbuild" >> "$GITHUB_ENV"
102+
103+
- name: Preflight on a throwaway prefix
104+
run: |
105+
set -euo pipefail
106+
celld deploy "$RUNNER_TEMP/celld/wrangler.json" --bucket "$PREFLIGHT_BUCKET"
107+
CELLD_WATCH="$RUNNER_TEMP/watch" celld --bucket "$PREFLIGHT_BUCKET" --listen 127.0.0.1:18080 > "$RUNNER_TEMP/node.log" 2>&1 &
108+
for _ in $(seq 1 90); do curl -sf http://127.0.0.1:18080/health > /dev/null && break; sleep 1; done
109+
cd ee/apps/headless-runner
110+
SMOKE_BASE=http://127.0.0.1:18080 HEADLESS_API_TOKEN="$(jq -r .HEADLESS_API_TOKEN "$RUNNER_TEMP/vars.json")" pnpm exec tsx scripts/celld-smoke.ts
111+
112+
- name: Preflight node log
113+
if: failure()
114+
run: grep -v -E "log_ship_loop|node_lease_attempt|celld::memory" "$RUNNER_TEMP/node.log" | tail -80 || true
115+
116+
- name: Deploy to the fleet
117+
id: fleet
118+
run: |
119+
set -euo pipefail
120+
live="$(aws s3 cp "$FLEET_BUCKET/deploy/current.json" - --endpoint-url "$S3_ENDPOINT" --region auto 2>/dev/null | jq -r '.version // empty' || true)"
121+
version="$(celld deploy "$RUNNER_TEMP/celld/wrangler.json" --bucket "$FLEET_BUCKET" --json | jq -r '.version')"
122+
if [ -z "$version" ] || [ "$version" = "null" ]; then echo "::error::celld deploy reported no version"; exit 1; fi
123+
# The version is a content hash: an unchanged bundle redeploys the live version, which nodes don't re-adopt.
124+
echo "unchanged=$([ "$version" = "$live" ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
125+
echo "version=$version" >> "$GITHUB_OUTPUT"
126+
echo "Deployed $version (was ${live:-none})"
127+
128+
# Nodes poll the pointer every 30 seconds. Every running instance must report adopting this version.
129+
- name: Wait for every node to adopt it
130+
if: steps.fleet.outputs.unchanged != 'true'
131+
env:
132+
VERSION: ${{ steps.fleet.outputs.version }}
133+
run: |
134+
set -euo pipefail
135+
started="$(date -u -d '-5 minutes' +%Y-%m-%dT%H:%M:%SZ)"
136+
instances="$(curl -sf -H "Authorization: Bearer $RENDER_API_KEY" "https://api.render.com/v1/services/$RENDER_SERVICE_ID" | jq -r '.serviceDetails.numInstances')"
137+
for _ in $(seq 1 30); do
138+
adopted="$(curl -sf -G -H "Authorization: Bearer $RENDER_API_KEY" https://api.render.com/v1/logs \
139+
--data-urlencode "ownerId=$RENDER_OWNER_ID" --data-urlencode "resource=$RENDER_SERVICE_ID" \
140+
--data-urlencode "text=deployment_adopted" --data-urlencode "startTime=$started" --data-urlencode "limit=100" \
141+
| jq --arg v "$VERSION" '[.logs[] | select(.message | contains("version=" + $v)) | (.labels[] | select(.name == "instance") | .value)] | unique | length')"
142+
echo "adopted on $adopted of $instances nodes"
143+
[ "$adopted" -ge "$instances" ] && exit 0
144+
sleep 10
145+
done
146+
echo "::error::Not every node adopted $VERSION within 5 minutes; check the headless-cells logs."
147+
exit 1
148+
149+
- name: Clean up
150+
if: always()
151+
run: |
152+
rm -rf "$RUNNER_TEMP/celld" "$RUNNER_TEMP/vars.json" "$RUNNER_TEMP/watch"
153+
aws s3 rm --recursive "$PREFLIGHT_BUCKET/" --endpoint-url "$S3_ENDPOINT" --region auto --only-show-errors || true

‎ee/apps/headless-runner/OWNER-CELLS.md‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,26 @@ Workbot ── + owner header ────┘ (src/worker/index.ts) └─ ce
2525

2626
1. Run celld ≥ 0.6.2 on at least two nodes sharing one bucket, behind one private address (see celld's docs for the
2727
bucket, TLS and peer network).
28-
2. `celld deploy` from `ee/apps/headless-runner`, with the same `HEADLESS_*` settings the Node runner has, and
28+
2. `celld deploy` a bundle (`tsx scripts/celld-bundle.ts <out> <vars.json>`), with the same `HEADLESS_*` settings the Node runner has, and
2929
`HEADLESS_FILES=s3`. Keep `wrangler.jsonc`'s `name` and class name: celld derives every cell's identity from
3030
them.
3131
3. Point `DEN_HEADLESS_RUNNER_URL` (den-api) and `WORKBOT_RUNNER_URL` (Workbot) at it. Tokens stay the same.
3232

33+
**Keep the runner current.** Nodes only run what was last deployed to the bucket; they never build from the repo. In
34+
production, `.github/workflows/celld-runner-deploy.yml` does it on every `dev` push that changes the runner or a
35+
package bundled into it: a real turn on a throwaway prefix first, then the fleet, then it waits until every node
36+
adopted the version. A Workbot or den-api change that needs a new runner field must not be turned on before that run
37+
is green; older runners refuse unknown fields.
38+
39+
**Hosts with temporary disks (Render, Fargate, most containers): set `CELLD_DURABILITY=bucket` on every node.**
40+
celld's default (`fleet`) acknowledges a write once another node has it on its local disk, before it reaches the
41+
bucket. If every node stops at once (for example, all lose their bucket leases during one storage outage) and their
42+
disks do not survive, celld cannot prove no acknowledged write was lost and refuses to open the affected cells. That
43+
is correct, but leaves conversations unavailable. On a host that also restarts a process at the same private IP,
44+
recovery waits until those IPs change. `bucket` mode acknowledges only after the bucket write, so
45+
any node can always recover. Keep `fleet` only with persistent disks for `CELLD_WATCH` and stable node identities.
46+
Also consider `CELLD_TTL_MS=30000` so a short storage outage does not fence every node.
47+
3348
**Switching starts every conversation fresh**: conversations on the Node runner stay in its SQLite file and are not
3449
copied. A Slack or Automation run in flight at the switch ends as `unknown_session`. Pointing the URLs back at the
3550
Node runner (kept with its disk until you are sure) returns to the earlier conversations.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Builds a deployable celld project for the runner: the bundled Worker plus a Wrangler config carrying its settings.
3+
*
4+
* tsx scripts/celld-bundle.ts <out dir> <vars.json>
5+
*
6+
* celld 0.6 reads Worker settings only from the config's `vars` (secrets included), so they travel inside the
7+
* deployment in the fleet bucket. Write <out dir> somewhere private and delete it after `celld deploy`.
8+
*/
9+
import { execFileSync } from "node:child_process"
10+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs"
11+
import { builtinModules } from "node:module"
12+
import { dirname, join, resolve } from "node:path"
13+
import { fileURLToPath } from "node:url"
14+
import { z } from "zod"
15+
16+
const [outArg, varsArg] = process.argv.slice(2)
17+
if (!outArg || !varsArg) throw new Error("usage: celld-bundle.ts <out dir> <vars.json>")
18+
const out = resolve(outArg)
19+
const project = join(dirname(fileURLToPath(import.meta.url)), "..")
20+
const vars = z.record(z.string(), z.string()).parse(JSON.parse(readFileSync(resolve(varsArg), "utf8")))
21+
if (vars.HEADLESS_FILES !== "s3" && vars.HEADLESS_FILES !== "off") throw new Error("cells need HEADLESS_FILES=s3 or off")
22+
23+
mkdirSync(out, { recursive: true })
24+
execFileSync(
25+
join(project, "node_modules/.bin/esbuild"),
26+
[
27+
join(project, "src/worker/index.ts"),
28+
"--bundle",
29+
"--platform=neutral",
30+
"--conditions=workerd,browser",
31+
"--main-fields=browser,module,main",
32+
"--format=esm",
33+
"--external:node:*",
34+
"--external:cloudflare:*",
35+
...builtinModules.filter((name) => !name.startsWith("node:")).map((name) => `--alias:${name}=node:${name}`),
36+
`--outfile=${join(out, "index.js")}`,
37+
"--log-level=warning",
38+
],
39+
{ cwd: project, stdio: "inherit" },
40+
)
41+
42+
// wrangler.jsonc carries only whole-line comments; the script and class names in it name every cell, so they are
43+
// copied as they are.
44+
const source = readFileSync(join(project, "wrangler.jsonc"), "utf8")
45+
.split("\n")
46+
.filter((line) => !line.trimStart().startsWith("//"))
47+
.join("\n")
48+
const config = z.object({ name: z.string(), main: z.string() }).passthrough().parse(JSON.parse(source))
49+
writeFileSync(join(out, "wrangler.json"), JSON.stringify({ ...config, main: "index.js", vars }), { mode: 0o600 })
50+
console.log(`bundled ${config.name} into ${out} with ${Object.keys(vars).length} settings`)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* A real turn against a deployed runner: owner cell, model answer, delete. Prints no credentials.
3+
*
4+
* SMOKE_BASE=http://127.0.0.1:8080 HEADLESS_API_TOKEN=... tsx scripts/celld-smoke.ts
5+
*/
6+
import { randomUUID } from "node:crypto"
7+
import { z } from "zod"
8+
9+
const base = z.url().parse(process.env.SMOKE_BASE)
10+
const token = z.string().min(32).parse(process.env.HEADLESS_API_TOKEN)
11+
const owner = `ci:smoke-${randomUUID().slice(0, 8)}`
12+
const sessionId = `hs_ci${randomUUID().replaceAll("-", "")}`
13+
const headers = { authorization: `Bearer ${token}`, "content-type": "application/json", "x-openwork-headless-owner": owner }
14+
const call = (path: string, init: RequestInit = {}) => fetch(`${base}${path}`, { ...init, headers, signal: AbortSignal.timeout(30_000) })
15+
const expect = (label: string, status: number, wanted: number) => {
16+
console.log(`${label}: ${status}`)
17+
if (status !== wanted) throw new Error(`${label} returned ${status}, expected ${wanted}`)
18+
}
19+
20+
expect("unauthenticated", (await fetch(`${base}/v1/models`)).status, 401)
21+
expect("create", (await call(`/v1/sessions/${sessionId}`, { method: "PUT", body: JSON.stringify({ owner }) })).status, 201)
22+
try {
23+
const sent = await call(`/v1/sessions/${sessionId}/turns`, { method: "POST", body: JSON.stringify({ messageId: "m1", prompt: "Reply with exactly the word: pong" }) })
24+
expect("send", sent.status, 202)
25+
const view = z.object({ status: z.string(), turns: z.array(z.object({ status: z.string() })), finalAssistantText: z.string() })
26+
const deadline = Date.now() + 120_000
27+
let read = view.parse({ status: "busy", turns: [], finalAssistantText: "" })
28+
while (Date.now() < deadline) {
29+
await new Promise((done) => setTimeout(done, 2_000))
30+
read = view.parse(await (await call(`/v1/sessions/${sessionId}`)).json())
31+
if (read.status === "idle" && read.turns.length > 0) break
32+
}
33+
const status = read.turns.at(-1)?.status
34+
console.log(`turn: ${status ?? "none"}, answer: ${JSON.stringify(read.finalAssistantText.slice(0, 40))}`)
35+
if (status !== "completed" || !/pong/i.test(read.finalAssistantText)) throw new Error("the smoke turn did not complete with the expected answer")
36+
} finally {
37+
console.log(`delete: ${(await call(`/v1/sessions/${sessionId}`, { method: "DELETE" })).status}`)
38+
}

‎infra/terraform/modules/openwork-aws-ecs/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ file bytes separate from the fleet database objects. Never put bucket credential
206206
or fleet tokens in committed `.tfvars` files. See
207207
[`OWNER-CELLS.md`](../../../../ee/apps/headless-runner/OWNER-CELLS.md).
208208

209+
**Required on Fargate and other temporary disks: set `CELLD_DURABILITY=bucket`
210+
on every fleet node.** The default `fleet` mode can keep acknowledged writes
211+
only on node-local disks until they reach the bucket. If all nodes stop
212+
together and lose those disks, celld refuses to open affected cells until it can
213+
verify the missing data. Bucket mode avoids that availability failure. Use
214+
`fleet` only with persistent `CELLD_WATCH` disks and stable node identities.
215+
Consider `CELLD_TTL_MS=30000` to tolerate brief bucket outages.
216+
209217
**Migration safety:** upgrade Workbot to a build with encrypted-cookie sign-in
210218
before applying the diskless task definition. Older builds require the database.
211219
The plan removes Workbot's obsolete EFS access point; its old sign-in sessions no

0 commit comments

Comments
 (0)