Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • upgraded abort controller to handle aborts for loops and parallels
  • cancels mid-loops and mid-parallels

Type of Change

  • Bug fix

Testing

Tested manually, added unit tests

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)

@waleedlatif1 waleedlatif1 requested a review from Sg312 January 19, 2026 03:33
@vercel
Copy link

vercel bot commented Jan 19, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 19, 2026 3:39am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 19, 2026

Greptile Summary

upgraded abort controller implementation to handle mid-loop and mid-parallel cancellations by introducing a cached abort promise pattern that enables immediate cancellation without waiting for all executing nodes to complete

Key changes:

  • added abortPromise and abortResolve fields to cache a single promise that resolves when abort signal fires
  • created initializeAbortHandler() to set up abort listener once during construction, preventing memory leaks from multiple listeners
  • modified waitForAnyExecution() and waitForAllExecutions() to race against the abort promise, enabling immediate return on cancellation
  • added check in run() to skip waitForAllExecutions() when cancelled, preventing blocking on incomplete executions
  • added cancellation check in processQueue() to prevent queueing new parallel branches after cancellation

The implementation properly handles edge cases like pre-aborted signals, preserves partial outputs, and maintains metadata on cancellation.

Confidence Score: 4/5

  • safe to merge with minor consideration for race condition handling
  • the implementation is well-designed with comprehensive test coverage including normal execution, abort scenarios, Redis cancellation, loop/parallel cancellation, and edge cases. The cached abort promise pattern effectively solves the memory leak issue and enables immediate cancellation. However, there's a theoretical race condition where nodes queued in processQueue() line 324 could still start executing even after checkCancellation() returns true on line 318, though this is minor and unlikely to cause issues in practice.
  • no files require special attention

Important Files Changed

Filename Overview
apps/sim/executor/execution/engine.ts upgraded abort handling to support immediate cancellation during loops and parallel execution with cached abort promise pattern
apps/sim/executor/execution/engine.test.ts comprehensive test suite added covering abort scenarios, Redis cancellation, loop/parallel cancellation, and edge cases

Sequence Diagram

sequenceDiagram
    participant User
    participant AbortController
    participant Engine
    participant AbortPromise
    participant ProcessQueue
    participant NodeExecution
    
    User->>AbortController: abort()
    AbortController->>Engine: abort event
    Engine->>Engine: set cancelledFlag = true
    Engine->>AbortPromise: resolve()
    
    alt During Queue Processing
        ProcessQueue->>Engine: checkCancellation()
        Engine-->>ProcessQueue: true (cancelled)
        ProcessQueue->>ProcessQueue: break queue loop
    end
    
    alt During Parallel Execution
        NodeExecution->>NodeExecution: executing parallel branches
        Engine->>Engine: waitForAnyExecution()
        Engine->>Engine: Promise.race([...executing, abortPromise])
        AbortPromise-->>Engine: resolves first
        Engine-->>ProcessQueue: returns immediately
        Note over NodeExecution: unfinished executions continue<br/>but won't be awaited
    end
    
    alt During Loop Iteration
        ProcessQueue->>Engine: checkCancellation()
        Engine-->>ProcessQueue: true (cancelled)
        ProcessQueue->>ProcessQueue: break loop
        Engine->>Engine: skip waitForAllExecutions()
    end
    
    Engine->>Engine: build result with status='cancelled'
    Engine-->>User: ExecutionResult (cancelled)
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@waleedlatif1
Copy link
Collaborator Author

@greptile

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.

2 participants