# W11-PREFLIGHT-2 output (opus-reviewer, 2026-11-29) Verbatim agent return. Advisory input; root dispositions are recorded in `DECISIONS.md`. **Task W11-PREFLIGHT-2. Verdict: CHANGES_REQUIRED.** The addendum and the root edits fix the first review's P1 (F1) and most of F2–F13. Six P2 gaps remain. One is a contradiction inside the addendum itself (N1). Four are gaps that the addendum's own resolutions create (N3–N6), and one is a state the addendum never covers (N2). All six can be fixed by adding sentences to the contract text. No re-plan, gate change or ownership change is needed. - **Blocked until the text is amended:** B2 (N3, N4), B3/B4 (N1, N2, N3), A2's channel deadlines (N5; the rest of A2 can proceed), A3's EventBus work (N6). A4 picks up N3's loop rules when its spec is written. - **Not blocked:** A1 (M-FUNCTIONAL-03) can continue. B1 (M-TIME-03) can continue but needs one documentation-only note (N5). Neither needs an interface change. Paths are relative to `/home/faumaray/Projects/VoidLibrary`. "Addendum" means `docs/agent-workflow/tasks/W11-PLAN-REV1-OUTPUT.md`; "plan" means `W11-PLAN-OUTPUT.md`. ## Item status | Item | Status | Evidence / residual | |---|---|---| | F1 | RESOLVED | Workers only run a syscall and queue the result, so no completion runs on a worker. They hold a separate worker-pool object, never the backend. Backend destructors never block, and only `~Driver` does a blocking teardown, behind two terminate markers. Residual: P3-9. | | F2 | RESOLVED for sockets | The epoll and wake fds still close in the backend destructor (`EpollDriver.cpp:953-963`). Every socket-path `wake()` caller holds a strong reference (`:589-596`, `Backend.hpp:89-96`, `Stream.hpp:105-120`). The file path depends on N4. | | F3 | RESOLVED | Phase 7 drops the components before IO stops (phase 8) and before the executor is joined (phase 9). | | F4 | PARTIAL | The per-call budget fixes the zero-budget repeat call, but it contradicts the destructor rule (N1). Phase 2 is missing from the waiting-phase list (P3-1). | | F5 | PARTIAL | Moved-from rules are fine; gaps in N1, N2, P3-3 and P3-7. | | F6 | PARTIAL | Borrowed resources are skipped, but the embedded `ManualExecutor` path hangs (N2). | | F7 | PARTIAL | The single-lock claim/hand-off rule is sound. The timer callback can still reach a destroyed waiter (N5). | | F8 | RESOLVED | `seeded_engine` is in `M-FUNCTIONAL-03.md:114-142`. Nit: P3-6. | | F9 | PARTIAL | The routing fix is done. Choosing `busy` without loop rules creates N3. | | F10 | RESOLVED | The `7f95f89` doc edits match the addendum. Small gaps: P3-4. | | F11 | RESOLVED | The IO and executor start hooks plus `cleanup_timeout` cover failures inside a step (a later destructor finishes the cleanup, see N1). | | F12 | PARTIAL | `TimerHandle` shared state and the `parallel_for` shared state are fine. Gaps: N5 (timer) and N6 (EventBus). | | F13 | PARTIAL | The `FileState` deferred close is right in direction. The fd state machine is incomplete (N4). | **First-review P3 items** | Item | Status | |---|---| | `retry_blocking` template defaults | RESOLVED (`M-FUNCTIONAL-03.md:135-142`) | | Observable/Signal move-only and "state restored" | RESOLVED | | Downstream build list | RESOLVED | | Error-kind alignment | RESOLVED; observed in `Runtime/Options.hpp`, `shutdown_incomplete` maps to `conflict` | | D1 regression seam | RESOLVED (seam at `:1083`/`:1098`); see P3-5 | | Mock reactor spin | PARTIAL: the mock case is covered, the epoll cases are open (N3) | | Business scope `stop_on_first_error` | RESOLVED | | MIGRATION: `shutdown_and_join` blocks / `max_file_queue==0` / Sync snapshot / `parallel_for` | RESOLVED, all four observed in `MIGRATION.md:61` | | Unspecified: concurrent `poll_once` | PARTIAL (N3) | | Unspecified: IO file ownership after G5 | RESOLVED (G6) | | Unspecified: stop-and-report if an IO edit is needed | PARTIAL: stated for B4 and A4, not for B3 | | Unspecified: worker detection | RESOLVED (`is_io_worker_thread`) | | `ThreadExecutor` endless drain, destructor without join | RESOLVED | | Acceptance gaps (layering `rg`, within-step faults, ordering, budget test, receiver stop, legacy-mode captures) | RESOLVED; budget test lifetime in P3-2 | **Named checks (§3)** | Check | Answer | |---|---| | `busy` breaking existing callers | It does not. The only library loop that polls is `~Session` (`src/IPC/Session.cpp:1118-1129`): bounded to 1,000 iterations, result ignored. Every test drives a driver from one thread, and the one cross-thread test polls from only one thread (`IoDriver.cpp:458-508`). The hazard is in the new loops (N3). | | `wake_closed_` atomic argument | Sound. The last `shared_ptr` release orders the destructor after every `wake()`. The flag is effectively optional because the fd closes only in the destructor. The file wake path is not enumerated (N4). | | `FileState` reserved close capacity | Bounded only if files take descriptor slots. The addendum doesn't say so (N4). | | `ThreadExecutor::idle()` in phase 9 | Usable, but it is a snapshot, so "join never unbounded" is overstated (posts after the snapshot still extend the join). Safe in Runtime because phase 8 has already stopped IO dispatch. | **Named hazards (§6.2)** | Hazard | Answer | |---|---| | Raw waker pointer lifetime | Sound for workers: every backend destruction path goes through `~Driver`, which joins the workers first. `~File` must not use that waker (N4). | | `busy` and loop callers | See N3. | | Reserved close capacity unbounded | See N4. | | Phase-9 idle wait vs inline resume after join | Unreachable from IO, because phase 8 runs first. External posts (stop callbacks, user threads) resume inline; this is documented. | | `~HostCore` unbounded shutdown on destruction | Contradicted by the per-call budget (N1). Hangs in embedded mode (N2). | **Planner adjustments** | Adjustment | Verdict | |---|---| | Signal adapter closes its fd off the owner thread | Agree. It matches `src/System/SignalWatcher.cpp:27-37`, and `Runtime.md` is updated. Test hygiene: P3-3. | | Injected syscall shim as the one exception | Agree. `IO.md:94-96` is updated. | | Observable FIFO ordering change | Agree. It is recorded in `MIGRATION.md`. | ## New findings **N1 (P2, observed contradiction): the destructor's shutdown is called "unbounded" but the budget rule caps it at 30 s.** - **Where:** addendum `:85` says "(unbounded)". Addendum `:75-79` caps every call at `min(deadline, now + total_timeout)` and returns `complete=false` on expiry. `validate_options` rejects `total_timeout <= 0`, so the cap can't be switched off. The failed-start continuation (`:230`) relies on the same path. - **What happens:** a stall longer than 30 s makes `~HostCore` return from the shutdown call incomplete. A joinable reactor `std::thread` then calls `std::terminate`. If it didn't, members would tear down while components still exist. - **Related:** `poll_shutdown()` takes no options, so its budget restarts on every call. The plan test `runtime_shutdown_budget_min_caller_policy_manual_clock (poll_shutdown)` (plan `:745`) can therefore never see an expiry. - **Fix:** `~HostCore` loops `shutdown_blocking({})` until `complete` (or calls an internal no-deadline variant). State "destruction blocks until complete". Move that test to `shutdown_blocking` with an expired or manual-clock deadline. Define how `poll_shutdown` relates to the budget. **N2 (P2, inferred hang): embedded mode with a borrowed `ManualExecutor`.** - **Where:** `~HostCore` calls `shutdown_blocking`. Phase 4 then reaches `TaskScope::join_blocking`, which waits on a condition variable that nothing will ever pump (`include/Void/Async/TaskScope.hpp:289-303`). Component `stop()` tasks also need pumping. - **What happens:** destroying an unstopped embedded Host that has a business task or any component hangs forever. - **Second problem:** the terminate check uses `executor->is_executor_thread()`, which is true inside an ordinary `manual.drain()` of the borrowed executor. - **Fix:** - `shutdown_blocking` returns `invalid_argument` when the executor has no background workers, as `flush_blocking` already does. - `~HostCore` with a `ManualExecutor` pumps, following the `~TaskScope` pattern (`TaskScope.hpp:562-575`). - The terminate check applies only to owned executors. - `shutdown_pumping` in managed mode returns `invalid_argument`, because the reactor owns polling and `pump_until` would just get `busy`. **N3 (P2, inferred spin plus one hang path): who polls during shutdown is never specified.** - **Spins:** - `busy` returns immediately, so the B3 reactor loop (`poll_once(5ms)`), A4's `Driver::run` and `pump_until` spin hot while `advance_shutdown` holds poll ownership. - The 1.x early return once stopping is set (`EpollDriver.cpp:1057-1059`) skips `epoll_wait`, so loops spin throughout the shutdown window. - After `shut_down_`, `poll_once` returns 0 immediately, so the reactor spins until phase 9 joins it. - **Hang:** the addendum doesn't say where file completions are drained relative to that early return. If the drain sits after `epoll_wait` (the natural place, next to `drain_wake_fd`), in-flight file requests are never retired. `quiescent()` then never becomes true, `advance_shutdown` never completes, and `teardown_blocking` in `~Driver` hangs. - **Undefined behaviour:** `try_lock` on `poll_mu_` by the thread that already owns it, reachable through an inline resume inside a turn. - **Fix, one sentence each:** - Cancels, controls and file completions drain before any stop-flag return. - Say whether `begin_shutdown` sets `stopping_`. - Library loops wait up to `max_wait` (stop-aware) on `busy` and exit on `shutdown_complete()`. - Choose one: phase 8 stops and joins the reactor before `advance_shutdown`, or the reactor exits on completion. - `advance_shutdown` either releases `poll_mu_` between its 1 ms slices or makes the other pollers park. - `poll_once` checks the thread-local polling marker before `try_lock`. - Define what `advance_shutdown` returns when its stop token fires. **N4 (P2, inferred double close / use-after-free): the File fd state machine is incomplete (F13).** - **Missing invariants:** - The transitions between handle drop, in-flight count and `close_pending` happen under one mutex, so exactly one close is enqueued. - A File that outlives shutdown completion or `~Driver` holds an fd that teardown closed. A later `~File` or `close_and_join` must not close that number again, because it may now belong to someone else. Reads and writes must return `closed` without a syscall. - `close_and_join` after the workers are joined has nothing to run the close on ("close always executes on a worker or `run_file_work`"). - `~File` must wake through a weak→strong backend lock or the worker condition variable, never the raw waker. - Reserved close capacity is not stated as bounded. - **Fix:** - Give `FileState` an `open → closing → closed` state under the pool mutex; whoever closes sets `closed`. - After completion, `close_and_join` returns at once and `~File` does nothing. - Files count against `max_descriptors`, which bounds the reserved close capacity. - Preallocate the close node inside `FileState`, so the `noexcept` `~File` path never allocates. **N5 (P2, inferred use-after-free; affects B1, which is running): channel timer callbacks vs waiter nodes.** - **Where:** `M-TIME-03.md:63-65,89,113` says callbacks fire outside the lock after pending→fired, and that `cancel()` returning true means "never runs". It does not cover a callback that has fired and is still running. Addendum F7 puts waiter nodes in coroutine frames and has the timer callback "do nothing if claimed". - **What happens:** a sender claims the waiter, the receiver resumes and its `cancel()` returns false, its frame is destroyed, and the in-progress callback then reads the dead node. - **Fix:** - B1, documentation only: `cancel()==false` does not mean the callback has finished. B1 may continue. - A2: the timer callback captures shared waiter state, or the channel plus a waiter id that it looks up under the channel lock. It must never hold a raw pointer into a frame. **N6 (P2, inferred use-after-free): `~EventBus` on an executor thread doesn't wait (F12).** - **Where:** `Subscription` holds a raw `EventBus*` (`include/Void/Async/EventBus.hpp:137-146`), and handlers commonly capture `EventBus&` to publish follow-up events. - **What happens:** frames already queued keep delivering after the destructor returns, and any handler that touches the bus hits a dead object. - **Fix:** `~EventBus` gates every admitted-but-not-started delivery on every thread before it returns. Either wait for callbacks running on other threads (excluding the current one, via a thread-local depth) or document that residual. **P3 (each changes one spec line)** 1. Add phase 2 to the list of phases that return incomplete when the call deadline expires. Today a caller deadline shorter than the drain grace is ambiguous. 2. The owned BudgetResource, executor and driver objects must live until `~HostCore`. - The budget test reads `memory_budget()` and `admitted()` after `complete`, and `admitted()` needs `ThreadExecutor`, not `Executor*`. - A `BufferLease` that outlives its resource is a use-after-free. 3. Signal gate: - The borrowed `signal_gate` must outlive the Host. - `uninstall` must be idempotent or tracked, because failed-start cleanup already uninstalls. - The off-owner signal test must restore the owner's mask and drain SIGUSR2 at the end. 4. MIGRATION and Runtime.md: - Add "concurrent `poll_once` returns `busy`" and "`~Driver` on a file worker or inside a poll turn terminates" to MIGRATION. - `Runtime.md` is missing the `TimerQueue*` parameter on `shutdown_pumping`. 5. The D1 seam clock must be armed after submission. `submit_io` reads the clock at `:503`, and a stop there takes the pre-queue path, so D1 never reproduces. 6. Use `G(std::random_device{}())` (parentheses). Braces are a narrowing error for engines whose seed type is narrower than `unsigned`. Documentation-only for A1. 7. Moved-from Host and HostCore: - The moved-from rules omit the reference accessors (`options`, `lifecycle_plan`, `embedded_resources`). - HostCore must not hold pointers into Host members, because Host is movable. 8. Carry D-W11-06's condition into A3: a throwing `error_sink` is caught and counted. Add a B3 stop-and-report rule for IO edits. 9. Teardown with an already-joined `ThreadExecutor` resumes continuations inline inside the shutdown's own poll turn. Either dispatch after releasing ownership, or document that the executor must not be joined before the Driver is torn down (the Runtime order already satisfies this). ## Re-review scope Only the amended text for N1–N6 and the P3 lines above. This can be checked on the B2, B3, B4, A2 and A3 task specs; no new planner round is needed. ## Checks not run - No builds, tests or compile probes. Everything above comes from direct `sed`/`rg` reads. No Serena or codebase-memory coverage checks. - Not read: `EpollDriver.cpp:1475-1640` (the rest of `drive_read` and `drive_write`), `ThreadPool.hpp`, `ResourceGraph.hpp`, the `RuntimeHost.cpp` tests, and TASKS/STATE. - `M-TIME-03.md` and `M-FUNCTIONAL-03.md` were only partly read. - A new commit, `a8a9249` (D-039), landed during the review. I checked it: it does not touch the W11 contracts.