Skip to content

feat(shutdown): handle SIGTERM for k8s graceful shutdown#594

Merged
thepagent merged 1 commit intoopenabdev:mainfrom
dogzzdogzz:feat/sigterm-graceful-shutdown
Apr 27, 2026
Merged

feat(shutdown): handle SIGTERM for k8s graceful shutdown#594
thepagent merged 1 commit intoopenabdev:mainfrom
dogzzdogzz:feat/sigterm-graceful-shutdown

Conversation

@dogzzdogzz
Copy link
Copy Markdown
Contributor

@dogzzdogzz dogzzdogzz commented Apr 27, 2026

Summary

  • Add a shutdown_signal() helper in src/main.rs that waits for SIGINT or SIGTERM on unix and falls back to ctrl_c on Windows.
  • Replace both tokio::signal::ctrl_c().await.ok() call sites with the helper so Kubernetes-style SIGTERM triggers the full cleanup path (Discord shard manager → Slack/gateway shutdown channel → ACP pool drain → child process group SIGTERM/SIGKILL escalation).

Fixes #593.

Discord discussion: https://discord.com/channels/1491295327620169908/1491365157010542652/1498213613410848789

Why

tokio::signal::ctrl_c() only catches SIGINT. Kubernetes sends SIGTERM to PID 1 during pod termination, so the previous code skipped graceful cleanup and got SIGKILL'd after terminationGracePeriodSeconds.

Relationship to #449

#449 added tini as PID 1 in the Dockerfiles, which ensures SIGTERM is delivered to openab (and reaps agent-grandchild zombies). This PR is the complementary second half: making openab handle the SIGTERM that tini forwards. Without this change, SIGTERM still hit the default disposition (terminate without running cleanup) even with tini in place.

Test plan

  • cargo clippy --all-targets -- -D warnings
  • cargo test --bin openab (124 passed)
  • Manual: kill -TERM <pid> against a running openab process and confirm "shutdown signal received" → "openab shut down" in logs.

🤖 Generated with Claude Code

@dogzzdogzz dogzzdogzz requested a review from thepagent as a code owner April 27, 2026 06:26
@github-actions github-actions Bot added closing-soon PR missing Discord Discussion URL — will auto-close in 3 days pending-screening PR awaiting automated screening and removed closing-soon PR missing Discord Discussion URL — will auto-close in 3 days labels Apr 27, 2026
@thepagent thepagent merged commit fe6ed2c into openabdev:main Apr 27, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pending-screening PR awaiting automated screening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support SIGTERM for k8s graceful shutdown

2 participants