Skip to content

fix(agent): isolate MCP transport failures - #365

Merged
gloryfromca merged 3 commits into
mainfrom
fix/agent_response_delivery
Aug 25, 2026
Merged

fix(agent): isolate MCP transport failures#365
gloryfromca merged 3 commits into
mainfrom
fix/agent_response_delivery

Conversation

@gloryfromca

Copy link
Copy Markdown
Contributor

Summary

Prevent a failed MCP transport from cancelling the main agent turn during startup.

Keep each MCP transport and handshake in one lifecycle so SDK task-group failures unwind into ordinary per-server connection errors. Raven can then continue with the remaining MCP servers and enter the model loop.

Type

  • Fix
  • Feature
  • Docs
  • CI / tooling
  • Refactor
  • Other

Verification

  • Relevant tests pass locally

  • Relevant lint / type checks pass locally

  • User-facing docs or screenshots are updated when needed

  • uv run pytest tests/test_sandbox_unit.py -x -q - 70 passed.

  • uv run ruff check raven/agent/tools/mcp.py tests/test_sandbox_unit.py - passed.

  • A real raven agent turn returned RAVEN_FIXED_OK after two configured MCP servers failed authentication.

  • Docs and screenshots are not needed because no user-facing contract changed.

Risk

  • Security impact considered
  • Backward compatibility considered
  • Rollback path is clear for risky changes

The change only alters failure isolation during MCP initialization. Roll back the single fix commit if transport lifecycle behavior regresses.

Related Issues

N/A

@gloryfromca gloryfromca left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: the required diff-coverage gate fails at 79.31%; see the inline note.

Reviewed current head 399a1dfd011d against github/main (b6f3818ae579). I covered AGENTS.md and the Runtime glossary, the complete diff, the AgentLoop startup and shutdown callers through close_mcp(), MCP 1.27.0 transport/session task-group behavior, relevant cancellation-fix history, backward compatibility, and whether tests were weakened. No other blocker or plain error survived refutation: the per-server nested stack unwinds a failed transport/session initialization before iteration continues, keeps successful sessions owned by the existing outer stack, and preserves the public function/config behavior.

Verification:

  • uv run pytest tests/test_sandbox_unit.py -x -q - 70 passed.
  • The new isolation regression fails against github/main and passes on this head.
  • A stronger external-cancellation probe using an AnyIO task group propagated CancelledError correctly.
  • uv run ruff check raven/agent/tools/mcp.py tests/test_sandbox_unit.py - passed.
  • git diff --check and merge-tree checks - clean.
  • GitHub CI executed 6901 tests successfully (33 skipped, 13 deselected), then failed the required changed-line coverage gate.

Comment thread raven/agent/tools/mcp.py

@gloryfromca gloryfromca left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers; this can merge as far as I am concerned.

Reviewed current head 404c4cf4b755 against github/main and the previously reviewed 399a1dfd011d. The new commit is test-only and directly resolves the prior coverage blocker with focused assertions for the SSE client/header path and unknown-transport skip; it does not weaken, skip, or replace the transport-failure tests. I rechecked the repository rules and Runtime terms, the complete diff, the existing AgentLoop ownership/lifecycle callers, relevant history, and backward compatibility. There is no production-code delta from the prior review and no new plain error survived refutation.

Verification:

  • uv run pytest tests/test_sandbox_unit.py -x -q --cov=raven --cov-branch --cov-report=json:/tmp/pr365-404c4cf4-coverage.json - 72 passed.
  • Project diff-coverage gate - 100.00% (29/29), required threshold 90%.
  • uv run ruff check raven/agent/tools/mcp.py tests/test_sandbox_unit.py - passed.
  • git diff --check and merge-tree checks - clean.
  • All GitHub checks are green, including the full unit and coverage job.

@gloryfromca
gloryfromca requested a review from 0xKT August 25, 2026 02:22
@gloryfromca
gloryfromca merged commit 9da50ac into main Aug 25, 2026
9 checks passed
@gloryfromca
gloryfromca deleted the fix/agent_response_delivery branch August 25, 2026 03:05
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.

2 participants