Files
faumarayandClaude Opus 5.5 5c24f8e84f feat(async): add retry_async over TimerQueue and deadline-domain conformance (M-TIME-03 B1b)
- NEW Async/Retry.hpp: retry_async drives RetryState with the TimerQueue's
  injected clock, awaits backoff via sleep_until, resumes only after a clean
  sleep (any sleep error ends the retry), preserves success after stop,
  supports Task-returning and move-only callables
- Tests: AsyncRetry (15), DeadlineDomains blocking-retry manual-clock case

Review: W11-REVIEW-B1b READY (deviation accepted; doc fix applied by root)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 00:35:20 +03:00

8.4 KiB

M-TIME-03 (step B1b) — Async::retry_async over TimerQueue and deadline-domain conformance

Task ID: M-TIME-03 Role: opus-implementer Status: READY

1. Context and baseline

  • Wave 11 package step B1b (gate G1 satisfied: M-FUNCTIONAL-03 committed 26edf65; M-TIME-03 B1 TimerQueue committed on the branch). Repo VoidLibrary, branch feat/roadmap-p2-wave11. You work in an isolated worktree; first fast-forward it to the HEAD stated in your prompt.
  • Baseline: full suite at 38436b1 = 1,484 tests (1,480 ✔, 4 ⊘). Since then: A1 adds RetryState (23 tests), B1 adds TimerQueue (15), DeadlineDomains (2), ClockSaturation (1).
  • Observed source:
    • include/Void/Functional/RetryState.hpp: RetrySpec, RetryState<URBG>::create(spec, start, urbg, admission_deadline), begin/next/resume/succeed (stop decisions are final), RetryError<E>{reason, attempts, last_error, config}, RetryEveryError, AttemptOutcome, detail::seeded_engine<G>().
    • include/Void/Functional/Retry.hpp: retry_blocking (reference shape for error mapping).
    • include/Void/Async/Timer.hpp: TimerQueue::sleep_until(when, OperationOptions) → {} on expiry after poll, cancelled on stop (only if the stop wins the timer cancel race; a stop after poll or close claimed the timer yields {}/stopped), timeout when options.deadline < when, stopped after close; resumes via executor().post_completion; clock() is the injected clock.
  • Requirements: roadmap row M-TIME-03 ("Validate injected-deadline domains with Async and blocking retry adapters; advancing manual time plus explicit polling expires an operation once"); C-03/C-04; D-038.

2. Objective and deliverables

  1. NEW include/Void/Async/Retry.hpp: Void::Async::retry_async.
  2. NEW tests/standalone/Async/AsyncRetry.cpp.
  3. EDIT tests/standalone/Async/DeadlineDomains.cpp: add deadline_domain_blocking_retry_manual_clock.

3. Scope and non-goals

Out: changes to Timer.hpp, RetryState.hpp, Retry.hpp, Executor/Operation/TaskScope, build files.

4. Files to inspect

The three headers above, include/Void/Async/{Task,Executor,TaskScope}.hpp, include/Void/Async/Detail/Types.hpp, tests/standalone/Async/{TimerQueue,DeadlineDomains}.cpp, tests/standalone/Functional/RetryBlocking.cpp, docs/agent-workflow/tasks/W11-PLAN-OUTPUT.md §M-TIME-03.

5. Write ownership and coordination

Write scope: include/Void/Async/Retry.hpp (NEW), tests/standalone/Async/AsyncRetry.cpp (NEW), tests/standalone/Async/DeadlineDomains.cpp. Forbidden: every other path. Other implementers work concurrently in other worktrees (IO files; Async ThreadExecutor/FuturePool/AsyncChannel/ParallelFor). No git operations except the root-authorized fast-forward in your prompt.

6. Implementation or investigation approach

MANDATORY semantics:

  • "now" is always timers.clock().now(); admission deadline = options.deadline; stop = options.stop.
  • Invalid spec → RetryError{config=err, attempts=0} without calling fn.
  • Loop: begin(now, stop_requested) → on attempt call fn; fn may return std::expected<T,E> or Coro::Task<std::expected<T,E>> (co_await it). Success → return T (also when stop was requested during the attempt). Failure → next(now, classify(error), stop_requested).
  • On wait_until(at): co_await timers.sleep_until(at, OperationOptions{options.stop, options.deadline}). After a {} sleep, ALWAYS call resume(now, options.stop.stop_requested()) — it re-checks stop itself, which covers the TimerQueue choice where a late stop yields {}. Any sleep error ends the retry without calling resume() (amended after W11-REVIEW-B1b: resuming after stopped/overloaded would start attempts with no wait). Sleep result mapping: {} → resume; cancelled → stop with stop_requested; timeout → stop with deadline_exceeded; stopped (queue closed) → stop with stop_requested (documented: queue closure aborts the retry; no further attempt); overloaded → stop with stop_requested and document (no silent busy retry).
  • Never sleep with the host clock; never spin; no attempt after any stop decision; last_error holds the most recent E (empty iff no attempt ran).
  • Default URBG seeded via Void::Retry::detail::seeded_engine<URBG>().

7. Interfaces and data contracts

namespace Void::Async {
template <class F, class Classify = Void::Retry::RetryEveryError, class URBG = std::mt19937_64>
  requires std::invocable<F&>
[[nodiscard]] auto retry_async(Void::Retry::RetrySpec spec, F fn, TimerQueue& timers,
                               OperationOptions options = {}, Classify classify = {},
                               URBG urbg = Void::Retry::detail::seeded_engine<URBG>())
  -> Coro::Task<std::expected<T, Void::Retry::RetryError<E>>>;   // T,E deduced from fn's (awaited) result
}

The coroutine owns fn, classify, urbg and spec by value. timers (and its executor) must outlive the returned task (document).

8. Dependencies and integration

Upstream: A1 (26edf65), B1 (TimerQueue). Downstream: none in this wave beyond conformance. Root integrates and commits.

9. Edge cases security and performance

Stop before first attempt; stop during fn (success preserved, no retry); stop during backoff; queue closed during backoff; deadline between attempts; zero attempts; move-only T/E/F; Task-returning fn that throws (exception propagates out of the retry task — document); manual clock far-future start.

10. Acceptance criteria

  1. AsyncRetry.cpp: async_retry_manual_clock_attempts_only_after_advance_and_poll, async_retry_total_deadline_expires_once, async_retry_stop_during_backoff_no_further_attempt, async_retry_success_after_stop_preserved, async_retry_zero_attempts_no_call, async_retry_task_returning_callable, async_retry_queue_closed_during_backoff_stops, async_retry_late_stop_after_timer_fired_no_further_attempt, async_retry_move_only_value — all pass.
  2. DeadlineDomains.cpp: deadline_domain_blocking_retry_manual_clock (retry_blocking with now = manual.now, a sleep callable that advances the ManualClock) passes; existing 2 tests pass.
  3. Existing TimerQueue, RetryState, RetryBlocking, OperationScope, Executor, Coro pass.
  4. TSan 0 races and ASan+UBSan 0 errors on AsyncRetry|DeadlineDomains|TimerQueue.
  5. -Werror syntax check of the new/edited test files and Async/Retry.hpp clean.

11. Verification commands and evidence

Cwd = worktree root; dev with the sandbox disabled. Confirm the new suite appears in the output.

dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w11-time3b -G Ninja -DVOID_ENABLED_MODULES="Async;Testing" -DVOID_WARNINGS_AS_ERRORS=ON && cmake --build /tmp/void-w11-time3b --parallel 8 && /tmp/void-w11-time3b/tests/VoidTests --filter "^(AsyncRetry|DeadlineDomains|TimerQueue|RetryState|RetryBlocking|OperationScope|Executor|Coro)\." && ctest --test-dir /tmp/void-w11-time3b --output-on-failure --timeout 60'
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w11-time3b-tsan -G Ninja -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Async;Testing" -DVOID_ENABLE_TSAN=ON && cmake --build /tmp/void-w11-time3b-tsan --parallel 8 && /tmp/void-w11-time3b-tsan/tests/VoidTests --filter "^(AsyncRetry|DeadlineDomains|TimerQueue)\."'
dev cpp-gcc -c bash -lc 'cmake -S . -B /tmp/void-w11-time3b-asan -G Ninja -DCMAKE_BUILD_TYPE=Debug -DVOID_ENABLED_MODULES="Async;Testing" -DVOID_ENABLE_ASAN=ON -DVOID_ENABLE_UBSAN=ON && cmake --build /tmp/void-w11-time3b-asan --parallel 8 && /tmp/void-w11-time3b-asan/tests/VoidTests --filter "^(AsyncRetry|DeadlineDomains|TimerQueue)\."'
dev cpp-gcc -c bash -lc 'for f in Async/AsyncRetry Async/DeadlineDomains; do g++ -std=c++26 -freflection -fsyntax-only -Iinclude -Wall -Wextra -Wpedantic -Werror -Wno-missing-field-initializers tests/standalone/$f.cpp || exit 1; done'

12. Constraints and stop conditions

No edits outside write scope; no weakened assertions. Stop and report BLOCKED if the TimerQueue or RetryState contract is insufficient (needs a forbidden edit), or two repair attempts at one check fail.

13. Authorization and decisions

Root decisions D-034, D-038, D-040, D-042 under user decisions D-027/D-029/D-031. Listed files only; no commits, pushes or other side effects.

14. Return format

Task ID; DONE/BLOCKED/PARTIAL; summary; files changed; decisions/deviations; evidence per acceptance criterion; commands with cwd/results; checks not run; residual risks; worktree path. Do not spawn children.