Bind a resumed run to a nonsecret route identity and reject missing or mismatched runtime configuration before creating a request.
A restored conversation needs a restored route contract
A foreground agent starts with a configured model gateway. Later, a background worker resumes the conversation without the same environment. If the request library silently falls back to its default endpoint, the resumed run can send the next request through a different route. The conversation history may be intact while the execution context that made the original run acceptable has disappeared.
Claude Code v2.1.326, released on 16 November 2026 UTC and reviewed here on 17 November Asia/Kolkata time, reports a fix for background sessions losing an exported LLM gateway after several restart scenarios. The notes say the affected sessions stop before a model request when the required gateway is missing. They do not disclose a complete implementation. This article develops an independent route-contract example rather than claiming to reproduce the product's internals.
The design question is straightforward: what nonsecret configuration must remain true before a persisted run is allowed to make its next request? A conversation checkpoint usually records messages and tool state. A reliable execution checkpoint also needs enough route identity to detect when a resumed worker would send data somewhere different. It should not persist credentials or infer permission from whatever environment happens to be available later.
Separate route identity from secret material
Represent the required route with a stable application identifier and a normalized endpoint identity. Include other decision-relevant routing properties, such as the intended provider family or an explicitly approved regional route, when they affect where requests go. Store a configuration revision so a deliberate route migration is distinguishable from an accidental fallback. These fields describe the destination contract; they do not contain API keys or authentication tokens.
Credentials remain in the normal protected credential mechanism and are resolved only after the route gate passes. Missing credentials and missing route configuration are different failures. Neither should cause an automatic switch to an unrelated provider. The example does not implement login, token refresh or billing logic; it compares nonsecret synthetic route records and returns a decision before any request object is created.
A route identifier alone is not sufficient if its mapping can change silently. The checkpoint must bind to the versioned mapping or to the relevant resolved endpoint properties. Conversely, pinning every incidental environment variable makes resumption brittle. Define a small contract around properties that affect request destination and execution semantics, and keep unrelated logging or display preferences outside that contract.
Refuse missing and changed routes before request creation
This original offline example uses reserved .invalid hostnames, which are synthetic placeholders. It permits only HTTPS endpoints without embedded user information, query strings or fragments. The normalization deliberately preserves path distinctions because gateways can use path prefixes to identify different routes. It does not attempt DNS resolution, make a network request or inspect the reader's environment.
# Author: Sandeep Belgavi. Nonsecret restored-route preflight.
from urllib.parse import urlsplit
def endpoint_identity(url):
if not isinstance(url, str) or url != url.strip():
raise ValueError("endpoint must be text")
parts = urlsplit(url)
if parts.scheme != "https" or not parts.hostname:
raise ValueError("HTTPS endpoint required")
if parts.username or parts.password or parts.query or parts.fragment:
raise ValueError("endpoint must contain no credentials, query or fragment")
port = parts.port if parts.port is not None else 443
if not 1 <= port <= 65535:
raise ValueError("invalid endpoint port")
return (parts.hostname.lower(), port, parts.path or "/")
def resume_route(required, current):
if current is None:
return "blocked-missing-route"
if not isinstance(required, dict) or not isinstance(current, dict):
return "blocked-invalid-contract"
if set(required) != {"route", "revision", "endpoint"} or set(current) != set(required):
return "blocked-invalid-contract"
if required["route"] != current["route"] or required["revision"] != current["revision"]:
return "blocked-route-revision"
if endpoint_identity(required["endpoint"]) != endpoint_identity(current["endpoint"]):
return "blocked-endpoint-change"
return "ready-for-credential-resolution"
required = {"route": "synthetic-a", "revision": 3,
"endpoint": "https://gateway.invalid/model/"}
assert resume_route(required, None) == "blocked-missing-route"
assert resume_route(required, dict(required)) == "ready-for-credential-resolution"The result is not permission to send a request. It confirms only that this preflight's route properties agree. The next stages still need valid credentials, request authorization, model availability and any application-specific data controls. Keeping these stages separate makes failure reports precise: a route mismatch should not masquerade as a provider timeout or a malformed model response.
Preserve the same contract across foreground and background paths
The foreground launcher should resolve and record the required route before creating the durable run. A background service should obtain its current route through the same configuration resolver, then compare it with the recorded requirement. If the two paths use different precedence rules, an apparently complete environment can still produce a different destination. Test configuration resolution as an application behavior, not merely as a list of environment-variable names.
Avoid default-endpoint fallback after a required route has been established. Defaults can be useful when creating a new run under an explicit policy, but a resumed run already has history and a route commitment. Replacing that commitment implicitly changes the execution context. Return a blocked state with a nonsecret explanation so the operator can restore the intended configuration or authorize a deliberate migration.
An in-memory client object may also carry stale routing state. Checking configuration and then reusing a client initialized under a different route can defeat the gate. Construct or select the client from the accepted route identity, and associate the request trace with that identity. Do not log secret headers while diagnosing this relationship. A route revision and a request correlation identifier are usually more useful than a dump of the entire environment.
Design deliberate migration separately from recovery
A route migration can be legitimate: a gateway moves, a model family changes or an endpoint path is replaced. Treat that as a versioned operation with explicit compatibility and authorization decisions. Record the old route, the new route and the reason the existing run may continue. Do not overload the recovery path so that any missing configuration is interpreted as an invitation to choose another available provider.
Compatibility includes more than successful HTTP connectivity. Request formats, supported tools, model behavior and retention expectations may differ. The synthetic preflight intentionally does not decide those questions. Its role is to prevent accidental destination drift while the broader application determines whether a planned migration is valid. A human-readable message should distinguish an approved migration from a configuration repair.
For disposable stateless requests, recording a durable route may be unnecessary. The application can resolve the route under its current policy for each new request. The stronger contract becomes useful when a run persists across processes, includes pending approvals, or assumes a specific provider configuration. Choose the boundary according to the lifecycle the application actually supports.
Test that blocked restoration makes zero requests
The most important test places a request-creation spy after the route gate. Restore a checkpoint with no current route and assert that the spy is never called. Repeat with a changed host, changed path, changed route revision and an endpoint containing embedded credentials. A failure status alone is insufficient if request creation or telemetry transmission already happened before the check.
The success fixture should use the exact same route and proceed only to a synthetic credential-resolution marker. No real provider call is needed. Add a case where a hostname differs only in letter case and the explicit default port equals the implicit one; these should normalize consistently under this narrow contract. Do not normalize away path differences or query parameters simply to make a comparison pass.
Integration testing should exercise the application's actual foreground-to-background handoff and its configuration resolver. Start a test run, restart the worker with the required configuration absent, and verify the blocked result using a controlled transport stub. Record separately whether a real provider request was made. The offline fixture is not evidence that any vendor gateway, account or authentication flow was tested.
Report restoration as an execution decision
Expose route-ready, route-missing and route-mismatch as distinct states in the run record. A conversation that can be displayed is not necessarily ready to execute. The operator should be able to inspect the nonsecret expected route and the reason execution stopped without being asked to paste credentials into a log or chat. Recovery can then be performed through the application's established configuration process.
The release note motivating this guide is a reminder that background execution is a separate environment, even when it resumes the same conversation. Agents can help explain a blocked run, but they should not improvise a new destination to preserve momentum. A small deterministic preflight preserves the intended route and makes absence of required configuration visible before the next model request exists.
Run the example yourself
The synthetic fixtures, expected output and tests behind this guide are in the companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.