Skip to content

fix(execution): treat an undetermined lease as a fallback, not a denial - #7228

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/isolated-vm-lease-fail-open
Aug 28, 2026
Merged

fix(execution): treat an undetermined lease as a fallback, not a denial#7228
waleedlatif1 merged 3 commits into
stagingfrom
fix/isolated-vm-lease-fail-open

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The distributed owner lease for code execution is a cross-process fairness check, not a correctness lock. A lease round trip that returned no answer before its deadline was treated as a hard failure and rejected the execution outright, even though the per-process pool and the per-owner active/queued limits already bound the work.
  • Fall back to those local limits when the lease is undetermined. limit_exceeded still denies, since it is an actual answer rather than the absence of one.
  • Renamed that outcome from unavailable to undetermined so a missing answer is not read as a negative one, and dropped its log level to warn.
  • Made the round-trip deadline configurable via IVM_LEASE_REDIS_DEADLINE_MS and raised the default from 200ms to 1000ms. This deadline and the client's commandTimeout are both plain timers, so a value close to normal event-loop latency misreads a scheduling pause (a GC pause, say) as an unreachable dependency.
  • Skip the lease-release round trip when no lease was ever registered.

Type of Change

  • Bug fix

Testing

vitest run lib/execution/isolated-vm.test.ts — 14 passing, including three new cases covering the fallback (no client, evaluation error, deadline exceeded) and one asserting the over-limit path still denies. Each new test was verified to fail against the previous behavior. bun run type-check, bun run lint, and bun run check:audits (39 audits) all 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)

The distributed owner lease is a cross-process fairness check, not a
correctness lock. A round trip that did not answer before its deadline was
reported as a hard failure and rejected the execution, even though the
per-process pool and the per-owner active/queued limits still bound the work.

- Fall back to the local limits when the lease is undetermined. Only
  `limit_exceeded` denies an execution, since it is an actual answer.
- Rename that outcome from `unavailable` to `undetermined` so the absence of
  an answer is not read as a negative one, and log it at warn.
- Make the round-trip deadline configurable and raise its default. This
  deadline and the client's `commandTimeout` are both plain timers, so a value
  near normal event-loop latency misreads a scheduling pause as an unreachable
  dependency.
- Skip the release round trip when no lease 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 9:30pm

Request Review

@greptile-apps

greptile-apps Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR changes an undetermined distributed execution lease from a denial into a fallback to process-local limits.

  • Adds a configurable Redis lease deadline with a 1000 ms default and rejects non-positive configured values.
  • Continues denying leases when Redis explicitly reports that the owner limit is exceeded.
  • Unconditionally attempts lease release so acquisitions completed after the local deadline are reclaimed.
  • Adds coverage for unavailable Redis, evaluation errors, deadline expiry, negative deadline configuration, explicit limit denial, and late lease completion.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported negative-deadline bypass is guarded by the positive-value check, and the late-acquisition path now issues release through the same ordered Redis client.

Important Files Changed

Filename Overview
apps/sim/lib/core/config/env.ts Adds the configurable Redis lease deadline environment variable with a 1000 ms default.
apps/sim/lib/execution/isolated-vm.ts Treats unresolved lease acquisition as a local-limit fallback, validates non-positive deadlines, and always attempts release for potentially late acquisitions.
apps/sim/lib/execution/isolated-vm.test.ts Expands scheduler coverage for fallback behavior, explicit limit rejection, deadline validation, and late lease release.

Reviews (3): Last reviewed commit: "test(execution): stop the lease deadline..." | Re-trigger Greptile

Comment thread apps/sim/lib/execution/isolated-vm.ts Outdated
Comment thread apps/sim/lib/core/config/env.ts
Addresses review findings on the fallback path.

- Always release the lease. The deadline abandons the local wait but cannot
  cancel the script, so a late completion still registers the lease id; leaving
  it unreleased kept it counted against the owner for the whole TTL and denied
  later executions that did have capacity. The id is unique per execution, so
  removing one that was never registered is a no-op.
- Treat a non-positive configured deadline as unconfigured. A timer of zero or
  less fires immediately, which would leave every acquisition undetermined and
  silently drop cross-replica enforcement.
- Cover both with tests: a lease that completes after the deadline is still
  released, and a non-positive deadline still lets a real answer land.

@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.

All reported issues were addressed across 3 files

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

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/lib/execution/isolated-vm.test.ts
Comment thread apps/sim/lib/execution/isolated-vm.ts Outdated
Comment thread apps/sim/lib/core/config/env.ts
Comment thread apps/sim/lib/execution/isolated-vm.test.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

- Add `IVM_LEASE_REDIS_DEADLINE_MS` to the harness env reset. It was absent, so
  a test that overrode it left the value in the module-scoped mock env for every
  later test in the file, quietly changing their fallback timing.
- Drop the duplicate over-limit test and fold its extra assertion into the
  existing one; the two had identical setup and covered the same path.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 merged commit 8a31757 into staging Aug 28, 2026
26 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/isolated-vm-lease-fail-open branch August 28, 2026 21:40
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