Add -d/--detach flag for background daemon mode#716
Add -d/--detach flag for background daemon mode#716ReSyncc wants to merge 3 commits intoRightNow-AI:mainfrom
Conversation
jaberjaber23
left a comment
There was a problem hiding this comment.
Breaking behavior change that needs more work:
-
--config/-cis not forwarded to the background process. If a user runsopenfang start -c /custom/config.toml, the background process starts with default config, not the custom one. -
Exit code contract change — "already running" changed from exit(1) to success return. Scripts checking exit codes will break silently.
-
This is a breaking change for every user, tutorial, and script that uses
openfang startexpecting foreground behavior. Needs discussion and a deprecation warning at minimum. -
Test plan items are unchecked — the PR was not actually tested.
Addresses review feedback on RightNow-AI#716: 1. **Non-breaking**: `openfang start` remains foreground (unchanged behavior). Background mode is opt-in via `-d`/`--detach`. 2. **Config forwarding**: `--config` and `--yolo` flags are forwarded to the background process. `openfang start -d --config /custom/config.toml` works correctly. 3. **Exit codes preserved**: "already running" still exits with code 1, matching existing script expectations. 4. **Docs updated**: cli-reference.md documents the new flag with examples for foreground, detached, and combined usage. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
11873cb to
29e301e
Compare
- Foreground start now shows: "Tip: use openfang start -d to run in the background" - README quickstart blocks mention -d flag alongside openfang start Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Great point, ended up going to a
|
- stdout/stderr redirected to ~/.openfang/daemon.log (append mode) so startup errors are debuggable. Falls back to /dev/null if log file can't be opened. - Unix: pre_exec hook calls setsid() to create a new session, making the daemon fully independent of the launching terminal. Prevents SIGHUP from killing the daemon when the terminal closes. - Detach output now shows log file path. - Timeout error message points user to daemon.log. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
openfang start daemonize by default
Problem
OpenFang is an autonomous agent OS — it should run as a background service without requiring a dedicated terminal session. Currently,
openfang startblocks the terminal and the daemon dies when the terminal is closed. Users have to manually background it withnohupor&, which is a poor experience for an always-on system.This contradicts the core design: agents, channels (Telegram, Discord, etc.), scheduled jobs, and workflows should keep running independently of any terminal session.
Solution
openfang startnow spawns the daemon in the background using the existingstart_daemon_background()function (which was already used byopenfang dashboardbut not exposed to users) and returns immediately, printing the API URL and dashboard linkopenfang startwhen a daemon is already running now reports the existing daemon's URL instead of erroring outopenfang start --foregroundpreserves the old blocking behavior for Docker containers and debuggingCMD ["start", "--foreground"]since containers need the foreground process to stay aliveBenefits
openfang startand close their terminal — the daemon keeps running--foregroundTest plan
cargo build -p openfang-clicompilesopenfang startreturns immediately, daemon accessible at printed URLopenfang startagain prints "already running" with URLopenfang start --foregroundblocks as beforeopenfang stopstops the background daemonstart --foreground🤖 Generated with Claude Code