Durable backend lifecycle for user-invoked shell commands (! / !!).
Enforces expected_seq conflict guards, persists "user_shell" task intent
before spawning workers on the bound H.ExecutionEnv, coordinates per-workspace
mutating leases via H.WorkspaceLease, supports cooperative and immediate
abort_ref cancellation, and never replays unsafe interrupted work across
worker crashes or VM restarts.
Summary
Functions
Returns true if a generation, user_shell, or compaction run is active in cid.
Requests cooperative cancellation of an active user_shell worker via abort_ref.
Buffers streamed user_shell output chunks into ephemeral live state.
Merges buffered ephemeral user_shell output into live.
Reconciles a non-terminal user_shell task ("running" or "pending") on
session open / VM restart. Because user_shell is unsafe, it NEVER replays;
any persisted partial output is recorded in an interrupted entry.
Acquires the workspace lease, persists "running" task state before spawning,
and launches the supervised worker executing on state.execution_env.
Stages a user_shell command batch after verifying expected_seq and
conversation idle state. Persists task intent (status: "pending",
replay: "unsafe") before spawning.
Stages immediate cancellation of an active user_shell task during session abort.
Captures partial output, marks entry cancelled, aborts task, and returns worker
termination + lease release effects.
Stages failure when a user_shell worker crashes abnormally. Never replays
unsafe work; preserves any streamed partial output.
Stages completion of a user_shell worker result.
Returns true for unsafe user_shell tasks that must never replay on recovery.
Validates external user_shell command arguments.
Functions
@spec busy?(map(), pos_integer()) :: boolean()
Returns true if a generation, user_shell, or compaction run is active in cid.
@spec cancel_worker(pos_integer(), map()) :: :ok | :not_found
Requests cooperative cancellation of an active user_shell worker via abort_ref.
@spec handle_output(map(), pos_integer(), pos_integer(), term()) :: map()
Buffers streamed user_shell output chunks into ephemeral live state.
Merges buffered ephemeral user_shell output into live.
@spec recover_on_open(map(), map(), integer()) :: {[H.Storage.write()], map()}
Reconciles a non-terminal user_shell task ("running" or "pending") on
session open / VM restart. Because user_shell is unsafe, it NEVER replays;
any persisted partial output is recorded in an interrupted entry.
@spec spawn_worker(pos_integer(), pos_integer(), map(), keyword()) :: map()
Acquires the workspace lease, persists "running" task state before spawning,
and launches the supervised worker executing on state.execution_env.
@spec stage( term(), pos_integer(), String.t(), String.t(), map(), map(), integer() ) :: {:immediate, term(), {:error, term()}, [term()], map()} | {:batch, map(), map()}
Stages a user_shell command batch after verifying expected_seq and
conversation idle state. Persists task intent (status: "pending",
replay: "unsafe") before spawning.
@spec stage_abort(map(), pos_integer(), String.t(), map(), integer()) :: {[H.Storage.write()], map(), [term()]}
Stages immediate cancellation of an active user_shell task during session abort.
Captures partial output, marks entry cancelled, aborts task, and returns worker
termination + lease release effects.
@spec stage_crashed(pos_integer(), pos_integer(), term(), map()) :: {:skip, map()} | {:batch, map(), map()}
Stages failure when a user_shell worker crashes abnormally. Never replays
unsafe work; preserves any streamed partial output.
@spec stage_done( pos_integer(), pos_integer(), {:user_shell_result, non_neg_integer(), term()}, map() ) :: {:skip, map()} | {:batch, map(), map()}
Stages completion of a user_shell worker result.
Returns true for unsafe user_shell tasks that must never replay on recovery.
Validates external user_shell command arguments.