Skip to content

Should not have giant hacks to reuse sandbox for validation loop #6961

Open

Description

@cgwalters

#6753 (comment)

This code is really, really bad.

I know dropping the validation loop would be a big change, but the only other non-hacky way I can think of to fix this is to not terminate the agent process - the agent has a MCP tool it calls that says "I think I'm done" which runs the validation loop.

Activity

  1. waynesun09 commented on Sep 3, 2026

    @waynesun09
    Member

    Updated 2026-09-06. Rewritten after measuring the runner's exact sandbox setup on a live OpenShell 0.0.116 gateway (podman driver). Key changes from the original comment:

    1. The proposal is now stop the sandbox, not the processes: sandbox stop at a deadline instead of the enumeration sweep, and a validation retry that never kills anything.
    2. All three runtimes resume after a stop, measured, so the sweep from fix(runtime): terminate stray sandbox processes between iterations #6753 can retire.
    3. Several claims in the original were wrong; they are listed at the end.

    Every claim below is either read from OpenShell v0.0.116 source (d1155aa) or measured on that gateway. My reply on the PR thread is superseded by this comment.

    Proposal

    1. A validation retry never kills anything. The retry becomes the next turn of the live session (Claude Code, pi) or a same-thread resume after a natural exit (Codex). No process exit between turns, so nothing to sweep. Tracked in runner: validation retry resumes the agent session instead of re-running it from a blank session #6965.
    2. When the runner must stop an agent, it issues sandbox stop. That is the budget deadline, and later a Codex mid-turn steer. Stop is the one released, driver-enforced operation that ends every process in the sandbox, detached children included, and keeps everything on disk. Then start (about a second) and either resume the session with a wrap-up steer, validated on all three runtimes, or extract and delete.
    3. The enumeration sweep from fix(runtime): terminate stray sandbox processes between iterations #6753 retires. Between-iteration cleanup is covered by 1, hard stops by 2.

    This matches what OpenShell told us on #3159: a caller that reuses a sandbox owns cleanup, and the platform's tool for that is the sandbox lifecycle, not the exec channel.

    What we measured

    Enumeration sweep (today) Fresh sandbox per iteration Stop, then resume
    Kills detached children best effort: warning-only, races new spawns, needs a working exec channel yes yes, kernel-enforced, no exec channel needed
    Keeps working tree and session yes no; re-upload, new session yes, /sandbox and /tmp both kept
    Cost under a second 13–24 s create + 5–7 s bootstrap + repo upload 45 s stop today + ~1 s start
    Resume after n/a n/a Claude 21 s, pi 8 s, Codex 9 s, same session

    The 45 s is upstream bug #2855: the podman driver drops CAP_KILL, so the supervisor cannot signal its main process and waits out the SIGKILL grace. Fixed by #3036, merged 2026-09-01, not yet in a release. fullsend already pays that 45 s on every sandbox delete.

    Honest limits

    • The agent tree gets SIGKILL, never TERM. Codex resumed with one tool call left without output, logging a warning; a stop landing mid-write was not exercised.
    • Measured on podman only. Docker and Kubernetes stop timing and retention are unmeasured.
    • 45 s per stop is fine for a budget deadline and a different trade for a steer; the steer keeps the sweep until setup-gcp action uses scripts/ path that breaks per-repo installs after #3000 #3036 ships. When it moves, the Codex interrupt seam is a command runner inside the sandbox, so wiring the lifecycle call in is an injection change, not a one-line swap.

    What the runner changes

    • Treat its own stop as a branch in the loop, not a message to relabel. The in-flight exec returns a relay-closed error that today ends the run (reported as "Agent exited with code 1"). On a steer that would end the run before the resume turn, so the loop has to distinguish "I stopped this to resume it" from "the sandbox went away", which reach the same error now. The deadline comes from the steer budget the runner already tracks.
    • start before extraction, since download needs Ready.
    • Hold the sandbox lock across stop and start so credential refreshers do not upload into a stopped sandbox.
    • Never run the run-scoped provider cleanup on a stop. It expires the OpenAI credential in place and the resumed turn fails; cleanup belongs to the real end of the run. Our first Codex resume failed exactly this way.

    Related

    What changed from the original version of this comment
    • The original proposal was live-session validation plus a process-group interrupt; the interrupt is replaced by sandbox stop, since a --no-tty exec inherits the supervisor's process group and a group kill from inside the sandbox would hit PID 1.
    • Turn ends are observed per runtime, not uniformly: Claude per turn, pi per prompt, Codex only at process exit. Live validation is a runner-loop change plus a Codex idle-aware next-turn path, not "no runtime change".
    • max_iterations and feedback_mode keep their names but change meaning, from process re-runs to turns.
    • fullsend-check-output is installed, not enforced.
    • The working-tree cost of a fresh sandbox was overstated; the runner already downloads the dirty tree every iteration. The real cost is the provisioning time in the table.
    • The second ADR was cited with a number that collides with a merged ADR; PR numbers only now.
    • "When Close issue #2574: recommendation contradicts ADR 43 and targets relocated code #3159 lands the sweep goes away" was wrong twice over: Close issue #2574: recommendation contradicts ADR 43 and targets relocated code #3159 was closed as not planned, and the replacement is the sandbox lifecycle, not an exec primitive.
  2. added
    component/runner
    component/sandbox
    on Sep 3, 2026
  3. self-assigned this
    on Sep 10, 2026
  4. waynesun09 commented on Oct 3, 2026

    @waynesun09
    Member

    Status (2026-10-03): still open. This closes with #6965, which delivers validation feedback as the next turn of the live session, so the validation loop no longer kills the agent or runs the stray-process sweep. #6965 lands after the steer stack (#7007 → #7461); the stack alone does not change the validation path.

    One update to the numbers in the comment above: fullsend now pins OpenShell 0.1.2 (#7233), where sandbox stop takes well under a second on podman when processes honour TERM, instead of 45 s. Exec'd processes also get their own process group. That makes stop-instead-of-sweep cheap for any remaining kill, such as the deadline or the Codex interrupt. One caveat: a stop issued right after a start can leave the sandbox in Error (ai-openshell/openshell#3776), so a restarted sandbox needs a short post-start check.

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

Metadata

Metadata

Assignees

Labels

component/runnercomponent/sandboxtype/enhancement

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions