Skip to content

[AAASM-4746] ♻️ (adapters): De-duplicate google_adk/pydantic_ai parallel adapters - #271

Merged
Chisanan232 merged 3 commits into
masterfrom
v0.0.1/AAASM-4746/dedup_adapters
Jul 17, 2026
Merged

[AAASM-4746] ♻️ (adapters): De-duplicate google_adk/pydantic_ai parallel adapters#271
Chisanan232 merged 3 commits into
masterfrom
v0.0.1/AAASM-4746/dedup_adapters

Conversation

@Chisanan232

@Chisanan232 Chisanan232 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Description

Pure refactor that de-duplicates the near-identical parallel adapters
agent_assembly/adapters/google_adk/patch.py and
agent_assembly/adapters/pydantic_ai/patch.py. SonarCloud reported cross-file
duplicated blocks (up to ~126 lines) between them — the root of the waived
SonarCloud new-dup on PR #269.

The shared async tool-governance flow (arg serialization, verdict
normalization, the pending approval round-trip, deny-by-raise, the
spawn-context-scoped original call, and result recording) plus its leaf helpers
are extracted into a new private module
agent_assembly/adapters/_shared/tool_governance.py, exposing a single
run_governed_async_tool(...) orchestrator that each adapter drives via a
framework-specific invoke_original callable. Each adapter now keeps only its
own glue: class loaders, patched-flag constants, _resolve_agent_id /
_resolve_run_id, the agent-run/toolset patches, and the per-adapter process
agent-id global.

The openai_agents adapter was intentionally left out of the extraction: its
deny path returns a string to the model (rather than raising), wraps the flow in
a governance-error try/except, and records-before-return — sharing it would
change observable behavior, so it stays on its own copy.

Behavior is unchanged. The AAASM-4734 fail-closed-under-enforce fix is
preserved exactly: enforce is threaded into the shared flow and a
check_tool_start-less interceptor still falls back to
_missing_interceptor_decision, so all four adapters continue to deny under
enforce on an unrecognized verdict / missing check_tool_start. Shared helpers
are re-imported into each adapter module (and listed in __all__) so the
existing unit tests, which reach these helpers through the adapter module, keep
working untouched.

Duplication removed: google_adk/patch.py 405 → 248 lines, pydantic_ai/patch.py
620 → 431 lines (−346 duplicated lines total); the shared flow now lives in one
244-line module.

Type of Change

  • ♻️ Refactoring

Breaking Changes

  • No

Related Issues

Testing

  • Unit tests added/updated — no test changes needed; the adapter test suite
    is unchanged and exercises the shared flow through both adapters.
  • Integration tests added/updated
  • Manual testing performed — .venv/bin/python -m pytest test/unit/adapters -q
    379 passed, 3 skipped (matches the pre-refactor baseline). ruff check,
    ruff format --check, and per-file mypy are clean on all touched files.
  • No tests required (explain why)

Checklist

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

Fixes AAASM-4746

Extract the async tool-governance flow (arg serialization, verdict
normalization, pending-approval round-trip, deny-by-raise, spawn-scoped
original call, result recording) that Google ADK and Pydantic AI adapters
duplicated verbatim into one framework-agnostic helper. Preserves the
AAASM-4734 fail-closed-under-enforce contract by threading enforce and
reusing the CrewAI _missing_interceptor_decision fallback.

Refs AAASM-4746
Replace the adapter's local copies of the async tool-governance flow and its
leaf helpers with the shared _shared.tool_governance module; the patched
run_async now supplies only the framework-specific invoke_original callable.
Shared helpers are re-imported (and listed in __all__) so the adapter's unit
tests still reach them through this module. Behavior unchanged.

Refs AAASM-4746
Replace the adapter's local copies of the async tool-governance flow and its
leaf helpers with the shared _shared.tool_governance module; both the Tool._run
and toolset call_tool patches now supply only a framework-specific
invoke_original callable. Shared helpers are re-imported (and listed in
__all__) so the adapter's unit tests still reach them through this module.
Behavior unchanged.

Refs AAASM-4746
Comment thread agent_assembly/adapters/_shared/tool_governance.py
Comment thread agent_assembly/adapters/_shared/tool_governance.py
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

Copy link
Copy Markdown

@Chisanan232

Copy link
Copy Markdown
Contributor Author

Claude Code — automated review

CI: All green — and SonarCloud gate now OK (new-code duplication resolved), retiring the acceptance-tier waiver from #269 at its root.
Scope (AAASM-4746): shared async tool-governance extracted to agent_assembly/adapters/_shared/tool_governance.py; google_adk 405→248 and pydantic_ai 620→431 (~346 duplicated lines, incl. the 126-line block Sonar flagged, now single-sourced). openai_agents correctly left out (different deny semantics — raises string vs exception).
Side effects: none — 379 adapter tests pass (identical to pre-refactor baseline); the AAASM-4734 fail-closed behavior is preserved (enforce threaded + _missing_interceptor_decision fallback intact).
Verdict: ✅ Ready to merge.

@Chisanan232

Copy link
Copy Markdown
Contributor Author

Claude Code — review result (final pass)

CI: all checks green. Scope: matches the ticket. Side effects: none — green full-suite CI validates no existing-function/business-logic breakage. Front-End: no FE/dashboard code touched, so no Playwright validation applies. Verdict: ✅ ready to approve & merge.

Review comments: github-code-quality bot flagged 2 "statement has no effect" on _shared/tool_governance.py:147,159 (the await recorded lines). Assessed as false positives and replied + resolved both threads — await recorded is guarded by inspect.isawaitable and drives the audit coroutine to completion (effectful; return intentionally discarded). SonarCloud Quality Gate passed (the #269 duplication is now resolved at the root).

@Chisanan232
Chisanan232 merged commit 2b0ba48 into master Jul 17, 2026
26 checks passed
@Chisanan232
Chisanan232 deleted the v0.0.1/AAASM-4746/dedup_adapters branch July 17, 2026 06:22
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