refactor: extract is_aborted helpers, DRY 16 call sites
This commit is contained in:
@@ -306,9 +306,7 @@ pub(super) fn run_agent_turn(
|
||||
// Check abort after pipeline completes, before entering main loop.
|
||||
// This catches the case where the user pressed Esc during the pipeline
|
||||
// phase, which previously ran unchecked for minutes at a time.
|
||||
if tc
|
||||
.abort_flag
|
||||
.load(std::sync::atomic::Ordering::SeqCst)
|
||||
if crate::app::util::abort::is_aborted_direct(&tc.abort_flag)
|
||||
{
|
||||
push_event(&events_q, TurnEvent::Error("Generation aborted by user".to_string()));
|
||||
return Ok(());
|
||||
@@ -326,9 +324,7 @@ pub(super) fn run_agent_turn(
|
||||
|
||||
// Skip message compaction if abort was requested — the non-streaming
|
||||
// LLM call for summarization would block without checking abort_flag.
|
||||
let wire_msgs = if !tc
|
||||
.abort_flag
|
||||
.load(std::sync::atomic::Ordering::SeqCst)
|
||||
let wire_msgs = if !crate::app::util::abort::is_aborted_direct(&tc.abort_flag)
|
||||
&& crate::app::runtime::context::shaping::should_shape(
|
||||
token_estimate,
|
||||
max_wire_tokens,
|
||||
@@ -371,7 +367,7 @@ pub(super) fn run_agent_turn(
|
||||
Some(tc.temperature),
|
||||
tc.max_tokens,
|
||||
|event| -> bool {
|
||||
if tc.abort_flag.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
if crate::app::util::abort::is_aborted_direct(&tc.abort_flag) {
|
||||
return false;
|
||||
}
|
||||
if let Ok(mut q) = events_q.lock() {
|
||||
@@ -425,7 +421,7 @@ pub(super) fn run_agent_turn(
|
||||
Ok((msg, u)) => (msg, u.or(usage)),
|
||||
Err(e) => {
|
||||
// If abort was requested, return immediately.
|
||||
if tc.abort_flag.load(std::sync::atomic::Ordering::SeqCst)
|
||||
if crate::app::util::abort::is_aborted_direct(&tc.abort_flag)
|
||||
|| e.to_string().contains("aborted")
|
||||
{
|
||||
push_event(&events_q, TurnEvent::Error(
|
||||
@@ -552,9 +548,7 @@ pub(super) fn run_agent_turn(
|
||||
});
|
||||
|
||||
for (tool_call, tool_name, args, output, is_error, is_edit) in results_vec {
|
||||
if tc
|
||||
.abort_flag
|
||||
.load(std::sync::atomic::Ordering::SeqCst)
|
||||
if crate::app::util::abort::is_aborted_direct(&tc.abort_flag)
|
||||
{
|
||||
push_event(&events_q, TurnEvent::Error(
|
||||
"Turn aborted by user".to_string(),
|
||||
|
||||
Reference in New Issue
Block a user