Skip to content

Commit 3a883ec

Browse files
ampagentIsaac Miller
andcommitted
Preserve retained adapter transport and adaptation policy
Per-operation reconstruction must honor the public router.lm() escape hatch for replacing transports. Sync and async regressions assert that only the replacement transport sends the request. This follows the managed snapshot patch without changing its authentication boundary. Amp-Thread-ID: https://ampcode.com/threads/T-01a0c095-4917-7617-9dac-e99f1ef22d41 Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
1 parent 1becdc1 commit 3a883ec

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎lm15/router.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,9 @@ def _build_managed_lm(resolution: Resolution, config: RouterConfig, adapters: Ma
11701170
inner = getattr(lm, "_inner", lm)
11711171
if snapshot is None:
11721172
def prepare():
1173+
execution_extra = dict(original_extra, transport=lm.transport, adaptations=lm.adaptations)
11731174
return _build_managed_lm(
1174-
resolution, config, adapters, cls, original_definition, dict(original_extra), hosted,
1175+
resolution, config, adapters, cls, original_definition, execution_extra, hosted,
11751176
original_url, snapshot=auth.request_auth(provider),
11761177
)
11771178
lm._managed_prepare = prepare

‎tests/test_managed_dispatch.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ def test_retained_adapter_follows_whole_local_connection(asynchronous, operation
8181
wire_pair(sent, f"token-{label}", f"https://{label}.example/v1{path}")
8282

8383

84+
@pytest.mark.parametrize("asynchronous", [False, True])
85+
def test_retained_adapter_uses_replacement_transport(asynchronous):
86+
auth = Auth.memory()
87+
local(auth, "a")
88+
original = transport_for("complete", asynchronous)
89+
replacement = transport_for("complete", asynchronous)
90+
lm = (AsyncLMRouter if asynchronous else LMRouter)(RouterConfig(auth=auth, transport=original)).lm("ollama:llama3")
91+
lm.transport = replacement
92+
invoke(lm, "complete", asynchronous)
93+
assert original.requests == []
94+
assert len(replacement.requests) == 1
95+
wire_pair(replacement.requests[0], "token-a", "https://a.example/v1/chat/completions")
96+
97+
8498
@pytest.mark.parametrize("asynchronous", [False, True])
8599
def test_delayed_stream_never_sends_a_stale_snapshot(asynchronous):
86100
auth = Auth.memory()

0 commit comments

Comments
 (0)