Skip to content

emrg: daemon all-path stop logging + stop-reason tracking - #868

Merged
argszero merged 1 commit into
masterfrom
feature/daemon-stop-all-path-logging
Aug 19, 2026
Merged

emrg: daemon all-path stop logging + stop-reason tracking#868
argszero merged 1 commit into
masterfrom
feature/daemon-stop-all-path-logging

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

Host rant 2026-08-19T14:02:37: any reason / any path the daemon stops must leave a detailed log — when, why, who triggered, what was cleaned up — so "why did the daemon disappear" is always answerable from emrgd.log instead of guesswork.

Changes (all in emrg/server/daemon.py unless noted)

  1. _stop_reason tracking — the daemon records why it is stopping on every path:
    • shutdown_msg (client shutdown message) — also logs the sender's source tag
    • cancel (asyncio CancelledError — Ctrl+C / parent kill)
    • sigint (KeyboardInterrupt handler in run_server)
    • bind_exit (fixed-port admission self-exit, EADDRINUSE)
    • crash (unhandled exception in serve() — now logged with full traceback via exc_info=True, previously depended on the top-level handler)
  2. serve() no longer swallows CancelledError silently — logs daemon serve cancelled (asyncio.CancelledError) — cleanup started.
  3. New _shutdown_all() — refactored teardown with per-step logging:
    • entry: daemon stopping (reason=…, handlers=N) — cleaning up
    • each step logged with success/failure: background loop cancellations, scheduler stop, LLM client close, port-file removal, pid-file removal
    • exit: daemon stopped (reason=…, uptime=…s, steps=…, all_ok=…)
  4. Shutdown message source tagging — loopback peers are indistinguishable, so senders now tag the message: emrg server stop (CLI) and stop_all (GUI/installer) send "source"; missing source degrades to unknown (backward compatible).
  5. KeyboardInterrupt — now logs shutdown signal received (SIGINT), cleanup started.

Tests

5 new unit tests in tests/test_daemon.py (pure mocks — mock scheduler/LLM/background tasks; no real daemon is stopped or restarted, per the highest principle). Cover: stop-reason echo in start/final log lines, per-step cleanup logging, failing-step handling (all_ok=False), and shutdown-message peer/source logging incl. legacy missing-source. Python suite: 979 collected, 978 passed + 1 skipped; import + CLI checks green. Agent.md test count synced 974 → 979.

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

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

✅ LGTM — cycle. CI test + test-windows PASS (run 32222270573); local suite 979 collected (978 passed + 1 skipped); stop-reason tracking covers all 5 stop paths (shutdown_msg/cancel/sigint/bind_exit/crash); pure-mock tests never stop/restart a real daemon.

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

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

✅ LGTM — cycle. Head unchanged (1baa40b), CI test + test-windows PASS, MERGEABLE/CLEAN; stop-reason + _shutdown_all logging verified in prior local run.

@argszeroargszero left a comment

Copy link
Copy Markdown
OwnerAuthor

Choose a reason for hiding this comment

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

✅ LGTM — cycle. Third consecutive approval (cycles 908/909/910); head unchanged, CI test + test-windows PASS, MERGEABLE/CLEAN.

@argszero
argszero merged commit 1e34202 into masterAug 19, 2026
2 checks passed
argszero added a commit that referenced this pull request Aug 19, 2026
Co-authored-by: EMRG Evolution <emrg@argszero.dev>
@argszero
argszero deleted the feature/daemon-stop-all-path-logging branch August 19, 2026 11:28
Sign up for freeto 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

@argszero