Add opt-in elastic budgeting for asynchronous Guardian requests (#61345)

## What changed

- Add `async_elastic_budgeting` and `async_elastic_sections` under `[features.guardianv2]`, independently of synchronous budgeting and disabled by default.
- Apply section limits and elastic allocation to new classifier evidence after accounting for setup and retained conversation history. Preserve the configured elastic policy when applying model defaults.
- Keep permission context whole during elastic allocation and record truncation observations when image preparation rejects an image.

## Testing

Add coverage for configuration validation, fixed and elastic conversation budgeting, retained history and cursor preservation, and complete classifier requests that retain evidence beyond the fixed entry limit.

GitOrigin-RevId: 2955f0482f7c3e18325e296fc2ccb6592ffcb73a
This commit is contained in:
ioanbudea-OAI
2026-11-13 18:46:45 +00:00
committed by copyberry
parent c33002259e
commit a655b50de9
29 changed files with 448 additions and 50 deletions
+6
View File
@@ -163,6 +163,12 @@ pub struct GuardianElasticSectionConfigToml {
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct GuardianV2ConfigToml {
/// Enable elastic allocation for asynchronous Guardian requests. Defaults to false.
#[serde(skip_serializing_if = "Option::is_none")]
pub async_elastic_budgeting: Option<bool>,
/// Section limits validated when asynchronous elastic budgeting is enabled.
#[serde(skip_serializing_if = "Option::is_none")]
pub async_elastic_sections: Option<BTreeMap<String, GuardianElasticSectionConfigToml>>,
/// Enable elastic allocation for synchronous Guardian requests. Defaults to false.
#[serde(skip_serializing_if = "Option::is_none")]
pub sync_elastic_budgeting: Option<bool>,
+2
View File
@@ -332,6 +332,8 @@ max_recent_non_user_entries = 12
assert_eq!(
features.guardianv2,
Some(FeatureToml::Config(crate::GuardianV2ConfigToml {
async_elastic_budgeting: None,
async_elastic_sections: None,
sync_elastic_budgeting: None,
sync_elastic_sections: None,
transcript_mode: None,