Reject empty supervised executables before spawn (#314) - #315
Merged
Merged
Conversation
Unix spawn treats a zero-byte +x file as an empty shell program, so the supervisor logged successful exits and retried forever. Fail closed before spawn and keep pending restart handoff from converging. Fixes #314
There was a problem hiding this comment.
🟡 Changes recommended
The lifecycle caller overwrites the new invalid-executable status with a generic restart failure.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds zero-byte executable rejection to prevent infinite supervisor restart loops and records invalid restart handoffs.
Changes:
- Validate executables before every spawn.
- Preserve pending restart state for invalid executables.
- Add regression tests for empty files and valid scripts.
File summaries
| File | Description |
|---|---|
crates/surge-supervisor/src/main.rs |
Integrates validation and handoff reporting. |
crates/surge-supervisor/src/handoff.rs |
Records unusable executable handoffs. |
crates/surge-supervisor/src/child.rs |
Implements pre-spawn validation. |
crates/surge-core/src/update/status/handoff.rs |
Defines the invalid-executable phase. |
crates/surge-core/src/update/status.rs |
Exports the new phase constant. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The post-update restart path only checked that the target existed, then overwrote the supervisor's invalid-executable status with a generic pid-file timeout. Reject an empty target before spawn so the persisted pending-restart record keeps the specific phase.
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
surge-supervisorspawns itpending_restartwithrestart handoff invalid executableand do not mark supervisor restart confirmedBehavior impact
On Linux, Unix command launch treats a zero-byte executable as an empty shell program.
Command::spawnsucceeds, the child exits 0 immediately, and the supervisor retried every two seconds indefinitely.The supervisor now fails closed before spawn. A later spawn of an empty replacement executable (for example after an update swap) also exits the supervisor instead of looping. Valid non-empty scripts that exit 0 still restart with the existing backoff.
A general immediate-exit circuit breaker was considered and not added:
clean_child_exit_triggers_restart_in_steady_stateencodes the current contract that a valid child which exits 0 is relaunched.Validation
cargo fmt --all -- --check./scripts/check-version-sync.sh./scripts/check-maintainability.shRUSTFLAGS="-D warnings" cargo test --workspacecargo clippy --all-targets --all-features -- -D warningscargo clippy --workspace --lib --bins --examples -- -D warnings -D clippy::unwrap_used -D clippy::expect_useddotnet format dotnet/Surge.slnx --verify-no-changesdotnet test dotnet/Surge.slnx --configuration Release(59 passed)Fixes #314