Skip to content

P4 microVM tier: WorkspaceIdle=30min deletes a HITL session's workspace mid-session, silently #338

Open

Description

@pdettori

Summary

WorkspaceIdle defaults to 30 minutes, and idle reclaim is the only trigger that deletes a session's workspace. A human-in-the-loop session can sit idle for hours awaiting a person's response — so the workspace is deleted mid-session, and the next turn silently resumes in an empty /workspace with no signal to the caller.

The keying is correct: workspace_key is the session id and cross-turn continuity is tested (see #267, now closed). This is about the workspace's lifetime, not its identity.

Why it bites

// remote-worker/internal/vmpool/config.go
DefaultStandbyIdle   = 90 * time.Second   // drop standbys, KEEP workspace
DefaultWorkspaceIdle = 30 * time.Minute   // delete the workspace too

The two-stage policy is sound in shape — memory is reclaimed aggressively, the durable thing is kept longer. The problem is only that 30 minutes is short relative to how long a HITL turn boundary can be, and there is nothing else to fall back on:

  • /workspace is the only durable thing on this tier. The writable guest layers (/tmp, /var) are tmpfs discarded on kill, and every Exec gets a fresh microVM, so a lost workspace loses everything the session had accumulated — a git clone, build artifacts, edited files.
  • The loss is silent. The next Exec succeeds. It just runs against an empty filesystem. An agent that cloned a repo in turn 1 and edits a file in turn 5 gets a confusing failure at best, and at worst re-clones and proceeds on a stale plan.
  • There is no explicit release. Grepping the proto and the harness, there is no Release{workspace_key} wire path — the only reference is a comment in select-sandbox.ts. P4 §9 anticipated one ("already guarding for Release{workspace_key}") and it has not landed, so reclaim cannot be driven by the session actually ending.

Why the TTL cannot simply be raised

Workspace disk is not admission-controlled. MaxCommittedBytes/MemoryReserveBytes gate VM memory only. The idle sweep is therefore the sole backstop against workspace disk exhaustion, and raising WorkspaceIdle trades HITL correctness directly against filling the host, with no other control in between.

Worth measuring before choosing a number: workspace.img is Truncate'd to WorkspaceImageBytes (2 GiB default) and then mkfs'd, so the real cost per idle session is what has actually been written rather than 2 GiB — but that should be confirmed on a real host rather than assumed, because it decides how long a TTL is affordable.

Options, not a decision

  1. Explicit release, as P4 §9 anticipated. The principled fix: the harness says when a session is over, so reclaim is not inferred from silence. Then WorkspaceIdle becomes a long backstop rather than the primary mechanism, and HITL gaps stop mattering. Costs the "one wire change" budget the spec reserved.
  2. Raise WorkspaceIdle and bound workspace disk. Independent of (1) and probably needed anyway: if disk is the real constraint, it should be a budget with admission control like memory, not a timer.
  3. Make the reset observable. Whatever the TTL, a first Exec for a key that previously existed and was reclaimed should be distinguishable from a genuinely new session. Needs a small amount of bookkeeping for reclaimed keys, and it turns a silent data loss into something an agent or operator can react to. Cheapest of the three and independently useful.
  4. Per-session-class TTLs. If HITL and autonomous sessions have different idle profiles, one timer may be the wrong shape.

Suggested first step

(3) then (1). Observability first because it is cheap, it makes the failure mode visible in any environment, and it would have surfaced this without anyone reasoning about it. Then the explicit release, which is the actual fix. Raising the default in isolation is the tempting move and it is the one that risks exhausting a host.

Notes

Refs #267, #274

Activity

  1. pdettori commented on Sep 30, 2026

    @pdettori
    MemberAuthor

    From the #369 live run (PR #376) on the KVM rig: m8i.xlarge, Amazon Linux 2023, Firecracker v1.17.0,
    2026-09-30.

    • The per-session cost is what was written, not the image size. Each session's workspace.img
      is 2 GiB apparent and 66 MiB actually on disk after a short session: a git init, a commit
      and a few small files, on a freshly mkfs'd ext4 of 2 GiB. The number grows with what a session
      writes, so it is a lower bound for real workloads, not a typical value.
    • The demo mitigation (M1) is in PR feat(microvm): P4 microVM worker on P6 — installer, rootfs recipe, first real turns (#369) #376. SH_WORKSPACE_IDLE (a Go duration)
      sets WorkspaceIdle on microvm-worker.
      • Unset keeps the 30-minute default.
      • A value at or below StandbyIdle is refused by Normalize.
      • deploy/microvm/setup-microvm.sh writes 8h.
      • At 66 MiB per idle session, 8h on that host (23G free) holds about 350 idle short sessions.
    • Still open, as this issue says: the reset is silent, and workspace disk is not
      admission-controlled. The knob buys time; it does not replace option 3 (an observable reset) or
      option 1 (an explicit release).
  2. pdettori commented on Oct 2, 2026

    @pdettori
    MemberAuthor

    Narrowing the scope after #370, which closed on 2026-10-01.

    Mitigated, for the demo path: SH_WORKSPACE_IDLE (#376) lets the worker keep a workspace longer, and setup-microvm.sh writes 8h. A HITL session on a deploy/microvm install no longer loses its workspace after 30 minutes. The code default is still 30 minutes, and the reset is still silent when it fires.

    What this issue still needs:

    1. An observable reset. A turn that lands on a reclaimed workspace should be told so, not left in an empty /workspace.
    2. An explicit release. A Release{workspace_key} wire path, so a session's end frees its workspace instead of waiting for idle reclaim.

    A third gap, found in the #412 review: a restarted worker never reclaims at all. Idle reclaim walks only the worker's in-memory runs map (remote-worker/internal/vmpool/sweep.go:36). A restarted worker starts with an empty map and "never sweeps a directory it does not know about" (vmpool/workspace.go:83-85). A session delete touches only Redis (packages/control-plane/src/ownership.ts, cascadeDelete). So across a worker restart, every session's workspace stays on disk indefinitely. That's a disk leak, and the users' files outlive their sessions.

    The demo runbook (docs/demos/vm-multi-user-demo.md, Cleanup) now deletes the run's workspaces by hand for this reason. The explicit release in item 2 would cover it, as long as the release survives a restart, for example as a sweep of directories with no live session at worker start.

  3. added this to the v0.11.0 milestone on Nov 17, 2026
  4. webchang commented on Nov 17, 2026

    @webchang
    Member

    @pdettori, a status check on what's left here, and four ways to close it. Each needs your call before anyone writes code.

    Where it stands on main

    • The microVM tier (deploy/microvm) is mitigated as you noted: setup-microvm.sh writes SH_WORKSPACE_IDLE=8h.
    • The container tier has the same silent reset, unmitigated. remote-worker/internal/exec/workspace.go keeps DefaultWorkspaceIdle = 30 * time.Minute. The container worker reads SH_WORKSPACE_IDLE (cmd/worker/main.go), but nothing under deploy/ sets it outside deploy/microvm. So a HITL session on a deploy/k8s stack that waits more than 30 minutes for a person still resumes in an empty workspace, with no signal.
    • Still missing on both tiers: an observable reset and an explicit release. fix(remote-worker): remove an empty per-session workspace no process is in #872 (part of /workspace/<sessionId>/ directories accumulate on sandbox pods for workload runs #551) removes only empty session directories early; it doesn't change when a directory with files goes.

    Options

    1. An observable reset (wire). The worker remembers keys it reclaimed, and the first Exec that re-creates one says so (a field on the Exec result, or a distinct frame). The harness turns that into a message to the model or the caller. This is the issue's option 3 and the most direct signal. It touches the proto and its generated code on both tiers, and the harness, so it's the largest of the four.
    2. A harness marker (no wire change). On a session's first Exec the harness writes a small marker file in the workspace with the session id. On later turns it checks for the marker before the agent runs; if it's gone, the turn starts with a note that the workspace was reset. This is cheap and works on both tiers unchanged. But it's a convention, not a guarantee: a session that deletes the marker gets a false reset, and it can't tell a reclaim from the session's own rm -rf.
    3. An explicit release. A Release{workspace_key} frame sent when a session ends, as P4 §9 anticipated. Idle reclaim then becomes a long backstop, and a long SH_WORKSPACE_IDLE is affordable. It also covers the restarted-worker leak if the worker sweeps unknown directories at start. It's a wire change, plus a session-end hook in the harness and the control plane, which has no path to the worker today. This is the same release /workspace/<sessionId>/ directories accumulate on sandbox pods for workload runs #551's remaining part needs, so one design could close both.
    4. Configuration only. deploy/k8s sets SH_WORKSPACE_IDLE (for example 8h, as deploy/microvm does) through moca-settings. A small change that removes the 30-minute cliff on the container tier, but the reset stays silent when it fires and disk stays unbounded, so it narrows this issue rather than closing it.

    Our suggestion: (4) now, as a small PR, since it matches what the microVM tier already does. Then (2) or (1) for the signal: (2) if a convention is acceptable, (1) if you want it in the protocol. Then (3) together with #551. Which would you like?

  5. pdettori commented on Nov 17, 2026

    @pdettori
    MemberAuthor

    @webchang I am ok with 4, 2 and then 3 with #551 as suggested

  6. evaline-ju commented on Nov 18, 2026

    @evaline-ju
    Contributor

    #551 is closed: #613 and #872 handle its empty-dir case. Its remaining part, freeing a non-empty session workspace when the session ends, is now tracked only here, as option 3 (the release signal).

  7. 20 remaining items

  8. added a commit that references this issue on Nov 20, 2026
  9. pdettori commented on Nov 23, 2026

    @pdettori
    MemberAuthor

    @webchang thanks — (a) on all four, with these conditions:

    1. HTTP control listener. Off unless MOCA_RELAY_CONTROL_ADDR is set, one route, its own Service + NetworkPolicy. Return the worker's ack (released / kept_busy / unknown_key) in the response, and release_unsupported as a distinct status, so the control plane can audit the outcome.
    2. Release from the sweep regardless of provenance, once. Write releasedAt only on a terminal answer from the worker (released, kept_busy, unknown_key, unsupported), not on send. A transport failure leaves it unset, so the next sweep retries while the record is retained. deleteSandbox uses the same path after markDeleted. Note in the PR that expiry is noticed only when the host janitor sweeps; elsewhere idle reclaim is the backstop.
    3. sandboxPod, else sandboxId; otherwise nothing. Read them before the cascade, but send the release only after the session delete commits: since a released key refuses new Execs, a release followed by a failed delete would strand a live session. Add an audit line when no worker is recorded.
    4. Its own Secret, like sbx-egress / sbx-template-hosts, generated by both setup scripts, with the boot-time refusal if it matches any other bearer.

    In every case the release is best-effort with a short bound, and it never fails or delays the DELETE beyond that bound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions