Skip to content

Commit dc57dc6

Browse files
committed
fix: cancel pending rate-limit retries (fixes #826)
1 parent 9d75bf6 commit dc57dc6

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ pub(super) fn handle_cancel_command(app: &mut App, trimmed: &str) -> bool {
836836
return false;
837837
}
838838

839+
let pending_retry = app.rate_limit_reset.is_some() && app.rate_limit_pending_message.is_some();
839840
if app.is_processing {
840841
app.cancel_requested = true;
841842
app.interleave_message = None;
@@ -847,6 +848,13 @@ pub(super) fn handle_cancel_command(app: &mut App, trimmed: &str) -> bool {
847848
} else {
848849
app.set_status_notice("Interrupting...");
849850
}
851+
} else if pending_retry {
852+
app.clear_pending_remote_retry();
853+
if matches!(app.status, ProcessingStatus::WaitingForNetwork { .. }) {
854+
app.status = ProcessingStatus::Idle;
855+
app.status_detail = None;
856+
}
857+
app.set_status_notice("Pending retry cancelled");
850858
} else {
851859
app.push_display_message(DisplayMessage::system(
852860
"Nothing to cancel: no prompt or operation is in progress.".to_string(),

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,46 @@ fn test_stop_command_processing_requests_interrupt() {
6161
assert!(app.cancel_requested, "'/stop' must interrupt like /cancel");
6262
}
6363

64+
#[test]
65+
fn test_cancel_and_stop_clear_pending_rate_limit_retry() {
66+
for command in ["/cancel", "/stop"] {
67+
let mut app = create_test_app();
68+
let retry_at = Instant::now() + Duration::from_secs(30);
69+
app.rate_limit_reset = Some(retry_at);
70+
app.rate_limit_pending_message = Some(PendingRemoteMessage {
71+
content: "retry me".to_string(),
72+
images: vec![],
73+
is_system: false,
74+
system_reminder: None,
75+
auto_retry: false,
76+
retry_attempts: 0,
77+
retry_at: Some(retry_at),
78+
});
79+
80+
app.set_input_for_test(command);
81+
app.submit_input();
82+
83+
assert!(
84+
app.rate_limit_reset.is_none(),
85+
"{command} must disarm the retry timer"
86+
);
87+
assert!(
88+
app.rate_limit_pending_message.is_none(),
89+
"{command} must discard the pending retry payload"
90+
);
91+
assert!(
92+
!app.cancel_requested,
93+
"{command} must not leak cancellation into the next turn"
94+
);
95+
assert_eq!(
96+
app.status_notice
97+
.as_ref()
98+
.map(|(message, _)| message.as_str()),
99+
Some("Pending retry cancelled")
100+
);
101+
}
102+
}
103+
64104
fn pending_api_key_login() -> crate::tui::app::PendingLogin {
65105
crate::tui::app::PendingLogin::ApiKeyProfile {
66106
provider_id: "openrouter".to_string(),

0 commit comments

Comments
 (0)