Skip to content

logs: flag fallback log files, add LaunchAgent log candidate - #3862

Merged
mstomar125 merged 2 commits into
mainfrom
fix/3832-logs-fallback
Oct 20, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
fix/3832-logs-fallback

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #3832

Changes

  • When the chosen log is not the state-directory log, a note on stderr names the path, its last-modified time, and that it may belong to another install rather than the running daemon (also notice in --json).
  • ~/Library/Logs/com.nodespace/nodespaced.log (named by scripts/pkg-resources/app.nodespace.daemon.plist) is the last candidate; not used when NODESPACE_HOME redirects.
  • The no-candidate error already listed the paths checked; unchanged (now includes the new path).

Testing

  • cargo test -p nodespace-cli --lib commands::logs: 10 passed (new: launch-agent candidate, fallback notice).
  • Mutation: notice always-None and dropping the new candidate fail both new tests.
  • cargo clippy -p nodespace-cli --all-targets -- -D warnings and cargo fmt --check clean.

🤖 Generated with Claude Code

@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.

Verdict: REQUEST CHANGES

Independent review of #3862 (Closes #3832). I ran cargo test -p nodespace-cli --lib commands::logs. All pass in UTC, but one test fails in a negative-offset timezone (finding 1).

Findings

  1. (BLOCKING) logs.rs:407 (fallback_notice_names_path_mtime_and_foreign_install): the test is timezone-dependent. fallback_notice formats in chrono::Local, and the test uses UNIX_EPOCH + 365 days and asserts contains("1971"). That instant is 1971-01-01 00:00 UTC, so in any zone west of UTC it renders as 1970-12-31. I reproduced it: TZ=America/New_York cargo test -p nodespace-cli --lib commands::logs fails with assertion failed: n.contains("1971"). CI is UTC, so it will be green there while failing on US developer Macs (a flaky-by-machine gate). Fix: pick an instant mid-year, such as epoch + 86_400365 + 630*86_400, and assert on "1971", or format the expected string with the same Local conversion, or assert only that a YYYY-MM-DD HH:MM:SS pattern is present.
  2. (non-blocking, but please decide before merge) logs.rs:97-106, logs.rs:121-145: the author's question. For a .pkg install the LaunchAgent log is exactly the daemon's log (scripts/pkg-resources/app.nodespace.daemon.plist:41-45 sets StandardOut/ErrorPath to ~/Library/Logs/com.nodespace/nodespaced.log). The issue's AC says the Library log is "a last candidate", and it puts the note on the Homebrew fallback. Today fallback_notice treats anything but ~/.nodespace/logs as a fallback, so a .pkg user is told their own daemon's log "may belong to another install, not the running daemon". That is misleading and trains users to ignore the note. Suggest a separate wording for the LaunchAgent path, for example "using the LaunchAgent log ... (last modified ...)", with the "another install" warning kept for the Homebrew prefixes only, or no note at all for it. Also consider that on a .pkg install a stale ~/.nodespace/logs/nodespaced.log from a former app run would win with no note, even though the LaunchAgent log is the live one. Out of scope here, but worth a follow-up issue.
  3. (non-blocking) logs.rs:338-341 vs logs.rs:315-327: notice is added only to the main --json object. The --path-only --json output has no notice key (the stderr note is still printed). Be consistent: add "notice" there too, or document that it is absent. Adding the key is additive and safe for jq-style consumers that read named fields (.path, .lines). A consumer that deserializes with deny_unknown_fields would break, but none exists in the repo. null is emitted when there is no fallback, which is the right stable-shape choice. Stderr for the human note is also the right channel, since stdout stays clean for $(nodespace logs --path-only).
  4. (non-blocking) Ordering is correct for each install type. NODESPACE_HOME gives the redirected home as the only candidate and no note (primary equals chosen). Dev and dmg use ~/.nodespace/logs first. Homebrew falls back to /opt/homebrew then /usr/local. .pkg reaches the LaunchAgent log last. The "no candidate exists" message already lists paths, and it will now include the Library path. AC met.
  5. (non-blocking nit) logs.rs:73-76: the home for ~/Library/Logs is derived as state_dir.parent(). That is only right because the redirected case returns earlier. A direct dirs::home_dir() (or the daemon crate's home helper) would be more robust than coupling to the state-dir layout.
  6. (non-blocking nit) mtime format %Y-%m-%d %H:%M:%S %z in local time with a numeric offset is unambiguous. Fine.
  7. (non-blocking, test strength) Mutations: flipping primary == Some(chosen) or changing the Library candidate order is killed by the two new tests. The wiring in run (eprintln, notice in JSON, path-only) and the modified: None branch ("unknown") have no test. The integration tests in packages/cli/tests/it/home_isolation.rs are a good place for one --json assertion that notice is null for the primary log.

Once finding 1 is fixed (and 2 is decided), I would approve.

mstomar125 and others added 2 commits October 20, 2026 16:32
… as last candidate

fallback_notice reports the chosen path, its last-modified time and that it may
belong to another install, on stderr (and as "notice" in --json output).
candidate_paths_for appends ~/Library/Logs/com.nodespace/nodespaced.log, the
path the pkg LaunchAgent plist names, after the Homebrew locations.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…pkg install's log, carry notice in --path-only --json

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the fix/3832-logs-fallback branch from 642e86f to 3d76a21 Compare October 20, 2026 14:32
@mstomar125
mstomar125 merged commit 4174080 into main Oct 20, 2026
@mstomar125
mstomar125 deleted the fix/3832-logs-fallback branch October 20, 2026 14:32
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.

nodespace logs falls back to another install's Homebrew log without saying so

1 participant