Repository navigation
feat(integrations): Defer langchain, langgraph and mcp setup with multi-module triggers - #8343
Draft
ericapisani wants to merge 1 commit into
Conversation
…ti-module triggers Behind the deferred_auto_enabling_integrations experiment, an integration can now have several trigger modules. Setup waits until the outermost trigger import in the current thread completes, so no package the integration imports from is half-initialised when it runs. Trigger imports during a setup are queued rather than set up halfway through it, which keeps langgraph working when langchain v1's agents module pulls it in during langchain's setup. langchain triggers on langchain_core, langchain, langchain_classic and the provider packages it patches; langgraph on langgraph.graph, .func and .pregel (langgraph is a namespace package); mcp on mcp and fastmcp. langgraph.py now imports the langchain integration after its own langgraph check. For the PY-2415 reporter's environment, init() drops from ~2.4 s to 270 ms and peak RSS from 379 MB to 108 MB with the flag on. Fixes TEL-136
Contributor
Coverage Results 📊✅ 139831 passed | ⏭️ 8016 skipped | Total: 147847 | Pass Rate: 94.58% | Execution Time: 814m 25s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 92.86% (39 of 42 changed executable lines covered; target 80%). Changed files with executable lines (2)
Coverage diff@@ Coverage Diff @@
## master #8343 +/-##
==========================================
- Coverage 90.23% 90.22% -0.01%
==========================================
Files 203 203 —
Tracked lines 27349 27462 +113
Branches 10252 10290 +38
==========================================
+ Hits 24675 24775 +100
- Misses 2674 2687 +13
- Partials 1557 1562 +5Generated by Coverage Action |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends the
deferred_auto_enabling_integrationsexperiment to langchain, langgraph and mcp, the last eager AI integrations. Stacked on #8342.A single trigger module isn't enough for these: importing
langchain_openaiorfastmcpfirst fires the hook while that package is half-initialised, soOpenAIEmbeddings/ the FastMCP methods are left unpatched, and langgraph has separate entry points (langgraph.graph,langgraph.func).Each deferred integration now has a tuple of trigger modules (the first decides whether it's installed). Setup runs when the outermost trigger import in the current thread completes, and trigger imports during a setup are queued until it finishes. The queue matters for langchain v1:
langchain.agentsimports langgraph during langchain's setup, and setting langgraph up right then would hit a circular import of the sentry langchain module.Known gaps:
Benchmark
PY-2415 reporter's
pip freeze, CPython 3.12, median of 15 runs:init()timeinit()Fixes TEL-136