Repository navigation
fix(graphai): preserve nesting headroom (regression from #1314 — nested mapAgent fails with "Concurrency is too low") - #1326
Conversation
…to siblings prepareForNesting() bumps `concurrency` to reserve a slot so a nested graph's own children have headroom to run (deadlock avoidance, which mapAgent asserts via `concurrency > running`). PR #1314 added a drain loop at the end of prepareForNesting that immediately dispatched already-queued sibling tasks into that reserved slot, pushing `running` up to `concurrency`. The next nested mapAgent then saw no headroom and threw "mapAgent: Concurrency is too low". At prepareForNesting time the nested children are not queued yet (the nested graph is built and run *after* it returns), so the drain can only consume the reservation with unrelated work. Remove the drain loop: nested children and any newly-eligible queued tasks are dispatched when they call addTask() or when a slot frees up in onComplete() (the onComplete drain is kept). This restores the pre-#1314 behavior for the global path while leaving the per-label feature intact. Reproduces with a mapAgent whose nested graph contains another mapAgent (e.g. mulmocast's translate action) under a low global concurrency. Tests: - unit: prepareForNesting must not dispatch a queued sibling (headroom preserved) - integration: nested mapAgent-within-mapAgent runs without tripping the guard Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughTaskManager.prepareForNesting() no longer drains the queued task execution queue after incrementing concurrency for nesting. Instead, it explicitly preserves the reserved headroom slot to prevent queued sibling tasks from consuming capacity needed by nested graph execution. Unit and integration tests validate the fix. ChangesNested graph concurrency headroom preservation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f07b4c87e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // IMPORTANT: do NOT drain the queue here. The concurrency++ above reserves a | ||
| // slot so the nested graph's own children have headroom to run (deadlock | ||
| // avoidance, which mapAgent asserts via `concurrency > running`). At this | ||
| // point the nested children are not queued yet -- the nested graph is built | ||
| // and run *after* prepareForNesting returns -- so draining now can only | ||
| // dispatch unrelated already-queued sibling tasks into the reserved slot, | ||
| // immediately consuming the headroom and tripping mapAgent's guard. The | ||
| // nested children, and any newly-eligible queued tasks, are dispatched when | ||
| // they call addTask() or when a slot frees up in onComplete(). |
There was a problem hiding this comment.
Update the compiled TaskManager output
This changes only src/task_manager.ts, but packages/graphai/package.json points runtime consumers at lib/index.js and publishes only ./lib; packages/graphai/lib/task_manager.js still contains the old prepareForNesting() drain loop. In any install or workspace import that resolves the package entrypoint instead of the TS source, the nested mapAgent regression remains unfixed despite these source tests passing. Please regenerate/commit the lib output for this TaskManager change.
Useful? React with 👍 / 👎.
Summary
Fixes a regression introduced by #1314 (
feat: concurrency per label with head-of-line skip). A graph with a mapAgent whose nested graph contains another mapAgent (e.g. mulmocast'stranslateaction) now fails with:…even when per-label concurrency is not used at all. It affects the plain
concurrency: numberpath.Root cause
prepareForNesting()bumpsconcurrencyto reserve a slot so the nested graph's own children have headroom to run — this is the deadlock-avoidance invariant thatmapAgentasserts viaconcurrency > running.#1314 added a drain loop at the end of
prepareForNesting():When a sibling task is already queued (common under a low global limit), this drain immediately dispatches it into the just-reserved slot, pushing
runningup toconcurrency. The next nestedmapAgentthen seesrunning == concurrency(no headroom) and throws.At
prepareForNestingtime the nested children are not queued yet — the nested graph is built and run afterprepareForNestingreturns — so the drain can only consume the reservation with unrelated sibling work.Fix
Remove the drain loop from
prepareForNesting(). Nested children and any newly-eligible queued tasks are dispatched when they calladdTask()or when a slot frees up inonComplete()(theonCompletedrain loop is kept). This restores the pre-#1314 behavior on the global path while leaving the per-label feature intact.Tests
test_task_manager.ts):prepareForNestingmust not dispatch a queued sibling — headroom preserved (running < concurrencyafter the bump). The pre-existing nesting test had no queued sibling, which is why the regression slipped through.test_nested_concurrency.ts, new): a mapAgent whose nested graph contains another mapAgent runs to completion underconcurrency: 1. Verified to fail (Concurrency is too low: 5) on the unfixed code and pass with the fix.npx tsc --noEmitclean. The 8 pre-existingCannot find module './array_find_first_exists'failures in the suite are unrelated (present on a clean checkout ofmain).🤖 Generated with Claude Code
Summary by CodeRabbit