Skip to content

Commit 3beeeb4

Browse files
committed
Retry unchanged incomplete todos up to three times in TUI
1 parent 82f35ef commit 3beeeb4

7 files changed

Lines changed: 53 additions & 6 deletions

File tree

‎crates/jcode-tui/src/tui/app.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,10 +1107,9 @@ pub struct App {
11071107
/// Todo state at the final-response handoff. Unchanged finished work must
11081108
/// not re-enter quality gates on later turn-end or timer callbacks.
11091109
final_response_todo_fingerprint: Option<String>,
1110-
/// Exact continuation sent for the last incomplete todo state. An unchanged
1111-
/// list must not trigger another automatic turn: the agent may be parked on
1112-
/// a worker, wake, or human decision, and repeated pokes cannot help.
1110+
/// Last incomplete state and its bounded automatic continuation budget.
11131111
last_auto_poke_fingerprint: Option<String>,
1112+
auto_poke_attempts: u8,
11141113
/// Set when the current turn ended with a provider guardrail/refusal stop
11151114
/// (ServerEvent::ProviderGuardrail). Consumed by the Done handler to
11161115
/// update `consecutive_guardrail_stops`.

‎crates/jcode-tui/src/tui/app/commands.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub(super) fn disable_auto_poke(app: &mut App) -> usize {
119119
app.todo_confidence_spike_challenged = false;
120120
app.todo_completion_gate_attempts = 0;
121121
app.last_auto_poke_fingerprint = None;
122+
app.auto_poke_attempts = 0;
122123
app.last_todo_ownership_fingerprint = None;
123124
app.todo_gate_digest_delivered = false;
124125
cleared
@@ -252,6 +253,7 @@ pub(super) fn activate_auto_poke(app: &mut App) -> PokeActivation {
252253
app.todo_confidence_spike_challenged = false;
253254
app.todo_completion_gate_attempts = 0;
254255
app.last_auto_poke_fingerprint = None;
256+
app.auto_poke_attempts = 0;
255257
app.last_todo_ownership_fingerprint = None;
256258
// Re-arming starts a fresh review cycle, so the deferred quality digest is
257259
// eligible to be delivered again for the upcoming work.

‎crates/jcode-tui/src/tui/app/input.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ impl App {
16561656
// equivalent work appears later, it is a new cycle and deserves
16571657
// one fresh nudge rather than being mistaken for the old stall.
16581658
self.last_auto_poke_fingerprint = None;
1659+
self.auto_poke_attempts = 0;
16591660
if todos.is_empty() {
16601661
// No todo list exists yet for this session. Auto-poke is armed
16611662
// by default (`features.auto_poke`), so disarming here would
@@ -1808,7 +1809,10 @@ impl App {
18081809
self.last_todo_ownership_fingerprint = None;
18091810
let fingerprint =
18101811
serde_json::to_string(&incomplete).unwrap_or_else(|_| poke_message.clone());
1811-
if self.last_auto_poke_fingerprint.as_ref() == Some(&fingerprint) {
1812+
if self.last_auto_poke_fingerprint.as_ref() != Some(&fingerprint) {
1813+
self.auto_poke_attempts = 0;
1814+
}
1815+
if self.auto_poke_attempts >= crate::todo::INCOMPLETE_TODO_MAX_ATTEMPTS {
18121816
crate::logging::info(&format!(
18131817
"AUTO_POKE_DECISION action=idle reason=unchanged_todos incomplete={}",
18141818
incomplete.len()
@@ -1836,6 +1840,7 @@ impl App {
18361840
// exhaustion should only trip when the gate itself stops moving.
18371841
self.todo_completion_gate_attempts = 0;
18381842
self.last_auto_poke_fingerprint = Some(fingerprint);
1843+
self.auto_poke_attempts += 1;
18391844
self.queued_messages.push(poke_message);
18401845
self.pending_queued_dispatch = true;
18411846
true
@@ -1896,7 +1901,10 @@ impl App {
18961901
if let Some(fingerprint) = self.current_incomplete_poke_fingerprint()
18971902
&& text.starts_with("You have ")
18981903
{
1904+
// A peer owns continuation for this unchanged state. Do not send
1905+
// competing retries from every attached window.
18991906
self.last_auto_poke_fingerprint = Some(fingerprint);
1907+
self.auto_poke_attempts = crate::todo::INCOMPLETE_TODO_MAX_ATTEMPTS;
19001908
}
19011909
}
19021910

‎crates/jcode-tui/src/tui/app/state_ui.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub(super) struct RestoredReloadInput {
2626
pub todo_confidence_spike_challenged: bool,
2727
pub last_todo_ownership_fingerprint: Option<String>,
2828
pub final_response_todo_fingerprint: Option<String>,
29+
pub last_auto_poke_fingerprint: Option<String>,
30+
pub auto_poke_attempts: u8,
2931
}
3032

3133
impl App {
@@ -264,6 +266,7 @@ impl App {
264266
&& !self.todo_confidence_spike_challenged
265267
&& self.last_todo_ownership_fingerprint.is_none()
266268
&& self.final_response_todo_fingerprint.is_none()
269+
&& self.last_auto_poke_fingerprint.is_none()
267270
{
268271
// Nothing to save, but a stale file from an earlier run could
269272
// still hold old queued messages/input. Leaving it behind would
@@ -357,6 +360,8 @@ impl App {
357360
"todo_confidence_spike_challenged": self.todo_confidence_spike_challenged,
358361
"last_todo_ownership_fingerprint": self.last_todo_ownership_fingerprint,
359362
"final_response_todo_fingerprint": self.final_response_todo_fingerprint,
363+
"last_auto_poke_fingerprint": self.last_auto_poke_fingerprint,
364+
"auto_poke_attempts": self.auto_poke_attempts,
360365
});
361366
let _ = std::fs::write(&path, data.to_string());
362367
}
@@ -613,6 +618,15 @@ impl App {
613618
.get("final_response_todo_fingerprint")
614619
.and_then(|v| v.as_str())
615620
.map(str::to_owned),
621+
last_auto_poke_fingerprint: value
622+
.get("last_auto_poke_fingerprint")
623+
.and_then(|v| v.as_str())
624+
.map(str::to_owned),
625+
auto_poke_attempts: value
626+
.get("auto_poke_attempts")
627+
.and_then(|v| v.as_u64())
628+
.unwrap_or(0)
629+
.min(u8::MAX as u64) as u8,
616630
last_todo_ownership_fingerprint: value
617631
.get("last_todo_ownership_fingerprint")
618632
.and_then(|v| v.as_str())
@@ -646,6 +660,8 @@ impl App {
646660
todo_confidence_spike_challenged: false,
647661
last_todo_ownership_fingerprint: None,
648662
final_response_todo_fingerprint: None,
663+
last_auto_poke_fingerprint: None,
664+
auto_poke_attempts: 0,
649665
})
650666
}
651667

‎crates/jcode-tui/src/tui/app/tests/auto_poke_cycles.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn auto_poke_stays_armed_when_a_turn_has_no_todos() {
3737
}
3838

3939
#[test]
40-
fn auto_poke_does_not_repeat_until_incomplete_todos_change() {
40+
fn auto_poke_retries_three_times_until_incomplete_todos_change() {
4141
with_temp_jcode_home(|| {
4242
let mut app = create_test_app();
4343
app.auto_poke_incomplete_todos = true;
@@ -56,17 +56,35 @@ fn auto_poke_does_not_repeat_until_incomplete_todos_change() {
5656
// Simulate dispatch and completion of the automatically poked turn.
5757
app.queued_messages.clear();
5858
app.pending_queued_dispatch = false;
59+
for expected in 2..=3 {
60+
assert!(app.schedule_auto_poke_followup_if_needed());
61+
assert_eq!(app.auto_poke_attempts, expected);
62+
app.queued_messages.clear();
63+
app.pending_queued_dispatch = false;
64+
}
5965
assert!(
6066
!app.schedule_auto_poke_followup_if_needed(),
61-
"an unchanged list must not consume another model turn"
67+
"an unchanged list must stop after three attempts"
6268
);
6369

70+
app.save_input_for_reload(&app.session.id);
71+
let restored = App::restore_input_for_reload(&app.session.id).expect("retry budget saved");
72+
let mut reloaded = create_test_app();
73+
reloaded.session.id = app.session.id.clone();
74+
reloaded.auto_poke_incomplete_todos = true;
75+
reloaded.auto_poke_default_on = true;
76+
reloaded.apply_restored_reload_input(restored);
77+
assert_eq!(reloaded.auto_poke_attempts, 3);
78+
assert!(!reloaded.schedule_auto_poke_followup_if_needed());
79+
app = reloaded;
80+
6481
crate::todo::save_todos(&app.session.id, &[pending("Review worker result")])
6582
.expect("update");
6683
assert!(
6784
app.schedule_auto_poke_followup_if_needed(),
6885
"changing the todo list must re-arm the automatic nudge"
6986
);
87+
assert_eq!(app.auto_poke_attempts, 1);
7088

7189
app.queued_messages.clear();
7290
app.pending_queued_dispatch = false;

‎crates/jcode-tui/src/tui/app/tui_lifecycle.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ impl App {
424424
todo_final_response_requested: false,
425425
final_response_todo_fingerprint: None,
426426
last_auto_poke_fingerprint: None,
427+
auto_poke_attempts: 0,
427428
turn_guardrail_stopped: false,
428429
consecutive_guardrail_stops: 0,
429430
overnight_auto_poke: None,
@@ -911,6 +912,7 @@ impl App {
911912
todo_final_response_requested: false,
912913
final_response_todo_fingerprint: None,
913914
last_auto_poke_fingerprint: None,
915+
auto_poke_attempts: 0,
914916
turn_guardrail_stopped: false,
915917
consecutive_guardrail_stops: 0,
916918
overnight_auto_poke: None,

‎crates/jcode-tui/src/tui/app/tui_lifecycle_reload_input.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ impl App {
4040
self.todo_confidence_spike_challenged = restored.todo_confidence_spike_challenged;
4141
self.last_todo_ownership_fingerprint = restored.last_todo_ownership_fingerprint;
4242
self.final_response_todo_fingerprint = restored.final_response_todo_fingerprint;
43+
self.last_auto_poke_fingerprint = restored.last_auto_poke_fingerprint;
44+
self.auto_poke_attempts = restored.auto_poke_attempts;
4345
self.todo_final_response_requested = self.final_response_todo_fingerprint.is_some();
4446

4547
let mut queued_messages = restored.queued_messages;

0 commit comments

Comments
 (0)