← Back to Pull requests

fix: preserve public built-in tool declarations in Responses metadata #451

Closed
unknown closed this pull request without merging on Oct 19, 2026 10:09 UTC
View on GitHub
unknown unknown commented on Oct 16, 2026 08:19 UTC
Author

summary

fixes #442.

built-in tools are lowered to function schemas before inference, and the model server echoes those schemas back. the public metadata snapshot was only supplied when tool search was active, or when the request declared a shell or async tool. a request declaring web_search_preview therefore got this back in its lifecycle snapshots:

{"type": "function", "name": "web_search"}

cassettes/parallel_tool_calls/parallel-mixed-gateway-Qwen-Qwen3.5-35B-A3B-FP8-streaming.yaml has it on response.created and response.in_progress, and the nonstreaming sibling carried no declarations at all.

three changes:

  • executor/upstream.rs: always pass the request's public declarations to with_response_metadata. the tool search branch stays first because that path replaces request.tools with the private list. sanitization stays inside with_response_metadata, so mcp headers and discovered tools still never reach clients.

  • executor/translate/tool_search.rs: insert the declarations when a lifecycle snapshot has no tools key, instead of leaving the [] default that complete_response_fields supplies. cassettes/web_search/web-search-gateway--streaming.yaml and cassettes/images/responses/image-tool-image-gateway-.yaml are recorded turns whose terminal frame has no tools key even though the request declared tools.

  • executor/translate/context.rs: same for tool_choice, so a gateway default cannot be reported for a client that asked for something else.
  • inference is unchanged. upstream requests still carry the lowered function schemas, and the declarations are reported as the typed public values the client sent rather than openai's normalized defaults.

    the gateway relaxes a forced selector to auto before the round that answers a tool result (engine/agent_turn.rs:357), so which round is authoritative for a single public response is left to #434.

    test plan

    four new tests, each failing without the change it covers:

  • cargo test -p agentic-server-core --lib builtin_tool_declarations_stay_public_in_stream_and_json_metadata covers response.created, a terminal frame with both keys missing, and the nonstreaming payload.

  • cargo test -p agentic-server-core --test web_search_tool_test builtin_tool_declarations covers the streaming lifecycle with the lowered echo, json plus stored retrieval, and a model server that omits the keys.
  • i reverted each production hunk on its own to confirm the tests are load bearing:

    | reverted | failing tests |
    | --- | --- |
    | snapshot gate in upstream.rs | all four |
    | declaration insert in translate/tool_search.rs | the omitted-frame test, which returns [] |
    | selector insert in translate/context.rs | the unit test, which returns auto |

    also ran cargo fmt -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (2423 passed), and pre-commit run --all-files including the production file-size check.

    recording gap

    the committed gateway web-search and parallel-tool captures were recorded before this change, so their response.created/response.completed frames still carry the lowered web_search schema. they are kept unchanged as evidence of the original behavior, and the new assertions run against synthetic upstream frames plus replays of those captures.

    re-recording them so the parity harness asserts the new wire shape needs a live vllm deployment and a working search provider, which this environment does not have. the path for whoever can run it:

  • gateway leg: crates/agentic-server-core/tests/cassettes/record_web_search_cassettes.sh

  • parallel-tool set: crates/agentic-server-core/tests/cassettes/record_parallel_tool_call_cassettes.sh with PARALLEL_RECORD_SET=gateway
  • once re-recorded, parallel_tool_calls_test.rs and web_search_tool_test.rs compare the public declarations in response.created, response.completed and the final response against the openai reference directly.

    Diff: 498 lines (+373 / -125) across 6 files Reviewer: franciscojavierarceo Review duration: 4430m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 498 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.372
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #451"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.5% (MEDIUM) · Higher = larger blast radius
    47.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.8% · Safe to merge
    18.8%