You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
cycle_detection: human_feedback ↔ generate_report_plan revision loop has no explicit max_revisions #269
legacy/graph.py's human_feedback node can route back to generate_report_plan indefinitely via the user-supplied feedback string, with no explicit upper bound on revisions. The cycle has a real exit branch (accept → research) so it's not structurally broken, but its bound is implicit — silently recursion_limit=25.
Surfaced by Shingan (shingan-lint@0.8.6) cycle_detection (Warning, confidence 0.9).
max_plan_revisions in Configuration + raise typed MaxPlanRevisionsExceededError. Same shape as the existing max_search_depth knob.
Document the recursion_limit=25 dependency in legacy/README.md (low cost; surfaces the trap without fixing it).
(1) is the minimal patch; (2) lines up with existing config knobs. Happy to send a PR for either if maintainers prefer one direction.
Severity
Not a security bug — UX / robustness. Reachable by reasonable callers; surfaces as GraphRecursionError.
Shingan trace
$ shingan analyze --format langgraph --input src/legacy/graph.py
[warning] cycle_detection (90%) on generate_report_plan
bounded cycle through non-Loop node "generate_report_plan" (type=llm):
the cycle has an exit branch, but no explicit
max_iterations / recursion_limit guard
(Side note: open_deep_research was a key dogfood target while building the v0.8.5+ analyser — its mix of Command(goto=...) + list path_map + multi-graph subgraph composition drove most of the LangGraph idiom support added in those releases. Down to 1 finding from 9 false positives in v0.8.4.)
One implementation detail that may keep this from fighting LangGraph's global recursion_limit: make the plan-revision budget part of the graph state/config,
not only an outer runner setting.
The test I would want is a fake/monkeypatched interrupt() that returns a
string max_plan_revisions + 1 times, asserting that the failure is a typed
plan-revision error rather than a generic GraphRecursionError. That keeps the
section-research recursion budget separate from "the human never accepted the
plan."
I would slightly prefer a typed error or explicit "needs human accept" terminal
state over force-accepting after N revisions, since auto-accept can hide exactly
the behavior the human feedback loop is meant to catch.
Agreed that wiring the counter into graph state/config (not just an outer recursion_limit) is the right shape. Two reasons your sketch is cleaner than the doc-only Option 3 I floated:
recursion_limit is global per super-step. Sharing it between the human-feedback loop and the section-research recursion (which has its own legitimate iteration budget) is exactly the kind of cross-cycle bleed that makes failures hard to interpret. Separating them via configurable.max_plan_revisions + state.plan_revision_count keeps each loop's intent local.
Typed error > auto-accept. I weakly preferred auto-accept in Option 2 of the original issue body because it degrades gracefully under noisy operators, but you're right that it silently masks exactly the signal the human-feedback loop is built to surface. A MaxPlanRevisionsExceededError (or a terminal "needs_human_accept" state) gives the calling layer the choice — retry, prompt operator, alert, etc. — rather than synthesizing one.
The fake-interrupt() test is good — it isolates the budget from any LLM/router stochasticity. I'd add one symmetric assertion: revisions < max_plan_revisions calls should not raise, and the state mutation should be visible to the next generate_report_plan invocation so downstream logic sees the increment.
Happy to draft this as a PR against langchain-ai/open_deep_research, taking your typed-error variant as the default. Two questions before I do:
Naming: MaxPlanRevisionsExceededError vs reusing an existing exception class — any preference in this repo's conventions?
Default for max_plan_revisions: 5? 10? (I'd lean 5 — keeps the budget tighter than recursion_limit's 25 default so it fires first.)
If a maintainer here can chime in on those two, I can keep the PR small and focused.
I've confirmed on current main that human_feedback (src/legacy/graph.py:189) still re-enters generate_report_plan with no revision bound.
Proposed shape:
add a max_plan_revisions configuration knob, defaulting to 5 and mirroring the existing max_search_depth pattern;
add a plain plan_revision_count: int field to ReportState (no operator.add reducer);
raise a typed MaxPlanRevisionsExceededError from the string-feedback branch when the budget is exhausted;
add offline tests with a monkeypatched interrupt() covering under-budget, at-budget, and approval paths.
Before I open the PR, could you confirm:
Typed error vs. force-accept? I lean toward a typed error, following the discussion above, because force-accept would silently proceed with a plan the user never approved.
Is a default limit of 5 acceptable?
Is there a preferred exception name/location, or would a new src/legacy/exceptions.py with MaxPlanRevisionsExceededError fit the project?
Happy to adjust the implementation to your conventions.
Typed error, yes. Force-accept was my weakly-held Option 2 and I've since talked myself out of it (see the exchange with CalibratedGhosts above): silently proceeding with a plan the user never approved hides the exact signal the human-feedback loop exists to surface. Raising MaxPlanRevisionsExceededError hands the decision back to the caller — retry, re-prompt the operator, alert — instead of the graph inventing an acceptance.
Default of 5 is good. The main thing I care about is that it sits belowrecursion_limit's default of 25 so the plan-revision budget fires first and attributes cleanly, rather than getting swallowed by the graph-wide limit it shares with the section-research recursion. 5 does that with margin. Keep it in Configuration so anyone who wants a looser budget can bump it.
A new src/legacy/exceptions.py with MaxPlanRevisionsExceededError is fine — I don't think there's an existing class worth reusing here. One request: have it carry the count and the limit (e.g. revisions/max_plan_revisions) on the exception so the message is self-explanatory in a traceback.
Two small things for the tests, since they're the part I most want locked in:
Assert the under-budget path does not raise and that the incremented plan_revision_count is visible to the nextgenerate_report_plan invocation — i.e. the state mutation actually round-trips, not just that the at-budget call throws.
The at-budget case should assert it's specifically MaxPlanRevisionsExceededError, not a generic GraphRecursionError. That separation (plan-revision budget vs. section-research recursion) is really the whole point of the change.
Keeping it a plain plan_revision_count: int with no operator.add reducer is the right call. Looking forward to the PR.
Activity
CalibratedGhosts commentedon May 10, 2026
One implementation detail that may keep this from fighting LangGraph's global
recursion_limit: make the plan-revision budget part of the graph state/config,not only an outer runner setting.
Possible minimal shape:
The test I would want is a fake/monkeypatched
interrupt()that returns astring
max_plan_revisions + 1times, asserting that the failure is a typedplan-revision error rather than a generic
GraphRecursionError. That keeps thesection-research recursion budget separate from "the human never accepted the
plan."
I would slightly prefer a typed error or explicit "needs human accept" terminal
state over force-accepting after N revisions, since auto-accept can hide exactly
the behavior the human feedback loop is meant to catch.
hatyibei commentedon May 11, 2026
Thanks CalibratedGhosts — strong points on both axes.
Agreed that wiring the counter into graph state/config (not just an outer
recursion_limit) is the right shape. Two reasons your sketch is cleaner than the doc-only Option 3 I floated:recursion_limitis global per super-step. Sharing it between the human-feedback loop and the section-research recursion (which has its own legitimate iteration budget) is exactly the kind of cross-cycle bleed that makes failures hard to interpret. Separating them viaconfigurable.max_plan_revisions+state.plan_revision_countkeeps each loop's intent local.Typed error > auto-accept. I weakly preferred auto-accept in Option 2 of the original issue body because it degrades gracefully under noisy operators, but you're right that it silently masks exactly the signal the human-feedback loop is built to surface. A
MaxPlanRevisionsExceededError(or a terminal"needs_human_accept"state) gives the calling layer the choice — retry, prompt operator, alert, etc. — rather than synthesizing one.The fake-
interrupt()test is good — it isolates the budget from any LLM/router stochasticity. I'd add one symmetric assertion:revisions < max_plan_revisionscalls should not raise, and the state mutation should be visible to the nextgenerate_report_planinvocation so downstream logic sees the increment.Happy to draft this as a PR against
langchain-ai/open_deep_research, taking your typed-error variant as the default. Two questions before I do:MaxPlanRevisionsExceededErrorvs reusing an existing exception class — any preference in this repo's conventions?max_plan_revisions: 5? 10? (I'd lean 5 — keeps the budget tighter thanrecursion_limit's 25 default so it fires first.)If a maintainer here can chime in on those two, I can keep the PR small and focused.
RerankerGuo commentedon Aug 3, 2026
Thanks hatyibei (@hatyibei) / CalibratedGhosts — I'd like to pick this up with a small, focused PR.
I've confirmed on current
mainthathuman_feedback(src/legacy/graph.py:189) still re-entersgenerate_report_planwith no revision bound.Proposed shape:
max_plan_revisionsconfiguration knob, defaulting to5and mirroring the existingmax_search_depthpattern;plan_revision_count: intfield toReportState(nooperator.addreducer);MaxPlanRevisionsExceededErrorfrom the string-feedback branch when the budget is exhausted;interrupt()covering under-budget, at-budget, and approval paths.Before I open the PR, could you confirm:
5acceptable?src/legacy/exceptions.pywithMaxPlanRevisionsExceededErrorfit the project?Happy to adjust the implementation to your conventions.
hatyibei commentedon Aug 4, 2026
Thanks Ziyang Guo (@RerankerGuo) — this is exactly the shape I was hoping for. Please go ahead.
Answers to your three:
Typed error, yes. Force-accept was my weakly-held Option 2 and I've since talked myself out of it (see the exchange with CalibratedGhosts above): silently proceeding with a plan the user never approved hides the exact signal the human-feedback loop exists to surface. Raising
MaxPlanRevisionsExceededErrorhands the decision back to the caller — retry, re-prompt the operator, alert — instead of the graph inventing an acceptance.Default of 5 is good. The main thing I care about is that it sits below
recursion_limit's default of 25 so the plan-revision budget fires first and attributes cleanly, rather than getting swallowed by the graph-wide limit it shares with the section-research recursion. 5 does that with margin. Keep it inConfigurationso anyone who wants a looser budget can bump it.A new
src/legacy/exceptions.pywithMaxPlanRevisionsExceededErroris fine — I don't think there's an existing class worth reusing here. One request: have it carry the count and the limit (e.g.revisions/max_plan_revisions) on the exception so the message is self-explanatory in a traceback.Two small things for the tests, since they're the part I most want locked in:
plan_revision_countis visible to the nextgenerate_report_planinvocation — i.e. the state mutation actually round-trips, not just that the at-budget call throws.MaxPlanRevisionsExceededError, not a genericGraphRecursionError. That separation (plan-revision budget vs. section-research recursion) is really the whole point of the change.Keeping it a plain
plan_revision_count: intwith nooperator.addreducer is the right call. Looking forward to the PR.