18 KiB
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::mutexacquired withtry_lock(l.86-87). - While stopping, a turn with no work holds ownership inside
epoll_waitfor up tomax_wait(l.89-90). advance_shutdowntakes ownership only between slices of at most 1 ms (l.125-127), and it must own the poll to close fds (l.131).
- The spec requires a
- Effect: a poller loop re-locks within nanoseconds after each
wake(), sotry_lockalmost never wins. The mandatory testio_epoll_shutdown_concurrent_with_poller_no_uaf_tsan(l.211) and a cross-thread 1.xshutdown_and_joincan stall for seconds or hang. - Append to Shutdown core: "Ownership handoff: before each slice
advance_shutdownsets atomicshutdown_waiting_and callswake(). While it is set,poll_onceon any other thread returnsbusybeforetry_lock, touching no fd and not incrementingturns. It is cleared onceadvance_shutdownholdspoll_mu_. Between slices, afteradvance_shutdownreleasespoll_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_onceno longer touches anything. - Replace l.131-132 with: "Order: (1)
begin_shutdown().advance_shutdowncalls it itself, because A4'sshutdown(options)wraps onlyadvance_shutdown. (2) Wait until no queued or active file request and no opin_execution. (3) Underpoll_mu_, run a final drain of cancels, controls, file completions and close waiters. (4) Join workers. (5) Still underpoll_mu_, close the remaining file fds (mark themclosedand complete pendingclose_and_joinwaiters with success), then close op and descriptor fds. (6) Setshut_down_(release), thenwake_closed_. (7) Releasepoll_mu_, then dispatch the tickets (P3-9).self_joinmisuse is detected before any state change.begin_shutdownonly 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 insidenow(). - 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 completescancelled/timeoutwith no syscall." - If the root prefers to keep the worker clock read, declare the clock a second documented exception that must be thread-safe.
ManualClockis atomic (Clock.hpp:129).
S4 (P2, observed; the tests cannot assert what they are named for): DomainOutcomeKind is not observable.
FilereturnsResult<…>, andErrorcarries only status andsystem_code()(Functional/Error.hpp:136-235). Soio_file_queued_cancel_not_committed_zero_effectsand…sync_failed_unknown_errno(l.202-205) cannot assertnot_committedorunknown.- Also, "via the existing
complete_op_and_collect_ticketspath" (l.95-96) cannot work as is. That function is typed forTransferand hard-codescancelled/failed(EpollDriver.cpp:421-447). - Add to §6: "Observable contract:
- Queued stop gives
IoErrorCode::cancelled; queued expiry givesIoErrorCode::timeout(both kIoErrorDomain), with zero shim calls and unchanged file bytes. - Sync failure gives
IoErrorCode::sync_failedwithsystem_code()==std::error_code{errno, std::generic_category()}, matchingerrno_code. - Internally, settle with
try_commit_error(err, not_committed|unknown).Resultdoes not expose that kind and tests do not assert it. - Retirement uses a retire-once path equivalent to
complete_op_and_collect_tickets, generalized forOperationState<void>and the file outcome kinds."
- Queued stop gives
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 closesslot.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 inactive_descriptors_, is bounded bymax_descriptors, andFile::id()is that slot'sDescriptorId. The slot hasfd = -1and a file-kind flag, and socket paths (interest updates,close_fdcontrols, stale-event checks, the shutdown sweep) skip it. The file fd lives only inFileState."
S6 (P2, inferred use-after-free): ~File after ~Driver must lock the pool mutex (l.115-123).
- Add: "
FileStateholdsshared_ptr<detail::FileWorkerShared>andweak_ptr<DriverBackend>, 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 setsstopping_(EpollDriver.cpp:282-286). Ifbegin_shutdown's idempotence is keyed on that flag (l.124-125), a priorrequest_stop()makes it a no-op. Queued file requests are then never cancelled, and with manual stepping~Driverhangs. - Mock held tokens: 1.x mock shutdown skips held requests (
:847-851). TheMockControllerdies with theDriver, so if teardown waits for those requests it deadlocks. - Add: "
request_stop()==begin_shutdown(), with idempotence on a separateshutdown_begun_flag. On mock, requests held by a token never blockadvance_shutdown;finish_*still completes them, andteardown_blockingcompletes any still held withIoErrorCode::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, leavesduplicate_completions_ignored == 0. - Add to the D1 bullet (l.82-85): "Increment
duplicate_completions_ignoredeach 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 firstclock_.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 asadvance_shutdown(nullopt, {}), throughshutdown_and_joinand~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
MockControllerstyle. - (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."
- (a) Add a NEW test-only accessor in the
P3 (editorial):
- l.20-21: fix the line citations.
StreamState'sweak_ptris atBackend.hpp:80-116(the file has 118 lines). The stop-forwarder lock is atEpollDriver.cpp:589-596. - l.86-88: "
busyonly 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_waitafterturnshas incremented. - Add a test
io_poll_once_reentrant_inline_resume_busy, using an executor whosepost_completionresumes inline.
- Give the busy test a deterministic hold point: the first poller is parked in a long
- l.89-90: append "mock
poll_oncestill ignoresmax_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 byio_file_shutdown_from_worker_self_join." - l.99-102:
- Error codes: closed →
closed, stop →cancelled, expired →timeout(assubmit_io,:495-506). - Overflow:
offset > OFF_MAXoroffset+len > OFF_MAX→invalid_argument. - Counting: file requests count in the shared
active_operations_until poll-turn retirement.
- Error codes: closed →
- 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_workwhile workers run →busy.
- A second
- l.115-123:
close_and_joinwaits 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 returnclosed, 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_atmirrorStream.hpp:126-180with 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;truncaterequires write;exclusiverequires create; alwaysO_CLOEXEC; runs on the caller's thread. adopt_file_fdtakes ownership only on success.
- Flag map: RDWR/WRONLY/RDONLY; neither read nor write →
- 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 againstmax_descriptors, a second start, andpoll_onceafter shutdown returning 0. - §5/§10:
IoFile.cppmay include only Void/{IO, Async, Time, Memory, Functional, Core, Testing} headers, or it is silently skipped (tests/CMakeLists.txt:12-41).ScopedTempDiris 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
PRIVATEand apply only to modules that have.cppsources (cmake/Module.cmake:176-178).src/Asyncholds onlymodule.cmake. -
VoidTestsgets no-Wflags (tests/CMakeLists.txt:113-123;cmake/VoidTesting.cmakesets no compile options). -
Sanitizers do reach the tests: they are
PUBLICthroughVoid::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):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
-freflectionon GCC 16 or later, asCMakeLists.txt:24-26does.
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 failedstart(), 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 underExecutorThreadGuard(counted asinline_after_join) and never wait.start()afterclose()or after a successfulstart()→invalid_argument. After a failedstart()it may be retried."
A3 (P2, inferred race): a reservation outstanding across close()/join().
TaskScopereserves 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_slotafterclose()→stopped. A reservation taken beforeclose()stays binding:commit_reservedafterclose()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 inSendFailure. TimerEvent::closed→cancelled(REV1 F12; today only a test name implies it).schedule_atfailure:overloaded→ChannelError::overloaded,stopped→cancelled.
- Deadlines are judged by
- Waiters and lifetime:
max_waitersapplies per direction; 0 →invalid_argument.- Frames hold
shared_from_this(). - Never construct or destroy a
std::stop_callbackwhile 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.
- Deadlines and timers:
- l.85-90 (parallel_for):
- At most
max_concurrencychunks run at once, counting the caller when it runs chunks inline. Kind::rejectedis not produced in this wave.- Precedence:
invalid_argument>failed>stopped. first >= last→ success.- Compute the range in the unsigned type of
I.
- At most
- 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.hppis missing or differs from M-TIME-03 §7. - l.16:
ExecutorThreadGuardis atExecutor.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.cppis picked up by the source glob (Module.cmake:14), somodule.cmakeneeds no edit.File.hppbecomes 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), includingTimerQueue(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.
- both specs, R2, REV1, the PLAN §§ for these tasks, PREFLIGHT-2,
- Not run: no builds, tests or compile probes.
Timer.hppis 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 publicDriver::shutdown_complete().
Re-review scope: only the amended text for S1–S9 and A1–A3.