Record neutral interruption markers for rollout budget stops (#61581)

## Why

Turns stopped by an exhausted rollout budget need a history marker without attributing the interruption to the user.

## What changed

- Record and flush a `<turn_aborted>` marker before the terminal event for `SessionBudgetExceeded`, respecting the interrupt-message setting.
- Use neutral guidance in a `developer` message for automatic budget stops.
- Centralize tool-start budget checks across parallel dispatch, tool handlers, and MCP handoff, retaining the check after tool-start observers finish waiting.
- Share interruption classification and history recording across turn and compaction paths.

## Testing

Extend the rollout-budget integration test to assert that both the budget-crossing turn and a later denied turn persist `developer` interruption markers.

GitOrigin-RevId: 2a49ac9824a4e95e4799f2d0f638f8c46889e8e8
This commit is contained in:
tongzhou wang
2026-11-15 00:02:01 +00:00
committed by copyberry
parent c8c3f70893
commit 2e61e8ec4e
13 changed files with 191 additions and 97 deletions
+7 -4
View File
@@ -1141,12 +1141,15 @@ fn assistant_msg(text: &str) -> ResponseItem {
}
fn contextual_user_interrupted_marker() -> ResponseItem {
interrupted_turn_history_marker(InterruptedTurnHistoryMarker::ContextualUser)
.expect("contextual-user interrupted marker should be enabled")
interrupted_turn_history_marker(
InterruptedTurnHistoryMarker::ContextualUser,
/*cause*/ None,
)
.expect("contextual-user interrupted marker should be enabled")
}
fn developer_interrupted_marker() -> ResponseItem {
interrupted_turn_history_marker(InterruptedTurnHistoryMarker::Developer)
interrupted_turn_history_marker(InterruptedTurnHistoryMarker::Developer, /*cause*/ None)
.expect("developer interrupted marker should be enabled")
}
@@ -3846,7 +3849,7 @@ fn multi_agent_v2_interrupted_marker_uses_developer_input_message() {
content: vec![ContentItem::InputText {
text: format!(
"<turn_aborted>\n{}\n</turn_aborted>",
crate::context::TurnAborted::INTERRUPTED_DEVELOPER_GUIDANCE
crate::context::TurnAborted::INTERRUPTED_NEUTRAL_GUIDANCE
),
}],
phase: None,