Skip to content

execHost: remote exec data service #1295

Open

Description

@eric8810

Current delivery boundary

The owner contract lists 13 operations. The product catalog still has native hostPlatform and no execHost. All 13 remain to be delivered at this face. Product catalog. Resource contract.

Design and API proposal: #1856 (Refs #1292).

Context

exec is a Session part and depends on HostPlatform (typed, handle-based: ProcessTree, PtyProcessTree, temporary directories). The resource leaf can implement the same capability locally and expose data operations.

Scope

  • Data service execHost: start → task id, wait, kill, output (cursor, limit); persistent shell: shell, write, resize, read; cancellation.
  • Implement in the resource leaf, reusing HostPlatform locally; execution settings and sandbox are read and enforced on the node.
  • Wire exec foreground first, then background handoff and PTY.
  • Output is bounded and stored on the node; the control side reads a tail and pages, never raw streams.
  • Background task ownership: the branch keeps the fact; the leaf keeps the process.

Acceptance

  • A foreground command, a failing command, a cancelled command and a background command run on a remote resource leaf.
  • Sandbox settings are read on the node; a sandboxed command on the leaf cannot write outside its workspace.
  • Leaf offline fails only the call; a reconnect does not reload the Session.
  • The model-visible result unchanged: bounded preview, exit status, output path.

Notes

Depends on the resource leaf contract. See the research doc §3.1–§3.2 for the operation split.

Activity

  1. added
    core
    on Nov 8, 2026
  2. self-assigned this
    on Nov 16, 2026
  3. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Design correction: no separate execHost face

    rutis already exposes a service's public &self methods by name (#[rutis::service] + ctx.provide); a HostDispatch is generated by the framework, not written by business code. Scope is orthogonal to exposure: a service is served in the scope it is provided, and a leaf mounts part copies in the host's instances (research/remote-plugins §4.2), so a Session/branch service crosses a leaf just as a process service does.

    The single process-scope execHost face in resource-faces.md §1/§3 is withdrawn. The corrected split:

    Service Scope Operations
    hostPlatform process info, and its own data methods; spawn/spawn_pty/build_process_spec stay #[service(skip)]
    toolHost session execute remains the exec entry
    backgroundExec branch output, outputPage, wait, stop; start stays skip (it takes ExecProcess)
    sessionMethods.shell session/branch the shell operations, at their existing scope

    No ownership move, no HostPlatform rename, no HostFacts, no hand-written HostDispatch or plugin.d.ts. Cancellation uses the existing cancelled: CancelledFn callback (as toolHost.execute does).

    The replacement PR updates resource-faces.md, service-faces.md and contracts/resource-owner-operations.md, and exposes hostPlatform.info with xtask types declarations. #1899 is closed.

  4. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    The corrected implementation is #2002: hostPlatform exposes its own data methods (info, execShell, sandboxBackend, execRoot); the task and shell operations stay on toolHost, backgroundExec and sessionMethods.shell. The design docs are updated in that PR.

  5. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Direction: data-shaped methods on HostPlatform

    The separate execHost face is withdrawn (#1899). The process owner keeps its type, file, scope and dependencies; the methods external plugins use become data operations. This follows the dependency review: 16 plugins inject HostPlatform, so their calls must be service methods; the process/PTY state moves into HostPlatform so handles never cross.

    Public methods (#[rutis::service] on the existing impl HostPlatform)

    Method Request Reply
    info {} {os, arch, home, timezone?, execRoot, platformRoots, backend, execShell}
    spawn {taskId, command, cwd, workspace, roots, outputDir, timeoutMs?} {outputPath}
    wait {taskId, timeoutMs?} + cancelled callback {status, exitCode?, signal?, durationMs, outputPath, outputBytes, outputTruncated, preview, previewTruncated, failureNote?}
    kill {taskId} {}
    settle {taskId} {}
    output {taskId, cursor?, limit?} or {outputPath, cursor?, limit?} {text, bytes, nextCursor?, truncated, retainedFrom, reset?}
    tail {taskId} {text, totalBytes, truncated}
    retainOutput {taskId} {outputPath}
    shell {taskId, cwd, workspace, roots, outputDir, cols, rows} {outputPath}
    write {taskId, data} (base64) {}
    resize {taskId, cols, rows} {}
    configured {command, cwd, env?, stdin?, timeoutMs, limits} + cancelled callback {status, exitCode?, signal?, durationMs, stdout, stderr, stdoutTruncated, stderrTruncated}
    confined {program, args, read, write, env?, timeoutMs, outputLimit, services} + cancelled callback {status, stdout, stderr, confined, stdoutTruncated, stderrTruncated}
    execShell / persistentShell — ShellStatus
    sandboxBackend — SandboxBackend
    execRoot — path
    removeOutputDirectory {path} {}
    childPath {directories, base} string?

    Internal, #[service(skip)]

    current, with_execution_settings, with_toolchain_source, build_process_spec, prepare_isolated_process, spawn_pty, spawn_with_stdin, installed_toolchains.

    These become the internal implementation of spawn / shell / configured / confined.

    Caller migration

    • WorkspaceTools / BackgroundExec: spawn / wait / output / kill / settle; the branch keeps the task record.
    • ShellSession: shell / write / resize / output / kill; the PTY stays in HostPlatform.
    • Hooks: configured.
    • Modality (OCR): confined.
    • Permission, PromptSources, Skills, FileAccess: info() / existing data methods.
    • MCP: childPath, or stays local if the path helper is not needed across nodes.

    Invariants

    • Type name HostPlatform, file host_platform.rs, plugin, scope and dependencies unchanged.
    • No separate face object, no hand-written HostDispatch, no hand-written plugin.d.ts; #[rutis::service] and #[service(skip)], with xtask types generating the declarations.
    • Process, PTY, output files and the task table are owned by HostPlatform; handles never cross.
    • Cancellation uses the existing cancelled: CancelledFn parameter; no cancel operation and no callId.

    Open points

    • childPath: string vs OS path; non-UTF-8 semantics.
    • removeOutputDirectory: error code when the path is outside execRoot.
    • tail / retainOutput: keep only if the current callers need them.
    • Shell protocol: ShellSession's marker/occupancy loop needs the output-delivery design (poll output vs an internal stream) before the PTY move.
    • The implementation will update/replace Serve hostPlatform's data methods; withdraw the execHost face #2002; the design docs will follow this direction.
  6. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Refined plan and staging

    The structural step has landed on #2002 (cbe4b75172): the service block is the original impl HostPlatform; execShell, sandboxBackend, execRoot and info are served from it; spawn, spawn_with_stdin, with_execution_settings, with_toolchain_source and prepare_isolated_process are #[service(skip)]. No new file and no new service object.

    Changed in place vs added

    Existing method Change
    spawn(spec) -> ProcessTree data spawn(request) -> {taskId, outputPath}; the handle method becomes internal spawn_tree
    spawn_pty(spec, size) -> PtyProcessTree data spawn_pty(request) -> {taskId, outputPath} (Stage 2)
    spawn_with_stdin(spec, stdin) data spawn_with_stdin(request) -> result (Stage 3)
    spawn_confined(spec, confinement) data spawn_confined(request) -> result (Stage 3)
    remove_exec_directory(&Path) remove_output_directory(PathBuf) (Stage 4)
    Added method Why it cannot be an existing one
    wait / kill / output / settle these operations are on the ProcessTree handle, not on HostPlatform; once spawn returns a task id, the owner needs them by id
    write / resize the same, for the PtyProcessTree handle (Stage 2)
    info home/os/arch/timezone/platformRoots are fields, not methods

    No configured/confined names: Stages 3 changes spawn_with_stdin/spawn_confined in place. tail/retainOutput only if the callers need them.

    Staging

    1. Stage 1 (now). HostPlatform owns the command task table and output files. spawn returns a task id; wait/kill/output/settle work by id. WorkspaceTools/BackgroundExec migrate; info consumers use the service. No new file.
    2. Stage 2. PTY ownership (spawn_pty -> task id, write/resize) and ShellSession; first decide the branch shell protocol's output delivery (poll output vs an owner-side stream).
    3. Stage 3. spawn_with_stdin/spawn_confined request/reply shapes; Hooks and OCR.
    4. Stage 4. remove_output_directory, childPath, and tail/retainOutput if needed.

    Stage 1 scope

    ~8–10 files, ~+900/−400: host_platform.rs (task fields and methods), workspace_tools/exec.rs, workspace_tools/background.rs, workspace_tools/mod.rs, shell_input.rs (spawn_tree), app-server/src/lib.rs (commandFiles), tests. No new file.

    Open

    • childPath should probably stay local to the App Server's MCP stdio child, not the remote node.
    • info() resolves the exec shell; callers that only need home/os can read the captured fields.
    • Shell output delivery is the Stage 2 design gate.
  7. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Stage 1 complete; wait is typed

    • wait now answers WaitReply with a WaitStatus union, optional exitCode/signal/failureNote, duration, output path, byte count and bounded preview. xtask types generates WaitReply/WaitStatus; the TS signature is wait(request: WaitRequest): Promise<WaitReply> (commit 8b17b575d9 on Serve hostPlatform's data methods; withdraw the execHost face #2002).
    • Stage 1 command task operations are in: spawn returns a task id; wait/kill/settle/output/retainOutput/tail work by id; WorkspaceTools/BackgroundExec use the owner's task; info, execShell, persistentShell, sandboxBackend, execRoot are served from the original impl HostPlatform. No new file.
    • Verification: host_platform_flow 20 passed; local_execution 42 passed; xtask check; clippy.

    Next: Stage 2 (shell/PTY). Decision for this stage: the branch shell protocol stays in ShellSession and runs where the shell owner runs; start_shell hands it an in-process output stream, while the public shell/write/resize/output operations serve foreign callers by task id. A control-side ShellSession against a remote owner is not part of this stage.

  8. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Stages 1–4 delivered on #2002

    • Stage 1 (b6ed380f2c, 8b17b575d9): command task table and output file on HostPlatform; spawn returns a task id; wait/kill/settle/output/retainOutput/tail by id; typed WaitReply/WaitStatus; info, execShell, persistentShell, sandboxBackend, execRoot. WorkspaceTools/BackgroundExec migrated.
    • Stage 2 (aabb04d4ba): PTY and shell task on HostPlatform; shell/write/resize; output/wait/kill/settle serve shell tasks; ShellSession runs its marker protocol over the owner's task.
    • Stage 3 (07fd907d2e): spawnWithStdin and spawnConfined are the data methods Hooks and OCR call; the low-level cores are *_process and stay off the service; SystemServices is data.
    • Stage 4 (cab9102422): removeOutputDirectory and childPath are data methods; SessionFiles and MCP keep the in-process binding.

    No new file: the shell module is inline in host_platform.rs; the service block is the original impl HostPlatform. The catalog and branch-services.d.ts are generated.

    Verification: host_platform_flow 24, hooks_flow 69, local_execution 42; xtask check; clippy; runtime/plugin-sdk.test.mjs 2. One combined run of host_platform_flow reported an uncaptured failure, and an immediate rerun passed 24/24; watch CI for a repeat.

    Remaining follow-ups (not blocking): the shell output path is the owner's capture; a control-side ShellSession against a remote owner is not part of Stage 2; childPath is a lossy string binding for non-UTF-8 paths.

  9. 6 remaining items

  10. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Wait-timeout kill: origin and fix

    • 2026-11-12, 0c74bdf45a ("docs: define resource leaf data faces (docs: define resource leaf data faces #1397)"): the execHost design says wait.timeoutMs "reaching it kills the tree". This is the design source; it also contradicted §3's rule that cancelling a read changes nothing.
    • 2026-11-21, 285941f0c1 ("Keep command processes on the execution host and expose start, wait, kill and settle"): CommandTask::wait implements it by cancelling the command's timeout token.
    • 2026-11-22, b6ed380f2c (Stage 1 of Serve hostPlatform's data methods; withdraw the execHost face #2002): the old exec.rs/background.rs were copied, so the implementation came along. ShellTask::wait copied the same pattern in Stage 2.
    • Fixed in 2d1e643d39: wait timeout answers WaitStatus::Running and leaves the task alive; a command's own spawn.timeoutMs still terminates it; kill is explicit. Test a_wait_timeout_leaves_the_command_running.

    This was not a requirement from the current work; it was inherited from the old design and never re-checked against the cancellation rule.

  11. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Correct the root, not by reverting

    Decision: keep the data face and fix the design; do not revert the shell work.

    Root cause of the 1 MiB reset: the owner owns the byte stream, but the marker/occupancy state machine is still in ShellSession. The bounded event queue is therefore being used as a lossless protocol stream; when it drops chunks, the parser resets and kills a healthy shell. ShellState and parse_shell_job are prefix/line scans, not the real parser. The fix is to move the marker/occupancy state and job registration to the owner, so output pages may be lossy while protocol state/events stay reliable.

    Order:

    1. P1 correctness first:
      • shell starts through start_shell without arc(); the minimal execution assembly must work.
      • removeOutputDirectory: reject ./.., canonicalize the target/deepest ancestor, compare with the canonical root, do not follow symlinks; SessionFiles defers to this authority.
      • spawnConfined maps ConfinedError::InvalidPath to HostPlatformError::InvalidPath { path, reason }; run the modality suite.
      • unify the sandbox_backend doc comment so xtask types is host-independent.
      • shell log: create_new + 0600; remove it when the shell task settles; no unbounded leak.
      • background jobs: resolve the node-local pid while the PTY is alive and store it in ShellJob; kill uses that pid; settle job records even when kill fails.
      • spawn maps task_exists/invalid ids to the typed errors; task_exists becomes reachable.
      • wait type docs and the running preview flag.
    2. Root parser/state:
      • move complete marker parsing and occupancy/background state into the owner;
      • expose reliable protocol events/state; output pages become a bounded display cache;
      • ShellSession no longer parses raw chunks; a lagging reader resynchronizes from state and never kills the shell;
      • job registration uses an owner reservation, not an unconditional scanner insert.
    3. Contract/docs/PathBuf cleanup and tests: minimal execution, burst >1 MiB, echo/fake markers, background job at shell exit, traversal/symlink, non-UTF-8.

    Verification must include cargo test --workspace --locked (the minimal execution assembly) and the modality suite, not only local_execution.

  12. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    P1 corrections landed (1e1f8c79)

    • shell calls start_shell directly; the minimal execution assembly works again (minimal_execution 22 passed).
    • Background shell jobs resolve the node pid while the PTY is alive and store it in ShellJob; kill uses it after the shell is gone; job records settle even when kill fails. stop_background_task and shell_exit_kills_background_jobs pass.
    • removeOutputDirectory rejects ./.., canonicalizes the target/deepest ancestor against the canonical root, refuses symlinks, and SessionFiles defers to it.
    • spawnConfined maps ConfinedError::InvalidPath to HostPlatformError::InvalidPath { path, reason }; the modality OCR test passes.
    • sandbox_backend has one doc comment; xtask types is host-independent.
    • Shell logs are create_new, 0600, and removed with the shell task.
    • spawn preflights the output directory and log path and maps task_exists/invalid requests.
    • wait docs say running; the running preview flag is computed.

    Still open (root): move the marker/occupancy parser and job reservation into the owner; make output pages a display cache and protocol state/events lossless; remove the reset-kill path; then PathBuf, settlement/owner docs and the PR description.

  13. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    P1 correction status and full-suite note

    P1 corrections are in 1e1f8c79. Targeted evidence:

    • minimal_execution 22 passed (including stop_background_task and shell_exit_kills_background_jobs);
    • local_execution 42 passed;
    • host_platform_flow 26 passed;
    • hooks_flow 69 passed;
    • the modality OCR helper test passed;
    • clippy and xtask check passed.

    cargo test --workspace --locked in this Linux environment is not a pass: transport_flow reports 338 failures with initialization timed out: AgentIndex Missing even when a single case is run alone, so the App Server suite cannot initialize here. This is not evidence for or against the execution changes; it needs separate environment/CI triage and is not claimed as passing.

    The root work is still open: owner-side marker/occupancy parsing, reliable protocol state/events, and removing the read-path reset that kills a healthy shell.

  14. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Root stage: lossless delivery and owner-side marker state

    1396403335:

    • The shell event page is now acknowledged by its cursor; the reader waits on a condvar when the 1 MiB queue is full instead of dropping chunks. A burst is backpressured, not reset; the shell stays alive.
    • ShellState is derived from full __DIM_START_/__DIM_END_ markers with cross-chunk line buffering; the echoed wrapper line no longer flips ready or sets lastCode.
    • parse_shell_job validates the full end marker and no longer accepts the echo; registration keeps the first record.

    Evidence: host_platform_flow 27, minimal_execution 22, local_execution 42, hooks_flow 69; the new burst test serves >1 MiB without reset; clippy and xtask check pass.

    Remaining root work:

    • ShellSession still owns the per-command capture/occupancy parser; the owner only owns the stream, the state hint and job registration. Moving the capture/occupancy state is the next structural step.
    • The reset branch in ShellSession still terminates the shell; with the ack it is unreachable for the sole reader, but it should be deleted, not kept as a kill path.
    • Job registration is still driven by the shell line, not an owner-issued reservation; zerob13's identity invariant remains open.
    • PathBuf across the face, owner/settlement docs and the PR description remain open.
  15. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Owner now emits output and marker events

    00b082b851:

    • The owner line-buffers the shell stream into ShellEvent::Output { text } and ShellEvent::Marker { line }.
    • ShellSession consumes named events instead of splitting raw chunks; the full marker line is already recognized by the owner.
    • ShellState and job registration use the same full-marker recognition; the echo no longer matches.

    Evidence: host_platform_flow 27, minimal_execution 22, local_execution 42, hooks_flow 69; burst >1 MiB backpressured; clippy and xtask check pass.

    Remaining: ShellSession still owns the per-command Capture/occupancy policy over the event stream; owner-issued job reservation; the reset branch that still terminates; PathBuf and owner/settlement docs.

  16. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Marker events and no read-path kill

    00b082b851 and 524deae114:

    • The owner line-buffers the stream into Output and full Marker events; ShellSession consumes named events, not raw chunks.
    • ShellState and job registration use the same full-marker recognition; the echo/partial marker does not match.
    • The 1 MiB queue is backpressured by cursor ack; a burst over 1 MiB is served without reset.
    • A reset/retained_from behind the cursor no longer terminates the PTY; kill remains the only operation that ends the shell.

    Evidence: host_platform_flow 27, minimal_execution 22, local_execution 42, hooks_flow 69; clippy and xtask check pass.

    The last structural piece is the per-command Capture/occupancy state in ShellSession: the owner now knows the stream and markers, but the command-to-marker-pair mapping is still control-side. Moving it needs a ShellWrite command id plus marker pair (or an equivalent start request) and a task-table entry for a shell command capture; that is the next shape decision.

  17. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Owner command capture is available

    17ec402af2 plus the a56c536f60 initializer fix:

    • ShellWrite can carry {command: {taskId, startMarker, endMarker}}.
    • The owner records the bounded output and exit code under that command id and serves output, wait and settle for it.
    • A foreground command capture test passes; plain shell writes pass command: None.

    Next switch: ShellSession.start_command/execute should use this capture instead of its own Capture; then Capture/occupancy can leave ShellSession. Until that switch the owner capture is exercised only by the new test.

    Evidence: host_platform_flow including the owner capture test, minimal_execution 22, local_execution 42; clippy and xtask check pass.

  18. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Foreground switch attempted; reverted on a hang

    Attempted to move ShellSession.run_foreground/start_command to the owner command capture and rewrite interrupt/occupy_current to read output/wait by command id.

    The minimal completion_markers_stay_out_of_captures case hangs: the owner command records the start line, but the foreground command's output/end never reaches run_foreground; the wait stays Running. Source-level attempts to follow the stream did not isolate whether the reader is blocked in the event/backpressure path or the active-command feed.

    The half-switch is reverted; the tree is at a56c536f60 with the owner capture capability and the 28/22/42 test suites passing. The foreground switch remains the next task; it needs an isolated repro before another large edit.

  19. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Second foreground-switch attempt: marker skip fixed, hang remains

    1fc4ecb071 fixes the owner command capture so a full marker line belonging to another command is skipped; the interleaved-marker owner capture test passes.

    The ShellSession foreground switch was re-applied and still hangs in completion_markers_stay_out_of_captures. A simple foreground_echo_returns_output passes under the same switch, so the hang depends on the background/foreground interleaving or the event consumer, not the basic owner capture. The switch was reverted again; the last committed state is owner capture + marker skip, with the old ShellSession path.

    Next investigation: instrument the completion_markers sequence at each command boundary and the event consumer, not just run_foreground.

  20. eric8810 commented on Nov 22, 2026

    @eric8810
    CollaboratorAuthor

    Shell capture and occupancy are now owner-owned

    0bc566e7fd completes the move:

    • ShellSession creates the command id and marker pair and sends them with write; the owner records output, exit code, the task log and the bounded tail.
    • Foreground, occupying and stop paths read output/wait by command id.
    • occupied_wait pages the owner's command output; handle_shell_exit and stop settle the owner command.
    • Capture, Inner.capture and advance_occupying are removed.
    • The active-command lock reentry that blocked the next write is fixed with Arc::ptr_eq.

    Evidence: minimal_execution 22, local_execution 42, host_platform_flow 28, hooks_flow 69, OCR 1; clippy and xtask check pass.

    Still from review, not in this move: PathBuf across the face, event-page limit, retainOutput for shell ids, settle on a running job, owner/settlement docs and the PR description.

  21. eric8810 commented on Nov 23, 2026

    @eric8810
    CollaboratorAuthor

    Path data, dead config and pid wait are closed

    aba6725310 and 7fd191ac77:

    • The hostPlatform data face no longer carries PathBuf: HostInfo, ExecShellRuntime,
      SpawnRequest/Reply, WaitReply, ShellRequest, ConfinedRequest,
      SpawnWithStdinRequest and RemoveOutputDirectoryRequest use UTF-8 strings; the owner
      converts at its boundary.
    • Removed the unused command_files config and FileStorage branch.
    • Removed the two-second PID_WAIT; a job kill waits on the reserved job's pid notification.
    • The job reservation/settle/kill semantics and the owner command capture remain as before.

    Verification: host 28, minimal 22, local 42, hooks 69, OCR 1; clippy, xtask types and
    xtask check pass.

  22. eric8810 commented on Nov 23, 2026

    @eric8810
    CollaboratorAuthor

    Non-UTF-8 path boundary is explicit

    984f6b59d1:

    • hostPlatform.info returns an error if the home, exec root or a platform root is not UTF-8.
    • A detected shell whose path is not UTF-8 answers exec_shell_unavailable.
    • Hooks fails the handler instead of lossy DIMCODE_HOME/DIM_PLUGIN_ROOT.
    • MCP returns no composed PATH for a non-UTF-8 base.
    • OCR fails the host task when the helper path, arguments, read/write paths or environment are not UTF-8.

    Verification: host 28, minimal 22, local 42, hooks 69, OCR 1; clippy, xtask types and xtask check pass.

  23. added
    P2
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2core

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions