Skip to content

Retain conversation protection in native LangChain retrieval - #904

Merged
zlareb1 merged 6 commits into
mainfrom
test/langchain-callback-protection-baseline
Nov 18, 2026
Merged

zlareb1 merged 6 commits into
mainfrom
test/langchain-callback-protection-baseline

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix

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

  • Wire, schema, settings and dependencies: unchanged.
  • Operator steps: none.
  • Rollback: revert the adapter, helper and guide changes together; the regressions expose the missing retained controls.

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.py in 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

  • Native regressions demonstrate the failure and pass after the correction.
  • Required CI checks pass on the final head.
  • No wire, schema, dependency or operation classification changes are introduced.
  • Commits are signed off.

@zlareb1 zlareb1 changed the title Exercise retained protection in native LangChain callbacks Retain conversation protection in native LangChain retrieval Nov 18, 2026
@zlareb1
zlareb1 marked this pull request as ready for review November 18, 2026 19:51
@zlareb1
zlareb1 merged commit b2824ae into main Nov 18, 2026
45 checks passed
@zlareb1 zlareb1 mentioned this pull request Nov 18, 2026
6 tasks done
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.

1 participant