fix(session-limit): émettre AgentRateLimited sur le chemin délégué (#7)
Sur le rendez-vous délégué (idea_ask_agent), quand la cible touchait sa limite de session, l'événement AgentRateLimited n'était pas émis : l'écart backend documenté (ticket #7/F2) laissait la surface UI sans signal de limite pour la cible déléguée. Le service orchestrateur relaie désormais la limite de la cible vers le service de limite de session, fermant l'écart en cohérence avec le chemin direct (#30). Couverture QA (sortie réelle) : orchestrator_service 63 passed, session_limit_service 15 passed, session_limit_t4 7 passed, cargo test -p application 0 failed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -20,8 +20,8 @@ pub(crate) use lifecycle::ReattachDecision;
|
||||
pub use session_limit::{AgentResumer, SessionLimitService, RESUME_PROMPT};
|
||||
pub use structured::{
|
||||
drain_reply_stream_with_readiness, drain_with_readiness,
|
||||
drain_with_readiness_and_announcements, drain_with_readiness_outcome, send_blocking,
|
||||
AnnouncementPublisher, TurnOutcome,
|
||||
drain_with_readiness_and_announcements, drain_with_readiness_and_announcements_outcome,
|
||||
drain_with_readiness_outcome, send_blocking, AnnouncementPublisher, TurnOutcome,
|
||||
};
|
||||
|
||||
pub use catalogue::{
|
||||
|
||||
@ -167,8 +167,35 @@ pub async fn drain_with_readiness_and_announcements(
|
||||
agent: AgentId,
|
||||
announcements: Option<AnnouncementPublisher>,
|
||||
) -> Result<String, AgentSessionError> {
|
||||
match drain_with_readiness_and_announcements_outcome(
|
||||
session,
|
||||
prompt,
|
||||
timeout,
|
||||
mediator,
|
||||
agent,
|
||||
announcements,
|
||||
)
|
||||
.await?
|
||||
{
|
||||
TurnOutcome::Completed(content) => Ok(content),
|
||||
TurnOutcome::RateLimited { .. } => Err(AgentSessionError::Io(
|
||||
"le tour s'est clos en limite de session, sans contenu Final".to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Comme [`drain_with_readiness_and_announcements`], mais conserve l'issue riche
|
||||
/// [`TurnOutcome::RateLimited`] pour les appelants capables d'armer la reprise.
|
||||
pub async fn drain_with_readiness_and_announcements_outcome(
|
||||
session: &dyn AgentSession,
|
||||
prompt: &str,
|
||||
timeout: Option<Duration>,
|
||||
mediator: &dyn InputMediator,
|
||||
agent: AgentId,
|
||||
announcements: Option<AnnouncementPublisher>,
|
||||
) -> Result<TurnOutcome, AgentSessionError> {
|
||||
let Some(publisher) = announcements else {
|
||||
return drain_with_readiness(session, prompt, timeout, mediator, agent).await;
|
||||
return drain_with_readiness_outcome(session, prompt, timeout, mediator, agent).await;
|
||||
};
|
||||
|
||||
let (tap_tx, tap_rx) = std::sync::mpsc::channel();
|
||||
@ -188,7 +215,7 @@ pub async fn drain_with_readiness_and_announcements(
|
||||
let _ = live_pump.join();
|
||||
let stream = stream_result?;
|
||||
|
||||
match drain_stream_to_final(
|
||||
drain_stream_to_final(
|
||||
stream,
|
||||
|event| {
|
||||
if !matches!(event, ReplyEvent::Final { .. }) {
|
||||
@ -201,12 +228,7 @@ pub async fn drain_with_readiness_and_announcements(
|
||||
mediator.mark_idle(agent);
|
||||
}
|
||||
},
|
||||
)? {
|
||||
TurnOutcome::Completed(content) => Ok(content),
|
||||
TurnOutcome::RateLimited { .. } => Err(AgentSessionError::Io(
|
||||
"le tour s'est clos en limite de session, sans contenu Final".to_string(),
|
||||
)),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/// Draine un flux de réponse déjà ouvert, avec la même politique de readiness que
|
||||
|
||||
@ -36,9 +36,10 @@ use crate::conversation::RecordTurn;
|
||||
use crate::memory::HarvestMemoryFromTurn;
|
||||
|
||||
use crate::agent::{
|
||||
drain_with_readiness_and_announcements, AnnouncementPublisher, CreateAgentFromScratch,
|
||||
drain_with_readiness_and_announcements_outcome, AnnouncementPublisher, CreateAgentFromScratch,
|
||||
CreateAgentInput, LaunchAgent, LaunchAgentInput, ListAgents, ListAgentsInput, McpRuntime,
|
||||
ReattachDecision, UpdateAgentContext, UpdateAgentContextInput, CODEX_SUBMIT_DELAY_MS,
|
||||
ReattachDecision, SessionLimitService, TurnOutcome, UpdateAgentContext,
|
||||
UpdateAgentContextInput, CODEX_SUBMIT_DELAY_MS,
|
||||
};
|
||||
use crate::background::{SpawnBackgroundCommand, SpawnBackgroundCommandInput};
|
||||
use crate::error::AppError;
|
||||
@ -484,6 +485,10 @@ pub struct OrchestratorService {
|
||||
/// `idea_ask_agent` comme [`BackgroundTaskKind::HeadlessRendezvous`]. `None` ⇒
|
||||
/// comportement historique sans persistance de tâche (call sites non câblés).
|
||||
background_tasks: Option<Arc<dyn BackgroundTaskStore>>,
|
||||
/// Service applicatif des limites de session, injecté depuis la composition root.
|
||||
/// `None` conserve les call sites/tests legacy ; les chemins conscients des limites
|
||||
/// publient alors seulement leur erreur de tour historique.
|
||||
session_limits: Option<Arc<SessionLimitService>>,
|
||||
/// Use case B8 qui produit une tâche de fond command-backed depuis la surface
|
||||
/// agent MCP `idea_run_in_background`. `None` ⇒ outil non configuré.
|
||||
spawn_background_command: Option<Arc<SpawnBackgroundCommand>>,
|
||||
@ -558,10 +563,18 @@ impl OrchestratorService {
|
||||
ask_liveness_probe: None,
|
||||
ask_ceiling: ASK_AGENT_CEILING,
|
||||
background_tasks: None,
|
||||
session_limits: None,
|
||||
spawn_background_command: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Branche le service de reprise automatique des limites de session.
|
||||
#[must_use]
|
||||
pub fn with_session_limits(mut self, service: Arc<SessionLimitService>) -> Self {
|
||||
self.session_limits = Some(service);
|
||||
self
|
||||
}
|
||||
|
||||
/// Branche le producteur B8 command-backed pour `idea_run_in_background`.
|
||||
#[must_use]
|
||||
pub fn with_spawn_background_command(mut self, spawn: Arc<SpawnBackgroundCommand>) -> Self {
|
||||
@ -1822,7 +1835,7 @@ impl OrchestratorService {
|
||||
target: agent_id,
|
||||
ticket: ticket_id,
|
||||
});
|
||||
let drain = drain_with_readiness_and_announcements(
|
||||
let drain = drain_with_readiness_and_announcements_outcome(
|
||||
session,
|
||||
&task,
|
||||
None,
|
||||
@ -1836,13 +1849,40 @@ impl OrchestratorService {
|
||||
// au no-reply du chemin headless : la cible a rendu la main sans réponse
|
||||
// exploitable, on expose donc l'erreur métier retryable plutôt qu'un PROCESS.
|
||||
let wait = async {
|
||||
drain.await.map_err(|err| {
|
||||
if structured_no_reply_error(&err) {
|
||||
AppError::TargetReturnedNoReply(target.to_owned())
|
||||
} else {
|
||||
AppError::from(err)
|
||||
match drain.await {
|
||||
Ok(TurnOutcome::Completed(content)) => Ok(content),
|
||||
Ok(TurnOutcome::RateLimited { resets_at_ms }) => {
|
||||
let conversation_id = session.conversation_id();
|
||||
let (conversation_id, resets_at_ms) = match (conversation_id, resets_at_ms) {
|
||||
(Some(conversation_id), resets_at_ms) => {
|
||||
(Some(conversation_id), resets_at_ms)
|
||||
}
|
||||
(None, None) => (None, None),
|
||||
// Reset connu mais conversation moteur absente : ne pas armer
|
||||
// une reprise non reprenable ; surfacer le fallback humain.
|
||||
(None, Some(_)) => (None, None),
|
||||
};
|
||||
if let (Some(service), Some(structured)) =
|
||||
(&self.session_limits, &self.structured)
|
||||
{
|
||||
if let Some(node_id) = structured.node_for_agent(&agent_id) {
|
||||
service.on_rate_limited(
|
||||
agent_id,
|
||||
node_id,
|
||||
conversation_id,
|
||||
resets_at_ms,
|
||||
);
|
||||
}
|
||||
}
|
||||
Err(AppError::Process(
|
||||
"le tour s'est clos en limite de session, sans contenu Final".to_owned(),
|
||||
))
|
||||
}
|
||||
})
|
||||
Err(err) if structured_no_reply_error(&err) => {
|
||||
Err(AppError::TargetReturnedNoReply(target.to_owned()))
|
||||
}
|
||||
Err(err) => Err(AppError::from(err)),
|
||||
}
|
||||
};
|
||||
|
||||
// Borne par la fenêtre d'inactivité (réarmée sur signe de vie) sous plafond absolu.
|
||||
|
||||
Reference in New Issue
Block a user