Skip to content

fix(approval,mcp): log silent exception handlers, narrow OAuth catches, close server on error - #6924

Closed
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/approval-mcp-oauth-safety-v2
Closed

fix(approval,mcp): log silent exception handlers, narrow OAuth catches, close server on error#6924
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/approval-mcp-oauth-safety-v2

Conversation

@aaronlab

Copy link
Copy Markdown
Contributor

Summary

  • approval.py: Three except Exception blocks (lines 345, 387, 469) silently return fallback values (set(), "deny", {}) with zero logging — making callback failures, allowlist load errors, and config read issues impossible to diagnose. Added logger.warning/logger.error calls consistent with the existing pattern used by save_permanent_allowlist() (line 357) and _smart_approve() (line 535) in the same file.

  • mcp_oauth.py – get_tokens() / get_client_info(): Narrowed overly-broad except Exception to (ValueError, TypeError, KeyError) — the specific exceptions Pydantic's model_validate() raises for corrupt data. The broad catch previously swallowed unexpected errors (e.g. MemoryError, filesystem bugs) that should propagate. Also added the exception message to the warning log.

  • mcp_oauth.py – _wait_for_callback(): Wrapped the polling loop in try/finally so server.server_close() is always called. Previously, an asyncio.CancelledError or any exception during await asyncio.sleep() would skip the close and leak the HTTPServer socket.

Test plan

  • Verify approval callback works normally (no regression in interactive approval flow)
  • Verify MCP OAuth flow still completes (tokens saved/loaded correctly)
  • Inject a broken approval callback and confirm the error is now logged
  • Cancel an OAuth flow mid-wait and confirm the server socket is cleaned up

🤖 Generated with Claude Code

…s, close server on error

Three silent `except Exception` blocks in approval.py (lines 345, 387, 469) return
fallback values with zero logging — making it impossible to debug callback failures,
allowlist load errors, or config read issues.  Add logger.warning/error calls that
match the pattern already used by save_permanent_allowlist() and _smart_approve()
in the same file.

In mcp_oauth.py, narrow the overly-broad `except Exception` in get_tokens() and
get_client_info() to the specific exceptions Pydantic's model_validate() can raise
(ValueError, TypeError, KeyError), and include the exception message in the warning.
Also wrap the _wait_for_callback() polling loop in try/finally so the HTTPServer is
always closed — previously an asyncio.CancelledError or any exception in the loop
would leak the server socket.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #7094. Your commit was cherry-picked onto current main with your authorship preserved in git log. All three fixes (approval logging, narrowed OAuth catches, server_close in finally) address real issues. Thanks!

@teknium1 teknium1 closed this Apr 10, 2026
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