Skip to content

diag(service): log the sender PID of received SIGTERM#194

Open
verveguy wants to merge 1 commit into
mainfrom
feat/sigterm-sender-trace
Open

diag(service): log the sender PID of received SIGTERM#194
verveguy wants to merge 1 commit into
mainfrom
feat/sigterm-sender-trace

Conversation

@verveguy

Copy link
Copy Markdown
Owner

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

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>
Copilot AI review requested due to automatic review settings July 19, 2026 00:21

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_SIGINFO SIGTERM observer (via signal-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.

Comment on lines +528 to 532
// 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())?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants