Skip to content

feat(daemon): run the daemon from the fbuild image by argv[0] (#1851 phase 1) - #1852

Merged
zackees merged 1 commit into
mainfrom
agent/daemon-multicall
Nov 2, 2026
Merged

zackees merged 1 commit into
mainfrom
agent/daemon-multicall

Conversation

@zackees

@zackees zackees commented Nov 2, 2026

Copy link
Copy Markdown
Member

What

Phase 1 of #1851: make the daemon runnable from the fbuild image itself, chosen by
argv[0] — busybox-style, the way soldr does it. Both binaries are still built and
shipped in this phase; no packaging, wheel or install change.

  1. crates/fbuild-daemon/src/entry.rs (new) — the whole body of the old async fn main() is
    now pub fn run() -> i32. run() starts heap_profile::start_from_env() as its first
    statement
    (the perf: adopt the mimalloc-pprof allocator for heap/leak profiling; verify on-CPU, off-CPU, and symbolization from running-process #1361 ordering, ahead of the tokio runtime it then builds) and blocks on the
    same multi-thread runtime the #[tokio::main] attribute used to create. Body moved verbatim;
    the two baseline #[expect]s (too_many_lines, cognitive_complexity) carry over — clippy
    exempts a function literally named main from exactly these two lints, so they must be
    explicitly expected at the new name and must not grow.
  2. crates/fbuild-daemon/src/main.rs — 3-line shim: std::process::exit(fbuild_daemon::entry::run()).
    The #[global_allocator] stays here, because it is a bin-level item and belongs to the
    executable that ships the profiler.
  3. crates/fbuild-cli/src/multicall.rs (new) — classify_argv0 / maybe_dispatch, recognising
    only fbuild-daemon. Separators are stripped as text (/ and \) and the final extension is
    removed textually, so a Windows path (C:\…\FBUILD-DAEMON.EXE) classifies identically on a
    Unix host — the dispatch rule must not depend on which platform runs it.
  4. crates/fbuild-cli/src/main.rs — the hook is the first thing in fn main(): before the 8 MB
    stack trampoline, before the dev-namespace hash, before the tokio runtime and clap. Anything
    that is not the daemon stem falls through unchanged.

Why argv[0] (per the issue)

External callers (FastLED, scripts, service definitions, the running-process broker) exec
fbuild-daemon by name, and fbuild identifies its daemon by exe stem
(fbuild_paths::daemon_ownership::DAEMON_EXE_STEM). A hidden fbuild __daemon subcommand would
give the process the stem fbuild and make it indistinguishable from a CLI invocation. Nothing
external has to change in this phase or the next.

Verification (real output)

$ soldr cargo test -p fbuild-daemon --lib -- entry::
test entry::tests::is_pid_alive_returns_true_for_self ... ok
test entry::tests::is_pid_alive_returns_false_for_obviously_dead_pid ... ok
test entry::tests::another_daemon_is_listening_detects_a_live_listener ... ok
test result: ok. 3 passed; 0 failed; 0 ignored

$ soldr cargo test -p fbuild-cli --bin fbuild -- multicall::tests
test multicall::tests::classifies_relocated_daemon_path ... ok
test multicall::tests::classifies_bare_daemon_name_and_exe_suffix ... ok
test multicall::tests::classifies_unix_daemon_path ... ok
test multicall::tests::classifies_windows_daemon_path_with_exe_and_any_case ... ok
test multicall::tests::falls_through_for_empty_and_foreign_names ... ok
test multicall::tests::falls_through_for_the_cli_itself ... ok
test multicall::tests::stem_strips_directories_and_the_final_extension_only ... ok
test result: ok. 7 passed; 0 failed; 0 ignored

$ SOLDR_VERDICTS=off soldr cargo clippy --workspace --all-targets -- -D warnings   # rc 0, 0 errors
$ soldr cargo fmt --all -- --check                                                # rc 0
$ uv run --no-project python ci/enforce_platform_boundary.py --print-totals        # rows=44; dylint_rows=43, rc 0
$ uv run --no-project python ci/check_test_layout.py                               # ok: 8 categories, rc 0

End-to-end, same image under two names (isolated HOME, dev mode, free port):

$ cp target/debug/fbuild bin/fbuild-daemon
$ ./bin/fbuild-daemon --help
fbuild daemon server
Usage: fbuild-daemon [OPTIONS]
  -p, --port <PORT>   --dev   --spawner-cwd <SPAWNER_CWD>

$ ./bin/fbuild --help
PlatformIO-compatible embedded build tool
Usage: fbuild [OPTIONS] [PROJECT_DIR] [COMMAND]

$ ./bin/fbuild-daemon --dev --port 8977 &
$ curl -s 127.0.0.1:8977/health
{"status":"healthy","uptime_seconds":12.7,"version":"2.5.49",…,"source_exe":"…/bin/fbuild-daemon"}
# every daemon log line is now target fbuild_daemon::entry

$ FBUILD_HEAP_PROFILE=1 ./bin/fbuild-daemon --dev --port 8979
INFO fbuild_daemon::entry: heap profiling enabled from process start, sampling every ~524288 bytes

The last two lines are the point of the move: the profiler still starts before anything else
when the daemon is entered through the multicall path (#1361), and the health payload still
reports the exe it was launched as.

Scope note

Phases 2–4 of #1851 (self-relocation into the cache root, dropping the second link from the
wheel, alias creation at spawn, restart_diag source-vs-relocated reporting) are deliberately
not in this PR. This one only proves the mechanism with both binaries still shipped, which
is the phase the issue asks to land first.

No new workspace crate, no new file lock, no packaging change.

Closes #1851 phase 1.

Dylint

Both crates pass the full lint set (run with the CI-pinned cargo-dylint 6.2.0; the
~/.venv/bin/soldr 0.9.41 on this host defaults to 6.0.3, whose driver does not build on
nightly-2026-08-15, so the gate must be invoked with the newer /usr/bin/soldr on PATH):

$ soldr dylint --all -- --package fbuild-daemon --all-targets   # rc 0, 0 errors
$ soldr dylint --all -- --package fbuild-cli --all-targets      # rc 0, 0 errors

The entry module is a program entry point, so it sits at src/bin/entry/mod.rs (a library
module — cargo only auto-discovers src/bin/*/main.rs, so no binary target is created; verified
with cargo metadata: [lib, containment_harness bin, fbuild-daemon bin, it test]). That is the
path scope ban_process_exit_outside_main and ban_env_var_set_after_import already exempt;
neither allowlist.txt is touched, since both say new files must not be added.

…phase 1)

Move the daemon's main body into the library as fbuild_daemon::entry::run(),
keeping heap_profile::start_from_env() as the process's first statement
(#1361). src/main.rs becomes a three-line shim; the #[global_allocator] stays
in the bin where it belongs.

fbuild-cli gains a multicall module that classifies argv[0] before the 8 MB
stack trampoline, the dev-namespace hash, the tokio runtime and clap, and
dispatches to entry::run() when the stem is fbuild-daemon. Separators and the
final extension are handled textually so a Windows path classifies the same
way on any host.

The entry module lives at src/bin/entry/mod.rs (a library module, not a
binary target): it is a program entry point, which is exactly the scope the
ban_process_exit_outside_main and ban_env_var_set_after_import dylints exempt
by path; neither allowlist is touched.

Both binaries are still built and shipped in this phase. No packaging, wheel,
service-definition or external-caller change.

Refs #1851
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@zackees

zackees commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

Local gates on d4a3c2d2 (all real output):

$ TMPDIR=/home/niteris/t bash test          # rc 0
47 suites, 4137 passed, 0 failed, 0 error

$ SOLDR_VERDICTS=off soldr cargo clippy --workspace --all-targets -- -D warnings   # rc 0, 0 errors
$ soldr cargo fmt --all -- --check                                                # rc 0
$ soldr dylint --all -- --package fbuild-daemon --all-targets                     # rc 0
$ soldr dylint --all -- --package fbuild-cli --all-targets                        # rc 0
$ uv run --no-project python ci/enforce_platform_boundary.py --print-totals        # rows=44; dylint_rows=43
$ uv run --no-project python ci/check_test_layout.py                              # ok: 8 categories
$ uv run --no-project python ci/check_workspace_crates.py                         # OK: 21 members, no new crates

E2E: the same image renamed to fbuild-daemon serves /health (source_exe = the alias path,
all daemon log targets fbuild_daemon::entry), FBUILD_HEAP_PROFILE=1 still logs "heap profiling
enabled from process start" (#1361), and the same file as fbuild prints the CLI help unchanged.

@zackees
zackees added this pull request to the merge queue Nov 2, 2026
Merged via the queue into main with commit be6059a Nov 2, 2026
29 checks passed
@zackees
zackees deleted the agent/daemon-multicall branch November 2, 2026 05:33
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

perf(size): ship one binary — run the daemon from fbuild instead of a second full-stack executable

1 participant