crabbox icon indicating copy to clipboard operation
crabbox copied to clipboard

Make crabbox runs durable, inspectable sessions

Open stainlu opened this issue 7 months ago • 2 comments

Summary

Make each crabbox run a first-class durable run session with an append-only event log, so humans and agents can reconnect, inspect, and recover from CLI or SSH failures.

Why

Crabbox already has strong lease infrastructure: the broker owns provider credentials, lease state, cleanup, cost/usage guardrails, and the CLI can sync a dirty checkout and stream command output from a short-lived Linux box.

For long-running agent-driven validation, the run lifecycle should be less coupled to the live CLI process. Managed-agent systems such as Claude Managed Agents and OpenClaw Managed Agents separate durable session state from the replaceable client/harness and the sandbox that executes work. Crabbox can use the same shape without becoming a full managed-agent runtime.

A useful split would be:

  • Run: broker-owned durable record and append-only event log.
  • CLI / OpenClaw plugin: client that can disconnect and reattach.
  • Leased runner: sandbox that executes commands and emits output.

Proposed model

Create a Run record before remote execution starts and append structured lifecycle events:

  • lease.created
  • sync.started
  • sync.finished
  • hydrate.started
  • hydrate.finished
  • command.started
  • stdout
  • stderr
  • command.finished
  • lease.released
  • run.failed

Expose the event stream through something like:

  • GET /v1/runs/:id
  • GET /v1/runs/:id/events
  • GET /v1/runs/:id/events?stream=true

CLI affordances:

  • crabbox run prints a stable run id.
  • crabbox status <run-id> shows phase, command, exit status, and lease state.
  • crabbox logs <run-id> prints durable stdout/stderr after completion.
  • crabbox attach <run-id> resumes streaming from the last seen event when still active.

Non-goals for a first PR

  • Full detached command execution.
  • Replacing SSH transport.
  • A general managed-agent API.

A v1 can persist events while the CLI is alive and already proxying output. A later version can add runner-side event upload with a narrow per-run append token, preserving the current model where leased machines do not receive broad broker/provider credentials.

Acceptance criteria

  • If the local terminal disconnects after a run starts, crabbox history or equivalent shows the run and last known phase.
  • A user can fetch structured events for a run after it completes.
  • A user can reattach to a still-active run, or at minimum inspect complete logs after completion.
  • OpenClaw plugin/tool output can include a stable run id and log URL instead of relying only on the live stream.
  • Runner machines do not receive broad broker/provider credentials.

Follow-ups

These are separate from this issue, but would become easier once runs are first-class:

  • crabbox doctor docker for Docker bridge, --internal networks, cgroups, and disk checks.
  • Repo-level command aliases in .crabbox.yaml.
  • Per-command secret forwarding for provider-key E2E runs.
  • Vitest/JUnit result parsing for concise failure summaries.

stainlu avatar May 02 '26 03:05 stainlu

Interesting. Might add, would look at PRs!

steipete avatar May 02 '26 05:05 steipete

This is now covered on current main and shipped in v0.3.0.

Landed pieces:

  • crabbox run prints an early durable run_... handle before leasing starts.
  • The coordinator stores append-only run events for lifecycle/output/failure paths.
  • crabbox events <run-id> reads structured durable events, with --after and --limit pagination.
  • crabbox attach <run-id> follows/replays an active run from the durable event log.
  • crabbox logs <run-id> returns the retained output tail after completion.
  • Pre-command failures now record run.failed events too.

Proof: local full gate plus live AWS coordinator runs verified attach, paged events, full event listing, retained logs, and lease release before the release. CI for the release-prep commit is green: https://github.com/openclaw/crabbox/actions/runs/25247351320

The remaining broader idea, fully detached runner-side execution after the local CLI dies, is a good separate follow-up because it needs a narrower per-run append token and changes the runner/coordinator trust boundary. Closing this issue as delivered for durable inspectable sessions.

steipete avatar May 02 '26 08:05 steipete