Skip to content

fix(execution): release the lease when abort races an undetermined acquisition - #7237

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/lease-release-on-abort
Aug 28, 2026
Merged

fix(execution): release the lease when abort races an undetermined acquisition#7237
waleedlatif1 merged 2 commits into
stagingfrom
fix/lease-release-on-abort

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The cancellation return for an aborted execution ran before releaseLease was declared, so it exited without releasing the distributed owner lease.
  • An undetermined acquisition can still be registered by Redis after the deadline abandons the local wait. Aborting in that window left the member counted against the owner for the whole TTL, denying later executions that had capacity — the same failure the fallback change set out to remove, on the one exit path that missed it.
  • Declared the release before the early returns so every exit path that can leave a registration behind reaches it, and call it on the cancellation path.
  • The over-limit return still skips the release deliberately: the script answers that before its ZADD, so nothing was ever registered. Noted inline so it is not "corrected" later.

Type of Change

  • Bug fix

Testing

vitest run lib/execution/isolated-vm.test.ts — 16 passing, including a new case asserting that an abort racing an undetermined acquisition still issues the release. Verified it fails against the previous behavior while the existing over-limit abort case keeps passing. bun run type-check, bun run lint, and bun run check:audits (39 audits) pass.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…quisition

The cancellation return for an aborted execution ran before `releaseLease` was
declared, so it exited without releasing. An undetermined acquisition can still
be registered by Redis after the deadline abandons the local wait, and that
member then counted against the owner for the whole TTL, denying later
executions that had capacity.

Declare the release before the early returns so every exit path that can leave a
registration behind reaches it, and call it on the cancellation path. The
over-limit return still skips it: the script answers that before its ZADD, so
nothing was ever registered.
@vercel

vercel Bot commented Aug 28, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 28, 2026 11:17pm

Request Review

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR ensures cancellation after an undetermined distributed-lease acquisition attempts to release the lease before returning.

  • Moves the idempotent lease-release closure ahead of acquisition-related early returns.
  • Releases an undetermined acquisition when cancellation wins the race.
  • Preserves the no-release behavior for over-limit responses and adds regression coverage for both paths.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/execution/isolated-vm.ts Moves lease cleanup before early returns and invokes it when cancellation follows an undetermined acquisition.
apps/sim/lib/execution/isolated-vm.test.ts Adds regression coverage for aborting an undetermined acquisition and verifies over-limit acquisitions remain unreleased.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant Executor
  participant Redis
  Caller->>Executor: Start execution
  Executor->>Redis: Acquire owner lease
  Note over Executor,Redis: Local deadline expires while acquisition is undetermined
  Caller->>Executor: Abort
  Executor->>Redis: Release unique lease ID
  Executor-->>Caller: Cancelled result
Loading

Reviews (2): Last reviewed commit: "fix(execution): keep the over-limit abor..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 5/5

  • In apps/sim/lib/execution/isolated-vm.ts, the aborted limit_exceeded path calls releaseLease() without a registered lease, which could make cleanup fail or add misleading lease-release errors; restrict the call to undetermined results.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/execution/isolated-vm.ts">

<violation number="1" location="apps/sim/lib/execution/isolated-vm.ts:1439">
P3: When Redis returns `limit_exceeded` while the signal is already aborted, this branch still calls `releaseLease()` even though no lease was registered. Restrict the call to `undetermined` results so over-limit aborts keep the documented no-release behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/execution/isolated-vm.ts Outdated
The abort guard fires for any non-acquired result, so an over-limit acquisition
that was already aborted also released — contradicting the rule stated two lines
below, where the same result returns without releasing because the script
answers before its ZADD. Restrict the release to undetermined results and assert
the no-release behavior in the existing over-limit abort test.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic review

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 28, 2026

Copy link
Copy Markdown

@cubic review

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 6ca5b52 into staging Aug 28, 2026
27 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/lease-release-on-abort branch August 28, 2026 23:26
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