Skip to content

fix(langchain): restore optional Protect hook on uninstrument - #393

Merged
nik13 merged 4 commits into
devfrom
fix/langchain-python-protect-lifecycle
Nov 9, 2026
Merged

nik13 merged 4 commits into
devfrom
fix/langchain-python-protect-lifecycle

Conversation

@nik13

@nik13 nik13 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Keep and repair traceAI-langchain; do not retire the callback integration for this lifecycle defect.

LangChainInstrumentor.instrument() saves and wraps the optional Protect.protect, but dev restores only the callback-manager constructor on disable. Guardrail exports therefore continue after uninstrument(), and later enable cycles retain old wrappers/providers/configuration.

  • Retain the optional class that was actually patched; restore its captured method on disable without importing the optional dependency again.
  • Clear the captured method/class after cleanup.
  • Preserve public APIs, callback registration, application results/exceptions and span semantics. Privacy defaults are unchanged; disabling now stops guardrail exports.
  • Add ten real callback/OTLP lifecycle contracts, including two independent ownership checks: replacing the optional class cannot redirect cleanup to the replacement, and a dependency that was absent at enable time is not modified when it appears before disable.

Five runtime lines. No dependencies, package versions, CHANGELOG, public APIs or shared CI files changed. Current dev 7c719369577243ee37e4688432f460d25b6b34cd is merged cleanly; qualified/pushed head is d34e836e7a824d3dfabee673c03eb630a144900b.

Current-base cloud requalification — 2026-11-09

All installs/tests ran in E2B or GitHub Actions, never on the local workstation. E2B used Python 3.12.16 and the current source core fi-instrumentation-otel==1.3.0 from the exact merged head. Both dependency environments passed python -m pip check.

Framework tuple Dev + final lifecycle tests Head lifecycle tests Dev full package + final tests Head full package
langchain-core==0.2.43, langgraph==0.2.0 9 failed / 1 passed 10 passed 75 passed / 23 failed / 2 skipped 84 passed / 14 failed / 2 skipped
Latest resolved: langchain-core==1.7.6, langgraph==1.2.20, deepagents==0.7.34 9 failed / 1 passed 10 passed 103 passed / 9 failed / 1 skipped 112 passed / 1 skipped

The original eight wire-level contracts cover exact method restoration, disabled exports, three enable/disable cycles, provider/config replacement, hidden inputs/outputs, absent or disappearing optional dependency, idempotence, unchanged application results/exceptions, and OTLP parent context/status/counts. The two additional tests pin class ownership and cleanup state.

The 14 historical floor failures remain explicitly unresolved. Their test IDs and failure messages are identical on current dev and head: six missing langgraph.types interrupt/command APIs, one missing langgraph.store API, and seven historical error-output expectations (KeyError: 'output.value'). All other existing test outcomes match between dev and head at both bounds. This is not an all-green historical-floor compatibility claim. No existing assertion was weakened and no skip/xfail was added. The floor skips are absent Deep Agents plus the existing opt-in resolver test; latest skips only the resolver test.

Only the evaluation service is synthetic. The LangChain callbacks, guardrail wrapper, OTLP serialization and loopback HTTP receiver are real. Test processes ran with an empty inherited environment, isolated home and an in-process loopback-only socket guard, with IPv4/IPv6/DNS denial probes. The cookbook subprocess uses the repository's synthetic model and loopback receiver; the parent-process socket guard is not claimed as OS-level confinement. No real provider credentials or model/vendor calls were used.

The successful exact-head E2B rerun is qw-393-current-base-fix-1109: exit 0; sandbox deletion and subsequent 404 confirmed. Source-core and package files were staged from the exact merged head with a SHA-256 source manifest. JUnit XML, resolved freezes, comparison output and source receipt are retained in the fetched results.tgz.tgz archive (the outer download archive contains results.tgz).

Readiness finding resolved: current base integration

The prior independent review found no implementation defect; it blocked only because four new core credential-header commits on dev were not included. Merge commit d34e836e7a824d3dfabee673c03eb630a144900b integrates current dev without conflicts. No additional runtime/test modifications were needed: the ten existing lifecycle contracts were rerun against the merged source core.

The added readiness regression check fails on the reviewed head and passes on the merged head:

git merge-base --is-ancestor 7c719369577243ee37e4688432f460d25b6b34cd 5579678674f3bf1e6caeb0915252e42af53c8257
# exit 1: prior reviewed head did not include current dev
git merge-base --is-ancestor 7c719369577243ee37e4688432f460d25b6b34cd d34e836e7a824d3dfabee673c03eb630a144900b
# exit 0: qualified head includes current dev
git diff --check 7c719369577243ee37e4688432f460d25b6b34cd...d34e836e7a824d3dfabee673c03eb630a144900b
# exit 0

The remote head was checked immediately before the non-force push and matched the previously reviewed head. The live dev reference remained 7c719369577243ee37e4688432f460d25b6b34cd at the final readiness check.

Reproduce in a disposable cloud checkout

Run each tuple in a fresh Python 3.12 environment. Keep python/tests/harness in the checkout because the Deep Agents cookbook test imports it.

python -m pip install -e ./python -e ./python/frameworks/langchain \
  'pytest==8.3.5' 'pytest-asyncio==0.23.8' \
  'langchain-core==0.2.43' 'langgraph==0.2.0'
# Latest cell: replace the final two pins with these three:
# 'langchain-core==1.7.6' 'langgraph==1.2.20' 'deepagents==0.7.34'
python -m pip check
export FI_BASE_URL=http://127.0.0.1:9 FI_GRPC_URL=http://127.0.0.1:9
export LANGCHAIN_TRACING_V2=false
python -m pytest python/frameworks/langchain/tests/test_protect_lifecycle.py \
  -q -p no:cacheprovider -o addopts=''
python -m pytest python/frameworks/langchain/tests \
  -q -p no:cacheprovider -o addopts=''

For the dev comparison, keep the final tests and replace only the changed runtime file with git show 7c719369577243ee37e4688432f460d25b6b34cd:python/frameworks/langchain/traceai_langchain/__init__.py in the disposable checkout; remove Python bytecode caches and run both commands again. That file is the only runtime difference. The E2B harness ran these same pytest arguments via pytest.main, added JUnit XML output, and compared every existing test outcome plus the floor failure messages. Resolved dependency freezes, XML and full logs are retained with the run receipt.

GitHub verification on the qualified head

All 10 executed checks completed green (13 other jobs skipped) on d34e836e7a824d3dfabee673c03eb630a144900b; unselected language/publication jobs are skipped, not claimed as executed.

  • Python package CI: 89 passed / 11 existing skips in the package suite, including all ten lifecycle contracts; 35 passed in the mapped framework suite.
  • Deep Agents and core privacy: 147 passed / 1 existing skip with source core; 138 passed / 10 existing skips with the workflow's published-core compatibility cell.
  • Core instrumentation, Python aggregate, integration plan/aggregate, conventional title and release planning checks passed. n8n was not selected on this head; no previous-head result is counted as current qualification.
  • git diff --check passed. No applicable Ruff configuration, frontend contract change or migration is present.

Review and release boundary

The prior independent review assessed the implementation against the applicable full internal coding standards at future-agi/internal-docs@64a741425b77922873f629bdb9416205fe2f9139: minimal code, typing, failure paths, PR scope, naming, testing, comments, banned patterns and structure. No introduced correctness blocker was found; its sole readiness finding was current-base integration, resolved and requalified above. No frontend, migration, API contract, tenant isolation or OSS/EE boundary changes.

E2E coverage: not applicable (no e2e/ harness); flows hit: n/a; marker: n/a; verdict: not applicable. The real callback/OTLP lifecycle tests are the relevant integration coverage.

The PR is non-draft and prepared for reviewer/coordinator action, not approved or merged by this qualification. Release-please owns the eventual package version; no tag or publication was performed. Historical floor compatibility debt is not silently waived. No new ticket ID was invented for this existing PR.

Generated with Claude Code

Retain the captured Protect class so disabling tracing restores its method without another optional dependency import. Clear the saved state before re-enabling to avoid stacked guardrail wrappers and stale provider/config exports.

Add offline lifecycle contracts with real LangChain callbacks and OTLP HTTP exports across enable/disable cycles.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@nik13
nik13 marked this pull request as ready for review October 31, 2026 14:54
nik13 and others added 3 commits November 9, 2026 14:43
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@nik13
nik13 merged commit 604a67a into dev Nov 9, 2026
33 checks passed
@nik13
nik13 deleted the fix/langchain-python-protect-lifecycle branch November 9, 2026 23:32
nik13 added a commit that referenced this pull request Nov 10, 2026
… traceAI-langchain 0.2.2, Java 1.0.3 (#636)

* chore(release): bump core, OpenAI, LangChain and Java patch versions

Synchronize runtime versions, reactor parent references and release changelogs for #155, #348, #397, #393 and #425. Dependency floors are unchanged.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* chore(release): list every change shipping in core 1.3.1, OpenAI 0.1.14 and Java 1.0.3

Core 1.3.1 also ships the PII-redaction scoping fixes (#195/#244) that sat under
Unreleased, and the 1.3.0 heading gets its release date. OpenAI 0.1.14 also
ships the Azure metadata (#154), Baseten (#541), Azure Government (#502),
OpenRouter host (#547), full multi-message input (#245) and exhausted-stream
changes. Java 1.0.3 also ships #543 and #605. Notes the remaining blank
OTEL-env Authorization limitation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Code <noreply@anthropic.com>
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