Extract cooperative-cancellation pattern into FiberBoundary.with_cooperative_timeout - #52
Merged
Merged
Conversation
…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
…rative-cancellation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:on_timeout:callable — store path buildsJoinTimeout, hook path buildsAsync::TimeoutError.new('execution expired'), messages byte-identical to before; the raise stays inside the rescue socausestill chains to the cancellationbodybefore 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