routing_policy first, then processes fallback_chain from top to bottom.
The requested model and capability remain fixed throughout the chain. A fallback step can choose another agent, region, engine, or hardware tier, but it cannot silently change the requested model or turn a chat request into an embedding or reranking request.
Execution order
For one request, Hivenet Router follows this sequence:- Evaluate the primary
routing_policy. - Forward to eligible agents until the step succeeds or reaches its attempt limit.
- Advance to the first fallback step.
- Repeat the same filtering, capacity, gating, and retry process.
- Continue through the remaining local steps.
- Try a configured external provider for eligible language-model requests.
- Return an error if no option serves the request.
fallback_provider is separate from the local chain. It is a top-level policy field rather than an item inside fallback_chain.
When Hivenet Router advances
Hivenet Router moves from one local step to the next when the current step cannot produce a successful forward. This can happen when:- no agents are registered for the requested model
- all registered agents are unhealthy
- no agent serves the required capability
- no agent passes the step’s static
matchfilters - every matching agent violates an
exclude_ifgate - matching agents remain at capacity and queueing cannot dispatch the request
- forwarding failures exhaust the step’s
max_tries
Errors that do not trigger fallback
Hivenet Router does not retry request-level errors that are expected to produce the same result on another agent. These include:- invalid request bodies
- invalid parameters
- context-length errors
- token-quota rejection
Fallback is designed for unavailable capacity, unhealthy backends, routing exclusions, and retryable forwarding failures. It does not repair an invalid client request.
Step structure
Each fallback item is a complete policy step.
The only implemented strategy is:
name is omitted, Hivenet Router generates a name from the step’s array position:
Forward-attempt budgets
max_tries limits the number of retryable forwarding failures within one step.
max_tries is omitted, zero, or negative, the step uses the router-wide value:
- try agent A
- record a retryable failure
- exclude A from this step
- try agent B
- record another failure
- advance to the next fallback step
What consumes a try
Retryable forwarding failures consume the budget, including:- backend unavailability returned by the agent
- overload or rate-limit responses from the backend
- retryable backend errors
- malformed or unsuccessful backend responses
- transport failures after connection recovery is exhausted
request_invalid, invalid_parameter, context_length_exceeded, and token_limit_exceeded stop immediately. They do not consume additional tries or advance through other local agents.
What does not consume a try
The following do not use the forward budget:- no registered agents
- no healthy agents
- static-filter exclusions
- dynamic-gate exclusions
- agents already at capacity
- losing a race for the final capacity slot
- the first connection-level recovery attempt for an agent
- waiting in the capacity queue
Connection-level recovery
A persistent router-agent connection can become stale after a network interruption, firewall change, container reschedule, or connection-tracking timeout. When Hivenet Router detects a connection-level forwarding failure, it can:- discard the stale peer connection state
- retry the request path without charging
max_tries
Capacity and the wait queue
Before moving to another fallback step, Hivenet Router can wait when eligible agents exist but all of them are at their declared capacity. The queue is:- separate for each model
- bounded by
--queue-depth - active only when the depth is greater than zero
- governed by the request deadline
- the queue is already full
- waiting ends without usable capacity
- the request deadline is reached
Model and capability remain fixed
Fallback steps relax infrastructure selection. They do not change the workload requested by the client. For a chat-completion request:llm agent registered for:
fallback_provider when you deliberately want a final provider-specific model substitution for supported chat requests.
Graduated relaxation
A common pattern is to begin with strict requirements and relax them gradually.- prefers production vLLM agents in France
- keeps the same region but relaxes tags and metric thresholds
- accepts vLLM agents in other regions
- accepts any healthy local engine serving the requested model
Geographic fallback
Use region metadata to move traffic through preferred locations.EU.
Engine fallback
Move between backend implementations serving the same model.- several serving stacks expose the same model
- a preferred engine is overloaded or unhealthy
- another engine provides acceptable continuity
Hardware-tier fallback
Move through preferred GPU classes.gpu_model matching is exact.
Confirm the reported value through:
Mixed fallback
Combine region, engine, tags, and health thresholds.eu-any-engine is preferred over any-region-vllm.
Reversing those two steps would prefer the engine type over geographic locality.
Add provider fallback
External provider fallback comes after every local step.Observe fallback activity
Hivenet Router exposes separate counters for the primary step, local fallback steps, provider fallback, and exhausted chains. Primary-step requests:hivenet_router_policy_fallback_routed_total aggregates every local fallback step. It does not currently include the individual fallback-step name as a Prometheus label.Use router logs and request diagnostics when you need to know which named step was used or exhausted.Diagnose an exhausted chain
Enable policy and router debug logging:- request ID
- model
- capability
- tenant
- policy-chain order
- number of exhausted steps
- the reason each step drained
X-Request-ID to correlate the client request with logs:
Test a fallback chain
Test each step before relying on the full chain. A practical sequence is:- Confirm the primary step routes normally.
- Stop or exclude its agents.
- Confirm the first fallback step serves the request.
- Repeat for each later step.
- Exhaust all local steps.
- Confirm provider fallback or the expected final error.
- Restore the primary agents.
- Check that routing returns to the preferred step.
Design guidance
Order steps by real preference
The first fallback should be the next acceptable operational choice, rather than simply the easiest policy to write. Consider:- data location
- latency
- backend compatibility
- hardware tier
- operating cost
- capacity
- compliance requirements
Relax one concern at a time
A chain is easier to understand when each step makes one deliberate compromise. For example:- same region and engine, relaxed cache threshold
- same region, any engine
- any region, preferred engine
- any local agent
Keep the chain short
Long chains increase:- worst-case latency
- policy complexity
- testing work
- difficulty explaining why a request landed on one backend
Set retry budgets deliberately
A largemax_tries on every step can produce long delays before the request reaches a viable fallback.
Use larger budgets when several independent agents are likely to recover the request.
Use smaller budgets when backend failures are expensive or likely to repeat across similar agents.
Monitor fallback rate
A high or rising fallback rate may indicate:- insufficient primary capacity
- unhealthy primary agents
- overly strict gates
- incorrect metadata
- mismatched model names
- backend instability
- network problems
Troubleshooting
The chain skips a step
Check whether the step had any eligible agents. Inspect registered metadata:A failed agent is tried again
An agent is excluded only for the remainder of the current step. It can become eligible again in a later fallback step because each step has its own failed-agent set and retry budget. Avoid overlapping steps when retrying the same agents is not useful. For example, these steps overlap completely:Requests wait instead of falling back
Matching agents are probably at capacity and queueing is enabled. Check:A fallback engine is never selected
Confirm that it:- registers the same model name
- serves the same capability
- passes the step’s static filters
- passes its dynamic gates
- is healthy
- has free capacity
Provider fallback is not reached
Check that:- all local steps are exhausted
- the request has not already exceeded its deadline
- the request uses the
llmcapability fallback_provideris at the top level- the provider engine and model are configured
- the corresponding API key environment variable is set
The exhausted metric increases despite provider fallback
hivenet_router_policy_exhausted_total also increases when the local chain is exhausted and the configured provider fallback fails.
Check provider logs and outbound HTTP metrics before assuming the router returned a normal local-capacity error.
Next steps
Provider fallback
Configure OpenAI or Anthropic after all local routing options fail.
Policy gates
Apply practical health, cache, latency, and hardware thresholds.
Prometheus metrics
Monitor fallback, exhaustion, queueing, failures, and routing activity.

