Skip to content

Conversation

@yashwanthjack
Copy link

Fix RouterRunnable being invisible in traces and incorrectly reporting its name.

Problem

RouterRunnable overrode invoke and ainvoke without tracing callbacks, causing:

  • Router to be invisible in trace hierarchies
  • Name defaulting to "RunnableSequence" instead of "RouterRunnable"

Solution

  • Added CallbackManager integration to invoke and ainvoke
  • Child runnables now receive patched config with proper callbacks
  • Updated test assertions for correct name and trace structure

AI Disclosure: This contribution was developed with assistance from an AI coding assistant.

@github-actions github-actions bot added core `langchain-core` package issues & PRs fix For PRs that implement a fix labels Dec 31, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 31, 2025

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing yashwanthjack:yashwanthjack/fix-router-runnable-tracing (e1eb317) with master (2ef2388)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched benchmarks
⏩ 21 skipped benchmarks1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@yashwanthjack yashwanthjack force-pushed the yashwanthjack/fix-router-runnable-tracing branch from c1ab981 to 2c369c4 Compare December 31, 2025 16:47
@yashwanthjack
Copy link
Author

Flaky test failure - I'm going to re-run by pushing an empty commit.

Copy link

@horus-bot horus-bot left a comment

Choose a reason for hiding this comment

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

The self.name = "RouterRunnable" assignment in init is redundant since you're already passing name="RouterRunnable" to super().init().

@yashwanthjack yashwanthjack requested a review from ccurme January 1, 2026 03:50
@mdrxy mdrxy changed the title fix(core): add tracing callbacks to RouterRunnable fix(core): add tracing callbacks to RouterRunnable Jan 8, 2026
@github-actions github-actions bot added fix For PRs that implement a fix and removed fix For PRs that implement a fix labels Jan 8, 2026
Copy link
Contributor

@aaron-seq aaron-seq left a comment

Choose a reason for hiding this comment

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

Code Review Summary

This PR successfully addresses the tracing callback issue in RouterRunnable. The implementation is well-structured and correctly integrates callback management for proper tracing visibility.


CI/CD Failure Analysis

Failures Identified:

1. CI Success Check (Required) - Exit code 1
The check shows "All Checks Passed" but exits with code 1, indicating a potential issue with the check aggregation logic itself rather than the code changes.

2. lint (libs/langchain, 3.14) / Python 3.14 - Exit code 2
This failure is due to infrastructure issues, not code quality:

  • Failed to download Python 3.14 build from astral-sh/python-build-standalone
  • HTTP 500 Internal Server Error from GitHub's release server
  • Dependency installation failure after 3 retries

Conclusion: Both CI failures are infrastructure/environment-related, not caused by code issues in this PR.


Code Logic Review

Implementation Quality: Excellent

The changes correctly implement tracing callbacks for RouterRunnable:

Positive Aspects:

  1. Proper Callback Manager Integration

    • Correctly creates CallbackManager with inherited callbacks, tags, and metadata
    • Properly configures run_manager for chain lifecycle tracking
    • Uses on_chain_start, on_chain_error, and on_chain_end appropriately
  2. Correct Child Config Handling

    • Creates proper child config with run_manager.get_child()
    • Uses set_config_context to ensure proper context propagation
    • Maintains config isolation between parent and child runnables
  3. Error Handling

    • Comprehensive try-except-else pattern
    • Proper error reporting via on_chain_error before re-raising
    • Handles both sync (invoke) and async (ainvoke) methods identically
  4. Name Fix

    • Setting name="RouterRunnable" in __init__ ensures correct tracing name
    • Previously defaulted to "RunnableSequence" causing confusion
  5. Test Updates

    • Updated assertions reflect the new trace structure
    • Now correctly expects RouterRunnable name and proper child run nesting
    • Changed from 2 direct children to 1 child with 2 nested children (correct structure)

Code Quality Observations:

Line 87: Adding explicit name parameter

name="RouterRunnable",

This is essential for proper identification in traces. Good fix.

Lines 114-149 (invoke): Callback integration

callback_manager = cb_manager.CallbackManager.configure(...)
run_manager = callback_manager.on_chain_start(...)

Follows LangChain's callback pattern correctly.

Lines 137-149: Context and config handling

with set_config_context(child_config) as context:
    output = context.run(runnable.invoke, actual_input, child_config)

Proper use of context manager ensures config is available during execution.

Lines 180-181: Error propagation

await run_manager.on_chain_error(e)
raise

Correct pattern: report error to callbacks before re-raising.

Test Changes (lines 2906-2908):

assert router_run.name == "RouterRunnable"  # Fixed from "RunnableSequence"
assert len(router_run.child_runs) == 1  # Now correctly structured
assert len(router_run.child_runs[0].child_runs) == 2

Test assertions now match the correct expected behavior.


Why CI/CD Failed

Root Causes:

  1. Python 3.14 Download Failure (lint check)

    • External dependency on GitHub's python-build-standalone releases
    • Server returned HTTP 500 error
    • Not related to code changes
    • Recommendation: Re-run the workflow when GitHub's servers are stable
  2. CI Success Aggregation Issue

    • The aggregation check may have strict requirements
    • Could be related to timing or specific check dependencies
    • Exit code 1 suggests a scripting/logic issue in the CI definition itself
    • Recommendation: Investigate .github/workflows/ configuration

Code Correctness: Verified

The code logic is correct and well-implemented:

  • Follows LangChain's callback patterns precisely
  • Proper lifecycle management (start, error, end)
  • Correct async/await handling in ainvoke
  • Appropriate use of context managers
  • Test updates align with new behavior
  • No race conditions or resource leaks
  • Proper exception handling and propagation

Recommendations

  1. CI Failures: These are infrastructure issues. Recommend re-running the failing workflows or waiting for GitHub's infrastructure to stabilize.

  2. Merge Readiness: From a code perspective, this PR is ready to merge once CI infrastructure issues are resolved.

  3. Consider: Adding a docstring example showing how callbacks are now properly traced.


Conclusion

The implementation correctly addresses the reported issue. The RouterRunnable now properly:

  • Appears in trace hierarchies
  • Reports its name as "RouterRunnable" instead of "RunnableSequence"
  • Integrates callbacks for child runnables
  • Maintains proper trace structure

The CI failures are unrelated to code quality and are caused by external infrastructure problems. Once these are resolved (via re-run or automatic recovery), this PR should merge successfully.

Copy link
Contributor

@aaron-seq aaron-seq left a comment

Choose a reason for hiding this comment

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

Follow-up Review

Excellent work addressing the previous feedback! All CI/CD checks passing and implementation looks solid.

Updates Verified

✅ Removed redundant self.name assignment
✅ Added set_config_context for proper config propagation
✅ All 88 checks passing
✅ Proper callback integration

Final Assessment

The code is production-ready and successfully addresses the RouterRunnable tracing visibility issue. Implementation follows LangChain patterns correctly.

Ready for merge once maintainers approve.

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

Labels

core `langchain-core` package issues & PRs fix For PRs that implement a fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants