Skip to content

Arm SIGTERM before a launcher-refused bot advertises health - #1200

Merged
jatmn merged 1 commit into
mainfrom
fix/queue-666-bot-refusal-shutdown
Dec 6, 2026
Merged

jatmn merged 1 commit into
mainfrom
fix/queue-666-bot-refusal-shutdown

Conversation

@jatmn

@jatmn jatmn commented Dec 6, 2026 •

Copy link
Copy Markdown
Owner

Part of #666. A bot held by an unsupported launcher could advertise its refusal, return HTTP 200 from /health and HTTP 503 from /ready, then die from SIGTERM instead of exiting cleanly. CI observed the failure and a pass on the identical checkout. Failure · Rerun

The bot now arms the shared shutdown listener before it publishes health or refusal in that startup path. On Unix the caller registers the SIGTERM stream synchronously. The receiving task uses the existing process-wide latch, so a signal delivered before the task first runs reaches later waiters.

Verification

  • With signal registration deliberately delayed, the original executable and a variant that armed only after logging refusal both served the two HTTP responses and died from signal 15. The corrected process exited 0 and created neither a database nor a ready marker. The hosted log records the missing exit code. The signal number was observed locally.
  • A new Unix integration test delivers real SIGTERM on a current-thread Tokio runtime before the receiver task can run. The original listener failed this test. The runtime suite and all five launcher tests passed. Both affected tests passed 20 serial and 12 contended repetitions each.
  • Formatting, affected Clippy, full-workspace pinned Dylint, contracts, service boundaries, four launcher-child tests and the real bot/API SQLite startup smoke passed on the integrated tree. The Unix SIGINT fallback was exercised with SIGTERM registration forced to fail. Windows validation was compile-only.

Summary by Sourcery

Ensure launcher-refused bots are ready to handle SIGTERM before advertising health or refusal.

Bug Fixes:

  • Capture SIGTERM reliably when a launcher-refused bot is stopped after advertising health, allowing it to exit cleanly.

Enhancements:

  • Expose the shared shutdown-listener arming function to the bot and register the Unix SIGTERM handler synchronously before the listener task runs.

Tests:

  • Add a Unix integration test that sends SIGTERM before the listener task can run and verifies the shutdown signal is observed.

@jatmn
jatmn marked this pull request as ready for review December 6, 2026 00:19

@sourcery-ai sourcery-ai 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@pullfrog pullfrog 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.

✅ No new issues found.

Approach
The bot registers its Unix SIGTERM handler before binding health or logging a launcher refusal, closing the window in which SIGTERM could kill an already observable child.

Reviewed changes
I traced the launcher refusal path, the shared shutdown listener, and the regression coverage.

  • Bot startup. A refused bot can answer health probes and idle without opening the database or writing a readiness marker.
  • Shared runtime. The Unix SIGTERM stream subscribes before the receiver task runs, and the existing process-wide latch retains the shutdown request for later waiters. Tokio signal registration
  • Regression coverage. The new test sends real SIGTERM before the receiver task can run. The existing launcher test checks HTTP 200 from /health, HTTP 503 from /ready, and exit code 0 after SIGTERM.

cargo test --locked -p jmodguard-runtime and cargo fmt --all -- --check passed locally. The new SIGTERM test also passed 20 additional runs. The bot CI job was still running at review time. Bot CI job

Pullfrog  | View workflow run | Using gpt-6.2-sol | 𝕏

@jatmn
jatmn merged commit af5f3ed into main Dec 6, 2026
22 checks passed
@jatmn
jatmn deleted the fix/queue-666-bot-refusal-shutdown branch December 6, 2026 00:32
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.

1 participant