Skip to content

[Feature]: Add managed background execution for local User Runners #1226

Closed

Description

@loveRhythm1990

Agent | Codex | GPT-6 (tier not exposed)

Existing issue check

  • Searched existing issues for background execution, daemon management, and astra-edge; no equivalent feature issue was found.

Problem and current user journey

MOI lets a user attach their own computer as a User Runner. The user opens the "Connect your own runtime environment" dialog, copies a server-generated command, changes into the directory they want to expose, and runs the local astra-edge binary. The command includes an explicit Edge identity, server URL, connection credential, and reconnect setting.

Today the process stays in the foreground and continuously prints structured logs. The dialog instructs the user to keep the terminal running. This occupies a terminal and makes a normal product connection look like a debugging session. The requested improvement is to let users keep using that terminal after the Runner connects, while retaining accessible diagnostics and explicit process control.

Agreed product behavior: commands generated by MOI should start a managed background Edge. After authentication and readiness are confirmed, the startup command should return control to the terminal. An explicitly selected foreground mode must remain available for debugging and container deployments. This does not mean silently changing every existing bare astra-edge invocation to background execution.

No implementation has been made for this feature. This issue records the investigation and handoff plan.

Implementation decision (2026-11-05): do not add a background flag to the MOI command. Details are in the issue comment linked from this thread.

Confirmed implementation baseline

Astra source inspected at main commit d6f6ce0afece513945b0537c042e4350bfc81c0c:

  • Edge binary entrypoint: Args exposes connection, workspace, identity, profile, reconnect, and capacity-provider inputs. There are no first-class background/start/status/stop/logs commands. The binary initializes logging, prints connection information to stderr, and runs the connection/reconnect loop.
  • Shared logging owner: formatting writes to stderr; this path has no managed rotating log-file sink.
  • Edge runtime: connection serving already has readiness/cancellation/drain machinery. The standalone binary currently supplies ready: None and fresh cancellation tokens. Reuse these owners when wiring startup acknowledgement and stopping.
  • Token renewal: renewal requires ASTRA_TOKEN_RENEW_URL. Without it, renewal is disabled. The reported foreground session explicitly logged that renewal was disabled. ASTRA_TOKEN_FILE is supported, with a workspace-relative default; existing TokenManager owns token state and persistence.
  • Local state owner: ASTRA_LOCAL_STATE_ROOT already supports an explicit override; the ordinary default is under ~/.astra.
  • Installation lease: MOI-managed binaries hold a shared runtime lease until work has stopped. A background child must preserve this contract.

MOI caller investigation used local Matrixflow revision 2ef1b5e2a4c69ff2e597fed30e99f9924fec970d (a local working-branch baseline, not a claim about deployed or upstream main):

  • moi/pkg/service/runner/connect_cmd.go, buildConnectCmd, generates the foreground connection command.
  • moi-frontend/modules/moi-agent/src/pages/runtime-environment/runnerInstall.ts, runnerConnectCommand, replaces the executable with the installed bundle executable path and preserves the remaining server-issued arguments.
  • moi-frontend/modules/moi-agent/src/pages/runtime-environment/ConnectCommandModal.tsx displays and copies the command and connection instructions.

The MOI dialog does not currently own process supervision. Background lifecycle should be owned by Astra Edge and consumed by MOI, rather than duplicated in frontend shell snippets.

Desired user experience

  1. User chooses a local directory and runs the MOI-provided connection command once.
  2. Startup validates configuration, captures the canonical absolute workspace path, and starts the managed child.
  3. The command waits for authenticated Edge readiness with a bounded deadline. It must not report success merely because a PID exists or a WebSocket opened.
  4. On success, print a short confirmation and ways to inspect status, read logs, and stop the Runner; then return the terminal prompt.
  5. Closing the terminal leaves the managed Runner running. The computer still needs to remain awake and online. Network loss should use existing reconnect behavior.
  6. Startup/authentication failures produce an actionable error and nonzero exit status, with an explicit cleanup outcome. They must not leave a hidden unowned child.
  7. Users can inspect whether the Runner is connected, reconnecting, stopped, or needs renewed authentication. A live process is not sufficient evidence of a healthy connection.
  8. Users can stop the selected Runner without affecting another Runner or environment.

The MOI connect command is unchanged and gains no flag. A new binary detaches only for an interactive terminal plus that existing runner- argv; sandbox, containers, and image-managed runners stay in the foreground. ASTRA_EDGE_FOREGROUND=1 keeps the new binary in the foreground. astra-edge status, stop, and logs are separate management commands and are not part of the connect command. See the implementation decision comment on this issue.

Implementation plan and ownership

1. Define the Edge-managed process contract

  • Add a background mode and local management operations in Astra, while preserving existing foreground/container use.
  • Identify managed instances using the existing Runner/server/workspace identity model. Isolate different environments and Runners.
  • Make repeated and concurrent starts deterministic: do not launch duplicate workers for the same managed instance; reject conflicting configuration explicitly.
  • Handle stale management records and PID reuse safely. Management operations must verify ownership before signalling a process.
  • Reuse existing readiness, reconnect, cancellation, drain, materialization, and invocation-journal owners. Do not create separate tool execution or task lifecycle semantics.
  • Define bounded startup and stop behavior, including what happens to already admitted work under the existing shutdown contract.

2. Define state, credential, and log storage

The user suggested a MOI-specific home directory. An illustrative layout is:

~/.moi/runners/<environment>/<runner-id>/
  <managed-process metadata>
  <restricted credential/config files>
  logs/

This layout is a proposal. Generic Edge should reuse the canonical Astra local-state owner; MOI may select a dedicated root through supported configuration. Resolve the exact layout before implementation, including the fact that existing token-file and journal defaults are not all governed by the same root.

  • Store management state and logs outside the exposed workspace.
  • Persist the selected absolute workspace before detaching; later startup or management from another directory must not retarget it.
  • Use restrictive permissions for state and credentials; never include credentials in logs, status output, or printed diagnostic command lines.
  • Bound log growth with documented rotation/retention. Capture relevant startup errors as well as normal runtime logs.
  • Reuse the existing logger and TokenManager. Do not silently relocate or discard existing identity, credentials, or invocation journals.

3. Make long-running authentication observable

Backgrounding alone does not solve credential expiry.

  • Determine whether the existing MOI credential flow can use the existing Edge renewal contract and configure it explicitly where supported.
  • Preserve existing remote-HTTPS and credential-persistence rules.
  • If renewal is unavailable or authentication becomes permanently invalid, expose an explicit recoverable state and instructions to refresh the connection through the product.
  • Do not invent a renewal endpoint, assume a permanent credential, retry a permanently invalid credential indefinitely, or add a second token-renewal owner.

The MOI renewal wiring is an integration question to verify, not a confirmed complete capability.

4. Integrate with the existing installer and MOI caller

  • Keep the background worker's existing installation lease for its full lifetime. Verify that status/stop operations remain usable while the worker is running and that an update cannot bypass active-runtime protections.
  • Document how users stop and restart a managed Runner around an update. Automatic seamless upgrades are not required for the first version.
  • Coordinate the supporting Edge bundle release with MOI command generation and frontend instructions. Do not emit unsupported flags/subcommands to older installed binaries; make the minimum-version/update requirement explicit.
  • Matrixflow follow-up work should update command generation and dialog guidance to use the new public Edge contract and explain background/online behavior.
  • This Astra issue owns the Edge capability. Track any Matrixflow implementation separately and link it; an Astra-only PR must not claim the full MOI journey is complete without integration verification.

Scope boundaries

  • First version: explicit user-started background execution that survives terminal closure, plus lifecycle/status/log management.
  • Keep foreground debugging and container behavior available.
  • OS-login/reboot autostart, automatic crash supervision, and automatic binary replacement are separate decisions and are not required for this issue.
  • Do not change server-side execution policy, Runner workspace boundaries, or credential authorization semantics.
  • No Helm chart change is inherently required for local process backgrounding.
  • This report contains no real connection credentials, private endpoints, Runner identifiers, or raw screenshots.

Acceptance criteria

  • A documented MOI-style connection invocation starts one background worker, returns only after authenticated readiness, and releases the terminal.
  • The worker survives parent-terminal closure on supported local-client platforms.
  • The explicitly selected foreground mode and existing container invocation continue working.
  • Wrong/expired credentials, unreachable server, readiness timeout, invalid workspace, and unwritable state/log directories produce actionable failures with deterministic child cleanup.
  • Repeated/concurrent starts and stale records cannot create duplicate workers or cause stop to target an unrelated process.
  • Status distinguishes connected/reconnecting/authentication failure/stopped; logs can be read without exposing credentials.
  • Stop integrates with existing admitted-work shutdown semantics and releases the installation lease after work has stopped.
  • Workspace identity and runtime journals remain stable across disconnect/reconnect and managed restart.
  • State/credential permissions, log rotation/retention, environment/Runner isolation, and paths with spaces are verified.
  • Token-renewal or credential-expiry recovery behavior is documented and tested; disabled renewal cannot appear as an indefinitely healthy Runner.
  • Existing installer/update locking is covered, including stopping a worker when an update is blocked by its lease.
  • Offline integration tests exercise the real parent/child lifecycle and readiness failure paths; document supported platforms and remaining manual checks.
  • A linked Matrixflow change updates the generated command and dialog guidance, and the end-to-end MOI connection is verified before declaring the product rollout complete.

Priority and verification status

Suggested priority: normal product usability improvement; no outage or security defect is being asserted.

Evidence consists of the reported foreground session and read-only source inspection. No new background process was launched, no code was changed, and no implementation tests were run for this proposal. The implementation agent should recheck latest main, relevant architecture contracts, existing local process utilities, and platform support before coding.

Activity

  1. added
    kind/feature
    on Nov 5, 2026
  2. loveRhythm1990 commented on Nov 5, 2026

    @loveRhythm1990
    CollaboratorAuthor

    Implementation decision (2026-11-05)

    The MOI connect command stays exactly:

    astra-edge --edge-id runner-… --server-url … --token … --reconnect true
    

    No new flag or subcommand is added to that command. Old binaries therefore keep running it in the foreground and do not fail on an unrecognized argument.

    A new astra-edge detaches only when all of the following are true:

    • The process argv itself contains that explicit set: --edge-id whose value starts with runner-, plus --server-url, --token, and --reconnect true. Environment-derived identity does not count.
    • stdin is a terminal.
    • ASTRA_EDGE_FOREGROUND is unset.
    • This process is not already the managed child.

    Every other invocation stays in the foreground. That includes today's binaries, non-interactive runs, debug runs, containers, and sandbox / OpenShell / image-managed runners. Those deployments start /usr/local/bin/astra-edge with credentials in the environment (ASTRA_TOKEN, ASTRA_EDGE_ID, ASTRA_WORKSPACE_DIR, and, for sandboxes, ASTRA_TOKEN_RENEW_URL). They do not use the MOI connect argv and must not be detached.

    ASTRA_EDGE_FOREGROUND=1 keeps a new binary in the foreground for debugging. Unknown environment variables are ignored by old binaries.

    Startup behavior for the detached path:

    • The parent waits until the existing authenticated-ready signal (after AuthOk and invocation-journal recovery). A live PID or an open WebSocket is not success.
    • On success the parent prints how to run status, logs, and stop, then returns the terminal. It does not print the token or the full command again.
    • On failure the parent exits non-zero and does not leave an unowned child.
    • The child calls setsid, ignores SIGHUP, canonicalizes the workspace before continuing, and holds the MOI installation lease until it exits. The parent must not be the process that keeps that lease.
    • Logs for this run go to a file outside the exposed workspace. Foreground and container runs continue to use stderr.
    • A second launch of the same runner does not start another worker. stop signals a process only after checking that it still owns the managed instance and is astra-edge.
    • status reads the managed phase (starting, connected, reconnecting, authentication-failure, stopped). A live process alone is not reported as connected.

    astra-edge status, astra-edge stop, and astra-edge logs are separate management commands. They are not inserted into the MOI connect command. --version and --moi-update-protocol stay ahead of connection startup.

    Dialog copy is a Matrixflow follow-up. The page cannot see which binary the user has, so the hint must describe both outcomes: if the command returns, the terminal may be closed; if it stays in the foreground and keeps logging, keep the terminal open. The generated command bytes stay unchanged.

    Token renewal and the product "refresh connection" action are unchanged. Backgrounding does not make the credential permanent. Refresh still revokes the current token. A managed runner with renewal disabled must be able to show authentication failure instead of looking healthy forever.

    Sandbox, OpenShell, server deployment, and Helm values are outside this change.

  3. loveRhythm1990 commented on Nov 5, 2026

    @loveRhythm1990
    CollaboratorAuthor

    Opened #1227. A new astra-edge detaches only the existing interactive MOI connect command after the authenticated-ready signal. Old binaries, containers, and sandbox stay in the foreground because the command bytes are unchanged.

  4. added a commit that references this issue on Nov 21, 2026
    d33c809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions