Skip to content

feat: implement task loop feature#211

Open
thalesraymond wants to merge 1 commit intomainfrom
feat-task-loop-7473620260144476195
Open

feat: implement task loop feature#211
thalesraymond wants to merge 1 commit intomainfrom
feat-task-loop-7473620260144476195

Conversation

@thalesraymond
Copy link
Owner

Implement LoopingExecutionStrategy feature per the feat-task-loop proposal in OpenSpec workflow. Ensure tasks can be conditionally polled without implementing imperative loops within their run context. The TaskLoopConfig now supports intervals, maxIterations, and an until predicate. Integrated cleanly into TaskRunnerBuilder and verified with comprehensive unit tests for intervals, limits, failure states, and cancellations. All linters and tests pass natively. Proposal is marked complete and moved to archive.


PR created automatically by Jules for task 7473620260144476195 started by @thalesraymond

Adds `loop` configuration to `TaskStep` to support conditional re-execution of a task until a condition is met. Introduces `TaskLoopConfig` interface. Implements `LoopingExecutionStrategy` that conditionally wraps `RetryingExecutionStrategy` inside `TaskRunnerBuilder`. Adds complete test coverage for polling delays, max iterations limits, and cancellation handling. Marks the related specification as implemented and archives the OpenSpec proposal.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new task looping mechanism, enabling tasks to be executed repeatedly until a specified condition is met. This feature is implemented via a dedicated LoopingExecutionStrategy and a TaskLoopConfig interface, which allows for fine-grained control over loop intervals, maximum iterations, and termination predicates. The changes enhance the flexibility of task execution within the system, allowing for conditional polling and retry logic to be managed declaratively.

Highlights

  • New Feature: Task Looping: Implemented a LoopingExecutionStrategy that allows tasks to be conditionally polled, enabling robust workflow automation without imperative loops within task execution contexts.
  • Configuration Interface: Introduced the TaskLoopConfig interface, providing configurable options for task looping, including interval (wait time between iterations), maxIterations (maximum attempts), and an until predicate function to define the loop's termination condition.
  • Task Definition Enhancement: The TaskStep interface was updated to include an optional loop property, allowing individual tasks to specify their looping behavior.
  • Execution Flow Integration: The TaskRunnerBuilder was modified to seamlessly integrate the LoopingExecutionStrategy, ensuring it wraps the configured or default execution strategy (e.g., RetryingExecutionStrategy) to apply looping logic at the appropriate level.
  • Comprehensive Testing: Extensive unit tests were added for the LoopingExecutionStrategy, covering various scenarios such as successful looping, reaching maximum iterations, interval delays, and cancellation handling.
  • OpenSpec Archival: The feat-task-loop proposal and specification documents have been moved to an archive directory, indicating the completion of the feature's implementation phase.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a task looping feature, allowing tasks to be polled until a condition is met. The implementation adds a LoopingExecutionStrategy which is correctly integrated into the TaskRunnerBuilder to wrap other strategies. The changes are well-tested. My feedback includes suggestions to improve the developer experience by changing a default value, enhance maintainability by removing duplicated code, and increase test reliability by using fake timers.

return this.innerStrategy.execute(step, context, signal);
}

const maxIterations = config.maxIterations ?? 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The default value for maxIterations is set to 1. This can lead to unexpected behavior where a task with a loop config only runs once and then fails if the until condition isn't met. This forces users to always specify maxIterations to get any looping behavior. A more intuitive default, like Infinity, would allow for indefinite polling until the condition is met or the task is cancelled.

Suggested change
const maxIterations = config.maxIterations ?? 1;
const maxIterations = config.maxIterations ?? Infinity;

Comment on lines +66 to +94
private sleep(ms: number, signal?: AbortSignal): Promise<void> {
if (ms <= 0) {
return Promise.resolve();
}

return new Promise((resolve, reject) => {
if (signal?.aborted) {
reject(new Error("AbortError"));
return;
}

const timer = setTimeout(() => {
cleanup();
resolve();
}, ms);

const onAbort = () => {
clearTimeout(timer);
cleanup();
reject(new Error("AbortError"));
};

const cleanup = () => {
signal?.removeEventListener("abort", onAbort);
};

signal?.addEventListener("abort", onAbort);
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This sleep method, which correctly handles AbortSignal, appears to be identical to the one in RetryingExecutionStrategy.ts. To adhere to the Don't Repeat Yourself (DRY) principle and improve maintainability, consider extracting this function into a shared utility file (e.g., src/utils/sleep.ts) and importing it in both strategies.

References
  1. To improve maintainability, define common utilities or constants in a shared file and import them where needed, rather than duplicating code. This principle extends beyond just strings to shared functions like sleep.

Comment on lines +85 to +91
const start = Date.now();
await strategy.execute(step, {});
const end = Date.now();

expect(mockInnerStrategy.execute).toHaveBeenCalledTimes(2);
// Should have waited at least 10ms once
expect(end - start).toBeGreaterThanOrEqual(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This test relies on Date.now() and real-time delays to verify the interval functionality. This can lead to flaky and slow tests, and the assertion toBeGreaterThanOrEqual(5) is not very precise for a 10ms interval. It's highly recommended to use vi.useFakeTimers() to control the passage of time deterministically. This will make the test faster, more reliable, and allow for more precise assertions about timing. The test should handle cancellation during sleep would also benefit from this approach.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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