diag(service): log the sender PID of received SIGTERM#194
Conversation
The context-graph service intermittently enters a restart loop on app startup: it is SIGTERM'd by something *outside* the Electron lifecycle manager's own stop paths (no "Stopping context graph service" log precedes the service's "received SIGTERM"), exceeds its 5s drain while mid-ingestion, exits, and is auto-restarted. Each restart drops the six socket connections, which surfaces to the user as "MCP Server knowledge-writer failed" toasts (the in-process knowledge-writer/reader providers can't connect during the teardown window). POSIX only exposes the sender PID via SA_SIGINFO, which tokio's signal stream does not surface. Register an observe-only SA_SIGINFO handler via signal-hook-registry (already in the tree; tokio uses it for unix signals) that records the sender PID into an atomic, and include it in the shutdown log line. Then `ps -p <pid>` on the next occurrence names the culprit (suspected: a second Liminis-family instance's stale-PID reclaim). Handler is async-signal-safe (single atomic store). libc/signal-hook- registry added as cfg(unix) deps. Verified: the clean-shutdown test now logs the real sender PID. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a diagnostic mechanism to capture and log the sender PID of a received SIGTERM signal on Unix platforms. It adds dependencies on libc and signal-hook-registry, registers a custom signal handler to store the sender PID in an atomic variable, and prints this PID when shutting down. There are no review comments, so we have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds a Unix-only diagnostic to help identify which external process is sending SIGTERM to the liminis-context-graph service during intermittent restart loops, by capturing the sender PID via an SA_SIGINFO observer and including it in the SIGTERM shutdown log.
Changes:
- Register an additional
SA_SIGINFOSIGTERM observer (viasignal-hook-registry) that records the sender PID into a global atomic. - Log the captured sender PID when the service receives SIGTERM and begins shutdown.
- Add
cfg(unix)dependencies (libc,signal-hook-registry) needed for the diagnostic.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/service/src/main.rs | Adds SIGTERM sender PID probe + includes sender PID in shutdown log output. |
| crates/service/Cargo.toml | Adds Unix-only deps required for SIGTERM sender capture (libc, signal-hook-registry). |
| Cargo.lock | Records new direct dependencies for lcg-service. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Observe-only: capture the SIGTERM sender PID (see the diagnostic block | ||
| // near the top of this file). Registered before tokio's stream so the | ||
| // sender is recorded by the time the async task logs it. | ||
| install_sigterm_sender_probe(); | ||
| let mut sigterm_stream = signal(SignalKind::terminate())?; |
The context-graph service intermittently enters a restart loop on app
startup: it is SIGTERM'd by something outside the Electron lifecycle
manager's own stop paths (no "Stopping context graph service" log
precedes the service's "received SIGTERM"), exceeds its 5s drain while
mid-ingestion, exits, and is auto-restarted. Each restart drops the six
socket connections, which surfaces to the user as "MCP Server
knowledge-writer failed" toasts (the in-process knowledge-writer/reader
providers can't connect during the teardown window).
POSIX only exposes the sender PID via SA_SIGINFO, which tokio's signal
stream does not surface. Register an observe-only SA_SIGINFO handler via
signal-hook-registry (already in the tree; tokio uses it for unix
signals) that records the sender PID into an atomic, and include it in
the shutdown log line. Then
ps -p <pid>on the next occurrence namesthe culprit (suspected: a second Liminis-family instance's stale-PID
reclaim).
Handler is async-signal-safe (single atomic store). libc/signal-hook-
registry added as cfg(unix) deps. Verified: the clean-shutdown test now
logs the real sender PID.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com