Fix #614: verify daemon lifecycle and stale server state - #705
Conversation
|
| Filename | Overview |
|---|---|
| tokenjam/cli/cmd_doctor.py | Adds daemon service, process inventory, and server-state diagnostics; the previously reported config-path mismatch is now checked. |
| tokenjam/cli/cmd_onboard.py | Adds independent post-registration verification for launchd and systemd onboarding. |
| tokenjam/core/server_state.py | Adds cross-platform unit inspection and process inventory while correctly excluding linked and aliased systemd states from enabled status. |
| tests/unit/test_doctor_daemon_lifecycle.py | Covers unloaded units, duplicate processes, stale PIDs, wrong ports, and mismatched configuration paths. |
| tests/unit/test_onboard_daemon.py | Covers failed systemd enable verification and launchd registration replacement behavior. |
| tests/unit/test_server_state.py | Covers service-manager state classification and machine-wide tj serve process discovery. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
Onboard[tj onboard] --> Write[Write launchd or systemd unit]
Write --> Register[Register and start unit]
Register --> Verify[Verify service-manager state]
Doctor[tj doctor] --> Unit[Inspect daemon unit]
Doctor --> Processes[Inventory tj serve processes]
Doctor --> State[Read server.state]
State --> Identity[Validate PID, process identity, port, and config path]
Reviews (2): Last reviewed commit: "Rebase onto main, fix Server state confi..." | Re-trigger Greptile
|
Thanks for this. The doctor checks and the process-listing helper are genuinely useful and I want them in. The problem is main moved under you. The launchd install path now uses Two things to fix while you're in there:
One thing I want to flag rather than change: a new warning here flips Also noticed the |
Verify launchd and systemd registration after onboarding, and teach doctor to report unloaded units, duplicate serve processes, and stale server state. :wq#
Rebased fix/614-daemon-lifecycle onto the launchd bootstrap/bootout/enable rework that landed on main since this branch was opened, dropping the _install_launchd verification hunk this PR added -- main's program-args comparison already covers what it checked, plus a resident-but-stale registration case it couldn't see. The systemd and doctor/server_state additions carried over unchanged. Also addresses two review comments: - Server state check now also compares config_path, not just port, so a same-port daemon running under a different config warns instead of reading healthy. - _SYSTEMD_ENABLED_STATES no longer treats linked/linked-runtime/alias as enabled -- those states don't autostart at login. Added a regression test for each.
97f8902 to
81a5184
Compare
|
|
Rebased onto main and dropped the _install_launchd verification hunk entirely. Your bootstrap/bootout/enable rework already covers what it checked, and catches the resident-but-stale case mine couldn't. Systemd, doctor, and server_state additions carried over clean. Fixed both: Server state now compares config_path too (a same-port daemon under a different config warns instead of reading healthy), and _SYSTEMD_ENABLED_STATES drops linked/linked-runtime/alias. Added a regression test for each. Added a note to the PR body about the exit-code change per your flag. |
Summary
Verifies that
tj onboardactually registers the generated launchd/systemd unit instead of treating a written file or successful load command as proof. Extendstj doctorto report unloaded services, multiple livetj serveprocesses, stale or mismatchedserver.state, and the existing OTLP endpoint reachability result in one diagnostic surface.The endpoint probe and shell-host correction had already landed on
mainin commitc76e1b7c; this PR keeps that implementation and adds the missing service-manager/process/state lifecycle checks from #614.Related issue
Closes #614
Validation
pytest tests/unit/test_server_state.py tests/unit/test_onboard_daemon.py tests/unit/test_doctor_daemon_lifecycle.py tests/unit/test_doctor_otlp_endpoint.py -q— 49 passedruff check tokenjam/— passedmypy tokenjam/— passedpsaccess and Python 3.14 Rich-color behavior outside the CI Python 3.10-3.12 matrixtest-ts,version-lockstep, and contributor guard all passedChecklist
pytest tests/unit/ tests/synthetic/ tests/agents/ tests/integration/) in GitHub CIruff check tokenjam/)mypy tokenjam/)tests/factories.py(not applicable; no spans added)@anilmurtyas reviewer (mentioned here: @anilmurty)Note: this PR changes tj doctor's exit code behavior: the new daemon-lifecycle checks (Daemon service, Daemon instances, Server state) can emit warnings that make doctor exit 1 in situations that previously exited 0. Anything scripting on tj doctor's exit code should account for this.
@anilmurty