Skip to content

Jcode cannot be stopped while retrying after rate limit is hit #826

Closed

Description

@renggap

Description

When using a model that has reached its rate limit, JCode continuously retries the request indefinitely. During this state, the application becomes effectively impossible to stop, interruption is ignored, and the retry loop continues.

Steps to Reproduce

  1. Configure a model/API with a low rate limit.
  2. Send requests until the rate limit is reached.
  3. Observe the retry behavior.
  4. Attempt to stop the current operation.

Expected Behavior

  • Retry logic should either:
    • stop after a configurable number of attempts, or
    • wait according to the provider's Retry-After header.
  • Instructing Stop should immediately cancel all pending retries and terminate the request.

Actual Behavior

  • The application keeps retrying indefinitely after receiving the rate limit error.
  • The Stop instruction has no effect while retries are occurring.
  • The only way to recover is to forcibly terminate the application/process.

Additional Information

I've attached a screenshot showing the retry loop and the inability to stop the process.

Image

Activity

  1. bevinkatti commented on Aug 7, 2026

    @bevinkatti

    Hi @maintainers,

    I'd like to work on this issue. I spent some time reproducing the behavior locally and tracing the retry flow through the TUI, and I believe I've identified the root cause.

    What I found

    The retry loop correctly schedules retries after a rate-limit response, but /cancel was only treated as an interrupt for an active in-flight request (is_processing). During the waiting period before the next retry, the application wasn't considered "processing", so the pending retry state remained armed and the retry loop continued.

    Additionally, there was no final cancellation guard immediately before dispatching the next retry, allowing a queued retry to be resent even if cancellation had just been requested.

    Fix implemented

    My changes address both parts:

    • /cancel (and /stop) now also recognize a pending rate-limit retry as an interruptible state.
    • Cancelling clears the pending retry state before another resend can occur.
    • Added a final guard before begin_remote_send(...) so a cancelled retry is never dispatched, even if cancellation happens immediately before the retry fires.

    Verification

    I tested this locally by intentionally using a rate-limited model and reproducing the issue multiple times.

    Verified behavior:

    • ✅ Rate-limit retry loop is reproduced.
    • ✅ /cancel immediately stops the pending retry.
    • ✅ No further automatic retries occur after cancellation (verified by waiting several minutes).
    • ✅ New prompts can be submitted normally after cancelling.
    • ✅ cargo fmt passes.
    • ✅ Project builds successfully with cargo build.

    The remaining failing tests in my environment are existing unrelated failures and do not touch the TUI retry/cancel path.

    If there are no objections, I'd be happy to open a PR with the fix right away. I'd really appreciate a review and, if everything looks good, a merge.

    Thanks!

  2. added
    bug
    triage: reproducible
    autonomous: likely
    on Aug 7, 2026
  3. 1jehuang commented on Aug 8, 2026

    @1jehuang
    Owner

    Fixed on agent/triage-2026-08-07 in commit dc57dc6ca. /cancel and /stop now clear a pending rate-limit retry instead of allowing the retry loop to continue. The focused cancellation regression test passes.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  4. added
    triage: fixed-pending-release
    on Aug 8, 2026
  5. 1jehuang commented on Aug 8, 2026

    @1jehuang
    Owner

    The validated fix is now available for review in #841 on a clean branch based on the public default branch.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

  6. added a commit that references this issue on Aug 8, 2026
    35e9e4b
  7. added a commit that references this issue on Aug 15, 2026
    a8e0afd
  8. added 5 commits that reference this issue on Aug 30, 2026
    058d7d4
    23bbc44
    0960775
    de72a5b
    d8b6bab
  9. added a commit that references this issue on Sep 18, 2026
    b7b5977
  10. added a commit that references this issue on Oct 9, 2026
    e2e161b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: likelybugtriage: fixed-pending-releasetriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions