Skip to content

Explore codebase loop task - #20

Merged
mytang0 merged 16 commits into
mainfrom
copilot/explore-codebase-loop-task
Apr 15, 2026
Merged

mytang0 merged 16 commits into
mainfrom
copilot/explore-codebase-loop-task

Conversation

@mytang0

@mytang0 mytang0 commented Apr 15, 2026

Copy link
Copy Markdown
Owner

This pull request introduces support for a new LOOP task type in the core task definitions and demonstrates its usage with a new flow example. The main focus is on enabling iteration over lists within flows, allowing child tasks to be executed for each item.

Core task system enhancements:

Added the LOOP task type to the core task registration in FlowTask, enabling flows to define iterative logic over collections.
Demo and documentation:

Added a new flow definition test-loop.json demonstrating the LOOP task, showing how to process each item in a list and how child task names are automatically suffixed for uniqueness.

Copilot AI and others added 16 commits April 14, 2026 02:43
- Add LoopTask.java implementing FlowTask interface with loopOver (collection)
  and loopCount (fixed iterations) modes
- Register LOOP task type in SPI descriptor file
- Add test-loop.json demo flow definition

Agent-Logs-Url: https://github.com/mytang0/brook/sessions/d425aa55-1b21-4472-9d6b-a9f2e21d2b7c

Co-authored-by: mytang0 <29346818+mytang0@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ual exclusivity, output size

- Per-iteration unique names: next() now returns deep-copied TaskDefs with
  names suffixed by __LOOP_<index>, preventing FlowExecutor's name-based
  deduplication from filtering out subsequent iterations
- Engine evaluation: only invoke engineActuator.compute() when loopOverRaw
  is a String, not when it's already resolved to a List
- Mutual exclusivity: doVerify() now rejects configs with both loopOver
  and loopCount set simultaneously
- Output size: removed full loopOverValue collection from task output;
  currentItem is now resolved from the task's input on each iteration

Agent-Logs-Url: https://github.com/mytang0/brook/sessions/486c704d-d9ca-4c67-9cf7-6fbf906d83ad

Co-authored-by: mytang0 <29346818+mytang0@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…d update demo

- Normalize loopOver to List: accept List, Collection, Iterable, and arrays
- Update demo flow description to document per-iteration naming scheme
- Add currentIndex reference to demo flow input

Agent-Logs-Url: https://github.com/mytang0/brook/sessions/ab678ddb-0163-4230-94fe-65be4add261c

Co-authored-by: mytang0 <29346818+mytang0@users.noreply.github.com>
- Use Array.getLength/Array.get for both object and primitive arrays
- Add explicit null check before instanceof chain to prevent NPE

Agent-Logs-Url: https://github.com/mytang0/brook/sessions/ab678ddb-0163-4230-94fe-65be4add261c

Co-authored-by: mytang0 <29346818+mytang0@users.noreply.github.com>
…ted TaskDef renaming

- Write resolved loopOverValue back to task input in getMappedTasks() so
  updateCurrentItem() can reliably index into it on subsequent iterations,
  even when the original loopOver was an engine expression or a non-List
  collection/array that was normalized
- createIterationTaskDef now recursively renames all nested child TaskDefs
  (e.g., inside IF/SWITCH branches) by walking the input tree and suffixing
  any Map with "name"+"type" keys, preventing name collisions across iterations

Agent-Logs-Url: https://github.com/mytang0/brook/sessions/36aeca0d-0e20-4bc5-936d-0c0072b7c987

Co-authored-by: mytang0 <29346818+mytang0@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…traversal

Replace name-only matching (findPositionInLoopBody) with
findNextTaskFromChildren() that delegates to flowExecutor.getNextTask()
per child, following the IFTask/SwitchTask pattern. This properly supports
nested control-flow tasks (IF/SWITCH/SUB_FLOW) inside the loop body.

Also fixes broken syntax (stray code from previous commit) that prevented
compilation, and removes unused helper methods (renameIterationTaskDefs,
renameIterationTaskDefsRecursively, isTerminalObject, stripIterationSuffix,
findPositionInLoopBody).

Agent-Logs-Url: https://github.com/mytang0/brook/sessions/58e258ef-bca8-4e09-86a7-6ddf71090f6f

Co-authored-by: mytang0 <29346818+mytang0@users.noreply.github.com>
Add LOOP task type to flow orchestration engine
…eter mappings

ParameterUtils.flowContext() now scans task instances for __LOOP_N-suffixed
names and injects unsuffixed aliases pointing to the latest iteration context.
This lets loop-body tasks use ${processItem.output.result} instead of the
hardcoded ${processItem__LOOP_0.output.result}. Non-suffixed tasks are never
shadowed. LOOP_INDEX_SEPARATOR made public for cross-package access.

Agent-Logs-Url: https://github.com/mytang0/brook/sessions/0840b969-932d-4bbf-80c7-c7aa75b346ba

Co-authored-by: mytang0 <29346818+mytang0@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 15, 2026 02:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new LOOP task type to Brook’s core task registry, introduces a LoopTask implementation to iterate over collections / counts within flows, and provides a demo flow showing how loop-body task names are suffixed for uniqueness.

Changes:

  • Registered LOOP as a core task type via the SPI mapping file.
  • Implemented LoopTask to drive per-iteration scheduling by suffixing loop-body task names.
  • Updated ParameterUtils.flowContext() to alias loop-suffixed task contexts back to their base (unsuffixed) names, plus added a demo flow test-loop.json.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
brook-demo/brook-demo-spring/src/main/resources/META-INF/flows/test-loop.json Adds a demo flow showcasing LOOP usage and name suffixing/aliasing behavior.
brook-core/src/main/resources/META-INF/brook/xyz.mytang0.brook.spi.task.FlowTask Registers the new LOOP task type to load LoopTask.
brook-core/src/main/java/xyz/mytang0/brook/core/utils/ParameterUtils.java Adds loop-suffix aliasing in flow context to enable ${baseTaskName.output...} references.
brook-core/src/main/java/xyz/mytang0/brook/core/tasks/LoopTask.java Implements LOOP task mapping and iteration-aware “next task” traversal with per-iteration task renaming.
brook-common/src/main/java/xyz/mytang0/brook/common/constants/TaskConstants.java Introduces a shared constant for the loop iteration name separator.

Comment thread brook-core/src/main/java/xyz/mytang0/brook/core/tasks/LoopTask.java
Comment thread brook-core/src/main/java/xyz/mytang0/brook/core/tasks/LoopTask.java
@mytang0
mytang0 merged commit 2d660b2 into main Apr 15, 2026
5 checks passed
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.

3 participants