emrg: daemon all-path stop logging + stop-reason tracking - #868
Merged
Conversation
argszero
commented
Aug 19, 2026
argszero
left a comment
OwnerAuthor
There was a problem hiding this comment.
✅ 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.
argszero
commented
Aug 19, 2026
argszero
left a comment
OwnerAuthor
There was a problem hiding this comment.
✅ LGTM — cycle. Third consecutive approval (cycles 908/909/910); head unchanged, CI test + test-windows PASS, MERGEABLE/CLEAN.
Uh oh!
There was an error while loading. Please reload this page.
argszero pushed a commit
that referenced
this pull request
Aug 19, 2026
argszero added a commit
that referenced
this pull request
Aug 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pyunless noted)_stop_reasontracking — the daemon records why it is stopping on every path:shutdown_msg(clientshutdownmessage) — also logs the sender'ssourcetagcancel(asyncio CancelledError — Ctrl+C / parent kill)sigint(KeyboardInterrupt handler inrun_server)bind_exit(fixed-port admission self-exit, EADDRINUSE)crash(unhandled exception inserve()— now logged with full traceback viaexc_info=True, previously depended on the top-level handler)serve()no longer swallows CancelledError silently — logsdaemon serve cancelled (asyncio.CancelledError) — cleanup started._shutdown_all()— refactored teardown with per-step logging:daemon stopping (reason=…, handlers=N) — cleaning updaemon stopped (reason=…, uptime=…s, steps=…, all_ok=…)emrg server stop(CLI) andstop_all(GUI/installer) send"source"; missing source degrades tounknown(backward compatible).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.mdtest count synced 974 → 979.