Skip to content

Commit 672edf9

Browse files
authored
fix(headless): bound runner reads, opt-in Sentry, safer runner deploys (#6090)
Phase 0 of hardening the headless runner, Workbot and their deploys. - Runner: GET /v1/sessions/:id always returns a window (30 turns by default, 200 at most); a messageId read returns that turn, its tasks and reports. Turn queries no longer load prompts or attachments. - Opt-in error reporting: Workbot server via @sentry/node (WORKBOT_SENTRY_*), the runner via a small fetch-based envelope reporter that also works inside celld cells (HEADLESS_SENTRY_*). Nothing is sent without a DSN; content, prompts and credentials are never sent. - celld deploy workflow: version compatibility check between the live and new runner (scripts/compat-check.ts) before the fleet deploy, optional Slack notice, and the Sentry DSN plus a source-tree version merged into the bundle. - Drift: Workbot image no longer declares a database path or volume, Terraform stops setting the retired DEN_FEATURE_HEADLESS_AUTOMATIONS, runner README and OWNER-CELLS.md match the code (API table, celld file storage, recommended production settings, deploy order), and Den's database is MySQL in docs/remote-chat-over-mcp-architecture.md. - owner-cells e2e uses Den's current Slack adapter (createSlackRunner); it imported a function removed in #5846. Signed-off-by: OmarMcAdam <gh@mcadam.io>
1 parent fcf44f8 commit 672edf9

30 files changed

Lines changed: 1612 additions & 96 deletions

‎.github/workflows/celld-runner-deploy.yml‎

Lines changed: 152 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ name: Deploy runner to celld
55
# workflow does that on every dev push that changes the runner or a package bundled into it, so the runner never
66
# falls behind Workbot and den-api (which Render deploys from the same push).
77
#
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.
8+
# Each run first checks that the live runner and this one can serve each other during the switch, then deploys the
9+
# bundle to a throwaway bucket prefix, starts a local node on it and runs a real turn; only then does it deploy to the
10+
# fleet, wait until every node has adopted the new version and tell Slack. Approval and batching are settings of the
11+
# celld-production environment. See "Deploying the runner" in ee/apps/headless-runner/OWNER-CELLS.md.
1112

1213
on:
1314
push:
@@ -21,6 +22,17 @@ on:
2122
- "pnpm-lock.yaml"
2223
- ".github/workflows/celld-runner-deploy.yml"
2324
workflow_dispatch:
25+
inputs:
26+
compat_base:
27+
description: "Commit or ref to check compatibility against (default: the commit behind the live fleet version)"
28+
required: false
29+
type: string
30+
default: ""
31+
skip_compat_check:
32+
description: "Deploy even if the live runner and this one can't serve each other during the switch"
33+
required: false
34+
type: boolean
35+
default: false
2436

2537
permissions:
2638
contents: read
@@ -45,6 +57,9 @@ jobs:
4557
S3_ENDPOINT: https://5abbcca46f2a1399566cab3a8f8bd2c6.r2.cloudflarestorage.com
4658
FLEET_BUCKET: s3://openwork-celld/fleet
4759
PREFLIGHT_BUCKET: s3://openwork-celld/ci/${{ github.run_id }}-${{ github.run_attempt }}
60+
# Which commit produced the live fleet version ({version, commit}), written after each green deploy. Outside the
61+
# fleet prefix: celld never reads it.
62+
DEPLOY_RECORD: s3://openwork-celld/ci/fleet-deployed.json
4863
RUNNER_VARS: ${{ secrets.CELLD_RUNNER_VARS }}
4964
RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
5065
RENDER_OWNER_ID: tea-cspud29u0jms7384itk0
@@ -66,6 +81,14 @@ jobs:
6681
- name: Checkout
6782
uses: actions/checkout@v6
6883

84+
- name: Read the live fleet version
85+
id: live
86+
run: |
87+
set -euo pipefail
88+
live="$(aws s3 cp "$FLEET_BUCKET/deploy/current.json" - --endpoint-url "$S3_ENDPOINT" --region auto 2>/dev/null | jq -r '.version // empty' || true)"
89+
echo "version=$live" >> "$GITHUB_OUTPUT"
90+
echo "The fleet runs ${live:-nothing yet}"
91+
6992
- name: Setup Node
7093
uses: actions/setup-node@v6
7194
with:
@@ -88,13 +111,59 @@ jobs:
88111
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
89112
"$HOME/.local/bin/celld" --version
90113
114+
# During the switch a request on the new deployment can reach a cell still on the old one, and the other way
115+
# round (OWNER-CELLS.md, "Deploying the runner"). Compare with the commit behind the live fleet version, else the
116+
# previous push. A real incompatibility stops the deploy; an old version that can't be fetched or built here is
117+
# only a warning. Uses a mock model and no secrets.
118+
- name: Check the live runner and this one can serve each other
119+
id: compat
120+
if: ${{ !inputs.skip_compat_check }}
121+
timeout-minutes: 10
122+
env:
123+
COMPAT_BASE: ${{ inputs.compat_base }}
124+
PUSH_BEFORE: ${{ github.event.before }}
125+
LIVE_VERSION: ${{ steps.live.outputs.version }}
126+
run: |
127+
set -euo pipefail
128+
base="$COMPAT_BASE"
129+
if [ -z "$base" ]; then
130+
record="$(aws s3 cp "$DEPLOY_RECORD" - --endpoint-url "$S3_ENDPOINT" --region auto 2>/dev/null || true)"
131+
recorded_version="$(printf '%s' "$record" | jq -r '.version // empty' 2>/dev/null || true)"
132+
if [ -n "$LIVE_VERSION" ] && [ "$recorded_version" = "$LIVE_VERSION" ]; then
133+
base="$(printf '%s' "$record" | jq -r '.commit // empty')"
134+
echo "Comparing with $base, which produced the live version $LIVE_VERSION"
135+
elif [ -n "$PUSH_BEFORE" ] && [ "$PUSH_BEFORE" != "0000000000000000000000000000000000000000" ]; then
136+
base="$PUSH_BEFORE"
137+
echo "No record of the commit behind the live version; comparing with the previous dev push $base"
138+
fi
139+
fi
140+
if [ -z "$base" ] || ! git fetch --no-tags --depth=1 origin "$base"; then
141+
echo "::warning title=Runner compatibility check skipped::no earlier runner commit could be fetched (${base:-none found})"
142+
exit 0
143+
fi
144+
cd ee/apps/headless-runner
145+
# The check runs on celld dev's local store: keep the fleet's credentials away from it.
146+
env -u AWS_ACCESS_KEY_ID -u AWS_SECRET_ACCESS_KEY -u S3_ENDPOINT -u RUNNER_VARS -u RENDER_API_KEY \
147+
pnpm exec tsx scripts/compat-check.ts --base FETCH_HEAD --runtime celld
148+
91149
# CELLD_RUNNER_VARS is one JSON object of the runner's HEADLESS_* settings (secrets included). Mask every value:
92150
# GitHub masks the whole secret, not the values inside it.
93151
- name: Bundle the runner
152+
env:
153+
HEADLESS_SENTRY_DSN: ${{ secrets.HEADLESS_SENTRY_DSN }}
94154
run: |
95155
set -euo pipefail
96156
umask 077
97157
printf '%s' "$RUNNER_VARS" > "$RUNNER_TEMP/vars.json"
158+
# Error reporting (opt-in): the DSN lives in its own secret so it can change without rewriting
159+
# CELLD_RUNNER_VARS. The version is the runner's source tree hash, not the commit, so an unchanged runner
160+
# still bundles to the same content hash and nodes don't re-adopt it.
161+
runner_version="$(git rev-parse --short=12 HEAD:ee/apps/headless-runner)"
162+
jq --arg dsn "${HEADLESS_SENTRY_DSN:-}" --arg version "$runner_version" '
163+
. + (if $dsn != "" then { HEADLESS_SENTRY_DSN: $dsn, HEADLESS_SENTRY_ENVIRONMENT: (.HEADLESS_SENTRY_ENVIRONMENT // "production") } else {} end)
164+
+ { HEADLESS_RUNNER_VERSION: (.HEADLESS_RUNNER_VERSION // $version) }
165+
' "$RUNNER_TEMP/vars.json" > "$RUNNER_TEMP/vars.merged.json"
166+
mv "$RUNNER_TEMP/vars.merged.json" "$RUNNER_TEMP/vars.json"
98167
jq -r '.[]' "$RUNNER_TEMP/vars.json" | while IFS= read -r value; do [ -n "$value" ] && echo "::add-mask::$value"; done
99168
cd ee/apps/headless-runner
100169
pnpm exec tsx scripts/celld-bundle.ts "$RUNNER_TEMP/celld" "$RUNNER_TEMP/vars.json"
@@ -115,9 +184,11 @@ jobs:
115184

116185
- name: Deploy to the fleet
117186
id: fleet
187+
env:
188+
LIVE_VERSION: ${{ steps.live.outputs.version }}
118189
run: |
119190
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)"
191+
live="$LIVE_VERSION"
121192
version="$(celld deploy "$RUNNER_TEMP/celld/wrangler.json" --bucket "$FLEET_BUCKET" --json | jq -r '.version')"
122193
if [ -z "$version" ] || [ "$version" = "null" ]; then echo "::error::celld deploy reported no version"; exit 1; fi
123194
# The version is a content hash: an unchanged bundle redeploys the live version, which nodes don't re-adopt.
@@ -127,27 +198,98 @@ jobs:
127198
128199
# Nodes poll the pointer every 30 seconds. Every running instance must report adopting this version.
129200
- name: Wait for every node to adopt it
201+
id: adopt
130202
if: steps.fleet.outputs.unchanged != 'true'
131203
env:
132204
VERSION: ${{ steps.fleet.outputs.version }}
133205
run: |
134206
set -euo pipefail
135207
started="$(date -u -d '-5 minutes' +%Y-%m-%dT%H:%M:%SZ)"
136208
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
209+
echo "instances=$instances" >> "$GITHUB_OUTPUT"
210+
adopted=0
211+
for attempt in $(seq 1 30); do
212+
# A failed log read counts as no progress this round rather than ending the wait.
138213
adopted="$(curl -sf -G -H "Authorization: Bearer $RENDER_API_KEY" https://api.render.com/v1/logs \
139214
--data-urlencode "ownerId=$RENDER_OWNER_ID" --data-urlencode "resource=$RENDER_SERVICE_ID" \
140215
--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')"
216+
| jq --arg v "$VERSION" '[.logs[] | select(.message | contains("version=" + $v)) | (.labels[] | select(.name == "instance") | .value)] | unique | length' \
217+
|| echo "$adopted")"
142218
echo "adopted on $adopted of $instances nodes"
143-
[ "$adopted" -ge "$instances" ] && exit 0
144-
sleep 10
219+
[ "$adopted" -ge "$instances" ] && break
220+
[ "$attempt" -lt 30 ] && sleep 10
145221
done
146-
echo "::error::Not every node adopted $VERSION within 5 minutes; check the headless-cells logs."
147-
exit 1
222+
echo "adopted=$adopted" >> "$GITHUB_OUTPUT"
223+
if [ "$adopted" -lt "$instances" ]; then
224+
echo "::error::Not every node adopted $VERSION within 5 minutes; check the headless-cells logs."
225+
exit 1
226+
fi
227+
228+
# The compatibility check of the next run compares with this commit.
229+
- name: Record the commit behind the live version
230+
if: steps.fleet.outcome == 'success' && (steps.fleet.outputs.unchanged == 'true' || steps.adopt.outcome == 'success')
231+
continue-on-error: true
232+
env:
233+
VERSION: ${{ steps.fleet.outputs.version }}
234+
run: |
235+
set -euo pipefail
236+
jq -n --arg version "$VERSION" --arg commit "$GITHUB_SHA" --arg run "$GITHUB_RUN_ID" '{version: $version, commit: $commit, run: $run}' \
237+
| aws s3 cp - "$DEPLOY_RECORD" --endpoint-url "$S3_ENDPOINT" --region auto --content-type application/json --only-show-errors
148238
149239
- name: Clean up
150240
if: always()
151241
run: |
152242
rm -rf "$RUNNER_TEMP/celld" "$RUNNER_TEMP/vars.json" "$RUNNER_TEMP/watch"
153243
aws s3 rm --recursive "$PREFLIGHT_BUCKET/" --endpoint-url "$S3_ENDPOINT" --region auto --only-show-errors || true
244+
245+
# Posts only when CELLD_DEPLOY_SLACK_WEBHOOK_URL (a Slack incoming webhook) is set on the celld-production
246+
# environment. A failed post is a warning: the deploy has already happened or failed by now.
247+
# TODO: add "cells switched" and "cells force-cancelled". celld v0.6.2 logs `generation_swap_out` per switched
248+
# cell (with a per-node generation number, not the version) and nothing distinct when CELLD_DEPLOY_MAX_AGE_S
249+
# forces a busy cell, so Render's logs can't give the forced count yet. Count it here, the way the wait step
250+
# counts deployment_adopted, once celld logs a forced swap.
251+
- name: Tell Slack
252+
if: always()
253+
env:
254+
SLACK_WEBHOOK_URL: ${{ secrets.CELLD_DEPLOY_SLACK_WEBHOOK_URL }}
255+
JOB_STATUS: ${{ job.status }}
256+
FLEET_OUTCOME: ${{ steps.fleet.outcome }}
257+
COMPAT_OUTCOME: ${{ steps.compat.outcome }}
258+
UNCHANGED: ${{ steps.fleet.outputs.unchanged }}
259+
VERSION: ${{ steps.fleet.outputs.version }}
260+
PREVIOUS: ${{ steps.live.outputs.version }}
261+
ADOPTED: ${{ steps.adopt.outputs.adopted }}
262+
INSTANCES: ${{ steps.adopt.outputs.instances }}
263+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
264+
COMMIT_URL: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}
265+
run: |
266+
set -euo pipefail
267+
if [ -z "$SLACK_WEBHOOK_URL" ]; then
268+
echo "CELLD_DEPLOY_SLACK_WEBHOOK_URL is not set; no Slack message."
269+
exit 0
270+
fi
271+
previous="${PREVIOUS:-unknown}"
272+
ended="$([ "$JOB_STATUS" = "cancelled" ] && echo "was cancelled" || echo "failed")"
273+
if [ "$JOB_STATUS" = "success" ] && [ "$UNCHANGED" = "true" ]; then
274+
outcome="unchanged"
275+
summary=":white_circle: Runner unchanged: the fleet already runs \`$VERSION\`."
276+
elif [ "$JOB_STATUS" = "success" ]; then
277+
outcome="deployed"
278+
summary=":large_green_circle: Runner deployed: \`$VERSION\` (was \`$previous\`), adopted on ${ADOPTED:-?} of ${INSTANCES:-?} nodes."
279+
elif [ "$FLEET_OUTCOME" = "success" ]; then
280+
outcome="failed"
281+
summary=":red_circle: Runner \`$VERSION\` is in the fleet bucket but only ${ADOPTED:-?} of ${INSTANCES:-?} nodes adopted it (was \`$previous\`)."
282+
elif [ "$COMPAT_OUTCOME" = "failure" ]; then
283+
outcome="failed"
284+
summary=":red_circle: Runner deploy stopped: the live runner and this one can't serve each other during a switch. The fleet stays on \`$previous\`."
285+
else
286+
outcome="failed"
287+
summary=":red_circle: Runner deploy $ended before the fleet changed. The fleet stays on \`$previous\`."
288+
fi
289+
text="$summary"$'\n'"Commit <$COMMIT_URL|${GITHUB_SHA:0:12}> · <$RUN_URL|run $GITHUB_RUN_ID>"
290+
if ! jq -n --arg text "$text" '{text: $text, unfurl_links: false}' \
291+
| curl -sS --fail --max-time 20 -X POST -H 'Content-Type: application/json' --data-binary @- "$SLACK_WEBHOOK_URL" > /dev/null; then
292+
echo "::warning::Could not post the $outcome deploy message to Slack."
293+
else
294+
echo "Posted the $outcome deploy message to Slack."
295+
fi

‎.github/workflows/ci-tests.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,12 @@ jobs:
9191
pnpm --filter @openwork-ee/headless-computer build
9292
pnpm --filter @openwork-ee/headless-computer test
9393
pnpm --filter @openwork-ee/headless-runner test:computer-config
94-
- name: Test headless conversations (follow-ups, read-only lookups, waiting messages)
94+
- name: Test headless conversations (follow-ups, read-only lookups, waiting messages, bounded reads)
9595
run: pnpm --filter @openwork-ee/headless-runner test:conversation
96+
- name: Test opt-in error reporting (runner and Workbot)
97+
run: |
98+
pnpm --filter @openwork-ee/headless-runner test:error-reporting
99+
pnpm --filter @openwork-ee/workbot test:error-reporting
96100
- name: Boot the app provider tree
97101
run: pnpm test:boot
98102
- name: Check desktop links open real Den pages

‎docs/remote-chat-over-mcp-architecture.md‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,17 +391,18 @@ pulls. Therefore:
391391
request-scoped (cloud wake-and-poll, <2 min) or edge-pull (the desktop
392392
runner cannot be an engine worker behind NAT — the claim/lease protocol
393393
stays bespoke regardless). Den's durability model is already crash-safe
394-
state machines in Postgres (worker status as cross-replica mutex, claimable
394+
state machines in MySQL (worker status as cross-replica mutex, claimable
395395
rows + deadline sweeps, durable receipts), so an engine would be a
396396
re-platform, not an enhancement — and it adds a second source of truth
397397
beside the receipt tables users read, plus heavy self-host burden for OSS
398398
deployers (own cluster/datastore for Temporal; second runtime for
399399
Inngest) and Temporal's determinism/versioning tax. Rejected for this
400-
design. Escalation path if pressure appears: (1) Postgres-native queue
401-
(pg-boss / graphile-worker) — no new vendor, ships with the existing DB;
402-
(2) only if the Workflows product ever needs true sagas, an internal
403-
orchestration seam with Postgres as the default implementation and an
404-
engine as an optional adapter, so self-deploy stays vanilla Postgres.
400+
design. Escalation path if pressure appears: (1) a queue on the existing
401+
database — no new vendor (pg-boss / graphile-worker are Postgres-only, so
402+
they don't fit Den's MySQL as-is); (2) only if the Workflows product ever
403+
needs true sagas, an internal orchestration seam with the existing database
404+
as the default implementation and an engine as an optional adapter, so
405+
self-deploy stays vanilla MySQL.
405406
- **A separate MCP server hosted by OpenWork Web.** There is no web MCP
406407
server today (den-web is dashboard-only); building one duplicates auth,
407408
policy, and exposure logic the gateway already owns. Rejected.

0 commit comments

Comments
 (0)