Repository navigation
Retain conversation protection in native LangChain retrieval - #904
Merged
Merged
Conversation
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
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.
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
Python LangChain retrievers retain conversation protection across native callbacks and client rebinding.
Why
A retriever can outlive its constructor binding and earlier response observers. Later callbacks must retain those contributors when the current transport binding changes.
Scope and risk
The retriever uses the existing callback protection helper, initialized through the native model lifecycle. Each callback retains its entry binding before search conversion, authentication or worker dispatch. Ambient automatic context guards retained contributors; directly invoked retrieval and selected retriever tools remain explicit and observe responses.
A mirrored result marks retained contributors before documents return. Failed durable marking withholds the result, and a protected contributor stops later automatic retrieval or serial native batches. Search calls, filters, identities, abstention, native documents and synchronous-agent routing are unchanged. Independent conversation families need separate retrievers.
The guide documents these boundaries. All 79 regression cases from the hosted failing baseline remain unchanged. A controlled concurrent native-callback case exposes the shared helper's lost update. The helper resolves entry contributors before taking a lock, then merges them with the latest retained tuple under that lock. Observer resolution, SDK work and response marking run outside the lock. No sender exception, collector or classification changes are introduced.
Compatibility, rollout and rollback
Tests
Hosted native baselines reproduce 54 retention failures and 25 passes on both supported dependency legs. A further concurrent native-callback regression reproduces the helper's lost contributor as one failure and 79 passes on both legs. All earlier inputs and assertions are retained.
The final 80-case module passes with langchain-core 1.8.3 on Python 3.12 in 3.55 seconds and 1.0.0 on Python 3.11 in 1.38 seconds. Strict adapter typing passes on both legs. Reproduce with
cd sdk/python && python -m pytest -q tests/test_langchain.pyin each supported native environment.The concurrent case stages real native callbacks with a fixed client binding and checks the later refusal after marking the retained contributor. Its coordination helper owns thread start, staged entry, release and bounded cleanup. Inlining the helper restores the complete regression body, preserving every assertion and input. Search calls, payload builders, document conversion and sender classifications remain unchanged.
Changed-file Ruff lint and formatting, strict mypy, guide formatting, whitespace and prose checks pass. The hosted function-size gate passes. No local native tests, collection, application imports or dependency installation ran.
Fresh independent review of all four files reports no findings or nits. All 45 check results are terminal: 43 successes and two expected publication skips. All four workflows succeed; all 44 underlying jobs are terminal, with 42 successes and those two publication skips.
AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated: An agent wrote the change. The complete diff and baseline evidence were checked; fresh independent review has no findings or nits, and corrected native execution and full hosted CI pass.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist