Skip to content

friglet-tray: real Stop scanning / daemon controls, no flashing errors, daemon log file (SNB-658) - #37

Merged
setavenger merged 1 commit into
integrationfrom
snb-658-tray-controls-errors-logs
Oct 2, 2026
Merged

setavenger merged 1 commit into
integrationfrom
snb-658-tray-controls-errors-logs

Conversation

@setavenger

Copy link
Copy Markdown
Owner

Fixes SNB-658: the bugs from the first mainnet run of friglet-tray (Sparrow SP wallet, Omarchy/Hyprland).

Root causes

  1. "Stop scanning does not stop, yet Start is pressable again." The daemon received Stop, but ScanSupervisor::stop() dropped its task record before the task had ended. GetStatus reported scanning: false straight away, so the UI enabled Start. The scan future only stops at its next .await, and blindbit-lib's P2P block download (P2pConnection::connect/fetch_block) is blocking socket I/O inside that future: 30 s read timeout, 90 s deadline per attempt, up to 4 attempts. So during a download the scan kept running. The Stop handler also held apply_lock while it waited, which meant a Start pressed in the meantime queued behind it and resumed scanning as soon as the old task ended. I reproduced this on the base commit with a unit test that uses a blocking scan step: is_running=false stop_returned=false, and the scan still processed a block after Stop.
  2. "Not easy to stop a daemon that was already running." The tray had no daemon stop control. Quit deliberately leaves a daemon it did not start running, and "Retry / Start daemon" did nothing while a daemon answered.
  3. "An error flashed and vanished during setup." This is a race between the setup Save and the 1 s status poller. save_local_config returns as soon as the spawned daemon answers, and the window then leaves setup mode and re-renders. The tray's cached status still said "unreachable" until the poller's next tick, so for up to about 1 s the Settings tab showed the red "Daemon unreachable — settings cannot be loaded or changed." and a red header pill. Both vanished once scanning started. I captured this in 2 of 5 setup runs with the fix reverted, and in 0 of 7 with it.
  4. "Errors in the app but not in the logs." The tray drained the daemon's output at debug level, which the default info filter hides. Neither the daemon nor the tray wrote a log file, and a fatal daemon error went only to eprintln!.

A related problem came up while testing: GetStatus fetched the oracle tip inline with a 2 s timeout. With an unresponsive oracle, every status answer took about 2.04 s (measured), longer than the tray's 0.9 s poll timeout. The tray therefore showed the daemon as unreachable, and after 120 s killed it as "wedged".

Changes

  • Daemon (friglet)
    • Scan states: ScanState is running, stopping, paused or failed. The task record stays until the task has really ended.
    • Stop answers within 3 s, adding a "stopping: …" note if the task is still finishing a blocking step.
    • Start is refused while a stop is still in progress.
    • The select! checks cancellation first (biased).
    • A pause survives an in-process settings restart.
    • A stall is not reported while the scan is paused.
    • The oracle tip comes from a background poller (oracle_error / oracle_down_since_unix), so GetStatus never waits on the network.
    • Before the first block, the height falls back to start_height - 1 instead of 0.
    • The daemon reports its pid and log_file.
  • Logs
    • friglet_ipc::logfile provides a size-capped RotatingLog (10 MiB, keeps .1/.2, 0600 in a 0700 directory).
    • The daemon writes $XDG_STATE_HOME/friglet/friglet.log (macOS ~/Library/Logs/friglet, Windows %LOCALAPPDATA%\friglet\logs). FRIGLET_LOG_FILE overrides the path or turns the file off.
    • Logging starts before the config is read, so config errors are logged too.
    • The tray writes friglet-tray.log next to it and forwards daemon lines at their own level.
    • The Docker image logs to /data/friglet.log.
  • Tray
    • Stop daemon / Start daemon are available in the window and in the tray menu.
    • The Status tab says who started the daemon (this tray, an earlier tray session, or external/attached), with its PID and what Quit will do.
    • An explicit stop, or a daemon exit with status 0, is never undone by the supervisor. Stop daemon also ends a crash-restart loop.
    • New view.rs (pure, unit-tested) computes the scan and daemon states and the ErrorBook. A stall or oracle outage shows as "waiting" for 2 min and an unanswering daemon as "reconnecting" for 10 s; after that each becomes an error.
    • Errors stay under "Needs attention" with their start time until resolved, and also go to a Recent errors list (with a repeat count) and to the log.
    • The Status tab shows the log paths and has an Open log folder button.
    • Disabled buttons look disabled.
    • Spawn failure reasons show only the daemon's error lines.
    • The spawn wait is now about 30 s instead of 5 s.
  • README (controls, waiting vs. errors, log locations), AGENTS.md and docs/docker.md are updated.

Verification

All runs used debug builds. cargo test --workspace passed: blindbit-lib 55 (1 ignored), friglet 69, friglet-ipc 26 + 1, friglet-tray 50 + 9. A later stop-race test brought friglet-tray to 51 + 9, and that crate was re-run. cargo clippy -p friglet -p friglet-ipc -p friglet-tray --all-targets reports nothing in these crates, and cargo fmt --check passes for them.

End-to-end runs under Xvfb, each with a fresh HOME, a throwaway signet descriptor, the hosted signet oracle and node signet.oracle.setor.dev. The UI was driven with xdotool clicks and the tray menu over dbusmenu, through a minimal StatusNotifierWatcher (the same path waybar uses). Screenshots were taken for each case.

  • (a) Setup. Pasted the descriptor and node, then Save. No red state appeared at any point: 120 frames sampled every 0.1 s across 6 runs. With the oracle's tip forced "not indexed" through a proxy, the scan showed "waiting — The oracle has not indexed block 324554 yet. Retrying automatically. (since …)". It became "Needs attention … since 10:22:06 PM" at exactly +2 min, was logged, and resolved to "up to date" when the fault was removed.
  • (b) Stop scanning. Clicked the window button during a catch-up from block 300000. The status read "paused" and the height stayed at 304221 for 61 s (sampled every 10 s). The menu showed Start on and Stop off. Start resumed scanning: 304733, then 305189, then 305756.
  • (c) External daemon. Started the daemon from a terminal, then launched the tray. It showed "running (attached) — Started outside the tray … (PID n). Quit leaves it running." Stop daemon (menu, and later the window button) stopped the process, which logged "friglet stopped". No daemon was restarted in the following 60–70 s.
  • (d) Tray-spawned daemon. Stop daemon gave "exit status: 0", and the state stayed "stopped" with no process for 70 s. Start daemon spawned a new one, which went back to scanning.
  • (e) Forced error. An unresolvable node address showed "Needs attention since 10:36:23 PM: … cannot resolve P2P node no-such-node.invalid …", and it stayed visible. Recent errors listed it as "(×6, last …)". The error is in friglet.log and in friglet-tray.log. Stop daemon ended the restart loop (7 attempts before the stop, 7 after 40 s).
  • (f) Log files. ~/.local/state/friglet/friglet.log exists (mode 600) with daemon lines in every run. FRIGLET_LOG_FILE=<path> writes there, including a missing-config error, and =off writes no file. Open log folder called xdg-open <log dir>.

Not covered: real Hyprland/waybar (the SNI host here is a stub watcher); macOS/Windows log paths (only compiled for Linux here); the Docker image (not rebuilt); and a live stop during a real blocking P2P download (unit-tested with a blocking scan step only).

…s, log files (SNB-658)

Scanning controls
- ScanSupervisor kept reporting "not running" the moment Stop was asked,
  while the scan task could not end until its next await: blindbit-lib's
  P2P block download is blocking I/O inside the scan future (up to 90 s
  per attempt). The UI then offered Start, and the Stop request held the
  apply lock, so a Start queued behind it resumed scanning right after.
  The task entry now stays until the task really ended (ScanState
  Stopping -> Paused), Stop answers within 3 s (with a note while still
  stopping), Start while stopping is refused, the select! checks the
  cancellation first, and the pause survives an in-process restart.
- GetStatus no longer waits on the oracle (a background poller keeps the
  tip): an unresponsive oracle made every status answer take ~2 s, longer
  than the tray's poll timeout, so the tray called the daemon unreachable
  and eventually killed it as wedged.

Daemon controls
- Stop daemon / Start daemon in the window and the tray menu, for a
  tray-spawned daemon and an attached external one alike; the Status tab
  says who started it and what Quit does. An explicit stop, and a daemon
  exiting with status 0, are never undone by the auto-restart supervisor.

Errors vs waiting
- view.rs derives what is shown: a stall or oracle outage is "waiting" for
  2 minutes, an unanswering daemon "reconnecting" for 10 s, then an error.
  Errors stay under "Needs attention" with their start time until
  resolved and remain in a Recent errors list; each one is logged.
- The setup flow no longer flashes "Daemon unreachable": attach/spawn
  publishes the daemon's status at once instead of waiting for the next
  poll.

Logs
- The daemon writes friglet.log and the tray friglet-tray.log in
  $XDG_STATE_HOME/friglet (macOS ~/Library/Logs/friglet, Windows
  %LOCALAPPDATA%\friglet\logs), 10 MiB cap with two rotations;
  FRIGLET_LOG_FILE overrides or turns off the daemon's. Logging starts
  before the config is read, so config errors land in the file too. The
  tray forwards daemon output at its own level (info/warn/error), shows
  both paths and has an Open log folder button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant