feat: Introduce step() method and timeout functionality - #9
Conversation
- Added `step(description, run, rollback, options?)` to streamline the process of running an action and registering its rollback in one call. - Implemented timeout options for both individual steps and the overall operation, throwing a `TimeoutError` if the action does not settle in time. - Updated documentation and tests to reflect these new features, ensuring clarity on usage and behavior during timeouts.
🦋 Changeset detectedLatest commit: 1f2b7fb The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Review limit reached
More reviews will be available in 44 minutes and 33 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. 📝 WalkthroughWalkthroughAdds a Changesstep API, TimeoutError, and AbortSignal integration
Sequence Diagram(s)sequenceDiagram
actor Caller
participant withRollback
participant runWithTimeout
participant AbortController
participant Rollback
participant step
Caller->>withRollback: withRollback(fn, { timeout: N })
withRollback->>Rollback: createRollback()
withRollback->>runWithTimeout: runWithTimeout(fn, N)
runWithTimeout->>AbortController: new AbortController()
runWithTimeout->>step: fn(rollback, signal)
alt forward action resolves in time
step->>runWithTimeout: result
runWithTimeout->>withRollback: result
withRollback->>Rollback: commit()
withRollback-->>Caller: return result
else step-level timeout fires
runWithTimeout->>AbortController: abort()
runWithTimeout-->>step: TimeoutError
step->>Rollback: throwIfAlreadyRolledBack (post-run guard)
step-->>withRollback: TimeoutError propagates
withRollback->>Rollback: rollback() → unwind LIFO
withRollback-->>Caller: throw TimeoutError
else outer withRollback timeout fires
runWithTimeout->>AbortController: abort()
runWithTimeout-->>withRollback: TimeoutError
withRollback->>Rollback: rollback() → unwind LIFO
withRollback-->>Caller: throw TimeoutError
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@CLAUDE.md`:
- Line 32: Update the post-rollback invariant description for the rollback()
method to specify that both add() and step() throw RolledBackError after the
instance is rolled back, rather than only mentioning add(). The current text on
line 32 states "After that, add() throws RolledBackError" but should be expanded
to indicate that step() also throws RolledBackError in the same scenario to
accurately reflect the engine contract for both methods.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 983705f1-55b5-4e48-9d9c-ad748da145b2
📒 Files selected for processing (9)
.changeset/curvy-steps-cancel.mdCLAUDE.mdREADME.mdsrc/index.tssrc/lib/errors.tssrc/lib/helpers.tssrc/lib/operations.tssrc/types.tstests/index.test.ts
- Clarified the behavior of the `step(description, run, rollback, options?)` method, emphasizing the return values and error propagation. - Simplified explanations regarding the use of timeouts in both individual steps and overall operations. - Enhanced documentation on handling `AbortSignal` and the implications of timeouts on resource creation and rollback registration.
- Updated the documentation for the `rollback()` method to specify that both `add()` and `step()` throw `RolledBackError` after a rollback, enhancing clarity on error handling. - Emphasized the safety of repeat `rollback()`/`commit()` calls as no-ops, while noting that registration after a rollback will throw an error.
- Updated the section on timeouts to clarify the implications of a step hanging and the importance of setting deadlines that precede platform timeouts. - Enhanced the language to improve readability and understanding of resource management during rollback scenarios.
step(description, run, rollback, options?)to streamline the process of running an action and registering its rollback in one call.TimeoutErrorif the action does not settle in time.Summary by CodeRabbit
Release Notes
New Features
step()method for atomic pairing of forward actions with rollback compensation in a single call.AbortSignalfor cancellation.TimeoutErrorexception class for timeout scenarios; rollback still executes on timeout.Documentation