An open-source, faster Devin alternative
TypeScript
design: OpenClaw managed agents → image-pull (replace checkpoint-fork) (#216)
Mohamed Habibbdab27a6a32c
diff --git a/.agents/design/openclaw-image-pull.md b/.agents/design/openclaw-image-pull.mdnew file mode 100644index 00000000..2574cb75--- /dev/null+++ b/.agents/design/openclaw-image-pull.md@@ -0,0 +1,255 @@+# OpenClaw managed-agent runtime: image-pull instead of checkpoint-fork++## TL;DR++Move OpenClaw managed agents from "fork from a baked OC checkpoint" to+"pull a Docker image into a fresh sandbox at agent-create time." The+checkpoint path is the leading source of paywall-flow incidents in+prod (silent fork failures, golden-version rebase races, snapshot drift+between OpenClaw releases). We trade ~1s warm forks for ~10s cold+pulls in exchange for two layers we can debug independently: a Docker+registry pull, and an in-sandbox boot of a known image. The OpenClaw+team's image becomes the source of truth for the runtime, and we stop+re-baking a snapshot every release.++The Stripe paywall, sandbox-billing exemption, agent metadata, and+sessions-api adapter shape are all unchanged — only the provisioning+path is.++## Problem++Today's flow:++```+sessions-api POST /v1/agents+ → OC POST /api/sandboxes/from-checkpoint/<OPENCLAW_CHECKPOINT_ID>+ → worker fork-from-checkpoint+ → restored sandbox has supervisord + openclaw running with build-time placeholder env+ → entrypoint writes ~/.openclaw/env, supervisorctl restart openclaw+ → adapter.waitReady polls /health+```++Recurring failure modes in prod, each of which has fired this week:++- **Fork race / orphan reaper.** worker's orphan-reaper kills the+ forked QEMU process before the VM registry sees it+ (commit `9fb6c9a` introduced this). User sees+ `instance_boot: rpc error ... QMP cont: connection reset by peer`+ and the agent stays in `error`. Repro is intermittent under load.+- **Golden-version rebase loops.** When we rebuild the rootfs, every+ in-flight checkpoint references the old golden. The worker+ downloads the prior rootfs to `bases/<ver>/default.ext4`; on slow+ blob storage this stalls the first fork of every new agent for 30++ seconds and occasionally times out.+- **Snapshot drift between OpenClaw releases.** OpenClaw 2026.4.16++ changed the channel-config schema; our adapter writes the old+ shape; OpenClaw silently rolls writes back. We pin to 2026.4.15 to+ avoid this and have to rebuild the snapshot for every bump.+- **Reboot recovery is supervisord-restart-dependent.** A guest reboot+ wipes everything; we need PID-1 (osb-agent) to start supervisord+ via the `f7f57a7` hook, then need ~18s of openclaw-gateway warm-up+ before chat works. Users hit "Agent ended the turn without sending+ any text" if they message during the warm-up window.+- **Cross-checkpoint org leakage.** Public-checkpoint forks via the+ `is_public` relaxation work, but checkpoint authorship is brittle —+ if we accidentally rebuild a checkpoint as private the entire user+ base hits 403.++The common thread: we treat the OpenClaw runtime as part of our+infra, but we ship it from a different repo on a different release+cadence. Every interaction between them (config schema, supervisord+program shape, checkpoint format) is a place state can diverge.++## Proposed flow++```+sessions-api POST /v1/agents (core=openclaw)+ → OC POST /api/sandboxes (fresh sandbox from default rootfs, secretStore=agent:<id>)+ → exec.run "docker pull diggerhq/openclaw-managed:<version>"+ → exec.run "docker run -d --name openclaw \+ -p 18789:18789 -p 8787:8787 \+ -v /home/sandbox/.openclaw:/data \+ --env-file /home/sandbox/.openclaw/env \+ --restart unless-stopped \+ diggerhq/openclaw-managed:<version>"+ → adapter.waitReady polls http://localhost:18789/health+```++Two new pieces of plumbing:++### 1. `digger/openclaw-managed:<version>` image++Built nightly via a workflow that pulls the official upstream+OpenClaw image, layers our supervisord + reload hooks + agent+metadata on top, and pushes to a registry. Layout sketch:++```dockerfile+ARG OPENCLAW_VERSION=2026.5.1+FROM openclaw/runtime:${OPENCLAW_VERSION}++# Base config — no per-agent secrets; those come from /data/env at runtime.+COPY openclaw.json /etc/openclaw/openclaw.json++# Launcher script that sources /data/env and execs the gateway in foreground.+COPY launcher.sh /usr/local/bin/openclaw-launcher+RUN chmod +x /usr/local/bin/openclaw-launcher++# Healthcheck baked in so docker can mark the container unhealthy without+# us shipping an external probe.+HEALTHCHECK --interval=10s --timeout=3s --start-period=30s --retries=3 \+ CMD curl -sf http://localhost:18789/health || exit 1++EXPOSE 18789 8787+ENTRYPOINT ["/usr/local/bin/openclaw-launcher"]+```++The image is the only place the OpenClaw runtime version lives.+Bumping OpenClaw is a tag bump, not a checkpoint rebuild. Rollback+is `docker run` with a previous tag — no rootfs surgery. CI tests+can `docker pull` and curl `/health` before promoting a tag.++### 2. Sessions-api adapter rewrite++`src/lib/cores.ts:openclaw` changes from "fork checkpoint, run+entrypoint" to "create sandbox, install image, start container."+The "core ready" gate becomes:++```ts+async function bootOpenclaw(sandbox, agentId, env) {+ await sandbox.files.makeDir("/home/sandbox/.openclaw");+ await sandbox.files.write(+ "/home/sandbox/.openclaw/env",+ Object.entries(env).map(([k, v]) => `${k}=${v}`).join("\n"),+ );+ await sandbox.exec.run(+ "docker pull diggerhq/openclaw-managed:" + OPENCLAW_VERSION,+ { timeout: 120 },+ );+ await sandbox.exec.run(+ `docker run -d --name openclaw --restart unless-stopped \+ -p 18789:18789 -p 8787:8787 \+ -v /home/sandbox/.openclaw:/data \+ --env-file /home/sandbox/.openclaw/env \+ diggerhq/openclaw-managed:${OPENCLAW_VERSION}`,+ { timeout: 30 },+ );+ await waitReady(sandbox);+}+```++Adapter methods that exist today (`restart`, `setModel`, `wireChannel`,+`waitChannelReady`) get simpler — they shell into the running container+or call its HTTP endpoints. Reboot recovery is free: `--restart+unless-stopped` brings the container back when the sandbox boots.++## Tradeoffs++| | Checkpoint fork (today) | Image pull (proposed) |+|---|---|---|+| Cold-start latency | ~3-5s warm fork + ~18s gateway | ~10s docker pull + ~5s warm boot |+| Warm-pool latency | ~1s | ~3s (cache hit) |+| Failure surface | rootfs/checkpoint/openclaw all coupled | layers debuggable independently |+| Runtime version control | rebuild snapshot, redeploy sessions-api | docker tag bump |+| Reboot recovery | osb-agent → supervisord → openclaw (~18s gap) | docker daemon → container (auto, ~3s) |+| Per-agent env | env file written post-fork, supervisorctl restart | env file mounted at container start |+| Cross-org issues | checkpoint ownership / `is_public` | none — image is a public dep |+| Worker disk pressure | one rootfs per template | rootfs + image cache (~500MB-1GB) |+| Storage growth | checkpoint blob per release | docker registry per release |++The honest cost: cold start is slower for the first agent on each+worker. A warm pool of "openclaw-image-prepulled" sandboxes mitigates+this — image is in the worker's overlay, fork-from-warmpool is fast,+agent-create just needs to run-the-container. The autoscaler already+maintains warm pools for the base template; we'd add a second pool+keyed on `template=openclaw-managed`.++The dishonest cost: nothing. We've been spending more eng-time on+checkpoint debugging this month than the latency difference can ever+charge back.++## Migration plan++Phased so we can roll back per-stage if anything misbehaves.++**Phase 0 — image registry plumbing (no user-visible change).**+1. Spin up `ghcr.io/diggerhq/openclaw-managed` (or push to the existing+ Azure Container Registry — `opencomputer-prod-acr` if it exists,+ easier vault story).+2. Author `Dockerfile.openclaw-managed` in this repo. Build via a new+ `.github/workflows/build-openclaw-image.yml` that runs nightly ++ on-demand, tags with `<openclaw-version>-<git-sha>`, pushes to+ registry.+3. Test: pull the image into a stock sandbox, `docker run`, curl+ `/health`. Verify Telegram + chat-completions still work. This is+ purely additive; no production code changes yet.++**Phase 1 — adapter behind a feature flag.**+1. Add `OPENCLAW_PROVISIONER` env to sessions-api: `checkpoint` (default,+ today's behaviour) or `image` (new).+2. New code path lives alongside the existing one in `src/lib/cores.ts`+ and `src/lib/adapters/openclaw.ts`. Old code keeps shipping.+3. Wire OC's billing exemption through metadata.agent_id same as today+ — provisioning path doesn't matter for billing.+4. Test on dev VM with `OPENCLAW_PROVISIONER=image`. Validate full+ create → connect Telegram → chat round-trip. Compare end-to-end+ timings.++**Phase 2 — flip prod, keep checkpoint as fallback.**+1. Set `OPENCLAW_PROVISIONER=image` on Fly's `bolt-platform` app.+2. Existing agents (created off the old checkpoint) continue to work+ — they're not re-provisioned. Only new agents take the image+ path.+3. Watch error rates, fork latencies (now image-pull latencies), and+ chat-turn latencies for 1 week.+4. If anything regresses, flip the flag back. No rollback needed+ beyond the env change.++**Phase 3 — retire the checkpoint path.**+1. Once a week of clean prod, delete the checkpoint code in+ `cores.ts` / adapter / `OPENCLAW_CHECKPOINT_ID` env.+2. Delete `scripts/build-openclaw-snapshot.ts`.+3. Remove the `is_public` checkpoint surface for OpenClaw (we keep+ it for any other public-checkpoint use cases).++**Phase 4 (optional) — warm pool for openclaw image.**+1. Teach the autoscaler to keep N idle sandboxes per region with the+ image already pulled. New OpenClaw agent grabs one off the pool;+ provisioning becomes "container start" only.+2. Trade-off is cost (idle worker capacity); only worth doing once+ we've got steady demand for managed agents.++## Open questions / unknowns++- **Does the official OpenClaw image exist?** If it doesn't, we'd+ build our own from source; same plan, more upstream-tracking+ obligation.+- **Networking for Telegram webhooks.** Today the sandbox listens on+ `:8787` directly; the outside world reaches it via OC's reverse+ proxy. With docker we'd port-publish 8787 from container to+ sandbox-host; same proxy contract holds. Want to confirm there's no+ bridge-mode quirk on the worker's docker daemon.+- **Image cache GC.** Workers will accumulate openclaw image layers;+ need an eviction policy on the worker. Probably reuse the existing+ base-image cleanup hook.+- **Versioning across regions.** If we eventually run multi-region,+ we want each region's worker pool pulling from the closest registry+ mirror to keep cold start under control.++## What we're NOT changing++- Stripe paywall + per-agent subscription gating (entitlement check+ still happens on `connect telegram`).+- Sandbox-billing exemption for subscribed-agent sandboxes+ (metadata.agent_id is set the same way regardless of provisioner).+- Sessions-api ↔ OC auth flow (identity JWTs, downstream tokens).+- CLI surface (`oc agent send/chat`, paywall preflight).+- Dashboard UX.++## Decision needed before phase 0++- Registry choice: `ghcr.io/diggerhq` or Azure ACR? ACR keeps the+ pull entirely on the Azure backbone for prod workers, which is+ faster and avoids GitHub rate limits.+- Image build cadence: nightly is fine; tag scheme like+ `<upstream-openclaw-version>-<our-build-sha>` makes per-build+ rollback trivial. Confirm before we ship.diff --git a/web/src/pages/AgentDetail.tsx b/web/src/pages/AgentDetail.tsxindex 4ac3167b..5b4ea4a1 100644--- a/web/src/pages/AgentDetail.tsx+++ b/web/src/pages/AgentDetail.tsx@@ -177,15 +177,9 @@ export default function AgentDetailPage() {{sandboxId && <span>sandbox: <code style={codeInline}>{sandboxId}</code></span>}</div>{detail.current_operation && (- <div style={{ fontSize: 12, color: 'var(--accent-amber, #fbbf24)', marginTop: 8, display: 'flex', alignItems: 'center', gap: 6 }}>- <span- className="loading-spinner"- style={{ width: 11, height: 11, borderWidth: 1.5, borderColor: 'rgba(251,191,36,0.25)', borderTopColor: 'var(--accent-amber, #fbbf24)' }}- />- <span>- {detail.current_operation.kind} · {detail.current_operation.phase}- {detail.current_operation.message ? ` — ${detail.current_operation.message}` : ''}- </span>+ <div style={{ fontSize: 11, color: 'var(--text-tertiary)', marginTop: 8, fontFamily: 'var(--font-mono)' }}>+ {detail.current_operation.kind} · {detail.current_operation.phase}+ {detail.current_operation.message ? ` — ${detail.current_operation.message}` : ''}</div>)}{detail.last_error && detail.status !== 'ready' && (@@ -251,6 +245,10 @@ export default function AgentDetailPage() {</div></div>+ {detail.current_operation && detail.status !== 'ready' && (+ <BootingClawPanel operation={detail.current_operation} />+ )}+{banner && (<divstyle={{@@ -1566,3 +1564,244 @@ const codeInline: React.CSSProperties = {fontFamily: 'var(--font-mono)', background: 'rgba(255,255,255,0.04)',padding: '1px 5px', borderRadius: 3, fontSize: 10.5,}++// ── Booting claw panel ─────────────────────────────────────────────────+//+// Shown while a managed agent has an in-flight current_operation. Existing+// raw-status copy is intentionally engineery ("create_instance · pull_image+// — pulling opencomputerdeveuacr.azurecr.io/openclaw-managed:2026.5.2-npm")+// — perfect for debugging, miserable to stare at for ~30s on cold start.+// This panel translates that into something with a heartbeat: the OpenClaw+// lobster mark animated, a friendly per-phase headline, and a rotating+// flavour-text subtitle so the page feels alive rather than stuck.+//+// Psychology: research on progress-bar perception (Harrison et al, CHI '07)+// suggests that *any* movement reduces perceived wait time, and rotating+// micro-copy creates the illusion of forward progress even when the+// underlying step is genuinely slow (a 4 GB docker pull doesn't move per-+// frame). We just need to look busy convincingly.+const PHASE_LABELS: Record<string, string> = {+ queued: 'Queued',+ provision_sandbox: 'Carving out a fresh tide pool',+ pull_image: 'Reeling in the lobster',+ start_entrypoint: 'Lighting the burner',+ wait_core_ready: 'Warming up the gateway',+ materialize_declared_state: 'Dressing the claw',+ install_gbrain: 'Wiring up the long-term memory',+ uninstall_gbrain: 'Pulling out the memory module',+ connect_telegram: 'Threading the Telegram leash',+ disconnect_telegram: 'Unhooking Telegram',+ configure_channel: 'Configuring the channel',+}++// Rotating subtitles by phase. Random selection on each tick keeps the+// page feeling lively without claiming progress that hasn't happened.+const PHASE_FLAVOUR: Record<string, string[]> = {+ queued: [+ 'In line behind some other lobsters…',+ 'Politely waiting our turn',+ 'The maître d\' is checking the list',+ ],+ provision_sandbox: [+ 'Booting a microVM just for you',+ 'Stretching the sandbox awake',+ 'Wiring up the pretend internet',+ 'Tuning the network qdisc',+ ],+ pull_image: [+ 'Tracking down a fresh claw image',+ 'Negotiating with the registry',+ 'Thawing 953 MB of OpenClaw',+ 'Decompressing layers, one at a time',+ 'The lobster is doing leg day',+ 'Pinching some bytes from the cache',+ 'Still pulling — bigger than it looks',+ ],+ wait_core_ready: [+ 'OpenClaw is checking its config',+ 'Booting the OpenAI-compat gateway',+ 'Loading 3 plugins (and not 39)',+ 'Waiting on /health to turn green',+ 'The lobster cleared its throat',+ ],+ start_entrypoint: [+ 'Launching the gateway process',+ 'Sourcing the per-agent env',+ 'Telling supervisord to do its thing',+ ],+ materialize_declared_state: [+ 'Reconciling channels and packages',+ 'Snapping things into place',+ 'Almost there, just dressing it up',+ ],+ install_gbrain: [+ 'Spinning up a Postgres for memories',+ 'Teaching the agent how to remember',+ 'Plumbing in pgvector',+ ],+ connect_telegram: [+ 'Registering the Telegram webhook',+ 'Bot meets API, API meets bot',+ 'Confirming the bot can phone home',+ ],+ default: [+ 'The lobster is busy. Please clap softly.',+ 'Crustacean cogs turning',+ 'Working on it',+ 'Just a moment, the claws are tangled',+ ],+}++function friendlyPhase(phase: string | null | undefined): string {+ if (!phase) return 'Working on it'+ return PHASE_LABELS[phase] ?? phase.replace(/_/g, ' ')+}++function flavourFor(phase: string | null | undefined): string[] {+ return (phase && PHASE_FLAVOUR[phase]) || PHASE_FLAVOUR.default+}++function BootingClawPanel({ operation }: { operation: AgentOperation }) {+ const [tick, setTick] = useState(0)+ useEffect(() => {+ const id = setInterval(() => setTick((t) => t + 1), 2600)+ return () => clearInterval(id)+ }, [])+ const lines = flavourFor(operation.phase)+ const flavour = lines[tick % lines.length]++ // Approximate elapsed time since the operation was created — gives the+ // user a sense of "how much longer". AgentOperation only carries+ // created_at; if it's ever omitted we fall through to "now" so the UI+ // doesn't crash, just shows 0s.+ const startedMs = operation.created_at ? new Date(operation.created_at).getTime() : Date.now()+ const elapsedSec = Math.max(0, Math.round((Date.now() - startedMs) / 1000))++ return (+ <div+ style={{+ display: 'flex', alignItems: 'center', gap: 18,+ padding: '20px 24px',+ borderRadius: 14,+ border: '1px solid rgba(255,77,77,0.22)',+ background:+ 'radial-gradient(ellipse at 0% 50%, rgba(255,77,77,0.10), transparent 55%), rgba(255,77,77,0.025)',+ marginBottom: 14,+ }}+ >+ <ScuttlingClaw />+ <div style={{ flex: 1, minWidth: 0 }}>+ <div style={{ fontSize: 17, fontWeight: 700, fontFamily: 'var(--font-display)', color: 'var(--text-primary)' }}>+ {friendlyPhase(operation.phase)}+ </div>+ <div+ key={tick}+ style={{+ fontSize: 13, color: 'var(--text-secondary)', marginTop: 5,+ animation: 'fadeUp 380ms ease-out',+ }}+ >+ {flavour}+ </div>+ <div style={{ fontSize: 11, color: 'var(--text-tertiary)', marginTop: 8, fontFamily: 'var(--font-mono)' }}>+ {operation.kind} · {operation.phase} · {elapsedSec}s elapsed+ </div>+ </div>+ <ProgressDots />++ {/* Animations defined inline so this component is self-contained;+ if we end up reusing them, lift to web/src/index.css. */}+ <style>{`+ @keyframes fadeUp {+ from { opacity: 0; transform: translateY(4px); }+ to { opacity: 1; transform: translateY(0); }+ }+ @keyframes claw-wave-left {+ 0%, 100% { transform: rotate(-4deg) translateX(0); }+ 50% { transform: rotate(8deg) translateX(-1px); }+ }+ @keyframes claw-wave-right {+ 0%, 100% { transform: rotate(4deg) translateX(0); }+ 50% { transform: rotate(-8deg) translateX(1px); }+ }+ @keyframes lobster-bob {+ 0%, 100% { transform: translateY(0); }+ 50% { transform: translateY(-3px); }+ }+ @keyframes eye-blink {+ 0%, 92%, 100% { transform: scaleY(1); }+ 95% { transform: scaleY(0.1); }+ }+ @keyframes dot-pulse {+ 0%, 80%, 100% { opacity: 0.25; transform: scale(0.7); }+ 40% { opacity: 1; transform: scale(1); }+ }+ `}</style>+ </div>+ )+}++// Animated lobster — derived from openclaw.ai/favicon.svg, with the two+// claws split into separate <g> tags so they can wave independently and the+// body bobs gently.+function ScuttlingClaw() {+ return (+ <svg+ width="68"+ height="68"+ viewBox="0 0 120 120"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ aria-hidden="true"+ style={{+ flexShrink: 0,+ filter: 'drop-shadow(0 0 18px rgba(255,77,77,0.45))',+ animation: 'lobster-bob 2.4s ease-in-out infinite',+ }}+ >+ <defs>+ <linearGradient id="boot-lobster-gradient" x1="0%" y1="0%" x2="100%" y2="100%">+ <stop offset="0%" stopColor="#ff4d4d" />+ <stop offset="100%" stopColor="#991b1b" />+ </linearGradient>+ </defs>+ {/* body */}+ <path d="M60 10 C30 10 15 35 15 55 C15 75 30 95 45 100 L45 110 L55 110 L55 100 C55 100 60 102 65 100 L65 110 L75 110 L75 100 C90 95 105 75 105 55 C105 35 90 10 60 10Z" fill="url(#boot-lobster-gradient)" />+ {/* left claw — waves */}+ <g style={{ transformOrigin: '20px 55px', animation: 'claw-wave-left 1.4s ease-in-out infinite' }}>+ <path d="M20 45 C5 40 0 50 5 60 C10 70 20 65 25 55 C28 48 25 45 20 45Z" fill="url(#boot-lobster-gradient)" />+ </g>+ {/* right claw — waves opposite */}+ <g style={{ transformOrigin: '100px 55px', animation: 'claw-wave-right 1.4s ease-in-out infinite' }}>+ <path d="M100 45 C115 40 120 50 115 60 C110 70 100 65 95 55 C92 48 95 45 100 45Z" fill="url(#boot-lobster-gradient)" />+ </g>+ {/* antennae */}+ <path d="M45 15 Q35 5 30 8" stroke="#ff4d4d" strokeWidth="3" strokeLinecap="round" />+ <path d="M75 15 Q85 5 90 8" stroke="#ff4d4d" strokeWidth="3" strokeLinecap="round" />+ {/* eyes — blink */}+ <g style={{ transformOrigin: 'center 35px', animation: 'eye-blink 4.6s ease-in-out infinite' }}>+ <circle cx="45" cy="35" r="6" fill="#050810" />+ <circle cx="75" cy="35" r="6" fill="#050810" />+ <circle cx="46" cy="34" r="2.5" fill="#00e5cc" />+ <circle cx="76" cy="34" r="2.5" fill="#00e5cc" />+ </g>+ </svg>+ )+}++function ProgressDots() {+ return (+ <div style={{ display: 'flex', gap: 6, alignItems: 'center', flexShrink: 0 }}>+ {[0, 1, 2].map((i) => (+ <span+ key={i}+ style={{+ width: 8, height: 8, borderRadius: '50%',+ background: 'rgba(255,77,77,0.85)',+ animation: `dot-pulse 1.4s ease-in-out ${i * 0.18}s infinite`,+ }}+ />+ ))}+ </div>+ )+}