fix: prevent lifecycle action races - #1562
Conversation
|
Warning Review limit reached
Next review available in: 30 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?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 reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. 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, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (22)
📝 WalkthroughWalkthroughLifecycle dispatch에 원자적 run claim, 만료 가능한 실행 lease, 규칙 스냅샷, 실패 시 claim 중단, 공개 타입 및 관련 테스트·문서가 추가되었습니다. ChangesLifecycle dispatch coordination
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Evaluator
participant RunStore
participant Registry
participant StateStore
Evaluator->>RunStore: claim idempotency and cooldown
RunStore-->>Evaluator: claim result
Evaluator->>Registry: executeIfActive
Registry->>StateStore: claim execution lease
StateStore-->>Registry: lease result
Registry-->>Evaluator: execution result
Evaluator->>RunStore: save or abort claim
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
📊 Benchmark Results✅ All benchmarks passed
Updated: 2026-07-27T14:04:53.425Z · Commit: c4e215a |
c34b8ed to
15f68c4
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 `@packages/lifecycle-core/src/libs/InMemoryLifecycleRuleStateStore.ts`:
- Around line 326-353: Resolve the clock mismatch in waitForExecutionClaimChange
by ensuring expiry wakeups use the same logical clock as this.now() and
pruneExpiredExecutionClaims, rather than relying on wall-clock setTimeout alone.
Either validate and document that the configured now function tracks real time,
or replace the timeout with the store’s logical-clock scheduling/polling
mechanism so expired claims are retried correctly.
In `@packages/lifecycle-core/src/libs/LifecycleRuleRegistry.ts`:
- Around line 412-419: Update the get(ruleId) lookup to query registrations
directly instead of calling getAll(), then deep-clone only the matching
registration or rule before returning it. Preserve the existing not-found
behavior and use the existing registrations map and clone helpers, consistent
with getRegistration.
- Around line 28-52: Update cloneValue and cloneRule to use structuredClone for
cloneable lifecycle data, preserving Map, Set, RegExp, class-instance values,
and prototypes across triggers, actions, and related descriptors. Ensure the
implementation retains the existing cloning behavior for supported fields while
accounting for structuredClone’s DataCloneError when the payload contract
permits functions or symbols.
In `@packages/lifecycle-core/src/tests/LifecycleRuleVersioning.spec.ts`:
- Around line 642-644: Replace the single Promise.resolve microtask yield in the
lease/pause test with a macrotask wait such as setTimeout(..., 0), or an
equivalent multi-tick flush, before asserting pauseCompleted remains false. Keep
the assertion and surrounding lease-gating behavior unchanged so the test
verifies pause is blocked across a meaningful event-loop delay.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8d9077c4-c975-4b9f-a4e9-d97412686fd0
📒 Files selected for processing (21)
.changeset/steady-lifecycle-dispatch.mdpackages/admin-ops/src/tests/RetryConsole.spec.tspackages/docs/src/content/docs/api/lifecycle-core/src/classes/InMemoryLifecycleRuleStateStore.mdpackages/docs/src/content/docs/api/lifecycle-core/src/classes/InMemoryLifecycleRunStore.mdpackages/docs/src/content/docs/api/lifecycle-core/src/classes/LifecycleRuleRegistry.mdpackages/docs/src/content/docs/api/lifecycle-core/src/interfaces/LifecycleRuleStateStore.mdpackages/docs/src/content/docs/api/lifecycle-core/src/interfaces/LifecycleRunStore.mdpackages/docs/src/content/docs/api/lifecycle-core/src/type-aliases/LifecycleRuleExecutionClaim.mdpackages/docs/src/content/docs/api/lifecycle-core/src/type-aliases/LifecycleRuleExecutionClaimResult.mdpackages/docs/src/content/docs/api/lifecycle-core/src/type-aliases/LifecycleRuleExecutionResult.mdpackages/docs/src/content/docs/api/lifecycle-core/src/type-aliases/LifecycleRunClaim.mdpackages/docs/src/content/docs/api/lifecycle-core/src/type-aliases/LifecycleRunClaimResult.mdpackages/lifecycle-core/README.mdpackages/lifecycle-core/src/index.tspackages/lifecycle-core/src/libs/InMemoryLifecycleRuleStateStore.tspackages/lifecycle-core/src/libs/InMemoryLifecycleRunStore.tspackages/lifecycle-core/src/libs/LifecycleRuleEvaluator.tspackages/lifecycle-core/src/libs/LifecycleRuleRegistry.tspackages/lifecycle-core/src/libs/types.tspackages/lifecycle-core/src/tests/LifecycleRuleVersioning.spec.tspublic-api-surface.snapshot.json
15f68c4 to
685da0f
Compare
|
@coderabbitai resolve |
✅ Action performedComments resolved and changes approved. |
Outcome
Lifecycle production dispatch now atomically reserves idempotency keys and cooldown windows before actions begin. Infrastructure failures explicitly abort unfinished claims, so a transient state-store or save failure cannot poison retries.
Pause and activation transitions now synchronize through uniquely owned, expiring execution leases. Adapter calls begin inside the active-version boundary, leases release before awaiting adapter completion to permit reentrant pause, and abandoned leases wake blocked transitions at expiry. Registered static rules and persisted descriptors are defensively snapshotted so caller mutation cannot alter reviewed behavior.
This is a concurrency-hardening follow-up to #1551 and the acceptance criteria from #1546.
Verification
pnpm check— repository profile passed; 22/23 gates passed and one was not applicablepnpm --filter @croco/lifecycle-core test— 31/31 passedpnpm --filter @croco/admin-ops test— 17/17 passed; typecheck, lint, and build passedpnpm docs:api:check— 112/112 build tasks; 3,784 pages; generated docs matchedpnpm docs:api-triggers:checkpnpm public-api:check— 111 package snapshots matchedpnpm problem-registry:check— 478 codes matched 478 discoveriespnpm architecture-policy:check— 4,702 imports across 113 packages passedpnpm changeset-required:check— all affected publishable packages coveredReview gates
Residual risk
Custom durable stores must implement atomic run claims and active-version lease acquisition in shared storage, wake waiting commands at lease expiry, and make abort and release idempotent. Existing custom LifecycleRunStore and LifecycleRuleStateStore implementations must adopt the documented new methods before upgrading.
Summary by CodeRabbit
새로운 기능
문서