Skip to content

[AAASM-4831] 🐛 (python): Harden langchain handler singleton + haystack positional-arg passthrough#278

Merged
Chisanan232 merged 2 commits into
masterfrom
v0.0.1/AAASM-4831/py_low_cluster
Jul 18, 2026
Merged

[AAASM-4831] 🐛 (python): Harden langchain handler singleton + haystack positional-arg passthrough#278
Chisanan232 merged 2 commits into
masterfrom
v0.0.1/AAASM-4831/py_low_cluster

Conversation

@Chisanan232

@Chisanan232 Chisanan232 commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Description

Two non-exploitable hardening fixes (LOW cluster AAASM-4831) in the python-sdk framework adapters:

  1. langchain (adapters/langchain/runtime.py) — auto_inject_callback_handler kept the module-level singleton for any second call regardless of the interceptor, so a differently-postured re-init without a prior shutdown() would silently reuse the stale handler. It now returns the existing handler only when the interceptor is identical (the matching-params re-init path, unchanged), and warns + clear-and-replaces on a mismatch. init_assembly blocks this path today, so this is defensive hardening for future refactors.

  2. haystack (adapters/haystack/patch.py) — patched_invoke accepted **kwargs only, so a positional Tool.invoke(x) raised TypeError (crash, not a bypass). It now accepts *args and forwards them to the wrapped invoke, so a positional call is governed and forwarded. Haystack's ToolInvoker calls invoke(**final_args) today, so this is defensive but matches the wrapped signature.

Type of Change

  • 🔧 Bug fix

Breaking Changes

  • No

Related Issues

Testing

  • Unit tests added/updated

Added regression tests: (1) re-injecting the langchain handler with a different interceptor warns (RuntimeWarning) and replaces rather than silently keeping the stale one; existing idempotency test updated to use the same interceptor for the matching path. (2) haystack patched_invoke handles a positional arg without TypeError and still governs (allow forwards, deny blocks the wrapped function).

Validation: pytest test/ -k "langchain or haystack" → 183 passed, 3 skipped (haystack real-package tests, not installed); ruff check + ruff format clean; mypy agent_assembly clean on changed files.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Comments added for complex logic
  • All tests passing

🤖 Generated with Claude Code

Chisanan232 and others added 2 commits July 18, 2026 08:49
auto_inject_callback_handler kept the existing module-level singleton for
any second call regardless of interceptor, so a differently-postured
re-init without a prior shutdown() would silently reuse the stale handler.
Return the existing handler only when the interceptor is identical; warn
and replace otherwise. Defensive hardening — init_assembly blocks this
path today (AAASM-4831).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
patched_invoke accepted **kwargs only, so a positional Tool.invoke(x)
raised TypeError instead of being governed and forwarded. Accept *args
and forward them to the wrapped invoke. Haystack's ToolInvoker calls
invoke(**final_args) today, so this is defensive but matches the wrapped
signature (AAASM-4831).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Chisanan232

Copy link
Copy Markdown
Contributor Author

🤖 Claude Code — PR review

Scope (AAASM-4831, LOW): ✅ langchain callback handler warns+replaces on a differing-config re-init (was stale reuse); haystack patched_invoke accepts *args (positional call was a TypeError).

  1. CI — ✅ green (19); 183 pass. 2. Scope — ✅ 2 adapter files + tests. 3. Side effects — none; matching-params path unchanged. 4. FE — n/a.
    Verdict: ready to merge pending Pioneer approval.

@Chisanan232
Chisanan232 merged commit 0495cd5 into master Jul 18, 2026
26 checks passed
@Chisanan232
Chisanan232 deleted the v0.0.1/AAASM-4831/py_low_cluster branch July 18, 2026 06:41
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