-
Notifications
You must be signed in to change notification settings - Fork 32
fix(launch): tier backend formats come from the preset, not launcher overrides #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryan-lempka
wants to merge
1
commit into
main
Choose a base branch
from
rlempka/switch-687-preset-owns-tier-formats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Zero-flag launcher configs keep Anthropic prompt caching on the wire. | ||
|
|
||
| The preset's strong tier is a Claude model with ``format=auto``. Built through | ||
| the launcher route builder and the deterministic profile, its outbound | ||
| ``/v1/messages`` body must carry ``cache_control`` markers even for an | ||
| OpenAI-shaped harness; the weak tier stays OpenAI format with no markers. | ||
| """ | ||
| import json | ||
| import threading | ||
| from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer | ||
|
|
||
| import pytest | ||
|
|
||
| from switchyard.cli.config.user_config import LaunchRouteConfig | ||
| from switchyard.cli.routing.route_builder import ( | ||
| LaunchTierConnectivity, | ||
| build_deterministic_routing_config, | ||
| ) | ||
| from switchyard.lib.backends.anthropic_cache_breakpoint_backend import ( | ||
| AnthropicCacheBreakpointBackend, | ||
| ) | ||
| from switchyard.lib.backends.deterministic_routing_llm_backend import ( | ||
| DeterministicRoutingLLMBackend, | ||
| ) | ||
| from switchyard.lib.profiles.deterministic_routing_profile_config import ( | ||
| DeterministicRoutingProfileConfig, | ||
| ) | ||
| from switchyard.lib.proxy_context import ProxyContext | ||
| from switchyard_rust.core import ChatRequest | ||
|
|
||
| CAPTURED = [] | ||
|
|
||
|
|
||
| class Upstream(BaseHTTPRequestHandler): | ||
| def do_POST(self): | ||
| body = json.loads(self.rfile.read(int(self.headers.get("content-length", 0)))) | ||
| CAPTURED.append({"path": self.path, "body": body}) | ||
| if self.path.endswith("/v1/messages"): | ||
| resp = {"id": "m1", "type": "message", "role": "assistant", "model": body.get("model"), | ||
| "content": [{"type": "text", "text": "ok"}], "stop_reason": "end_turn", | ||
| "usage": {"input_tokens": 1, "output_tokens": 1}} | ||
| else: | ||
| resp = {"id": "c1", "object": "chat.completion", "model": body.get("model"), | ||
| "choices": [{"index": 0, "message": {"role": "assistant", "content": "ok"}, | ||
| "finish_reason": "stop"}], | ||
| "usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2}} | ||
| data = json.dumps(resp).encode() | ||
| self.send_response(200) | ||
| self.send_header("content-type", "application/json") | ||
| self.send_header("content-length", str(len(data))) | ||
| self.end_headers() | ||
| self.wfile.write(data) | ||
|
|
||
| def log_message(self, *a): | ||
| pass | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def upstream(): | ||
| server = ThreadingHTTPServer(("127.0.0.1", 0), Upstream) | ||
| t = threading.Thread(target=server.serve_forever, daemon=True) | ||
| t.start() | ||
| yield f"http://127.0.0.1:{server.server_port}/v1" | ||
| server.shutdown() | ||
|
|
||
|
|
||
|
|
||
|
|
||
| async def test_launcher_preset_path_emits_cache_control_on_strong(upstream) -> None: | ||
| config = build_deterministic_routing_config( | ||
| LaunchRouteConfig(type="deterministic"), | ||
| primary=LaunchTierConnectivity(base_url=upstream, api_key="sk-test"), | ||
| weak=LaunchTierConnectivity(base_url=upstream, api_key="sk-test"), | ||
| classifier_model=None, | ||
| profile_name=None, | ||
| classifier_min_confidence=None, | ||
| timeout=30.0, | ||
| ) | ||
| assert config.strong.model == "anthropic/claude-opus-4.7" | ||
| assert str(config.strong.format).lower().endswith("auto") | ||
|
|
||
| profile = ( | ||
| DeterministicRoutingProfileConfig.from_config(config) | ||
| .build() | ||
| .with_runtime_components(enable_stats=False) | ||
| ) | ||
| backend = next( | ||
| c for c in profile.iter_components() | ||
| if isinstance(c, DeterministicRoutingLLMBackend) | ||
| ) | ||
| assert isinstance(backend._backends["strong"], AnthropicCacheBreakpointBackend) | ||
| assert not isinstance(backend._backends["weak"], AnthropicCacheBreakpointBackend) | ||
|
|
||
| CAPTURED.clear() | ||
| request = ChatRequest.openai_chat({ | ||
| "model": "inbound", | ||
| "messages": [ | ||
| {"role": "system", "content": "You are a coding agent."}, | ||
| {"role": "user", "content": "hello"}, | ||
| ], | ||
| }) | ||
| ctx = ProxyContext() | ||
| response = await backend._backends["strong"].call(ctx, request) | ||
|
ryan-lempka marked this conversation as resolved.
|
||
| assert response is not None | ||
|
|
||
| strong_calls = [c for c in CAPTURED if c["path"].endswith("/v1/messages")] | ||
| assert strong_calls, f"no anthropic call captured; saw {[c['path'] for c in CAPTURED]}" | ||
| body = strong_calls[-1]["body"] | ||
| flat = json.dumps(body) | ||
| assert '"cache_control"' in flat and '"ephemeral"' in flat, ( | ||
| f"cache_control missing from wire body: {flat[:400]}" | ||
| ) | ||
|
|
||
| CAPTURED.clear() | ||
| await backend._backends["weak"].call(ctx, request) | ||
| weak_calls = [c for c in CAPTURED if c["path"].endswith("/v1/chat/completions")] | ||
| assert weak_calls, f"no chat call captured; saw {[c['path'] for c in CAPTURED]}" | ||
| assert "cache_control" not in json.dumps(weak_calls[-1]["body"]) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.