Skip to content
This repository was archived by the owner on Aug 21, 2026. It is now read-only.
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

Open

Description

@hatyibei

Summary

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).

Where

src/legacy/graph.py:142-189 (human_feedback) + src/legacy/graph.py:497 (generate_report_plan → human_feedback).

def human_feedback(state, config) -> Command[Literal["generate_report_plan","build_section_with_web_research"]]:
    interrupt_message = f"..."
    feedback = interrupt(interrupt_message)
    if isinstance(feedback, bool) and feedback is True:
        return Command(goto=[Send(...)])  # accept → research path
    elif isinstance(feedback, str):
        return Command(goto="generate_report_plan",
                       update={"feedback_on_report_plan": feedback})

The structural cycle is generate_report_plan → human_feedback → revise → generate_report_plan → …, exiting only when the user feeds True.

Why it matters

Three reachable paths trip GraphRecursionError mid-iteration:

  1. Automated reviewer (LLM acting as the human, no accept heuristic): revises indefinitely.
  2. Adversarial / accidentally-rejecting human.
  3. Property-based / chaos test suites that always feed a string.

recursion_limit is graph-wide, shared with the section-research subgraph, so attribution to the revision loop is hard.

Proposed remediation

  1. revisions_count field on ReportState + force-accept after N:

    if isinstance(feedback, str) and state.get("revisions_count", 0) < MAX_REVISIONS:
        return Command(goto="generate_report_plan", update={
            "feedback_on_report_plan": feedback,
            "revisions_count": state.get("revisions_count", 0) + 1,
        })
    return Command(goto=[Send(...)])  # force-accept
  2. max_plan_revisions in Configuration + raise typed MaxPlanRevisionsExceededError. Same shape as the existing max_search_depth knob.

  3. 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.)

Activity

  1. CalibratedGhosts commented on May 10, 2026

    @CalibratedGhosts

    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:

    max_revisions = configurable.max_plan_revisions
    revisions = state.get("plan_revision_count", 0)
    
    if isinstance(feedback, str):
        if revisions >= max_revisions:
            raise MaxPlanRevisionsExceededError(...)
        return Command(
            goto="generate_report_plan",
            update={
                "feedback_on_report_plan": feedback,
                "plan_revision_count": revisions + 1,
            },
        )

    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.

  2. hatyibei commented on May 11, 2026

    @hatyibei
    Author

    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:

    1. 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.

    2. 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.

  3. RerankerGuo commented on Aug 3, 2026

    @RerankerGuo

    Thanks hatyibei (@hatyibei) / CalibratedGhosts — I'd like to pick this up with a small, focused PR.

    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:

    1. 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.
    2. Is a default limit of 5 acceptable?
    3. 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.

  4. hatyibei commented on Aug 4, 2026

    @hatyibei
    Author

    Thanks Ziyang Guo (@RerankerGuo) — this is exactly the shape I was hoping for. Please go ahead.

    Answers to your three:

    1. 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.

    2. 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 in Configuration so anyone who wants a looser budget can bump it.

    3. 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 next generate_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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions