Skip to content

Poll daemon-status steady-state so a mid-session restart re-fires onDaemonReconnect (#1678) - #1683

Merged
mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:issue-1678-daemon-status-steady-poll
Jul 17, 2026
Merged

mstomar125 merged 1 commit into
NodeSpaceAI:mainfrom
mstomar125:issue-1678-daemon-status-steady-poll

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Summary

Fixes #1678. The shared daemon-status service fans a reconnect signal to every daemon-dependent store (schemas, collections, children-tree, pane hydration) via onDaemonReconnect, fired on a not-healthy → healthy transition. That signal was reliable for the initial boot, but a mid-session daemon restart emitted nothing: all daemon-status emit sites live in the backend's one-shot startup task (src-tauri/src/lib.rs), so a daemon that dies and is relaunched while the app is running pushes no healthy event and no consumer retries — a wedged pane/store stays wedged until an app restart.

Fix

Add a low-frequency steady-state poll of check_daemon_status (which probes the socket live each call) in daemon-status.ts, started after the listener wires up. A healthy → not_running → healthy cycle is now observed and applyStatus re-fires onDaemonReconnect. Reconnect callbacks fire only on the not-healthy → healthy edge, so steady healthy polls are no-ops. Also adds stopDaemonStatusListener (test teardown; production never calls it) and .unref()s the interval so it can't keep a process alive on its own.

Why it matters for #1672

This closes one of the two plausible root causes of the journal "Loading…" hang: the case where the daemon's healthy transition is never observed by the frontend (the push fires before the webview registers its listener, and the single pull-on-subscribe caught starting), so the pane's onDaemonReconnect retry never runs. With the steady-state poll the daemon is re-observed and the pane self-heals.

Tests

Relates: #1672, #1644, #1677.

…aemonReconnect (#1678)

The backend emits daemon-status only from its one-shot startup task, so a
daemon that dies and is relaunched while the app is running pushes no healthy
signal and every reconnect consumer (schemas, collections, children-tree, pane
hydration) stays wedged until an app restart. Add a low-frequency steady-state
poll of check_daemon_status (which probes the socket live) so the
healthy -> not_running -> healthy cycle is observed and applyStatus re-fires
onDaemonReconnect. Reconnect callbacks fire only on the not-healthy -> healthy
edge, so steady healthy polls are no-ops.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (adversarial self-review)

Went looking for ways this breaks:

  • Reset on error: pollInFlight is cleared in .finally(), so a thrown getCurrent can't wedge the poll permanently. ✓
  • Reconnect storm: applyStatus fires onDaemonReconnect only on the not-healthy→healthy edge, so steady healthy polls are no-ops — the expensive store reloads don't re-run every 15s. Only the _status.set repeats, and downstream $derived memoizes identical values → no visible churn. ✓
  • No cross-thread race: JS single-threaded; applyStatus is synchronous; pollInFlight only guards overlapping getCurrent. ✓
  • unref on browser-style handle: optional-chained (?.unref?.()), so a numeric setInterval id is a safe no-op; node's Timeout gets .unref() so it can't keep a process/test-worker alive. ✓
  • Test isolation: afterEach stops the singleton (same module instance the case used, since resetModules runs in beforeEach), so intervals don't leak across cases — 16/16 green. ✓

Pre-push gate green (test:all + cargo build + e2e), twice. Minimal, correct, tested. Merging.

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.

[bug] daemon-status emits no healthy signal after a mid-session daemon restart — reconnect consumers never retry

1 participant