6.6 KiB
6.6 KiB
Wave 11 contract amendment R2 (root resolutions of PREFLIGHT-2)
Source findings: W11-PREFLIGHT-2-OUTPUT. Base contracts: W11-PLAN-OUTPUT amended by W11-PLAN-REV1-OUTPUT. These rules are MANDATORY text for the B2, B3, B4, A2, A3, A4 specs (decision D-040). Where this file and earlier documents disagree, this file wins.
N1 — Host destruction and shutdown budgets (B3/B4)
~HostCoreblocks until shutdown is complete: it loops an internal no-deadline shutdown (equivalent to repeatedshutdown_blocking({})ignoring the total-timeout cap) untilcomplete == true. Documented: "destruction blocks until complete".poll_shutdown(Async::OperationOptions = {})takes options; every shutdown entry point (shutdown_blocking,poll_shutdown,shutdown_pumping) uses the same per-call budgetmin(options.deadline, deadline_after(clock, total_timeout)).- The budget test uses an already-expired caller deadline (or manual-clock deadline) with
shutdown_blocking/poll_shutdown, so expiry is observable. - Waiting phases that return
complete=falseon call-deadline expiry: 2, 4, 5, 6, 8, 9 (P3-1).
N2 — Embedded mode (B3/B4)
shutdown_blockingreturnsRuntimeErrorCode::invalid_argumentwhen the Host's executor has no background workers (!has_background_workers());shutdown_pumpingin managed (owned executor) mode returnsinvalid_argument(the reactor owns polling).~HostCorein embedded mode: if the borrowed executor is aManualExecutor(dynamic_cast), it loopsshutdown_pumping(manual)until complete; otherwise, if shutdown is not already complete, it prints a diagnostic and callsstd::terminate(documented programmer error: embedded Host destroyed before shutdown completed).- The "destroyed on a Runtime worker" terminate check applies only to OWNED executors/reactor/
IO workers; never to a borrowed executor's
is_executor_thread().
N3 — Who polls during shutdown (B2, A4, B3/B4)
- B2: every poll turn drains cancels, control messages and file completions BEFORE any
stop-flag early return.
begin_shutdownsets the existing stopping flag (admission closed). While stopping (but not yet shut down), a turn with no work waits inepoll_waitup tomax_wait(wake fd stays registered) instead of returning immediately; it must not spin. - B2: after shutdown completes,
poll_oncereturns 0 without touching any fd (F2), andshutdown_complete()is true; library loops must exit on it (below). - B2:
poll_oncechecks the thread-local polling marker beforetry_lock(poll_mu_); a reentrant call from inside a turn returnsbusy(no recursive try_lock UB). - B2:
advance_shutdownreleasespoll_mu_between its ≤1 ms slices; other pollers may run turns in between (they only drain/dispatch). If its stop token fires it returns the current report withcomplete=false(not an error). - B2: when
advance_shutdown/teardown dispatches resume tickets, it does so after releasing poll ownership (P3-9). Document: an owned executor must not be joined before the Driver is torn down. - A4:
Driver::runandpump_untilonbusywait up tomax_wait(stop-aware, at most 1 ms slices) and retry; they exit whenshutdown_complete()is true. - B3/B4: Runtime phase 8 first requests reactor stop and JOINS the reactor thread, then drives
driver->shutdown(remaining)from the shutdown thread. The reactor loop also exits onshutdown_complete(); onbusyit waits as A4's loops do.
N4 — File descriptor state machine (B2)
detail::FileStatehasenum { open, closing, closed }guarded by the pool mutex; the handle-drop / in-flight count /close_pendingtransitions happen under that mutex, so exactly one close is enqueued and whoever closes the fd setsclosed.- Driver teardown closes any still-open file fds after joining workers and marks them
closed. Afterwards File reads/writes/syncs returnIoErrorCode::closedwithout a syscall,~Filedoes nothing, andclose_and_joinreturns success immediately (idempotent). - Files count against
IoLimits::max_descriptors; that bounds the reserved close capacity. The close request node is preallocated insideFileState, so~File(noexcept) never allocates. ~Filewakes the poller only through a weak→strong backend lock or the worker condition variable, never through the raw waker pointer.
N5 — Channel timer callbacks (A2; B1 documents)
- B1 documents:
TimerHandle::cancel() == falsemeans the callback fired or is firing, not that it finished. - A2: an AsyncChannel timer callback captures shared waiter state (
shared_ptrcontrol block for the waiter) or aweak_ptrto the channel plus a waiter id looked up under the channel lock. It never holds a raw pointer into a coroutine frame.
N6 — EventBus destruction (A3)
~EventBusgates every admitted-but-not-started delivery on every thread before returning (shared coreclosedflag checked under the core lock before each delivery starts).- It waits for callbacks running on OTHER threads to finish, excluding the current thread's own in-progress callback (thread-local dispatch depth). Residual documented: destroying a bus from inside a callback that another thread's callback waits on can deadlock (caller error).
- A throwing
error_sinkis caught and counted (D-W11-06 condition, P3-8).
P3 lines
- P3-2 (B3/B4): owned
BudgetResource, executor and driver objects live until~HostCore; NEW[[nodiscard]] std::size_t Host::cpu_admitted() const noexcept(0 when not started or embedded) for the budget test; aBufferLeasemust not outlive its resource. - P3-3 (B3/B4): the borrowed
SignalGatemust outlive the Host; Host tracksgate_installed_souninstallruns at most once (failed-start cleanup and teardown cannot double-uninstall); the off-owner signal test restores the owner mask and drains SIGUSR2 before finishing. - P3-4 (root): MIGRATION records "concurrent
poll_oncereturnsbusy" and "~Driveron a file worker or inside a poll turn terminates";Runtime.mdshows theTimerQueue*parameter onshutdown_pumping. - P3-5 (B2): the D1 seam clock is armed only after submission (
submit_ioreads the clock atEpollDriver.cpp:503). - P3-6 (A1):
seeded_engineconstructs with parenthesesG(std::random_device{}())(sent). - P3-7 (B3): moved-from Host reference accessors (
options,lifecycle_plan,embedded_resources) have preconditionvalid()(documented, asserted in debug);HostCoreholds no pointers intoHostmembers. - P3-8 (B3): stop-and-report if an IO edit is needed (IO files are owned elsewhere).