Skip to content

fix: surface child research errors in supervisor_tools (#283)#286

Open
pii (rohan4naik) wants to merge 1 commit into
langchain-ai:mainfrom
rohan4naik:fix/supervisor-tools-surface-research-errors
Open

fix: surface child research errors in supervisor_tools (#283)#286
pii (rohan4naik) wants to merge 1 commit into
langchain-ai:mainfrom
rohan4naik:fix/supervisor-tools-surface-research-errors

Conversation

@rohan4naik

Copy link
Copy Markdown

Summary

supervisor_tools guarded its ConductResearch exception handler with:

if is_token_limit_exceeded(e, configurable.research_model) or True:

The trailing or True made the branch fire for every exception, so any child researcher failure was silently treated as a normal end of the research phase. The top-level graph then continued from research_supervisor to final_report_generation, meaning a run could still produce a final report after part of the research fan-out had failed.

Fix

Remove the or True:

  • Token-limit errors still end the research phase gracefully with the notes gathered so far (unchanged behavior).
  • Any other exception is now re-raised and surfaced instead of being swallowed.

This mirrors the error handling already used in final_report_generation, which distinguishes token-limit errors from genuine failures rather than treating all errors the same.

Testing

Added tests/test_supervisor_tools.py with two regression tests:

  • test_child_research_error_is_surfaced — a non-token-limit child failure now propagates instead of returning goto=END.
  • test_token_limit_ends_research_phase_gracefully — a token-limit error still ends the phase with the gathered notes.
2 passed

ruff check clean on changed files.

Fixes #283

supervisor_tools guarded its ConductResearch exception handler with
`if is_token_limit_exceeded(...) or True:`. The `or True` made the
branch fire for every exception, so any child researcher failure was
silently treated as a normal end of the research phase. The graph then
continued to final_report_generation and could produce a final report
from failed/incomplete research.

Remove the `or True`: token-limit errors still end the phase gracefully
with the notes gathered so far, but any other exception is now re-raised
and surfaced instead of being swallowed. This mirrors the error handling
in final_report_generation, which also distinguishes token-limit errors
from genuine failures.

Add regression tests covering both paths.

Fixes langchain-ai#283
Copilot AI review requested due to automatic review settings July 3, 2026 06:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the Deep Research agent’s supervisor_tools where all child ConductResearch exceptions were incorrectly treated as a graceful end-of-research due to an unconditional or True, allowing the outer graph to proceed to final_report_generation after partial research failure.

Changes:

  • Remove the unconditional exception-swallowing logic so only token-limit errors end the research phase gracefully; other errors are re-raised.
  • Add regression tests to ensure non-token child failures propagate and token-limit failures still return goto=END.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/open_deep_research/deep_researcher.py Fixes supervisor_tools exception handling to surface non-token child research errors.
tests/test_supervisor_tools.py Adds regression tests covering error propagation vs token-limit graceful termination.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 329 to 331
if raw_notes_concat:
update_payload["raw_notes"] = [raw_notes_concat]

Comment on lines +55 to +64
def test_token_limit_ends_research_phase_gracefully():
"""A token-limit error should end the research phase with gathered notes."""
with (
patch.object(researcher_subgraph, "ainvoke", side_effect=_boom),
patch.object(deep_researcher, "is_token_limit_exceeded", return_value=True),
):
command = asyncio.run(supervisor_tools(_supervisor_state(), _CONFIG))

assert command.goto == END
assert "research_brief" in command.update
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.

[BUG] supervisor_tools treats any child ConductResearch exception as successful research completion

2 participants