Skip to content

fix(terminal): use wall-clock duration for loop iterations with concurrent children#4443

Merged
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/loop-iter-time
May 5, 2026
Merged

fix(terminal): use wall-clock duration for loop iterations with concurrent children#4443
waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1/loop-iter-time

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Fixes rapidly-climbing iteration durations (e.g. 18m → 20m → 22m within seconds) shown in the live terminal/console view for workflows with a parallel block nested inside a loop.
  • Root cause: terminal utils.ts was summing child durationMs for loop iteration containers. When children were concurrent parallel branches, each completing branch added its full duration to the displayed iteration time, over-counting by ~Nx.
  • Fix: always use wall-clock (max(endedAt) − min(startedAt)) for synthetic subflow and iteration entries, regardless of iterationType. Matches the post-run trace span builder's behavior.
  • Added 9 regression tests covering parallel-in-loop, loop-in-parallel, loop-in-loop, sequential, single-block, and 20-branch concurrency cases.

Type of Change

  • Bug fix

Testing

  • 22/22 tests pass in apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/utils.test.ts
  • bun run lint passes
  • bun run check:api-validation:strict passes

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)

@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 5, 2026 3:08am

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 5, 2026

PR Summary

Low Risk
Low risk: small, localized change to duration math for synthetic terminal rows plus additional regression tests; primary risk is minor display/ordering regressions for edge-case timestamps.

Overview
Fixes terminal tree-building to compute synthetic subflow and iteration durationMs as wall-clock (max(endedAt) - min(startedAt)) for all iteration types, eliminating over-counting when concurrent branches run inside a loop.

Adds a focused regression test suite in utils.test.ts covering parallel-in-loop, concurrent subflow containers, nested loop/parallel scenarios, gaps between iterations, and high-branch-count concurrency to ensure durations never sum across parallel work.

Reviewed by Cursor Bugbot for commit 2c729c0. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 5, 2026

Greptile Summary

This PR fixes a bug where terminal/console view showed rapidly-climbing iteration durations (e.g. 18m → 20m → 22m) for workflows with a parallel block nested inside a loop. The root cause was that utils.ts summed child durationMs values for loop iteration containers — when children were concurrent parallel branches, each completing branch added its full duration, overcounting by ~Nx. The fix drops the iterationType-conditional and always uses wall-clock (max(endedAt) − min(startedAt)) for both subflow containers and iteration entries, matching the post-run trace span builder's behavior. Nine regression tests are added covering parallel-in-loop, loop-in-parallel, loop-in-loop, sequential, single-block, and 20-branch concurrency cases.

Confidence Score: 5/5

Safe to merge — minimal targeted fix with comprehensive regression coverage and no side-effects on other code paths.

The change is a two-line deletion and replacement with the simpler wall-clock expression. Wall-clock is strictly correct for both sequential and parallel cases. All 9 new tests and the full 22/22 suite pass. No pre-existing logic is removed that would be needed for other display paths.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/utils.ts Removes the iterationType-gated conditional for duration calculation and always uses wall-clock (max(endedAt) − min(startedAt)) for both subflow containers and iteration entries — minimal, targeted, and correct.
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/utils.test.ts Adds 9 regression tests covering parallel-in-loop, loop-in-parallel, loop-in-loop, sequential, single-block, and high-branch-count concurrency cases to guard against the summed-duration bug.

Sequence Diagram

sequenceDiagram
    participant UI as Terminal UI
    participant BET as buildEntryTree()
    participant Old as Old Logic
    participant New as New Logic

    UI->>BET: ConsoleEntry[] (loop + parallel children)

    Note over BET: Build subflow groups per iterationContainerId

    BET->>Old: iterationType === 'parallel' ?
    Old-->>BET: wallClock (parallel) OR sum(durationMs) (loop) — BUG: loop children can be parallel!

    BET->>New: always wallClock = max(endedAt) − min(startedAt)
    New-->>BET: correct wall-clock duration

    BET-->>UI: EntryNode[] with correct durationMs for iterations & subflows
Loading

Reviews (1): Last reviewed commit: "fix(terminal): use wall-clock duration f..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit 51addc5 into staging May 5, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/loop-iter-time branch May 5, 2026 03:23
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