fix(desktop): stop the sidecar with SIGTERM first, and free a stale WhatsApp profile (UF-046)

On macOS and Linux the shell stopped the sidecar with Child::kill(), which is
SIGKILL, so the sidecar never ran its shutdown: the processes it started (MCP
servers, a managed Ollama, the WhatsApp browser) kept running. After an app
restart the orphaned WhatsApp browser still held the session profile, and the
channel failed with "The browser is already running".

The shell now sends SIGTERM, waits up to 5 seconds for the sidecar to exit,
then sends SIGKILL; Windows keeps its kill-on-close job. For crashes, where no
shutdown runs, the WhatsApp channel stops a browser left over from an earlier
run before starting its own. It only stops a process whose command line uses
this profile and whose parent is gone; a browser another running Waggle server
owns is left alone, and the channel says so instead of retrying.
This commit is contained in:
shumeiko.it
2026-10-26 12:03:31 +01:00
parent 48bdab8087
commit 1e826aa220
8 changed files with 345 additions and 6 deletions

View File

@@ -74,6 +74,7 @@ Baseline: commit `b20b138` of `git.os-dev.tech/oleg.m/waggle-os`.
| UF-043 | The chat composer draws two focus outlines | Fixed | Web UI |
| UF-044 | A working API key shows as not responding, and other internal model calls fail | Fixed | Sidecar, models, auth |
| UF-045 | Generating a persona from a description calls a route that does not exist | Fixed | Sidecar, agents |
| UF-046 | On macOS and Linux the desktop app kills the sidecar without its shutdown | Fixed | Desktop shell, sidecar |
## Entries
@@ -455,3 +456,12 @@ Entries UF-010 to UF-019 come from the UI audit `anti-slop/audit-001-2026-10-14.
- Cause: the route posts to `/api/anthropic/v1/messages`, which no route serves. The request also has no session token, and its port comes from `address().toString()`, which is `[object Object]`, so the URL does not even parse. The model was fixed to `claude-sonnet-4-6`, so without an Anthropic key the call could not work either.
- What we did: the route calls the built-in proxy (`/v1/chat/completions` through `self-request.ts`, UF-044) and reads its OpenAI-format reply with `parseOpenAiTextCompletion`. The model starts from the user's default and falls back through `resolveUsableModel`, the way chat does, so a local Ollama model works too. An end-to-end test with localhost trust off checks that the persona the model wrote comes back; before the fix it got HTTP 500.
- Recommendation: apply the same change in the main project.
### UF-046. On macOS and Linux the desktop app kills the sidecar without its shutdown
- Status: Fixed
- Found: 2026-10-26
- Where: at commit `b20b138`, `app/src-tauri/src/service.rs:1569` (`stop_service_sync`) and `:1632` (watchdog restart), both `launch.child.kill()`
- Symptom: quitting or restarting the desktop app leaves the processes the sidecar started running, because their stop code runs only on a graceful shutdown: MCP servers (`mcpRuntime.stopAll()` in `onClose`, `index.ts:3319`) and the managed Ollama (`stopTree` on SIGTERM, `managed-ollama-runtime.ts:138`). In the community edition the WhatsApp browser is one of them: after a restart the channel fails with "The browser is already running for …/channels/whatsapp/session", because the orphaned browser still holds the session profile.
- Cause: `Child::kill()` sends SIGKILL on Unix, so the sidecar gets no chance to shut down. Windows is not affected: there the sidecar runs in a job object that ends its whole process tree.
- What we did: on Unix the shell now sends SIGTERM, waits up to 5 seconds for the sidecar to exit (it exits on SIGTERM since UF-041) and only then sends SIGKILL; Rust tests cover both paths. For the crash case, where no shutdown runs at all, the WhatsApp channel now stops a browser left over from an earlier run before it starts its own (`whatsapp-profile-lock.ts`): it reads the profile's `SingletonLock`, and stops the process only if its command line uses this profile and the process that started it is gone. A browser that another running Waggle server still owns is left alone, and the channel says so instead of retrying.
- Recommendation: stop the sidecar with SIGTERM first in the main project as well.