Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dimos/core/run_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RunEntry:
cli_args: list[str] = field(default_factory=list)
config_overrides: dict[str, object] = field(default_factory=dict)
grpc_port: int = 9877
original_argv: list[str] = field(default_factory=list)
Copy link
Collaborator

@Dreamsorcerer Dreamsorcerer Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor suggestion, but it might be good to make these kind of things immutable in future generally. This also avoids needing the default_factory:

Suggested change
original_argv: list[str] = field(default_factory=list)
original_argv: Sequence[str] = ()


@property
def registry_path(self) -> Path:
Expand Down
44 changes: 44 additions & 0 deletions dimos/robot/cli/dimos.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import inspect
import json
import os
import sys
import time
from typing import Any, get_args, get_origin

import click
Expand Down Expand Up @@ -190,6 +192,7 @@ def run(
log_dir=str(log_dir),
cli_args=list(robot_types),
config_overrides=cli_config_overrides,
original_argv=sys.argv,
)
entry.save()
install_signal_handlers(entry, coordinator)
Expand All @@ -203,6 +206,7 @@ def run(
log_dir=str(log_dir),
cli_args=list(robot_types),
config_overrides=cli_config_overrides,
original_argv=sys.argv,
)
entry.save()
try:
Expand Down Expand Up @@ -394,6 +398,46 @@ def agent_send_cmd(
typer.echo(text)


@main.command()
def restart(
force: bool = typer.Option(False, "--force", "-f", help="Force kill before restarting"),
) -> None:
"""Restart the running DimOS instance with the same arguments."""
Comment on lines +401 to +405
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--daemon usage in PR description is unimplemented

The PR description explicitly advertises dimos restart --daemon as a supported invocation, but the restart command only declares a --force / -f option. Running dimos restart --daemon today produces a Typer "Unexpected option" error.

If background restart is genuinely desired, a --daemon flag needs to be added here (and os.execvp replaced with a subprocess spawn for that code path). If the feature is out of scope for this PR the description should be corrected to avoid user confusion.

from dimos.core.run_registry import get_most_recent, stop_entry

entry = get_most_recent(alive_only=True)
if not entry:
typer.echo("No running DimOS instance to restart", err=True)
raise typer.Exit(1)

if not entry.original_argv:
typer.echo("Cannot restart: run entry missing original command", err=True)
raise typer.Exit(1)

# Save argv and pid before stopping (stop removes the entry)
argv = entry.original_argv
old_pid = entry.pid

typer.echo(f"Restarting {entry.run_id} ({entry.blueprint})...")
msg, _ok = stop_entry(entry, force=force)
typer.echo(f" {msg}")

# Wait for the old process to fully exit so ports are released.
from dimos.core.run_registry import is_pid_alive

for _ in range(20): # up to 2s
if not is_pid_alive(old_pid):
break
time.sleep(0.1)

typer.echo(f" Running: {' '.join(argv)}")
try:
os.execvp(argv[0], argv)
except OSError as exc:
typer.echo(f"Error: failed to restart — {exc}", err=True)
raise typer.Exit(1)


@main.command()
def show_config(ctx: typer.Context) -> None:
"""Show current config settings and their values."""
Expand Down
Loading