fix(task-graph): cap bridgeSubGraphTaskEvents depth to prevent event amplification#601
Open
sroussey wants to merge 1 commit into
Open
fix(task-graph): cap bridgeSubGraphTaskEvents depth to prevent event amplification#601sroussey wants to merge 1 commit into
sroussey wants to merge 1 commit into
Conversation
…amplification bridgeSubGraphTaskEvents installs one re-emit listener per event type per nesting level. A deeply nested compound task (e.g., a MapTask containing GraphAsTask containing MapTask) turns one inner task_progress into N parent emits before reaching any wire subscriber. Downstream consumers with a bounded event log (the sec/builder ExecutionEventLog is capped at 10k events) can evict legitimate events under sustained nested fan-out. Add a default depth cap of 16 with a logged drop once exceeded, and let callers override via the new maxDepth parameter. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V3e3m8cMRy5stFhDzGmZrF
Coverage Report
File CoverageNo changed files found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bridgeSubGraphTaskEventsinstalls one re-emit listener per event type per nesting level. A deeply nested compound task (e.g. aMapTaskcontaining aGraphAsTaskcontaining aMapTask…) bridges every level independently, so a single innertask_progressbecomes N parent emits before reaching any wire subscriber. Combined with downstream consumers that keep a bounded event log (the sec/builderExecutionEventLogis capped at 10k events), sustained nested fan-out can silently evict legitimate events.This PR adds a defense-in-depth depth cap with a default of 16 levels. Once exceeded, the bridge installs no listeners and emits a single
warnlog noting the cap hit. The cap is overridable via a newmaxDepthparameter; depth is auto-derived from a symbol-keyed marker on the parent graph so existing call sites (GraphAsTaskRunner,WhileTask,IteratorTaskRunner,FallbackTaskRunner,GraphAsTaskstreaming path) compile unchanged.Approach
Depth tracking lives on the graph instance via a
Symbol.for("@workglow/task-graph/SubGraphEventBridge.depth")keyed property — chosen over threading a counter through every caller because it keeps the diff to one file of fix code plus one re-export. The teardown restores the previous marker so an independently-rooted later bridge of the same subgraph instance does not inherit a stale counter.Files
packages/task-graph/src/task-graph/SubGraphEventBridge.ts— depth cap + warn logpackages/task-graph/src/common.ts— re-exportbridgeSubGraphTaskEventsso the test can drive it directlypackages/test/src/test/task-graph/TaskCompleteEvent.test.ts— three new testsBackwards compatibility
Patch-bump compatible: both new parameters have defaults; every existing caller still compiles. No behavior change for graphs nesting fewer than 16 bridges deep.
Test plan
bun scripts/test.ts graph vitest— 74 files, 728 tests passing (including 3 new)bun run build:types— 36 successful, 36 total{ depth, maxDepth }fields;maxDepthoverride is honoredGenerated with Claude Code
https://claude.ai/code/session_01V3e3m8cMRy5stFhDzGmZrF
Generated by Claude Code