R5
What to build¶
Cleanup errors do not replace caller cancellation, interrupts or the original candidate failure.
Source and evidence¶
Repository scientific/architectural review, snapshot 86c8517, item R5.
Classification: confirmed defect; medium severity.
The finally block awaits teardown without preserving a pending exception. A
teardown RuntimeError replaces a CancelledError from invocation. Direct callers
therefore observe an ordinary failure instead of cancellation, breaking structured
cancellation semantics. The analogous synchronous finally block can also replace
an invocation exception, despite its docstring promising propagation.
Reproduction: successful setup, invoke awaiting an unset asyncio Event, teardown
raising RuntimeError. Create a task for execute_async(), yield once, cancel it,
and await it. Observed exception class: RuntimeError. The task completed; no
background work was left running.
Acceptance criteria¶
- [ ] Async invocation cancellation plus teardown RuntimeError propagates cancellation and completes owned cleanup.
- [ ] Sync and async ordinary invocation failure plus teardown failure preserves documented primary-exception precedence.
- [ ] Teardown-only failure after successful invocation remains observable through a safe documented mechanism.
- [ ] Teardown runs exactly once only after successful setup; tests retain no private exception messages.
- [ ] Preserve Consumer-owned meaning, payload-free evidence, disabled optional-import isolation, safe diagnostics and the non-relaxable Safety Floor.
- [ ] Run the narrowest observable contract, then applicable committed Make gates. Record every command and outcome; update specifications/compatibility evidence for changed public or wire contracts. Run native Collector verification for changed Collector assets and build for packaging changes.
Design guidance¶
Make exception precedence an explicit lifecycle policy. Preserve the primary exception and expose secondary cleanup failure only through bounded diagnostics or an appropriate causal mechanism; share policy across sync/async seams.
Keep prefactoring narrow and verifiable in this slice. Reuse established owners and structural interfaces; introduce a pattern only when it clarifies a real responsibility or variation point. Do not add consumer vocabulary or private payloads to platform code or evidence. Mocked/local results must not claim hosted, production, accelerator or release qualification.
Blocked by¶
None (can start immediately). Shared-area coordination is useful, but no other review fix is a genuine prerequisite for this slice.
Verification scope¶
Convert the described counterexample or investigation oracle into an observable test at the lowest suitable public boundary. Prefer bounded operation-count or deterministic interleaving evidence to flaky timing assertions; timing guarantees need a declared tolerance and independently owned cleanup. This ticket authorizes remediation/research, not publication or deployment.