Repository navigation
Description
Problem and expected behavior
EvidenceHost can enforce a producer deadline and then wait indefinitely during cleanup, preventing RunAsync() from returning its terminal manifest. CI consumers consequently need their own outer process watchdog to bound the host lifecycle. The reusable lifecycle behavior belongs in AppSurface; consumer CI still owns work before and after the host and the runner-level timeout.
Expected behavior: a responsive host reaches a terminal, non-passing outcome within its execution budget plus an explicitly bounded cleanup allowance. An unfinished cleanup operation must never be reported as successful cleanup, complete evidence, or a release-eligible claim.
Verified current state
Verified by source inspection on 2026-10-05 in both:
- Consumer package
ForgeTrust.AppSurface.Evidence.Aspire0.2.0-preview.8, whose package metadata identifies source commitb34970c87489a63b132531657c043e075b092e5e. - Upstream main at
3bce0bdbef5e7ae3137f0bb90dbd3d0ff9f08183.
| Phase | Existing behavior | Gap |
|---|---|---|
| Resource readiness | Linked cancellation and WaitAsync(deadline.Token) |
Stopping the wait does not itself stop a non-cooperative callback. |
| Producer execution | Linked cancellation and WaitAsync(deadline.Token); deadline expiry records TimedOut |
The underlying callback can remain active after the host stops waiting. |
| Manifest collection | CollectAndCleanAsync() awaits cleanup before building the manifest |
A cleanup hang prevents terminal output. |
| Registered cleanup | CleanAsync() directly awaits IAsyncDisposable.DisposeAsync() or calls synchronous Dispose() |
No host-owned cleanup time budget is enforced at this boundary. |
| Host disposal | DisposeAsync() waits for the execution semaphore, then calls cleanup |
A run stuck in cleanup can also block subsequent host disposal. |
Relevant source: producer deadline, collection and cleanup, and host disposal.
Existing tests cover a producer ignoring cancellation, disposal exactly once, and cleanup throwing. They do not establish a bound when disposal never completes. Extend EvidenceHostBootstrapTests.cs.
Minimal reproduction
This is a source-derived reproduction recipe; it has not yet been executed as an upstream fixture.
- In
EvidenceHostBootstrapTests, reuseCreatePlan(),ReadyResource("postgres"), andPassingProducer("coverage", "coverage/assertion@1"). - Make the passing producer implement
IAsyncDisposable. Its disposal signals that cleanup began, then awaits aTaskCompletionSourcethat the fixture controls. Do not release that gate yet. - Start
host.RunAsync(cancellationToken: caller.Token)and wait for the cleanup-start signal. - Cancel the caller token. Observe from a separately bounded fixture wait that
RunAsync()remains incomplete while the cleanup gate is closed. The producer has already finished successfully; execution cancellation does not bound cleanup. - In the fixture's
finally, release the gate, await the run, and dispose the host. The fixture must leave no hanging tasks or processes.
Repeat with a producer whose ProduceAsync() ignores cancellation and whose disposal awaits that callback. Give it a one-second producer timeout. The host stops awaiting production, then re-enters an unbounded wait through disposal.
Required change and acceptance criteria
- Define and enforce an explicit cleanup allowance for the complete host lifecycle, including terminal collection, error unwinding, caller cancellation, and direct host disposal. For deterministic tests, use a one-second cleanup allowance and require completion within that allowance plus a documented scheduling tolerance, rather than waiting for CI's full timeout.
- A producer or resource whose asynchronous disposal never completes cannot prevent terminalization indefinitely. A synchronous disposal that blocks is also covered by an explicit supported execution boundary or rejected with an actionable restriction before execution; merely applying
WaitAsync()after invoking blocking synchronous code is insufficient. - Cleanup timeout or failure yields no complete/release claim, records
CleanupCompleted = false, and emits a bounded diagnostic identifying the affected registration and phase. Preserve the initiating producer outcome (TimedOut,Cancelled, orFailed) alongside cleanup failure. - Track callbacks that outlive their execution deadline. Stopping an await must not be represented as proof that the callback stopped or its resources were released. Do not race disposal with ongoing producer work without an explicit ownership contract.
- Provide or reuse an AppSurface-owned supervision seam for process-backed producers that supports cancellation, bounded termination, and verification that owned descendants exited. An in-process cancellation token cannot forcibly stop arbitrary managed code; document when process isolation and a consumer outer watchdog are required.
- Hanging cleanup for one registration must not silently skip cleanup of unrelated owned registrations. Preserve reverse ownership order, disposal exactly once, and a bounded total cleanup budget.
- Terminal manifest, exit/exception behavior, and diagnostics agree. Diagnostic failures cannot replace the original execution outcome or disable deadline enforcement. Diagnostics contain no credentials, connection strings, environment dumps, or raw producer payloads.
- Add documentation and a package-consumer example explaining execution budget, cleanup allowance, process ownership, and the remaining CI/runner responsibilities. Confirm package-consumer behavior in the released artifact, not only source tests.
Verification plan
- Host regression tests: successful producer with hanging disposal; timed-out non-cooperative producer with hanging disposal; caller cancellation during production and during cleanup; hanging resource disposal; direct disposal without a run; concurrent/repeated host disposal; and cleanup of another registration after one times out.
- Process integration tests: child ignoring graceful termination, descendant outliving its parent, and process termination/cleanup failure. Use short configured budgets and an independent fixture supervisor; prove owned processes are gone before teardown.
- Regression checks: existing readiness timeout, producer timeout, cleanup exception, complete/observation/release claim, and first-party coverage watchdog outcomes retain their intended semantics.
- No browser or production deployment is needed to demonstrate this host contract.
Consumer impact and evidence limits
The motivating consumer is Skoolit's Linux GitHub Actions native Core lane, which has a 60-minute lane deadline and a 75-minute job timeout. The consumer review found a job reaching the full timeout and a separate job losing runner communication. Worker logs for those incidents were unavailable, so this issue does not assert that hanging EvidenceHost cleanup caused them. A watchdog on an unresponsive runner cannot reliably resolve machine loss.
Skoolit draft PR #1213 adds whole-shell supervision and bounded diagnostics as a consumer mitigation. It also covers startup and shell finalization outside EvidenceHost. The current upstream gap is independently supported by the source paths above.
Scope, sequencing, and related work
First establish the bounded cleanup and ownership contract, then implement its enforcement and fault tests, then publish the package-consumer adoption path. Estimate implementation effort after choosing the ownership boundary; arbitrary in-process callbacks and supervised external processes have different termination guarantees.
The consumer should keep its outer CI guard until it has adopted and verified the upstream guarantee. Recover from regressions with a forward package correction; no application data migration is involved.
Out of scope: increasing CI timeouts, runner sizing, changing coverage thresholds, proving the missing historical logs' root cause, building a general-purpose container sandbox, or moving Skoolit's trusted-control and artifact-upload policies into AppSurface.
Related: #777 (reference evidence workflow), #778 (Skoolit acceptance consumer), #779 (hostile-input/cancellation proof), and #815 (VSTest hang diagnostics). VSTest hang diagnostics cover test execution and do not establish a whole-host cleanup bound.
Activity