Skip to content

fix(tools): replace unsafe signal sending with nix crate, decompose long functions#3465

Merged
bug-ops merged 1 commit intomainfrom
3449-nix-signal-shell-tools
Apr 26, 2026
Merged

fix(tools): replace unsafe signal sending with nix crate, decompose long functions#3465
bug-ops merged 1 commit intomainfrom
3449-nix-signal-shell-tools

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Apr 26, 2026

Summary

Changes

#3449 — nix-based signal safety

  • Added nix = "0.31" as a direct workspace dep (was already transitive); gated [target.'cfg(unix)'.dependencies] in zeph-tools with features = ["signal", "process"]
  • send_signal_with_escalation(pid): SIGTERM → 250ms wait → pkill -P descendants → SIGKILL; ESRCH treated as process-already-gone
  • run_background_task: new async fn that spawns the child directly inside the tokio task and writes child_pid into the registry before entering the stream loop — making the escalation path reachable from shutdown()
  • kill_process_tree: delegates to send_signal_with_escalation on unix before the tokio kill

#3450 — function decomposition

  • execute_blockcapture_snapshot_for, maybe_rollback, classify_and_audit, apply_output_filter
  • execute_bashbuild_bash_command, apply_sandbox, spawn_output_readers, BashLoopOutcome enum, run_bash_stream, finalize_envelope
  • scrape.rs execute_tool_callrun_with_audit helper
  • Removed all three #[allow(clippy::too_many_lines)] suppressions

Test plan

  • cargo +nightly fmt --check — clean
  • cargo clippy --package zeph-tools --all-targets --all-features -- -D warnings — 0 warnings
  • cargo nextest run --package zeph-tools --lib --bins — 1075/1075 passed (3 new unix-gated signal tests)
  • Windows: nix-gated code compiles without the unix target

Closes #3449
Closes #3450

@github-actions github-actions Bot added documentation Improvements or additions to documentation rust Rust code changes dependencies Dependency updates bug Something isn't working size/XL Extra large PR (500+ lines) labels Apr 26, 2026
…e long functions

Implement safe SIGTERM→SIGKILL escalation in the shell executor using
nix::sys::signal::kill instead of raw libc calls (#3449). The nix crate
is already a transitive dep; added as a direct dep gated to cfg(unix)
with the signal and process features.

Key changes in shell/mod.rs:
- send_signal_with_escalation: sends SIGTERM, waits 250ms, kills
  descendants via pkill -P, then sends SIGKILL; ESRCH is treated as
  process-already-gone and silently ignored
- run_background_task: new async fn that spawns the child directly and
  writes child_pid into the registry before entering the stream loop,
  making the escalation path reachable from shutdown()
- kill_process_tree: delegates to send_signal_with_escalation on unix

Decompose three long functions that had clippy::too_many_lines
suppressions (#3450):
- execute_block → capture_snapshot_for, maybe_rollback,
  classify_and_audit, apply_output_filter
- execute_bash → build_bash_command, apply_sandbox, spawn_output_readers,
  BashLoopOutcome enum, run_bash_stream, finalize_envelope
- scrape.rs execute_tool_call → run_with_audit helper

Closes #3449
Closes #3450
@bug-ops bug-ops force-pushed the 3449-nix-signal-shell-tools branch from 142cab7 to af94a92 Compare April 26, 2026 12:45
@bug-ops bug-ops enabled auto-merge (squash) April 26, 2026 12:45
@bug-ops bug-ops merged commit de75099 into main Apr 26, 2026
32 checks passed
@bug-ops bug-ops deleted the 3449-nix-signal-shell-tools branch April 26, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Dependency updates documentation Improvements or additions to documentation rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tech-debt: decompose long functions in zeph-tools (scrape, shell) tech-debt: replace unsafe signal sending in shell executor with nix crate

1 participant