Enforce refreshed Guardian policy on running threads (#62585)

## Why

A Guardian policy refresh could leave a thread using its previous restrictions
if the new policy disallowed its current model. A refresh could also report
success after its managed policy source changed before publication.

## What changed

- Use the app server's configuration manager to load Guardian policy from
  current local and managed configuration. Report an error when the policy
  source changes before publication or a live thread rejects the update.
- Apply updated reviewer and model restrictions even when they block the
  current model. Keep automatic work queued while the model is blocked and
  wake it when a later refresh permits it. Allow a new turn to supply a
  compliant replacement model.

## Testing

Regression tests cover policy changes during thread startup and live refresh,
queued work resuming after a blocking policy is lifted, and updated policy
text reaching Guardian reviews without reconnecting MCP.

GitOrigin-RevId: c7d3e119aa409342cc2fa18946ce2b6a4392e0e3
This commit is contained in:
ioanbudea-OAI
2026-11-19 20:26:00 +00:00
committed by copyberry
parent 81ef12b617
commit 90dd6cf9df
15 changed files with 454 additions and 89 deletions
+5 -24
View File
@@ -610,23 +610,8 @@ impl Session {
.models_manager
.refresh_after_auth_change(self.get_config().await.http_client_factory())
.await;
let session_configuration = if self.enabled(Feature::WakeOnAgentMessages) {
let Some(configuration) = self.pending_work_turn_configuration(&turn_state).await
else {
return;
};
Some(configuration)
} else {
if self
.active_turn
.lock()
.await
.as_ref()
.is_none_or(|turn| !Arc::ptr_eq(&turn.turn_state, &turn_state))
{
return;
}
None
let Some(configuration) = self.pending_work_turn_configuration(&turn_state).await else {
return;
};
// Read the routing options now and leave the mail queued until task registration.
let wake_options = self.input_queue.pending_wake_options().await;
@@ -639,13 +624,9 @@ impl Session {
cyber_access_program: start_options.cyber_access_program,
helper_admission: triggered.then_some(helper_admission).flatten(),
};
let turn_context = match session_configuration {
Some(configuration) => {
self.new_turn_with_configuration(sub_id, configuration, options)
.await
}
None => self.new_turn_with_default_settings(sub_id, options).await,
};
let turn_context = self
.new_turn_with_configuration(sub_id, configuration, options)
.await;
if let Some(trigger) = start_options.turn_trigger {
turn_context.turn_metadata_state.set_turn_trigger(trigger);
}