Skip to content

Extract cooperative-cancellation pattern into FiberBoundary.with_cooperative_timeout - #52

Merged
ya-luotao merged 2 commits into
mainfrom
refactor/dedupe-cooperative-cancellation
Jul 31, 2026
Merged

Extract cooperative-cancellation pattern into FiberBoundary.with_cooperative_timeout#52
ya-luotao merged 2 commits into
mainfrom
refactor/dedupe-cooperative-cancellation

Conversation

@ya-luotao

Copy link
Copy Markdown
Owner

Follow-up to the v0.25–v0.27 adversarial release audit (fixes landed in 6e4d9c8). Codex's non-blocking design concern: the "fresh InlineCancellation subclass + consume only your own scope's cancellation + translate back to the outward exception" mechanism was duplicated between fiber_boundary.rb (inline store-timeout branch) and query.rb (inline hook-timeout path).

Extracted into FiberBoundary.with_cooperative_timeout(task, timeout, on_timeout:, &block) (@api private), which also centralizes the nested-scope rationale (a shared cancellation class would let nested timeout scopes consume each other's deadline). The two call sites' genuine differences stay parameterized, not unified:

  • translation target via the zero-arg on_timeout: callable — store path builds JoinTimeout, hook path builds Async::TimeoutError.new('execution expired'), messages byte-identical to before; the raise stays inside the rescue so cause still chains to the cancellation
  • wrapper composition position remains each caller's decision (invoke composes into body before entering the scope; the hook path composes inside the block)

No behavior change; no spec edits needed. Verification: 1210 examples, 0 failures; RuboCop 64 files, no offenses.

Note: independent of #51 (both branch from 6e4d9c8); whichever merges second has a small mechanical conflict in the shared region — resolve by using the renamed identifiers inside the helper.

🤖 Generated with Claude Code

https://claude.ai/code/session_019Manwfh1GRrJtQfgTm1dtt

…erative_timeout

FiberBoundary.invoke's inline store-adapter branch and Query's inline
hook-timeout path both hand-rolled the same mechanism: run under
Async's with_timeout with a fresh per-invocation InlineCancellation
subclass, then translate the consumed cancellation back into the call
site's outward exception. The shared helper parameterizes exactly the
two real differences — the translation target (JoinTimeout vs
Async::TimeoutError, via on_timeout:) and wrapper composition, which
stays the caller's choice (invoke composes it into the body before the
scope; the hook path composes it inside the block). The
fresh-subclass / nested-scope rationale now lives in one place.
No behavior change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QFYekWo9xbMekqyu4Qj6Dk
@ya-luotao
ya-luotao merged commit a7db2fe into main Jul 31, 2026
@ya-luotao
ya-luotao deleted the refactor/dedupe-cooperative-cancellation branch July 31, 2026 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant