fix(mcp): actually reuse pooled aiohttp session in _execute_on_server - #996
fix(mcp): actually reuse pooled aiohttp session in _execute_on_server#996groupthinking wants to merge 5 commits into
Conversation
Replaces the `NotImplementedError` in `MCPOrchestrator._execute_on_server` with an actual `aiohttp.ClientSession` based JSON-RPC 2.0 implementation that respects `auth_token` and `timeout` settings from the MCP server configuration. Also updates corresponding tests.
Implements the minor nit from review: uses `self._session` (the pooled session instance) initialized in `start_orchestration`, instead of instantiating an entirely new `aiohttp.ClientSession` object on every single request. This prevents connection pooling anti-patterns.
Implements the minor nit from review: uses `self._session` (the pooled session instance) initialized in `start_orchestration`, instead of instantiating an entirely new `aiohttp.ClientSession` object on every single request. This prevents connection pooling anti-patterns.
PR #994's prior "fix: Use pooled aiohttp session" commits only added pr_description.md and never touched orchestrator.py, so _execute_on_server still opened a fresh aiohttp.ClientSession() per call while the pooled self._session (created in start_orchestration, closed in stop_orchestration) was dead code. Reuse self._session when it is open, and fall back to a temporary per-call session (closed in a finally block) when orchestration isn't running, so direct/one-off execution still works. All 85 tests in tests/unit/test_mcp_orchestrator.py pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CbarUK84Qn5HB1NrVMSC6S
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
Agent Completion Truth Gate: BLOCKEDReasons: Machine-readable verdict{
"details": {
"collection_errors": [
"incomplete_linked_issue_contract",
"missing_linked_issue",
"missing_closing_issue_reference",
"missing_agent_run_id",
"missing_agent_login"
],
"invalid_fields": [
"issue.number",
"policy.agent_login",
"policy.run_id"
]
},
"reasons": [
"invalid_payload"
],
"verdict": "blocked"
} |
CI status: code green, blocked at the governance gate (human/trusted-publication required)Summary of checks on head
The two red checks are not code defects. They require a trusted agent-lock publication carrying a real Code posture: the actual change (reuse the pooled Optional: adding one of the required review labels (e.g. Generated by Claude Code |
Duplicate implementation quarantine — 2026-07-25T16:12:02Z
Preserve this branch as duplicate evidence only. Any useful delta must be ported to the one canonical PR after a focused child issue is bound; do not merge or mark ready independently. |
|
Sequencing: this PR must land before #995. They are stacked, not duplicates. Verified by diff inspection:
That draining fix exists only in #995 and is not reproduced here. Closing #995 as a duplicate of this PR would silently drop a shutdown-safety guarantee. Actions:
Also overlapping: #1040 ("green up MCPOrchestrator._execute_on_server E2E tests") touches |
pr_description.md was inherited from an upstream commit and is a stray authoring artifact (placeholder "Closes #1" and a fake agent-lock manifest), not source: it is imported nowhere and referenced by no CI config. Its content belongs in the PR description field, not the tree. Removing it leaves this branch as the focused orchestrator pooled-session fix. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CbarUK84Qn5HB1NrVMSC6S
|
Acting on the sequencing note, partially: Done (safe, in-scope): dropped Not done (deliberately left to a human): "merge this PR first." I'm not auto-merging, for three reasons:
Sequencing / cross-PR work also left to a human: rebasing #995 onto this and ordering #1040 last touch branches outside this PR's scope; I'll only do that once a maintainer confirms the stack order and binds the governance payload. Net: this branch is cleaned and merge-ready pending the governance/trusted-publication step and a maintainer decision on stack order. Generated by Claude Code |
Closing — branch orphaned by the secret-purge force-pushNo common ancestor with current The work is unlanded — actually reusing the pooled Branch retained for archive-tagging. Generated by Claude Code |
Canonical issue
Closes #
Outcome
MCPOrchestrator._execute_on_servernow actually reuses the pooledaiohttp.ClientSessioncreated instart_orchestration, so orchestrated tasks share TCP/TLS connections instead of paying full connection setup on every call.Why this PR exists: PR #994's two
fix: Use pooled aiohttp sessioncommits (7f53ded,94ee188) only addedpr_description.md— they never touchedorchestrator.py. Verified:git diff 2dc0c61..94ee188 -- src/youtube_extension/services/mcp/orchestrator.pyis empty. So the pooled-session finding raised in the #994 review was reported as fixed but the code still opened a freshaiohttp.ClientSession()per call, leavingself._sessionas dead code (created instart_orchestration, closed instop_orchestration, never used). This PR applies the real fix.Scope
src/youtube_extension/services/mcp/orchestrator.pyRisk
not self._session.closed).Verification
Tied to head
f9a7821:tests/unit/test_mcp_orchestrator.py→ 85 passed (incl.test_execute_on_server_success,test_execute_on_server_handles_http_errors,test_raises_value_error_for_unknown_server)Tests patch
aiohttp.ClientSession.postat class level and call_execute_on_serverdirectly (soself._sessionisNone), exercising the temporary-session fallback path.Production evidence
N/A — backend change verified via unit tests; no runtime/deployment change.
Agent handoff
main, truth-gate)Agent provenance
Agent-authored. A valid
agent-lock-manifestrequires a trusted publication with a realissue_number/agent_login/run_id— the same governance path that blocks #994 (agent-completion/truth-gate→invalid_payload). Fabricating those values to satisfy the gate would defeat its purpose, so this is left for the maintainer/trusted-publication flow rather than filled in the diff.🤖 Generated with Claude Code
https://claude.ai/code/session_01CbarUK84Qn5HB1NrVMSC6S
Generated by Claude Code