Repository navigation
Conversation
Draft an RFC for stopping sandboxes whose terminal program reports over OSC 7501 that it is waiting on the user, and starting them again on connect. Maintainers assign the RFC number from the originating issue. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Coding agents such as Claude Code and Codex report on their terminal whether they are working, done, or blocked on the user. The supervisor now scans workload PTY output for these reports, answers the support query itself, and reports a sandbox-wide summary to the gateway over the supervisor session. The gateway records the latest report as a ProgramStatus condition. With the idle_stop_after_seconds runtime setting, it stops a sandbox whose program has waited on the user past the timeout and settles it as IdleStopped. openshell sandbox connect starts an idle-stopped sandbox before connecting. Idle stop is off unless the setting is set, and the public Sandbox messages are unchanged. Closes ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Run rustfmt on the conformance workspace and remove semicolons from the RFC's Mermaid labels, which Mermaid parses as statement separators. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Review found cases where a running sandbox could be stopped: recent input lost to throttling, a lost Working write, a restored condition after a gateway restart, a stale timeout, and an explicit stop that a later connect undid. The gateway now decides idleness only from the latest report of the sandbox's current supervisor session, kept in memory on the replica that holds it, with exact input time. Every replica sweeps its own sessions, and nothing stops until the current session reports. The stored ProgramStatus condition is display-only and retries write conflicts. The stop re-reads the live report and the setting under the lifecycle lock and waits out a 15-second input report lag. An explicit stop of an idle-stopped sandbox becomes an ordinary stop. The supervisor reports input within seconds, keeps the latest input after a terminal closes, applies reports, prompts, and full resets in output order, clears records on RIS, and counts terminals with a current report. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Re-review found that a stop could still be decided from a report that was already stale: input since the supervisor's last poll, a Working report racing admission, or a session that another replica had taken over. An explicit stop during an in-flight idle stop could also settle as IdleStopped. Before committing an idle stop, the gateway now sends a WorkloadActivityRequest over the current session and requires a fresh due report within 5 seconds. Only supervisors that advertise supports_workload_activity_requests are idle-stopped. Admission also requires the shared owner record to name the session, and holds an activity gate across the final check and the Stopping write. Every live report update takes the same gate. An explicit stop on the in-flight retry path drops the idle intent. The supervisor notes every transition while it applies a read's events, so a turn within one read restarts the timer. It publishes summaries under the activity lock with a revision that advances on each transition, so concurrent terminals cannot suppress a notification. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Third review found four races between the supervisor's confirmation snapshot and the Stopping write: the session reader could block on the sandbox lock behind a stop, a write conflict kept a global gate across a second confirmation, a takeover could slip past a local session check, and an older confirmation could overwrite a newer push. The stop task now confirms before taking any lifecycle lock. Under the lock, each Stopping attempt requires a confirmation at most 2 seconds old, the re-read setting, a still-due live report from the confirming session, and a fresh owner record naming it. It holds a per-sandbox activity gate for that attempt only. Display persistence moves to a background task, so recording a report never waits on the sandbox lock. The supervisor serializes snapshot and enqueue for pushes and replies and stamps each summary with an increasing sequence. The gateway drops an older summary from the same session. The RFC states the remaining stop boundary. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Fourth review found that the confirmation's 2-second freshness was checked before the final check's waits, so a slow owner read could admit a stop with an older confirmation. It also found that a former owner's delayed display write could overwrite the new owner's status, and that every report spawned its own display task. The final check now runs every wait under the confirmation's deadline, and the deadline is checked again just before the Stopping write is issued. Display writes coalesce behind one writer per sandbox. Each attempt rereads the newest live report and is fenced to the session the shared owner record names. The RFC states report ordering in terms of the activity gate. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Fifth review found that the confirmation deadline started when the stop task resumed rather than when the reply reached the report handler, so scheduling delay extended it. It also found that a display write checked ownership before reading the sandbox, so a takeover between the two let a former owner overwrite the new owner's status. The report handler now captures a monotonic arrival time and sends it through the confirmation waiter, and the deadline derives from it. Each display write attempt reads the versioned sandbox, then checks ownership, then writes conditionally on that version, so any later status write forces a retry with a fresh ownership check. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Architecture review found that a superseded session's late report could displace its replacement's live report, that overlapping sweeps shared one confirmation slot per sandbox, and that connecting during an in-flight idle stop failed instead of waking the sandbox. Recording a report now re-checks the session under the activity gate, and a replaced session's reply wakes no waiter. The confirmation travels with its own stop attempt as QuiesceCause::Idle, and a per-sandbox in-flight guard runs one idle stop at a time. The gateway keeps the IdleStopping reason through driver snapshots, and sandbox connect waits for the stop to finish before starting the sandbox. The docs and RFC state that a waiting report covers only its own program, and record the review's remaining architecture questions. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Re-review found that connect during IdleStopping waited strictly for Stopped. A stop that rolled back to Ready, or a sandbox another client had already restarted, never reaches Stopped, so connect waited for the full lifecycle timeout. Connect now waits until the sandbox leaves Stopping. It connects to a Ready sandbox, waits for Ready from Starting, and starts the sandbox only when it settled as IdleStopped, printing one notice. The lifecycle watch loop is shared between both waits. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Rename the draft from its placeholder number and link its pull request. Refs ai-openshell#5852 Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
8 tasks
Program status reports no longer write the sandbox record. GetSandbox and each WatchSandbox snapshot attach the owning replica's live report as the ProgramStatus condition while the sandbox is Ready, and a replica without the session reads it from the owner over the peer-only PeerGetSandboxProgramStatus RPC, bounded to 2 seconds. A change of state, blocked kind, or app notifies local watchers. This removes the display writer, its owner fencing and conflict retries, condition merging, snapshot preservation, and the phase-change clearing in set_phase. The supervisor now sends input-only reports only while the program waits on the user. ListSandboxes and watchers on other replicas do not show the condition; the RFC records this as a risk and an open question. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Record storing ProgramStatus in its own object, merged on read, as an open future option for cross-replica visibility, and update the implementation plan for the read-time condition. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
…ification The first ProgramStatus change notifies watchers at once and opens a 2-second window. Further changes inside it collapse into one notification at its end, so flips such as working, blocked, working cost at most one watch read per window. Notifications go only to sandboxes that already have watchers, so a late one never recreates a bus entry for a deleted sandbox. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
Idle stop decides from the owning replica's live report and never needed the ProgramStatus condition. Showing it had uneven visibility: ListSandboxes never carried it, watchers on other replicas saw no updates, and each of their watch events cost a peer call. Remove the read-time condition, the PeerGetSandboxProgramStatus RPC, its routed-request metric, and the watch notification window. The RFC lists showing status to clients as a non-goal and keeps a separate status record as the open option. The conformance test now waits for the idle stop directly. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
The supervisor now applies the sandbox's effective idle_stop_after_seconds itself. Once a program has waited on the user, with no client input, past the timeout, it sends a SupervisorWorkloadIdle proposal, repeats it each minute while the wait continues, and retracts it on input or a new turn. The setting reaches it through the configuration poller. The gateway keeps the session's latest proposal and stops the sandbox through the ordinary stop path. Before the Stopping write it checks the proposal, the sandbox's phase and instance, its own effective timeout, and the owner record. After the write and before the driver call it checks the proposal again and rolls the sandbox back to its previous state if a retraction arrived. This removes the gateway's 30-second sweep, the input report lag, the summary sequence numbers, the confirmation round trip and the per-sandbox activity gate, which made the session's receive loop wait on a store write. The idle reporter sends from its own task, so a full outbound queue no longer stalls the receive loop. The two explicit-stop retry blocks share one helper, and the idle orchestration moves into idle_stop.rs. Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
mrunalp
force-pushed
the
feat/5852-idle-stop/mrunalp
branch
from
November 24, 2026 16:05
8c0c308 to
8c4ee70
Compare
2 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stop a sandbox whose coding agent has waited on the user longer than a configured timeout, and start it again on
openshell sandbox connect. Agents such as Claude Code and Codex declare their state on their terminal with OSC 7501. The supervisor reads those reports from workload PTYs, applies the timeout itself, and proposes the stop to the gateway. This PR also adds the draft RFC 0025.Related Issue
Closes #5852
Changes
openshell-supervisor-process,openshell-supervisor):program_statusmodule that scans OSC 7501 reports in the canonical process output and in SSH PTY sessions, and keeps the protocol's per-terminal records.msgandtitleare validated and then dropped.idle_stop_after_secondscurrent, and an idle reporter on each gateway session checks every second and on every summary change.working, and the later of the state change and the latest client input is older than the timeout, the reporter sends aSupervisorWorkloadIdleproposal. It repeats it with a new id every minute while the wait continues, and retracts it on input or a new turn.SupervisorMessage.workload_idle = 7(SupervisorWorkloadIdle), two enums, andSupervisorHello.supports_idle_proposals = 10. This is supervisor control traffic only. No publicSandbox,SandboxSpec, orSandboxStatusfields change, so the SDK's exhaustive-literal fixture still compiles, and the durable schema hash is unchanged.openshell-server):Stoppingwrite, under the lifecycle lock, each attempt requires:Readysandbox on the proposing instance;internal.openshell.ai/idle-stopmarker survives recovery and settles the stop asIdleStopped, which is reapplied after driver snapshots of the stopped runtime. An explicit stop of an idle-stopped sandbox becomes an ordinary stop, including while the idle stop is still in flight on another replica.compute/idle_stop.rs.idle_stop_after_seconds. Unset, zero, or negative disables it; it is capped at 30 days, and gateway scope wins over sandbox scope as for every runtime setting.sandbox connectstarts anIdleStoppedsandbox before connecting, first waiting for an in-flight idle stop (IdleStopping) to leaveStopping. It connects without a start if the sandbox came backReadyorStarting. An explicitly stopped sandbox keeps the existing error.rfc/0025-workload-idle-stop/README.md. Showing program status to clients is a non-goal for this change; the RFC keeps a separate status record as the open option.Release Notes
Set
idle_stop_after_secondsto stop a sandbox after its coding agent has waited on you that long.openshell sandbox connectstarts it again. Agents that report OSC 7501 program status, such as Claude Code and Codex, are supported; sandboxes whose programs never report are never stopped.Testing
cargo fmt --check, including the conformance workspacecargo clippy --all-targets -D warningsfor core, supervisor-process, supervisor, server, cli, and sdkcargo testfor core, supervisor-process, supervisor, server, cli, and sdkIdleStopped, kept after an exited-container snapshot and cleared by a startStoppingwrite restoring the sandboxIdleStoppingwhen the watch reportsReady,Starting, orIdleStoppedidle_stop::idle_stopped_sandbox_wakes_on_connect_until_stopped_explicitly. It checks that idle stop thensandbox connectstarts the sandbox, and that idle stop, explicit stop, thensandbox connectleaves it stopped.attach,cli,ssh,exec_cli, andlifecyclesuites against a local Docker gateway: 21 of 21.working/doneper turn andblocked:kind=permissionat approval prompts.idle_stop_after_seconds=30. After a one-prompt turn, the gateway loggedStopped idle sandbox ... program=codex state=Done, and the sandbox settled asIdleStopped.sandbox connectstarted it again, and the restarted Codex was idle-stopped a second time. Codex neededTMPDIRset inside the sandbox, because its SQLite state otherwise fails on the read-only/var/tmp; that's unrelated to idle stop.claude-codeprovider profile carrying an Anthropic API key. Its turn reachedPOST /v1/messagesthrough the provider policy and answered "OK". The gateway loggedStopped idle sandbox ... program=claude-code state=Donefor both idle stops, before and after asandbox connectwake.Checklist