Files
Mansurshakh JaparovandJerrettDavis cde584d7fe fix(langchain): check optional integration availability (#4042)
## Description

Closes #4039.

The optional integration uses the existing LANGCHAIN_AVAILABLE guard;
installed LangChain binding precedence remains intact. Current head:
`ac9e49af43501d2b3bbb6d0a21cb07fe94030bc9`, normally updated onto main
`f1bc`.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [x] Documentation update

## Changes Made

- Install langchain-core in the existing CI lint job, with the
optional-extra version range, so the normal mypy invocation covers the
integration. Remove the pytest-launched mypy subprocess.
- Keep our nested unwrap-precedence regression (sync and async) and two
real loopback HTTP cases: bind_tools and nested caller-overrides. Remove
the vendor tool-response/usage-parsing matrix, as requested by the
maintainer.
- Replace the private LiteLLM cache invalidator with the public
register_model API; preserve the independent cost_per_token billing
oracle and fixture/catalog restoration.
- Correct the compatibility doc numbering and document the normal typing
path in CONTRIBUTING.
- Preserve the published startup SDK/provider module and parent-package
restoration fixes.

## Testing

- [ ] Unit tests pass (pytest) — no whole-project suite pass claimed.
- [ ] Linting passes (ruff check .) — changed-file Ruff passed; no new
whole-repository Ruff claim.
- [x] Type checking passes (mypy headroom)
- [x] Manual testing performed

### Test Output

Current published head, Python 3.13.14, installed langchain-core 1.6.10,
langchain-openai 1.7.1, LiteLLM 1.105.0 and a fresh native build:

`python -m pytest tests/test_integrations/langchain/test_binding_http.py
tests/test_integrations/langchain/test_langchain_1x_compat.py
tests/test_startup_log_noise.py tests/test_xai_cache_economics.py -q`

```text
28 passed, 1 skipped in 14.73s
```

The skip is optional trafilatura unavailable. A SQLite ResourceWarning
was emitted at interpreter teardown; it is not suppressed or claimed
fixed.

Normal mypy command in an isolated lint environment with mypy 1.20.2 and
installed langchain-core: success, no issues in 569 source files. This
local lint environment uses Python 3.14; the runtime consumer suite uses
Python 3.13.14. Existing untyped-body/unused-ignore notes remain.

Ordinary push gates: Rust workspace tests, fresh native extension build,
181 critical Python tests, and commitlint passed. Two prior normal
publication attempts failed seven native parity cases; neither was
bypassed or repinned. Publication passed with a separate clean Cargo
target. This establishes the successful isolated build, not a proven
root cause for the earlier build discrepancy.

## Real Behavior Proof

- Environment: installed SDKs, actual localhost HTTP server, no
provider-network or billing requests.
- Exact command / steps: an independent runtime driver invoked
HeadroomChatModel with bind_tools and nested RunnableBinding objects
against the real local ChatOpenAI transport; the retained HTTP
regressions exercised both cases again on the published head.
- Observed result: two actual requests; bind_tools sent lookup; nested
caller temperature 0.3 won, and inner top_p 0.8 survived. The sync/async
unwrap regression retains the real RunnableBinding precedence check. The
pricing oracle and startup teardown regressions passed.
- Not tested: live provider invoices, paid requests, remote production
deployment, or current-head hosted CI completion. Historical CI/approval
is not attributed to this new head.

## Runtime Rollout Safety

- Rollout-managed feature(s): none; optional integration guard and test
isolation.
- Minimum rollout channel: N/A.
- Stable/default behavior changed: no binding precedence, runtime
defaults, authentication or serialization changes; CI lint now
explicitly installs the existing optional typing dependency.
- Kill switch / disable path: existing optional extra remains optional;
no new runtime switch.
- Unsafe override required: no.
- Qualification impact: optional-extra typing and real binding consumers
are exercised; normal local native/critical gates passed.
- Rollback path: revert the bounded guard/CI/test edits; no
persistent-state migration.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have made corresponding changes to the documentation
- [x] I did not edit CHANGELOG.md — release-please owns it

## Additional Notes

AI-assisted without subagents. No force push, skipped hook, new approval
or merge. The reduced HTTP scope follows the maintainer's explicit
request:
https://github.com/headroomlabs-ai/headroom/pull/4042#issuecomment-6157529674
.


### Maintainer current-main requalification

Exact head `ff329f3e487940f85d56ba0b35bd9994afadb506`, upstream main
`c01cf07d943d816cfd9d97e6838ed4e38f1ff9a4`.

Requalified against upstream main
c01cf07d94. The only merge conflict
combined main's Python 3.11 minimum with the contributor's
optional-integration typing guidance; both retained. No contributor
availability/binding policy rewritten. Current author/chopratejas/Devin
discussion reviewed, including the intentional removal of vendor-owned
response-parsing coverage. Nested binding precedence, real loopback HTTP
controls, public LiteLLM register_model isolation, independent billing
oracle and parent-module restoration remain covered.

Fresh focused tests: 29 passed with installed langchain-core 1.4.2 and
langchain-openai 1.2.2. Full mypy against the Linux CI target checked
580 source files: PR reports 22 errors; an actual detached current-main
run with the same environment reports those same 22 plus a
RunnableBinding truthy-function error that this PR removes. The 22
shared errors are in unrelated unchanged prefix-tracker, optional
memory/MCP and CrewAI modules; they are not contributor blockers and
this is not a clean full-mypy claim. Five changed Python files pass Ruff
lint/format and main-relative whitespace checks. Current-main DLL
supports local startup, without a branch-specific native-build or live
model-provider claim. No new source blocker; approval awaits exact-head
hosted qualification. Nothing merged.


Exact-head hosted checks are being handled by maintainers. No new
finding in the reviewed scope; formal approval awaits exact-head hosted
qualification; nothing merged.

---------

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-11-06 09:24:06 -06:00
..