refactor(tower-runtime): structured AppCompletion / Status::Failed plumbing#274
Merged
Merged
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
…umbing
`LocalApp::start` previously spawned `execute_local_app` with a
`oneshot::Sender<i32>`; every `?` early-return in that task dropped the
sender silently, and `LocalApp::status()` reported the resulting closed
channel as `Error::WaiterClosed` — losing the actual cause (env join
errors, `tower_uv::Error` variants, panics, etc.).
Replace the channel payload with an internal `AppCompletion` enum and a
new `Status::Failed(AppFailure)` shape that preserves the structured
error. Highlights:
- `AppCompletion` (internal) has `Exit(i32)`, `Cancelled`,
`Failed(AppFailure)` variants. The spawn wrapper in `LocalApp::start`
runs `inner_execute_local_app` inside `AssertUnwindSafe(...).catch_unwind()`
and always sends an `AppCompletion` before exiting, so a closed waiter
channel can no longer mask a real failure.
- `Status::Failed(AppFailure)` replaces the old
`Status::Failed { error_code, error_message }` strings.
`AppFailure` has:
* `Runtime(Error)` — structured runtime error
* `Panic(String)` — `catch_unwind` payload
* `Platform { error_code, error_message }` — opaque strings for
callers that construct `Status::Failed` from outside
`tower_runtime` (e.g. Kubernetes pod-status reconciliation).
Stringification (`error_code` / `error_message`) is the consumer's
responsibility, not the runtime's.
- `Status::Cancelled` is a new terminal variant for explicit
cancellation via the `CancellationToken`. Previously cancellation
was represented as `Crashed { code: -1 }`, indistinguishable from
an app that legitimately exits with code 255 / -1 or an IO error
in `wait_for_process`. `inner_execute_local_app` now returns
`Err(Error::Cancelled)` on every cancellation path (4 prologue
checks + 3 post-`wait_for_process` checks that disambiguate
cancellation from a child's genuine non-zero exit), and the spawn
wrapper special-cases that into `AppCompletion::Cancelled`.
- `Error` gains `Clone + PartialEq + Eq` (all variants are unit, so
this is free) so `Status` can keep deriving `Clone + PartialEq`,
which is required by status caching in `LocalApp::status()` and by
existing integration tests.
- `tower-cmd` (the only other in-crate consumer of `Status::Failed`)
is updated for the new variant shape and prints a dedicated
"cancelled" message for `Status::Cancelled`.
- The integration test `test_abort_on_dependency_installation_failure`
keeps asserting that `uv sync` non-zero exits surface as
`Status::Crashed { code }` — `Status::Failed` is reserved for
platform failures where the child never ran.
`Error::WaiterClosed` now only fires when the spawn was aborted or the
runtime was dropped — both real bugs worth surfacing as-is.
ca64d62 to
744f6d1
Compare
sammuti
approved these changes
May 13, 2026
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
LocalApp::startpreviously spawnedexecute_local_appwith aoneshot::Sender<i32>; every?early-return in that task dropped the sender silently, andLocalApp::status()reported the resulting closed channel asError::WaiterClosed— losing the actual cause (env join errors,tower_uv::Errorvariants, panics, etc.).This PR replaces the channel payload with an internal
AppCompletionenum and a newStatus::Failed(AppFailure)shape that preserves the structured error.Changes
AppCompletion(internal tolocal.rs) hasExit(i32),Cancelled,Failed(AppFailure)variants. The spawn wrapper inLocalApp::startrunsinner_execute_local_appinsideAssertUnwindSafe(...).catch_unwind()and always sends anAppCompletionbefore exiting — a closed waiter channel can no longer mask a real failure.Status::Failed(AppFailure)replaces the oldStatus::Failed { error_code: String, error_message: String }.AppFailurehas:Runtime(Error)— structuredtower_runtimeerror.Panic(String)—catch_unwindpayload (the panic loses type info, so a string is the most we can carry).Platform { error_code, error_message }— opaque strings for callers that constructStatus::Failedfrom outsidetower_runtime(e.g. Kubernetes pod-status reconciliation in downstream consumers).Stringification (mapping
Errorvariants to a stableerror_code, debug-formatting the message) is the consumer's responsibility, not the runtime's.Status::Cancelledis a new terminal variant for explicit cancellation via theCancellationToken. Previously cancellation was represented asCrashed { code: -1 }, indistinguishable from an app that legitimately exits with code 255 / -1 or an IO error inwait_for_process.inner_execute_local_appnow returnsErr(Error::Cancelled)on every cancellation path (four prologue checks + three post-wait_for_processchecks that disambiguate cancellation from a child's genuine non-zero exit), and the spawn wrapper special-cases that intoAppCompletion::Cancelled.ErrorgainsClone + PartialEq + Eq(all variants are unit, so this is free) soStatuscan keep derivingClone + PartialEq, which is required by status caching inLocalApp::status()and by existing integration tests.tower-cmd(the only other in-crate consumer ofStatus::Failed) is updated for the new variant shape and prints a dedicated "cancelled" message forStatus::Cancelled.What stays the same
uv venv/uv syncnon-zero exits still surface asStatus::Crashed { code }(verified bytest_abort_on_dependency_installation_failure).Status::Failedis reserved for platform failures where the child process never ran.Error::WaiterClosedis preserved but now only fires when the spawn was aborted or the runtime was dropped — both real bugs worth surfacing as-is.