Skip to content

Remove the pro feature and --edition from nodespaced; reject unknown arguments - #3375

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3348-reject-unknown-args
Sep 30, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3348-reject-unknown-args

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #3348

What changed

  • packages/daemon/Cargo.toml: delete the [features] table (pro was its only entry and nothing enables it).
  • packages/daemon/src/main.rs:
    • delete is_pro_build(), edition() and the --edition early exit; pass false to marker_path and default_socket_path_for.
    • main() keeps --version, then calls a new pure first_unrecognized_arg(&[String]) -> Option<&str> (accepts only ACCEPTED_ARGS = [TRAY_FLAG], skips argv[0]). On Some, before tracing or the runtime start: one stderr line naming the argument and the supported ones (--tray, --version), then exit(2). Nothing on stdout, no socket bound.
    • reword the argv comment that cited the postinstall.
  • packages/daemon/src/tray.rs: ui_pid_path passes false instead of cfg!(feature = "pro"); doc now says the variant is the build flavour (debug or release).
  • .claude/skills/run-app/SKILL.md: the "nodespaced --help starts a daemon on the real database" warning is no longer true, so it now says the flag is refused with status 2.

Out of scope, as the issue says: marker_path(is_pro), default_socket_path_for(_, is_pro), proto::socket and the Pro rows of the variant tests (#3355), the postinstall guard (#3349), LAUNCHER_ARGS (#3352).

Deviations from the issue text

  • std::env::args_os() with lossy conversion instead of std::env::args(). args() panics (exit 101) on a non-UTF-8 argument, which would break "any other unknown argument exits 2". A lossy string is unrecognized, so it takes the same path. One line.
  • VERSION_FLAG / UNRECOGNIZED_ARG_EXIT_CODE constants added so the stderr message and the check share one spelling. --version is answered before first_unrecognized_arg, so it is not in ACCEPTED_ARGS (as specified); nodespaced --bogus --version therefore still prints the version, as before.
  • .claude/skills/run-app/SKILL.md edit was not in the issue's scope list; it documented the exact hazard this PR removes.
  • The unit tests share tray_mode_tests::argv (made pub(super)) rather than duplicating it.

Launcher audit (the issue's "Risks" step)

Re-checked every place that spawns nodespaced. Arguments passed: only --tray (app plist in daemon_setup.rs, systemd ExecStart, Windows spawn and HKCU autorun, scripts/pkg-resources/app.nodespace.daemon.plist) or none (Homebrew formula service, test-support, daemon-harness.ts, packages/daemon/tests/it), plus --version (formula test). The only remaining --edition caller is scripts/pkg-resources/postinstall:34, which falls back to unknown via || echo and is removed by #3349; sync's Pro postinstall does the same. No launcher missed.

Ratchet

scripts/check-pro-boundary.ts (#3299) is not on origin/main yet, so there is no BASELINES to lower in this PR. Measured with the checker from the #3299 branch, run over origin/main and over this branch:

marker delta
editionBranching -9 (is_pro_build x5 incl. its doc, feature = "pro" x2, --edition, tray line)
proWording -4
cloudWording -1
all others 0

This PR adds no marker: the retired flag is built with concat!("--", "edition") in both test files. Whichever of #3299 and this PR lands second must lower BASELINES by 9 / 4 / 1 (editionBranching, proWording, cloudWording).

Verification

  • git grep -nw is_pro_build -- packages/daemon and git grep -n -F -e --edition -e 'feature = "pro"' -e 'fn edition' -- packages/daemon both print nothing.
  • Built binary, isolated home: --edition, --help, --no-such-flag exit 2 with empty stdout, the stderr line, and no socket; --version prints 0.3.2, exit 0.
  • cargo clippy -p nodespace-daemon --all-targets -- -D warnings -D clippy::unused-async: clean. cargo fmt -p nodespace-daemon -- --check: clean.
  • bun run test:changed (rust workspace nextest + scripts tiers): passed.
  • New tests: 6 unit tests (unrecognized_arg_tests) and 4 integration tests (unrecognized_flag::).

Mutation checks (each reverted afterwards)

mutation result
delete the exit(2) line 3 refusal integration tests fail (daemon really starts, hits the 10 s timeout, is killed); --version test passes
exit code 2 -> 1 3 integration tests fail
message to stdout instead of stderr 3 integration tests fail
drop --version handling --version integration test fails
drop .skip(1) 6 unit tests fail
empty ACCEPTED_ARGS 3 unit tests fail
.last() instead of first the_first_of_several_unknown_arguments_is_reported fails
accept everything 3 unit tests fail

Not verified here

nodespaced --tray was not launched (needs a display and an NSApplication run loop); it is covered by the tray_mode / first_unrecognized_arg unit tests and by the audit above. The Windows and Linux builds were not compiled; the change touches only cfg-independent code and the unix-only integration test is #![cfg(unix)].

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic Code Review

Review Type: Initial Review (commit 16e749b6; no prior reviews or comments on the PR)

Summary

Net positive and correct. The dead pro feature, is_pro_build(), edition() and --edition are gone, and main() now refuses any argument other than --tray / --version (stderr line, exit 2) before tracing or the runtime start. I independently audited every launcher and found no caller that passes an argument the daemon now rejects. The tests are real and non-vacuous by design. One small documentation finding (SKILL.md) and a few nits; nothing blocking.

Requirements Check (issue #3348)

  • ✅ AC1: git grep -nw is_pro_build -- packages/daemon and git grep -n -F -e --edition -e 'feature = "pro"' -e 'fn edition' -- packages/daemon both print nothing (ran both).
  • ✅ AC2: the retired flag, --help and any other unknown argument exit 2, print nothing on stdout, bind no socket. Re-ran nextest run -p nodespace-daemon --test it unrecognized_flag:: (4/4 pass, 1.1 s) and drove the built binary in an isolated home: --help, --edition, --tray --bogus, --tray=foo, "", -psn_0_12345 all exit 2 with the one-line stderr and no socket file.
  • ✅ AC3 (with a caveat): nodespaced --version prints 0.3.2, exit 0 (also --bogus --version and --version --bogus). Bare nodespaced and --tray are unchanged code paths; bare launch is still exercised by sigterm_during_model_load, and --tray acceptance is pinned only at unit level (first_unrecognized_arg returns None), since --tray needs a display. I did not launch a tray daemon.
  • ❌ AC4 (not achievable on this branch, documented): scripts/check-pro-boundary.ts is not on origin/main (git ls-tree empty; it lives in open PR Add the Pro-boundary ratchet check and the Pro/sync placement rule #3376), so there is no BASELINES to lower. I checked the claim by loading MARKERS from the Add the Pro-boundary ratchet check and the Pro/sync placement rule #3376 worktree and applying it to this diff: added lines hit zero markers; removed lines drop editionBranching -9, proWording -4, cloudWording -1, exactly matching the PR body. Coordination note: whichever of Add the Pro-boundary ratchet check and the Pro/sync placement rule #3376 and this PR lands second must lower BASELINES by 9 / 4 / 1 or its gate will fail.
  • 📝 Scope list: every item present (Cargo.toml [features] deleted; marker_path(false); socket_path fallback; first_unrecognized_arg(&[String]) -> Option<&str> with ACCEPTED_ARGS = &[TRAY_FLAG]; edition() deleted; test updated to false; tray.rs false and doc reworded; unrecognized_flag.rs registered in tests/it/main.rs). Deviations (args_os + lossy, VERSION_FLAG/UNRECOGNIZED_ARG_EXIT_CODE consts, SKILL.md edit, pub(super) on argv) are all justified and small.

Launcher audit (independent, not taken from the PR body)

I grepped nodespaced across scripts/, .github/, packages/, .claude/, all *.json/*.toml/*.plist/*.sh, and read each spawn site. Arguments passed today: only --tray, or none, plus --version.

  • --tray: daemon_setup.rs launchd plist template (~L1195) and systemd ExecStart (~L1470), Windows spawn_daemon_windows (.arg(DAEMON_TRAY_FLAG)) and HKCU autorun ("\"bin\" --tray"), and scripts/pkg-resources/app.nodespace.daemon.plist.
  • none: Homebrew formula service (run [opt_bin/"nodespaced"], update-homebrew-formula.ts ~L331), test-support SpawnedDaemon::spawn (env only), daemon-harness.ts (child_process.spawn(binary, [])), sigterm_during_model_load, scripts/eval/preflight.ts (prints a bare command), SKILL.md launch step.
  • --version: formula test (shell_output("#{bin}/nodespaced --version")).
  • Tauri: tauri.conf.json and tauri.pro.conf.json only list externalBin names (no args); the app has no tauri-plugin-shell dependency (Cargo.toml, capabilities), so no sidecar launch path appends args. The bundled sidecar is copied to ~/.nodespace/bin and started through launchd or Command::new.
  • History: before the --tray opt-in commit the launchers passed no daemon arguments (the old control was an env var), so plists/autorun entries written by older app versions carry either nothing or --tray. No restart-loop risk on upgrade.
  • Cargo: no Cargo.toml in this repo enables nodespace-daemon features; the only other consumer is packages/cli (no features). Sibling repo sync: nodespaced-pro/Cargo.toml depends on nodespace-daemon by git rev with no features, has no --features pro in any workflow/script, and has its own --edition handling in its own main.rs, so it is unaffected.
  • Remaining --edition callers: scripts/pkg-resources/postinstall:34 (core) and sync's postinstall:33, both ... 2>/dev/null || echo "unknown". I ran the exact core substitution under bash -c 'set -euo pipefail' against the built binary: yields EXISTING_EDITION=[unknown], continues, rc 0, no hang. Sync's "unknown" only skips a log line.
  • Residual, unverified by execution: I cannot run a Finder/LaunchServices launch here. Reasoning: the daemon is never a bundle's CFBundleExecutable (that is NodeSpace), so LaunchServices does not append -psn_*; the binary does reject that argument (verified), so a hypothetical launch that added it would exit 2.

Findings

🟡 Important: SKILL.md now tells agents it is "safe" to probe the binary, and points at the wrong file

📁 .claude/skills/run-app/SKILL.md:18-23 (and step 1 at :39)

The new text says nodespaced --help is refused, "so probing the binary that way is safe", and "Read packages/daemon/src/lib.rs for the flags and environment it honours."

  • "Safe" holds only for a binary built from this change. Step 1 is ls target/debug/nodespaced || bun run build:sidecars --debug, i.e. it deliberately reuses any existing target/debug/nodespaced, and the installed /usr/local/bin, Homebrew and app-bundled daemons all pre-date this change. Any of those still ignores --help and starts a daemon against the real ~/.nodespace database, which the section itself says "has bitten before". The old rule ("do not probe the binary") stays correct for those binaries.
  • The flags are consts in packages/daemon/src/main.rs (TRAY_FLAG L1134, VERSION_FLAG L1139, ACCEPTED_ARGS L1142); lib.rs contains none (grep). lib.rs holds the env/db-path resolution only.

Recommendation: keep the "do not probe with --help" advice with a qualifier, e.g. "A binary built with the unknown-argument check exits 2 on --help without starting anything; an older binary starts a daemon on the real database, so do not probe an unknown binary", and point to main.rs for flags and lib.rs for environment.
Engineering principle: a safety warning must stay true for the worst-case reader, not only the freshest build.
Verified: read SKILL.md before/after (git diff), git grep -n -e '--tray' -e '--version' packages/daemon/src/lib.rs (no hits), read step 1.

🟢 Suggestion (Nit): supported-argument list is written in two places

📁 packages/daemon/src/main.rs:445-447 vs :1142

The stderr message hard-codes {TRAY_FLAG}, {VERSION_FLAG} while acceptance is driven by ACCEPTED_ARGS + the separate --version branch. Adding a flag to ACCEPTED_ARGS without touching the format string would print an inaccurate "supported" list. Deriving it (ACCEPTED_ARGS joined plus VERSION_FLAG) keeps one source of truth. The integration test does assert both names appear, which limits the damage. Optional.

🟢 Suggestion (Nit): main() comment slightly conflates two mechanisms

📁 packages/daemon/src/main.rs:432-436

"a probe such as the Homebrew formula's test" is protected by the --version early return, not by the new reject path. The comment reads as if the reject path is what makes the formula probe safe. Rephrase to name the two cases separately (known query flags answered up front; unknown flags refused).

🟢 Suggestion (Nit): ui_pid_path doc overstates parity until the follow-up lands

📁 packages/daemon/src/tray.rs:46-51

"both sides derive the identical path from their own build flavour (debug or release)" is true for the community pairing, but the app side (daemon_setup.rs ui_pid_relative, ~L329) still folds in is_pro_build(), and tray is a pub mod in lib.rs that the Pro daemon links. Behaviour is unchanged (the old cfg!(feature = "pro") was false in every link because nothing enabled it), and the wording follows the issue text, so this is only worth a word if you want the comment exactly true before the variant-collapse follow-up.

What I attacked and found sound (no action)

  • main() ordering/semantics (packages/daemon/src/main.rs:431-449): --version is answered before the reject check (needed, since --version is deliberately not in ACCEPTED_ARGS; the --version integration test would catch a reorder); argv[0] is skipped in first_unrecognized_arg (unit-tested); args_os + lossy handles non-UTF-8 without the args() panic; empty string, --tray=foo, -psn_*, --tray --bogus all exit 2 (run against the binary, which I first confirmed was newer than main.rs and contains the message). exit(2) skips no destructors that matter, eprintln! is unbuffered, and nothing has started yet.
  • Integration test is not vacuous (packages/daemon/tests/it/unrecognized_flag.rs): Command::env isolates HOME, NODESPACE_HOME, socket and db into a tempfile dir, so a regression daemon cannot touch the real home; stdout/stderr go to files (no pipe wedge); on timeout the child is kill()ed and wait()ed before the panic, so a regression fails in 10 s rather than hanging; stdin is null; no ports; env!("CARGO_BIN_EXE_nodespaced") makes cargo rebuild the bin. If exit(2) were removed the daemon would keep running and hit the timeout panic (matches the author's mutation table; I did not re-run the mutations). --help has no separate code path. #![cfg(unix)] matches siblings (sigterm_during_model_load.rs, agent_session_grpc.rs), and the pure-function unit tests still cover Windows builds.
  • Unit tests: 6 unrecognized_arg_tests plus tray_mode_tests and socket_fallback_variant_tests pass (--bins -E 'test(unrecognized_arg_tests) | ...', 11/11). pub(super) on argv is the minimal visibility for a sibling test module; no issue.
  • Ratchet hygiene: no added line contains a marker (measured with Add the Pro-boundary ratchet check and the Pro/sync placement rule #3376's MARKERS); the retired flag is built with concat!("--", "edition") in both test files; no #NNNN issue references in added lines (grep).
  • Comments ACCEPTED_ARGS, VERSION_FLAG, UNRECOGNIZED_ARG_EXIT_CODE, first_unrecognized_arg: accurate. git status clean after my test runs; PR is MERGEABLE/CLEAN, origin/main has not advanced past the branch base.

Recommendation

APPROVE (non-blocking): correct, well-tested, launcher audit clean. Please fix the SKILL.md wording (the one 🟡) before merge; the nits are optional. Reminder for merge order: lower BASELINES 9/4/1 in whichever of this PR and #3376 lands second.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Automated pragmatic-code-review: APPROVE (posted as a comment — GitHub blocks self-approval). No blockers; one 🟡 doc-accuracy fix recommended before merge (SKILL.md 'safe to probe' wording and the lib.rs pointer) plus optional nits. Full findings in the review comment above: #3375 (comment)

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary (commit e97e0c0)

Reviewer verdict on 16e749b: APPROVE with one Important and three Nits. Each claim was re-verified against the code before acting.

Addressed (3):

  • 🟡 .claude/skills/run-app/SKILL.md: verified both points. The flags are constants in packages/daemon/src/main.rs, not lib.rs (git grep of --tray/--version in lib.rs is empty), and step 1 reuses any existing target/debug/nodespaced, so "probing is safe" was only true for a freshly built binary. The warning now says a current build refuses unknown flags with status 2, an older binary (installed, Homebrew, or a stale target/debug one) ignores them and starts serving, so do not probe a binary you did not just build; and it points at main.rs for flags and lib.rs for environment variables.
  • Nit, main() comment: it implied the reject path protects the Homebrew formula's test; that is the --version early return. Reworded to name --version and the reject path separately.
  • Nit, ui_pid_path doc: verified the app side (daemon_setup.rs:329) still folds in its own Pro discriminator, so "both sides derive it from the build flavour" overstated parity. Reworded: each side derives the path from its own build flags, and this side's only flag is debug or release.

Skipped (1):

  • Nit, supported-flag list written in two places (main.rs message vs ACCEPTED_ARGS plus the separate --version branch). With one accepted flag, deriving the list is speculative generality, and the integration test asserts both --tray and --version appear in the message, so a drift would fail a test rather than ship silently. Revisit if a second accepted flag is added.

Checks after the fix: comment and documentation changes only, no logic touched. cargo fmt -p nodespace-daemon -- --check clean, cargo clippy -p nodespace-daemon --all-targets -- -D warnings -D clippy::unused-async clean, bun run test:changed passed, and the added lines contain no ratchet marker and no #NNNN reference.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: the follow-up commit changes one skill document paragraph and two comments; no code, test, or behaviour changed, and the reviewer's APPROVE stands for the code as reviewed.

Rebase note: origin/main advanced by two commits after the branch was cut (#3373, #3374). Neither touches packages/daemon or .claude/skills/run-app (no file overlap), and the ratchet script is still not on main, so the BASELINES follow-up stands: whichever of this PR and #3376 lands second lowers editionBranching by 9, proWording by 4 and cloudWording by 1.

🤖 Generated with Claude Code

mstomar125 and others added 2 commits September 30, 2026 12:14
…nknown arguments

The `pro` cargo feature was never enabled by any build, so `is_pro_build()`
was always false and `--edition` always printed `community`. Delete the
feature, `is_pro_build`, `edition()` and the `--edition` early exit, and pass
`false` where the Pro discriminator was read (the incompatible-database
marker, the fallback socket path, the UI pid-file path).

`main` now refuses any argument other than `--tray` and `--version` before
tracing or the runtime start: one line on stderr naming the argument and the
supported ones, exit status 2, nothing on stdout, no socket bound. Without
this, a caller that runs `nodespaced <flag>` inside `$(...)` would start a full
daemon and never return. `first_unrecognized_arg` is a pure function over the
argv slice; a non-UTF-8 argument is converted lossily so it takes the same
path instead of panicking.

Tests: unit tests for `first_unrecognized_arg` beside `tray_mode_tests`, and an
integration test that spawns the real binary with the retired flag, `--help`
and an arbitrary flag, and with `--version`. The retired flag is built from
fragments in both so the boundary ratchet does not count the test that guards
against it.

The run-app skill no longer warns that `nodespaced --help` starts a daemon
against the real database.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…hten two comments

The run-app skill said probing the daemon with --help is safe and pointed at
lib.rs for its flags. Both were wrong for the worst-case reader: step 1 reuses
any existing binary, and an installed or stale daemon still ignores unknown
flags and starts serving. Say so, and point at main.rs for the flags and lib.rs
for the environment variables.

The main() comment now names --version (which the Homebrew formula's test
runs) and the reject path separately instead of implying the reject path
covers the formula. The ui_pid_path doc no longer claims both sides derive the
path from the same flag set; this side's only flag is debug or release.

Comment and documentation changes only.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.

Remove the pro feature and --edition from nodespaced and reject unknown arguments

1 participant