fix(tools): replace unsafe signal sending with nix crate, decompose long functions#3465
Merged
fix(tools): replace unsafe signal sending with nix crate, decompose long functions#3465
Conversation
…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
142cab7 to
af94a92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nix::sys::signal::killfor safe SIGTERM→SIGKILL escalation in shell executor (tech-debt: replace unsafe signal sending in shell executor with nix crate #3449)clippy::too_many_linesfunctions inzeph-toolsinto focused helpers (tech-debt: decompose long functions in zeph-tools (scrape, shell) #3450)Changes
#3449 — nix-based signal safety
nix = "0.31"as a direct workspace dep (was already transitive); gated[target.'cfg(unix)'.dependencies]inzeph-toolswithfeatures = ["signal", "process"]send_signal_with_escalation(pid): SIGTERM → 250ms wait →pkill -Pdescendants → SIGKILL; ESRCH treated as process-already-gonerun_background_task: new async fn that spawns the child directly inside the tokio task and writeschild_pidinto the registry before entering the stream loop — making the escalation path reachable fromshutdown()kill_process_tree: delegates tosend_signal_with_escalationon unix before the tokio kill#3450 — function decomposition
execute_block→capture_snapshot_for,maybe_rollback,classify_and_audit,apply_output_filterexecute_bash→build_bash_command,apply_sandbox,spawn_output_readers,BashLoopOutcomeenum,run_bash_stream,finalize_envelopescrape.rs execute_tool_call→run_with_audithelper#[allow(clippy::too_many_lines)]suppressionsTest plan
cargo +nightly fmt --check— cleancargo clippy --package zeph-tools --all-targets --all-features -- -D warnings— 0 warningscargo nextest run --package zeph-tools --lib --bins— 1075/1075 passed (3 new unix-gated signal tests)Closes #3449
Closes #3450