Skip to content

Sandbox / coder autonomous container recovery - #171

Merged
seamus-brady merged 1 commit into
mainfrom
feat/sandbox-autonomous-recovery
Apr 26, 2026
Merged

seamus-brady merged 1 commit into
mainfrom
feat/sandbox-autonomous-recovery

Conversation

@seamus-brady

Copy link
Copy Markdown
Owner

Summary

Three independent fixes so the agent can survive corrupted podman state on a VPS without an operator on hand. Originated from a real incident where a corrupted sandbox image left the agent stuck calling `request_human_input` — fine in dev, fatal on a VPS.

  • Sandbox manager auto-recovers from image corruption: detects podman stderr like `manifest unknown` / `blob unknown` / `layer corrupt`, force-removes the local image, re-pulls, and retries container creation. Applied at startup AND on health-check restart.
  • Coder manager gets the same image-recovery on `spawn_container`, plus a startup sweep of stale `springdrift-coder-*` containers (mirrors the existing sandbox sweep), plus a piggy-backed health check on the janitor tick that drops idle dead containers so the next dispatch spawns fresh.
  • New `sandbox_reset` cog-loop tool — last-resort escape hatch that bypasses both manager actors and talks to podman directly, so it works even when a manager is itself wedged. `purge_coder` (default true) and `repull_image` (default false) options.

The auto-recovery in (1) and (2) is the load-bearing piece — it fires without the agent having to notice anything is wrong. (3) exists for the cases the heuristics miss.

Files

  • `src/sandbox/recovery.gleam` — pure `is_image_error` detector + `recover_image` action (rmi -f + pull). Unit-tested with real podman stderr fragments.
  • `src/sandbox/manager.gleam` — wires recovery into startup + health-check restart paths.
  • `src/coder/manager.gleam` — startup sweep + piggy-backed health-check on JanitorTick + image recovery in `spawn_container`.
  • `src/tools/sandbox_admin.gleam` — new `sandbox_reset` tool (cog-loop only).
  • Config: `sandbox.image_recovery_enabled` / `image_pull_timeout_ms`, mirrored under `[coder]`. Both default true.
  • Docs: `CLAUDE.md` config tables + cog-loop tools table; `HOW_TO.md` Degradation Paths section.
  • Tests: `recovery_test.gleam` (12 detector cases — positive and negative), `sandbox_admin_test.gleam` (tool surface + safe-when-nothing-matches paths), `coder/manager_test.gleam` (sweep zero-match safety).

Test plan

  • `gleam build` — warning-free (also fixed one pre-existing `element/2` warning in `coder/manager.gleam` that was already on main)
  • `gleam format` — clean
  • `gleam test` — 2173 passed, no failures
  • Manual: corrupt the sandbox image (`podman rmi --force python:3.12-slim && touch /tmp/bogus && podman tag bogus python:3.12-slim`) and confirm the manager recovers on next start
  • Manual: from the chat, ask the agent to run `sandbox_reset` with `repull_image: true` and confirm clean rebuild on next sandbox use

🤖 Generated with Claude Code

Three independent fixes so the agent can survive corrupted podman
state on a VPS without an operator on hand:

1. Sandbox manager: detect image-corruption stderr from podman
   (manifest unknown, blob unknown, layer corrupt, etc.) and
   auto-recover by force-removing the local image, re-pulling, and
   retrying. Applied at startup AND on health-check restart, so a
   corrupted image discovered mid-session no longer wedges every
   slot. Off switch: sandbox.image_recovery_enabled = false.

2. Coder manager: same image-corruption recovery on spawn_container,
   plus a startup sweep of stale springdrift-coder-* containers
   (matches the existing sandbox sweep), plus a piggy-backed health
   check on the janitor tick that drops idle dead containers from
   the pool so the next dispatch spawns fresh.

3. New sandbox_reset cog-loop tool — last-resort escape hatch that
   bypasses both manager actors and talks to podman directly, so it
   works even when a manager is itself stuck. Force-removes
   springdrift-sandbox-* and (optionally) springdrift-coder-*
   containers; with repull_image=true it also rmi+pulls the
   configured images. Only registered when sandbox_enabled = true.

The auto-recovery in (1) and (2) is the load-bearing piece — it
fires without the agent having to notice anything is wrong. (3)
exists for the cases the heuristics miss.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@seamus-brady
seamus-brady merged commit 99c4b00 into main Apr 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant