Skip to content

fix: enforce parent-first langchain splitter imports - #6226

Merged
LearningCircuit merged 8 commits into
LearningCircuit:mainfrom
AbarnaaSree:fix/6143-langchain-import-order
Sep 6, 2026
Merged

LearningCircuit merged 8 commits into
LearningCircuit:mainfrom
AbarnaaSree:fix/6143-langchain-import-order

Conversation

@AbarnaaSree

Copy link
Copy Markdown
Contributor

Summary

  • Removed the redundant _LANGCHAIN_TEXT_SPLITTERS_IMPORT_LOCK.
  • Kept langchain_text_splitters imports function-local and lazy.
  • Added an AST-based guard to enforce the parent-first import invariant for all langchain_text_splitters submodule imports.
  • Added negative-control tests to ensure the guard actually detects invalid import ordering.
  • Updated stale concurrency comments and the #4829 release-note narrative.

Testing

  • 34 passed
  • Ruff checks passed
  • git diff --check passed
  • Concurrent cold-import tests remain green

Fixes #6143

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Welcome to local-deep-research — and thank you for your contribution. We genuinely appreciate the time you're putting in.

Here's a starter pack to help your PR move smoothly:

Get set up locally

  • Installation guide — running LDR
  • Developer guide — setting up a dev environment
  • Install our pre-commit hooks (one-time, details in CONTRIBUTING.md):
    pre-commit install
    pre-commit install-hooks
    
  • 📧 Privacy tip — check your commit email (details):
    use an address verified on your GitHub account — or your GitHub noreply address if you'd rather keep your email private.
    This matters here because we squash-merge PRs: if your commit email isn't verified on your account,
    GitHub authors the squash commit with your account's email instead — which can permanently expose an address you didn't intend to publish.

Understand the codebase

Before you ask for review

  • Open PRs against main unless a maintainer says otherwise.
  • Confirm your PR has a single clear purpose (PR process).
  • Describe in your PR body what you tested by hand — "CI is green" alone isn't enough.
  • Drop by Discord if you'd like to chat with maintainers or other contributors.

A maintainer will take a look — if you don't hear back within 7 days, feel free to ping.

@LearningCircuit

Copy link
Copy Markdown
Owner

This is the right shape for #6143, and the enforcement half is better than what the issue asked for.

Verified on this head:

  • The lock really was redundant. It only serialized our own two call sites and never protected against any other code importing a submodule first, which is the ordering that produces the inversion. The AST guard covers every source import in src/, so it is strictly stronger than what was removed.
  • Parent-first is now local to the risk. BoundedSemanticChunker.__init__ imports the parent itself instead of trusting callers to have warmed it, so the invariant no longer depends on a documented contract between two files.
  • The guard discriminates. Run against main, it fails and names exactly bounded_semantic_chunker.py:45 — the one submodule import that relied on its caller. It passes here. Per-scope tracking, both import a.b and from a.b import c forms, negative controls that assert the guard rejects submodule-first ordering, and assert scanned > 0 so it can never silently sweep nothing.
  • The safety net is intact. test_text_splitter_concurrency.py is byte-unmodified and still passes — 3/3 runs here, plus 29/29 for the splitter suite.

One note, not a blocker: the guard requires the parent import in the same executable scope, so a module-level parent import will not satisfy a function-level submodule import. That is stricter than the runtime requirement (once the parent is in sys.modules, any later submodule import is safe), and it is the right default for this invariant — but the failure message is worth extending with a one-line hint of the fix, since a future contributor hitting it will reasonably think their module-level import already covers them.

Decision: APPROVED

AI-assisted review.

@LearningCircuit

Copy link
Copy Markdown
Owner

@AbarnaaSree if i squash merge this it will expose your gmail email address are you fine with this? In github there is a setting to always use noreply email addresses you could also do that.

@LearningCircuit

Copy link
Copy Markdown
Owner

@AbarnaaSree converting this temporarily to draft so nothing can happen - awaiting your response than we can merge it.

@LearningCircuit
LearningCircuit marked this pull request as draft September 5, 2026 15:54
@AbarnaaSree

Copy link
Copy Markdown
Contributor Author

Thanks for checking! I’d prefer to keep my Gmail address private. I’ll use my GitHub noreply email instead.

@LearningCircuit
LearningCircuit marked this pull request as ready for review September 5, 2026 19:49
@LearningCircuit
LearningCircuit enabled auto-merge (squash) September 5, 2026 19:49
@LearningCircuit
LearningCircuit merged commit 83be9f0 into LearningCircuit:main Sep 6, 2026
@LearningCircuit LearningCircuit added the follow-up-issues-extracted All eligible follow-up issues have been extracted from the PR review label Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

follow-up-issues-extracted All eligible follow-up issues have been extracted from the PR review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

embeddings: delete the redundant langchain_text_splitters import lock — but only with an enforced parent-first invariant

2 participants