R7
What to build¶
A caller's shutdown deadline can expire without abandoning eventual provider cleanup.
Source and evidence¶
Repository scientific/architectural review, snapshot 86c8517, item R7.
Classification: confirmed defect; medium severity.
Shutdown marks the runtime closed before waiting for an existing flush worker. If that wait expires, it returns without arranging provider shutdown. The old worker only flushes; when it eventually finishes, no code shuts down providers. Further shutdown calls return immediately because the runtime is closed. This can retain exporter/processor resources in a process that continues serving or recreates runtimes. A finite caller deadline should not lose eventual cleanup.
Reproduction using the repository's _runtime_with_providers fixture: block a
provider flush on an Event; use a 10 ms shutdown timeout; invoke force_flush,
then shutdown; release the Event and join the worker; invoke shutdown again.
Observed provider_shutdowns_after_worker_exit: 0, worker_alive: False.
The existing timeout test checks closed state and worker reuse but never checks
eventual provider shutdown after release.
Acceptance criteria¶
- [ ] Block a provider flush, call shutdown with a short deadline, then release it: every owned provider is eventually shut down exactly once.
- [ ] The shutdown caller returns within its deadline; repeated flush/shutdown calls do not spawn extra lifecycle workers.
- [ ] Closed/pending-cleanup/completed states behave consistently under concurrent callers.
- [ ] A release-after-deadline contract verifies actual provider shutdown, not merely closed flags.
- [ ] 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¶
Represent pending shutdown explicitly and serialize cleanup through the existing lifecycle worker. The worker that finishes the prior flush must transfer to queued shutdown; avoid unbounded background-worker multiplication.
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.