# W11-SPEC-REVIEW-1 output (opus-reviewer, 2026-11-29) Verbatim agent return. Advisory input; root dispositions are recorded in `DECISIONS.md`. **Task W11-SPEC-REVIEW-1. Verdict: S-IO-03 is CHANGES_REQUIRED and M-ASYNC-04 is CHANGES_REQUIRED.** There are no P0 or P1 findings. Every fix below is added spec text. None needs a re-plan, a change to ownership or reopening a D-W11 decision. Each finding says whether I saw it in the text and code ("observed") or worked out an interleaving ("inferred"). - **Blocks dispatch:** S-IO-03 S1–S8, plus a root decision on S9. M-ASYNC-04 A1–A3. - **Editorial:** all P3 items. They are clarifications and can be folded into the same edit. Spec line numbers refer to `docs/agent-workflow/tasks/S-IO-03.md` and `docs/agent-workflow/tasks/M-ASYNC-04.md` as they are now. ## S-IO-03 (B2): CHANGES_REQUIRED **S1 (P2, inferred): shutdown can be starved by a concurrent poller (§6 l.86-91, l.124-131).** - **Text:** - The spec requires a `std::mutex` acquired with `try_lock` (l.86-87). - While stopping, a turn with no work holds ownership inside `epoll_wait` for up to `max_wait` (l.89-90). - `advance_shutdown` takes ownership only between slices of at most 1 ms (l.125-127), and it must own the poll to close fds (l.131). - **Effect:** a poller loop re-locks within nanoseconds after each `wake()`, so `try_lock` almost never wins. The mandatory test `io_epoll_shutdown_concurrent_with_poller_no_uaf_tsan` (l.211) and a cross-thread 1.x `shutdown_and_join` can stall for seconds or hang. - **Append to Shutdown core:** "Ownership handoff: before each slice `advance_shutdown` sets atomic `shutdown_waiting_` and calls `wake()`. While it is set, `poll_once` on any other thread returns `busy` before `try_lock`, touching no fd and not incrementing `turns`. It is cleared once `advance_shutdown` holds `poll_mu_`. Between slices, after `advance_shutdown` releases `poll_mu_`, other pollers may run turns (R2 N3)." **S2 (P2, observed omission): completion order, final drain and fd-close ownership are unstated (l.124-132).** - REV1 F2 says shutdown closes operation and descriptor fds "only after it holds poll ownership" (W11-PLAN-REV1-OUTPUT.md:43). That sentence is missing from the spec. - The step order is not given. Inferred consequence: a completion pushed after the last drain is stranded, because after shutdown `poll_once` no longer touches anything. - **Replace l.131-132 with:** "Order: (1) `begin_shutdown()`. `advance_shutdown` calls it itself, because A4's `shutdown(options)` wraps only `advance_shutdown`. (2) Wait until no queued or active file request and no op `in_execution`. (3) Under `poll_mu_`, run a final drain of cancels, controls, file completions and close waiters. (4) Join workers. (5) Still under `poll_mu_`, close the remaining file fds (mark them `closed` and complete pending `close_and_join` waiters with success), then close op and descriptor fds. (6) Set `shut_down_` (release), then `wake_closed_`. (7) Release `poll_mu_`, then dispatch the tickets (P3-9). `self_join` misuse is detected before any state change. `begin_shutdown` only records intent and wakes the poller; it never completes or dispatches anything (F1(a))." **S3 (P2, observed contradiction): l.107-108 has workers re-check expiry with the driver clock at dequeue.** - That conflicts with l.92-94, with D-038 ("file workers never call … user code except the injected syscall shim") and with IO.md:95-96. `MonotonicClock::now()` is injected user code. The D1 seam clock even requests stop from inside `now()`. - **Replace l.107-108 with:** "Expiry is checked with the driver clock in `poll_once`. The epoll wait bound includes the earliest queued-file deadline. At dequeue, a worker checks under the pool mutex, without calling the clock, the request's stop flag and the expired mark set by the last turn. Such a request completes `cancelled`/`timeout` with no syscall." - If the root prefers to keep the worker clock read, declare the clock a second documented exception that must be thread-safe. `ManualClock` is atomic (`Clock.hpp:129`). **S4 (P2, observed; the tests cannot assert what they are named for): `DomainOutcomeKind` is not observable.** - `File` returns `Result<…>`, and `Error` carries only status and `system_code()` (`Functional/Error.hpp:136-235`). So `io_file_queued_cancel_not_committed_zero_effects` and `…sync_failed_unknown_errno` (l.202-205) cannot assert `not_committed` or `unknown`. - Also, "via the existing `complete_op_and_collect_tickets` path" (l.95-96) cannot work as is. That function is typed for `Transfer` and hard-codes `cancelled`/`failed` (`EpollDriver.cpp:421-447`). - **Add to §6:** "Observable contract: - Queued stop gives `IoErrorCode::cancelled`; queued expiry gives `IoErrorCode::timeout` (both kIoErrorDomain), with zero shim calls and unchanged file bytes. - Sync failure gives `IoErrorCode::sync_failed` with `system_code()==std::error_code{errno, std::generic_category()}`, matching `errno_code`. - Internally, settle with `try_commit_error(err, not_committed|unknown)`. `Result` does not expose that kind and tests do not assert it. - Retirement uses a retire-once path equivalent to `complete_op_and_collect_tickets`, generalized for `OperationState` and the file outcome kinds." **S5 (P2, observed omission plus inferred double close): it is unspecified whether files use the socket slot table (l.101-102, l.115-118).** - The shutdown sweep calls `release_slot_locked(idx, true)` on every in-use slot (`EpollDriver.cpp:1209-1223`), and that closes `slot.fd` (`:362-363`). If an implementer stores the file fd in a slot, the fd gets closed twice. - **Add:** "A File occupies a `DescriptorSlot`. It counts in `active_descriptors_`, is bounded by `max_descriptors`, and `File::id()` is that slot's `DescriptorId`. The slot has `fd = -1` and a file-kind flag, and socket paths (interest updates, `close_fd` controls, stale-event checks, the shutdown sweep) skip it. The file fd lives only in `FileState`." **S6 (P2, inferred use-after-free): `~File` after `~Driver` must lock the pool mutex (l.115-123).** - **Add:** "`FileState` holds `shared_ptr` and `weak_ptr`, never raw pool or backend pointers. The raw-context waker is called only by workers, which are joined before the backend is destroyed." **S7 (P2, observed plus inferred hang): stop flag and mock held tokens.** - **Shared stop flag:** `request_stop()` already sets `stopping_` (`EpollDriver.cpp:282-286`). If `begin_shutdown`'s idempotence is keyed on that flag (l.124-125), a prior `request_stop()` makes it a no-op. Queued file requests are then never cancelled, and with manual stepping `~Driver` hangs. - **Mock held tokens:** 1.x mock shutdown skips held requests (`:847-851`). The `MockController` dies with the `Driver`, so if teardown waits for those requests it deadlocks. - **Add:** "`request_stop()` == `begin_shutdown()`, with idempotence on a separate `shutdown_begun_` flag. On mock, requests held by a token never block `advance_shutdown`; `finish_*` still completes them, and `teardown_blocking` completes any still held with `IoErrorCode::closed`." **S8 (P2, observed ambiguity): the D1 seam test (l.212-213) can fail even with a correct fix.** - An implementation that purges retired ops from `cancel_queue_`, or that reads the clock before the start-of-turn drain, leaves `duplicate_completions_ignored == 0`. - **Add to the D1 bullet (l.82-85):** "Increment `duplicate_completions_ignored` each time a cancel, expiry or shutdown path meets an already-retired op and skips it. Retired ops are not purged from the cancel queue early. A turn's first `clock_.now()` comes after the start-of-turn cancel/control/file drain; the queued-file expiry scan reads the clock only when queued file requests have deadlines." **S9 (P2, observed verification gap; needs a root decision): B2 cannot test the bounded primitive it owns.** - `advance_shutdown`'s deadline, stop, report and slice-release behaviour is reachable only as `advance_shutdown(nullopt, {})`, through `shutdown_and_join` and `~Driver` (`Driver.hpp:98-104`, `backend_` is private). - A4 may not edit `EpollDriver.cpp` (REV1:340, G6). A defect found in A4 therefore bounces back to the root. - **Choose one and write it into §10/§14:** - (a) Add a NEW test-only accessor in the `MockController` style. - (b) "B2 lists the unexercised primitive paths. A4's IoShutdown tests are the G4 acceptance gate before B2 is VERIFIED, and fixes found there are root-owned." **P3 (editorial):** - **l.20-21:** fix the line citations. `StreamState`'s `weak_ptr` is at `Backend.hpp:80-116` (the file has 118 lines). The stop-forwarder lock is at `EpollDriver.cpp:589-596`. - **l.86-88:** "`busy` only if the marker equals this backend; save and restore it for nested turns of other drivers." - Give the busy test a deterministic hold point: the first poller is parked in a long `epoll_wait` after `turns` has incremented. - Add a test `io_poll_once_reentrant_inline_resume_busy`, using an executor whose `post_completion` resumes inline. - **l.89-90:** append "mock `poll_once` still ignores `max_wait` (REV1 P3)". - **l.92-94:** carve-out: "a Driver API called from a worker is detected (`shutdown_and_join` → `self_join`). This is the only worker-side Driver call, used by `io_file_shutdown_from_worker_self_join`." - **l.99-102:** - Error codes: closed → `closed`, stop → `cancelled`, expired → `timeout` (as `submit_io`, `:495-506`). - Overflow: `offset > OFF_MAX` or `offset+len > OFF_MAX` → `invalid_argument`. - Counting: file requests count in the shared `active_operations_` until poll-turn retirement. - **l.103-105:** "reads are unordered relative to writes". - **l.112-114:** - A second `start_file_workers` → `invalid_argument`. - `file_workers==0` → success with no threads. - After shutdown begins → `closed`. - `run_file_work` while workers run → `busy`. - **l.115-123:** - `close_and_join` waits for (and does not cancel) the file's queued and active requests. Success invalidates the File. - After an expired call, the File is `valid()` but closing. New ops return `closed`, and a repeat call waits. - Document the difference from `ByteStream::close_and_join` (`Stream.hpp:102-120`) (F13). - **l.128:** say exactly `Async::make_async_error(Async::AdmissionError::self_join)`. - **l.131:** add the P3-9 documentation requirement: "the executor must outlive the Driver; an owned executor must not be joined before Driver teardown." - **l.161-162:** `read_exact_at`/`write_all_at` mirror `Stream.hpp:126-180` with the offset advancing and one deadline. A 0-byte pwrite with bytes remaining returns an error; it must not loop. - **l.165-166:** - Flag map: RDWR/WRONLY/RDONLY; neither read nor write → `invalid_argument`; `truncate` requires write; `exclusive` requires create; always `O_CLOEXEC`; runs on the caller's thread. - `adopt_file_fd` takes ownership only on success. - **l.173:** the shim must outlive Driver teardown. - **§10:** add tests for EINTR via the shim, zero-length/overflow/`max_file_queue==0`, files counting against `max_descriptors`, a second start, and `poll_once` after shutdown returning 0. - **§5/§10:** `IoFile.cpp` may include only Void/{IO, Async, Time, Memory, Functional, Core, Testing} headers, or it is silently skipped (`tests/CMakeLists.txt:12-41`). `ScopedTempDir` is local to the CryptoAsync test file. ## M-ASYNC-04 (A2): CHANGES_REQUIRED **A1 (P2, observed): "`-Werror` clean" is never actually checked (l.174, §11).** - The warning flags are `PRIVATE` and apply only to modules that have `.cpp` sources (`cmake/Module.cmake:176-178`). `src/Async` holds only `module.cmake`. - `VoidTests` gets no `-W` flags (`tests/CMakeLists.txt:113-123`; `cmake/VoidTesting.cmake` sets no compile options). - Sanitizers do reach the tests: they are `PUBLIC` through `Void::Testing` (`Module.cmake:184-209`), so the TSan and ASan runs are valid. - **Add to §11** (and to S-IO-03 for `IoFile.cpp`, optionally): ```sh dev cpp-gcc -c bash -lc 'for f in ThreadExecutor FuturePool AsyncChannel ParallelForBounded; do g++ -std=c++26 -fsyntax-only -Iinclude -Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers tests/standalone/Async/$f.cpp || exit 1; done' ``` Add `-freflection` on GCC 16 or later, as `CMakeLists.txt:24-26` does. **A2 (P2, inferred hang): `join()` and the destructor when no worker is running (l.61-71).** - If work is queued before `start()`, or after a failed `start()`, then `~ThreadExecutor` → `join()` waits for workers that do not exist. - **Add:** "Admission before `start()` queues normally. When no worker is running, `join()` and the destructor drain both lanes inline on the caller under `ExecutorThreadGuard` (counted as `inline_after_join`) and never wait. `start()` after `close()` or after a successful `start()` → `invalid_argument`. After a failed `start()` it may be retried." **A3 (P2, inferred race): a reservation outstanding across `close()`/`join()`.** - `TaskScope` reserves and commits in separate steps (`TaskScope.hpp:679-732`), and FuturePool will do the same. - **Add:** "A reserved slot counts in `admitted()` and in the bound. `try_reserve_slot` after `close()` → `stopped`. A reservation taken before `close()` stays binding: `commit_reserved` after `close()` enqueues normally. `join()` also waits until no reservation is outstanding." **P3 (editorial):** - **l.125:** must be `inline` (Async is header-only, so the ODR applies): `[[nodiscard]] inline Void::Result::Error make_async_error(ChannelError, std::string message = {});` - **l.75-84 (AsyncChannel):** - Deadlines and timers: - Deadlines are judged by `timers->clock()`. - Check stop, then deadline, then "deadline without timers" → `invalid_argument`, before any state change. The value is returned in `SendFailure`. - `TimerEvent::closed` → `cancelled` (REV1 F12; today only a test name implies it). - `schedule_at` failure: `overloaded` → `ChannelError::overloaded`, `stopped` → `cancelled`. - Waiters and lifetime: - `max_waiters` applies per direction; 0 → `invalid_argument`. - Frames hold `shared_from_this()`. - Never construct or destroy a `std::stop_callback` while holding the channel mutex. - Destroying a suspended Task is a caller error. - The resume executor must outlive every pending resume. - FIFO means per-producer order. - **l.85-90 (parallel_for):** - At most `max_concurrency` chunks run at once, counting the caller when it runs chunks inline. - `Kind::rejected` is not produced in this wave. - Precedence: `invalid_argument` > `failed` > `stopped`. - `first >= last` → success. - Compute the range in the unsigned type of `I`. - **ThreadExecutor:** `idle()`/`stats()` are snapshots. The switch to inline mode happens under the executor mutex. `admitted()` = queued + running + reserved. - **FuturePool:** if creating the frame throws, release the slot and rethrow. - **§12:** stop if `Async/Timer.hpp` is missing or differs from M-TIME-03 §7. - **l.16:** `ExecutorThreadGuard` is at `Executor.hpp:32-51`. ## R2 and carry-over coverage | Spec | Item | Status | | --- | --- | --- | | S-IO-03 | N3 | Partial. All B2 bullets are present; the owned-executor documentation and handoff liveness are missing (S1, P3). | | S-IO-03 | N4 | Yes, l.115-123. S5 and S6 are needed to implement it without guessing. | | S-IO-03 | P3-5 | Yes, l.212-213, but see S8. | | S-IO-03 | P3-9 | Partial. Dispatch after release is there; the documentation is missing. | | S-IO-03 | F1 | Yes, but contradicted by l.107-108 (S3). | | S-IO-03 | F2 | Partial: fd close under poll ownership is missing (S2). | | S-IO-03 | F9 | Yes, except that `advance_shutdown` must begin shutdown implicitly (S2). | | S-IO-03 | F11 | Yes. | | S-IO-03 | F13 | Yes, except "success invalidates the File" and the ByteStream note (P3). | | M-ASYNC-04 | N5 | Yes, l.80-82. | | M-ASYNC-04 | F7 | Yes. | | M-ASYNC-04 | F11 | Yes. | | M-ASYNC-04 | F12 | Yes, except `TimerEvent::closed`→`cancelled` is implicit (P3). | | M-ASYNC-04 | REV1 P3 ThreadExecutor, `idle()` | Yes. | ## Write scope The two specs' write sets are disjoint. Neither touches `Timer.hpp` (B1), Functional (A1) or Runtime (B3). - **Driver.hpp:** it passes from B2 to A4 in sequence at G4 (REV1:339-340), so there is no concurrent ownership. - **No build edits needed:** `src/IO/FileWorkers.cpp` is picked up by the source glob (`Module.cmake:14`), so `module.cmake` needs no edit. `File.hpp` becomes a public header through the header glob. - **Commands select the new tests:** the module closures cover the includes, and the filters match the file stems (`Runner.cpp:205-225`), including `TimerQueue` (M-TIME-03.md:34). ## Checks executed and not run - **Executed:** read-only reads of: - both specs, R2, REV1, the PLAN §§ for these tasks, PREFLIGHT-2, `IO.md`, `Async.md`; - all of `EpollDriver.cpp`, the IO headers, `Executor.hpp`, `Operation.hpp`, `Detail/Types.hpp`; - `TaskScope.hpp` (parts), `ThreadPool.hpp`, `ParallelFor.hpp`; - the cmake files and `tests/CMakeLists.txt`, the IoDriver tests and consumer tests; - M-TIME-03.md §§6-10 and DECISIONS D-034/038/040. - **Not run:** no builds, tests or compile probes. - `Timer.hpp` is not in the main checkout, so I checked it against M-TIME-03.md §7 only. - S-IO-04 and S-RUNTIME-02 specs do not exist yet, so disjointness was checked against PLAN §3 and the REV1 ownership tables. - No Serena or codebase-memory coverage checks; the hooks reported partial indexing, so I read the source directly. - **Residual for the A4 spec:** R2 N3 loops must exit on `shutdown_complete()`, but F9's public wrapper list has no public `Driver::shutdown_complete()`. **Re-review scope:** only the amended text for S1–S9 and A1–A3.