Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions crates/aisix-proxy/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ scoped to a member never runs for group traffic (measured: direct 422, via group
is correct — input guardrails run before a target is picked, and under failover
there is no single "winning member" to resolve against. Tracked in
AISIX-Cloud#1090; do not cite it as precedent for scoping a new gate to the entry.
The 2026-08 model-kind audit re-confirmed the same gap for **ensemble panel/judge
sub-calls and semantic-router targets**, and the ruling (project decision) is that
all three kinds stay under #1090's one unified design pass: the operator can
attach the guardrail to the parent entry, so member scope is a mitigable gap, not
an unavoidable bypass. Do not piecemeal-fix one kind ahead of that decision, and
do not re-audit it as a new finding. The same project ruling holds for the OTHER
member gates on **ensemble** sub-calls (member `allowed_cidrs`, cooldown/health
consumption, Prometheus usage, caching): ensemble is an experimental surface and
its parity gaps are deliberate TODOs, not fresh findings — semantic-router
targets got these gates first because they share the single-winner dispatch
shape; graduate ensemble deliberately, in one pass.

Two shapes, both already implemented — copy the nearest one:

Expand Down
27 changes: 21 additions & 6 deletions crates/aisix-proxy/src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,19 @@ async fn cache_semantic_embed(
) -> Option<Vec<f32>> {
let started = Instant::now();
let texts = [sem.text.clone()];
// Same deadline chain as the semantic router's embed call: the
// policy knob wins, then the embedding model's own `timeout`, then
// the deployment default — a hung embedding upstream must not stall
// the cache gate unbounded either.
let embed_deadline = sem.cfg.embedding_timeout().or_else(|| {
crate::routing::effective_timeouts(&sem.embed_entry.value, None, state.default_timeouts)
.request
});
match crate::semantic::embed_texts(
state,
snapshot,
&sem.embed_entry,
sem.cfg.embedding_timeout(),
embed_deadline,
request_id,
&texts,
)
Expand Down Expand Up @@ -1334,9 +1342,16 @@ async fn dispatch(
let (attempt_models, semantic_route): (Vec<AttemptModel>, Option<String>) =
if virtual_entry.value.is_semantic() {
let prompt = last_user_message_text(req).unwrap_or_default();
crate::semantic::resolve(state, snapshot, &virtual_entry, &prompt, request_id)
.await
.map_err(&with_model)?
crate::semantic::resolve(
state,
snapshot,
&virtual_entry,
&prompt,
&client.source_ip,
request_id,
)
.await
.map_err(&with_model)?
} else {
let attempts = resolve_attempt_models(
&state.routing,
Expand Down Expand Up @@ -1539,7 +1554,7 @@ async fn dispatch(
// existed on the group.
let budget = crate::routing::effective_retries(
model,
virtual_entry.value.routing.as_ref(),
crate::routing::group_retries_of(&virtual_entry.value),
state.default_retries,
target_idx + 1 < attempt_models.len(),
);
Expand Down Expand Up @@ -2615,7 +2630,7 @@ async fn dispatch(
// Per-target retry budget — see the streaming loop above.
let budget = crate::routing::effective_retries(
model,
virtual_entry.value.routing.as_ref(),
crate::routing::group_retries_of(&virtual_entry.value),
state.default_retries,
target_idx + 1 < attempt_models.len(),
);
Expand Down
2 changes: 1 addition & 1 deletion crates/aisix-proxy/src/count_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ async fn dispatch(
.any(|t| crate::dispatch::speaks_anthropic(snapshot, &t.model));
let budget = crate::routing::effective_retries(
&target.model,
model_entry.value.routing.as_ref(),
crate::routing::group_retries_of(&model_entry.value),
state.default_retries,
has_usable_fallback,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/aisix-proxy/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ async fn dispatch(
// because the knob only existed on the group.
let budget = crate::routing::effective_retries(
&target.model,
model_entry.value.routing.as_ref(),
crate::routing::group_retries_of(&model_entry.value),
state.default_retries,
i + 1 < n,
);
Expand Down
2 changes: 1 addition & 1 deletion crates/aisix-proxy/src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ async fn dispatch(
// model gets a budget too.
let budget = crate::routing::effective_retries(
&target.model,
model_entry.value.routing.as_ref(),
crate::routing::group_retries_of(&model_entry.value),
state.default_retries,
target_idx + 1 < attempt_models.len(),
);
Expand Down
64 changes: 61 additions & 3 deletions crates/aisix-proxy/src/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ pub fn retry_after_hint(err: &BridgeError) -> Option<Duration> {
/// keeps the default for.
pub fn effective_retries(
target: &aisix_core::Model,
group: Option<&aisix_core::models::routing::Routing>,
group_retries: Option<u32>,
deployment_default: u32,
has_fallback_targets: bool,
) -> RetryBudget {
if let Some(explicit) = target.retries.or_else(|| group.and_then(|r| r.retries)) {
if let Some(explicit) = target.retries.or(group_retries) {
return RetryBudget {
attempts: explicit as usize,
configured: true,
Expand All @@ -208,6 +208,22 @@ pub fn effective_retries(
}
}

/// The group-level slot of the member → group → deployment-default
/// retries chain, resolved from the caller-addressed parent entry:
/// `routing.retries` for a Model Group, the parent's own top-level
/// `retries` otherwise — a semantic router has no `routing` block, so
/// its group level lives on the Model itself (the same place a routing
/// group keeps its group-level `timeout`).
pub fn group_retries_of(parent: &aisix_core::Model) -> Option<u32> {
match parent.routing.as_ref() {
// A Model Group's group slot is `routing.retries` alone — a
// stray top-level `retries` on the group Model stays inert
// (the schema-convergence work forbids that shape outright).
Some(routing) => routing.retries,
None => parent.retries,
}
}

/// How many same-target retries this dispatch may spend, and whether the
/// operator asked for them.
#[derive(Debug, Clone, Copy)]
Expand Down Expand Up @@ -1581,11 +1597,53 @@ mod tests {
) -> RetryBudget {
let m = model_with_retries(target);
match group {
Some(g) => effective_retries(&m, Some(&group_with_retries(g)), default, has_fallback),
Some(g) => effective_retries(
&m,
group_retries_of(&{
let mut parent = model_with_retries(None);
parent.routing = Some(group_with_retries(g));
parent
}),
default,
has_fallback,
),
None => effective_retries(&m, None, default, has_fallback),
}
}

#[test]
fn group_retries_reads_the_routing_block_then_the_parent_model() {
// Model Group: the group slot is `routing.retries`; a stray
// top-level value on the parent stays shadowed by it.
let mut group_parent = model_with_retries(Some(7));
group_parent.routing = Some(group_with_retries(Some(3)));
assert_eq!(group_retries_of(&group_parent), Some(3));
// …and stays INERT even when `routing.retries` is unset — the
// routing block's presence pins the group slot, so the target →
// routing.retries → deployment-default chain is unchanged for
// every Model Group shape.
let mut sparse_group = model_with_retries(Some(7));
sparse_group.routing = Some(group_with_retries(None));
assert_eq!(group_retries_of(&sparse_group), None);
// Semantic router (no routing block): the parent's own top-level
// `retries` IS the group slot — the member → group → default
// chain unified across virtual parents.
let semantic_parent = model_with_retries(Some(2));
assert_eq!(group_retries_of(&semantic_parent), Some(2));
assert_eq!(
effective_retries(
&model_with_retries(None),
group_retries_of(&semantic_parent),
9,
false
)
.attempts,
2
);
// Neither configured → no group level.
assert_eq!(group_retries_of(&model_with_retries(None)), None);
}

#[test]
fn effective_retries_prefers_the_target_then_the_group_then_the_default() {
// Target wins over group.
Expand Down
Loading