fix(server): let the CLI server exit on Ctrl+C and SIGTERM (UF-041)
The OAuth routes started a module-level cleanup interval that was never cleared or unref'd. The service's SIGTERM/SIGINT handler closes the server and relies on the event loop going empty, so the process kept running: a first Ctrl+C in `npx waggle` or `npm run dev:server` left it alive, and SIGTERM never ended it. The interval is now unref'd. The launcher tests left two `waggle` processes behind on every run: they stopped `npx` but not the waggle process it started. They now start it in its own process group and stop the whole group, with a SIGKILL fallback, and a new test checks that the built CLI exits by itself after SIGTERM.
This commit is contained in:
@@ -69,6 +69,7 @@ Baseline: commit `b20b138` of `git.os-dev.tech/oleg.m/waggle-os`.
|
||||
| UF-038 | Marketplace installs never notify the running sidecar | Open | Marketplace, sidecar |
|
||||
| UF-039 | A memory saved to an unknown workspace lands in personal memory | Fixed | Sidecar, memory, privacy |
|
||||
| UF-040 | The support bundle never includes recent installs | Fixed | Sidecar, support |
|
||||
| UF-041 | The CLI server does not exit on Ctrl+C or SIGTERM | Fixed | Sidecar, CLI |
|
||||
|
||||
## Entries
|
||||
|
||||
@@ -405,3 +406,12 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14.
|
||||
- Cause: the route reads the private `db` field of the audit store and calls `prepare` on it. That field is the database wrapper (`MindDB`), which has no `prepare` method, so the call throws and the empty `catch` drops the error.
|
||||
- What we did: the server's `InstallAuditStore` got `getRecentSummary()`, which returns only the timestamp, action and capability type of the latest 50 events, and the route calls it. A test checks the field and its columns.
|
||||
- Recommendation: read the trail through the store's own API in the main project as well, and log errors in this route instead of dropping them.
|
||||
|
||||
### UF-041. The CLI server does not exit on Ctrl+C or SIGTERM
|
||||
- Status: Fixed
|
||||
- Found: 2026-10-25
|
||||
- Where: at commit `b20b138`, `packages/server/src/local/routes/oauth.ts:67-73` (a module-level `setInterval`), together with the signal handler in `packages/server/src/local/service.ts:305-312`
|
||||
- Symptom: after Ctrl+C in `npx waggle` or `npm run dev:server` the HTTP server closes, but the process keeps running until a second Ctrl+C. After SIGTERM, for example from `kill` or a process manager, it never exits. The launcher's own test left two `waggle` processes running after every test run. The desktop app is not affected: it stops the sidecar with SIGKILL.
|
||||
- Cause: the OAuth routes start a cleanup interval when the module loads and never clear or unref it. The service installs SIGTERM and SIGINT handlers, which replace Node's default exit, closes the server, and relies on the event loop going empty; the interval keeps it alive.
|
||||
- What we did: the interval is unref'd. A launcher test checks that the built CLI exits by itself after SIGTERM, and the launcher tests now stop `npx` and the `waggle` process it starts as one process group.
|
||||
- Recommendation: unref housekeeping timers or clear them when the server closes, and consider ending the signal handler with an explicit exit.
|
||||
|
||||
Reference in New Issue
Block a user