Skip to content

fix(discovery): bound tool-call probe response reads (#1041) - #1131

Draft
seonghobae wants to merge 1 commit into
mainfrom
fix/discovery-probe-response-bounds-1041
Draft

seonghobae wants to merge 1 commit into
mainfrom
fix/discovery-probe-response-bounds-1041

Conversation

@seonghobae

Copy link
Copy Markdown
Contributor

Summary

Closes the last unbounded provider-body read in model discovery. probe_discovered_model_tool_call_capability read both its success body and its HTTP 400 error body with a bare response.read(), while every sibling fetch (_fetch_json, _fetch_json_same_host_https, _fetch_configured_gateway_json) caps its read at MAX_DISCOVERY_RESPONSE_BYTES. A compromised or misbehaving provider could therefore stream an arbitrarily large body into memory during a capability probe.

Changes

  • contextual_orchestrator/model_discovery.py
    • Success body read is capped at MAX_DISCOVERY_RESPONSE_BYTES + 1; an oversized body is treated as ambiguous evidence and returns None (fail-closed), never buffered whole.
    • HTTP 400 error body read uses the same cap; an oversized error body returns None.
    • Docstring documents the untrusted-input bound.
  • tests/test_model_discovery_boundaries.py
    • RED-first: caps success-body read, rejects oversized success body without buffering, caps 400 rejection body read, and preserves the in-budget explicit single-call rejection (False).
    • Focused suite: 25 passed.

Verification

  • pytest tests/test_model_discovery_boundaries.py -q -> 25 passed
  • pytest tests/test_model_discovery.py tests/test_model_discovery_boundaries.py tests/test_discover_models_cli.py -q -> 169 passed
  • Full suite: pytest -q -> 3497 passed, 2 skipped
  • python -m compileall -q contextual_orchestrator tests -> clean; git diff --check -> clean

Scope

Independent slice under #1041, branched from origin/main (abc2dea8) in its own worktree. Does not touch the PR #1121 review head. ModelClient default transport and EgressWeave adoption remain a separate design item.

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant