Skip to content

fix(executor): strip childTraceSpans from block state before LLM tool calls#4428

Merged
waleedlatif1 merged 2 commits intostagingfrom
fix/workflow-block
May 4, 2026
Merged

fix(executor): strip childTraceSpans from block state before LLM tool calls#4428
waleedlatif1 merged 2 commits intostagingfrom
fix/workflow-block

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • When a workflow block runs a child workflow inline, the execution trace (childTraceSpans) was being stored in execution state alongside the actual output
  • Downstream Agent blocks reading that state sent the full trace to the LLM as tool result context — up to 148k tokens for workflows processing ~50 records, and over the 200k context limit at larger scale
  • Strip childTraceSpans from the output before setBlockOutput on the success path; never put it in errorOutput on the failure path — it stays in blockLog only, which is where the Logs UI reads it from

Type of Change

  • Bug fix

Testing

Tested manually

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 4, 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 4, 2026 5:44pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 4, 2026

PR Summary

Medium Risk
Changes what gets persisted to execution state by stripping childTraceSpans, which could affect any downstream blocks or UI code that previously relied on that field being present in state/output. The change is localized to BlockExecutor logging/state writing and should mainly reduce oversized LLM/tool-call context payloads.

Overview
Prevents large nested-workflow execution traces from being persisted into per-block execution state by stripping childTraceSpans before calling setBlockOutput on successful executions, while still keeping spans on blockLog for the Logs UI.

On error paths, stops adding childTraceSpans to the returned errorOutput and instead conditionally attaches spans to blockLog only when the thrown error is a ChildWorkflowError with non-empty spans.

Reviewed by Cursor Bugbot for commit 293c1f9. Configure here.

Comment thread apps/sim/executor/execution/block-executor.ts
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Greptile Summary

This fix strips childTraceSpans from the execution state on both the success and error paths in BlockExecutor, preventing the full child workflow trace (up to 148k+ tokens) from being forwarded to downstream Agent blocks as LLM tool result context. On success, a simple destructure produces outputForState before setBlockOutput; on error, traces are read directly from ChildWorkflowError to populate blockLog.childTraceSpans without ever touching errorOutput.

Confidence Score: 5/5

Safe to merge — the core state/LLM leakage is correctly fixed with no new issues introduced.

The change is minimal and targeted. childTraceSpans is stripped from both setBlockOutput and the return value on the success path, and never placed into errorOutput on the error path. The ChildWorkflowError.childTraceSpans field is always an array (defaulted to [] in the constructor), so the .length > 0 guard is safe. The only open item is the pre-existing cosmetic duplication of childTraceSpans inside blockLog.output on the success path (noted in a prior review comment), which does not affect the LLM token fix.

No files require special attention; the single changed file is well-contained.

Important Files Changed

Filename Overview
apps/sim/executor/execution/block-executor.ts Correctly strips childTraceSpans from execution state on both success (via destructuring before setBlockOutput) and error paths (via direct read from ChildWorkflowError rather than errorOutput); traces are preserved in blockLog only for the Logs UI.

Sequence Diagram

sequenceDiagram
    participant Handler as Block Handler
    participant BE as BlockExecutor
    participant State as BlockStateWriter
    participant Log as blockLog (Logs UI)
    participant LLM as LLM Tool Context

    Handler->>BE: returns normalizedOutput (with childTraceSpans)
    BE->>Log: blockLog.output = filterOutputForLog(normalizedOutput)
    BE->>BE: destructure → outputForState (childTraceSpans stripped)
    BE->>State: setBlockOutput(outputForState)
    BE->>LLM: return outputForState (no childTraceSpans)

    Note over State,LLM: Traces never reach LLM tool result context
Loading

Reviews (2): Last reviewed commit: "fix(executor): return stripped output so..." | Re-trigger Greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 293c1f9. Configure here.

@waleedlatif1 waleedlatif1 merged commit 5d53847 into staging May 4, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/workflow-block branch May 4, 2026 17:55
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