Skip to content

Fix --detach-process for standalone CLI - #12873

Open
Travor278 wants to merge 3 commits into
rerun-io:mainfrom
Travor278:fix/cli-detach-process
Open

Fix --detach-process for standalone CLI#12873
Travor278 wants to merge 3 commits into
rerun-io:mainfrom
Travor278:fix/cli-detach-process

Conversation

@Travor278

@Travor278 Travor278 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Related

What

--detach-process was copied into StartupOptions, but that field is never read by the standalone CLI, so the viewer kept running in the invoking process.

This change relaunches native-viewer CLI invocations once as a detached child:

  • preserves the original CLI arguments and inserts a hidden child marker before any -- end-of-options separator to prevent recursion;
  • starts a new session with setsid on Unix and uses DETACHED_PROCESS on Windows;
  • disconnects standard streams so captured pipes do not keep the launcher attached;
  • leaves subcommands, headless/server/web/save/test/version modes in the original process.

Focused tests cover the one-time relaunch guard, representative native-viewer invocations, rerun --detach-process -- recording.rrd, and the modes that must remain attached.

Testing

  • cargo test -p rerun --lib --no-default-features --features rerun/native_viewer,rerun/run detach_ (Windows and Linux; 3 passed on each)
  • cargo clippy -p rerun --lib --no-default-features --features rerun/native_viewer,rerun/run -- --deny warnings (Windows and Linux)
  • cargo fmt -p rerun -- --check (Windows and Linux)
  • cargo check -p rerun --lib --tests --no-default-features --features rerun/native_viewer,rerun/run (Linux)
  • cargo build -p rerun-cli --no-default-features --features rerun-cli/native_viewer (Linux)
  • pixi run lint-codegen
  • Changed-file fast lint checks for Rustfmt, TOML formatting, repository lint, typos, and notebook stripping
  • Windows lifecycle test: the launcher exited successfully in 546 ms, the detached child was observed alive, produced a screenshot, and exited without a leftover process
  • Linux lifecycle test: the launcher returned in 0 seconds, the child was observed with PID == SID == PGID, wrote a 124,236-byte PNG, and terminated

Confidence

High. The dead data flow was reproduced on current main; both platform-specific paths compile, Windows and Linux process lifecycles were validated end to end, and viewer/non-viewer mode selection plus end-of-options handling have regression coverage.

Agent

🤖 This PR was opened by a coding agent. The implementation and test results were reviewed in an LLM-assisted workflow.

@wuisabel-gif wuisabel-gif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The child marker should be inserted before any -- end-of-options separator rather than appended to the argument list. With an invocation such as rerun --detach-process -- recording.rrd, the child receives rerun --detach-process -- recording.rrd --detached-process-child. Clap treats the marker as a positional argument after --, leaving detached_process_child false, so should_relaunch_detached can recursively relaunch. Could we construct the child arguments by inserting the marker before the first --, and add a regression test for this invocation?

@Travor278

Copy link
Copy Markdown
Contributor Author

Good catch — you were right. I was appending the marker blindly, which breaks as soon as -- is present. Fixed in d471eb3: the child marker is now inserted before the first --, and I added the exact rerun --detach-process -- recording.rrd case as a regression test. I also reran the focused tests and Clippy on both Windows and Linux. Thanks for spotting this one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--detach-process doesn't work on standalone CLI (but works fine from spawn in the SDK)

2 participants