Skip to content

Queued message disappears after reload instead of persisting until turn ends #391

Closed

Description

@1jehuang

Problem

When a message is queued during an active turn and a reload happens, the queued message sometimes does not persist. Instead of staying queued, it just disappears.

Expected behavior

A queued message should remain in the queue across a reload. It should only be dequeued and sent once the current turn naturally completes (i.e. the model stops on its own, not because of the reload). Concretely:

  1. Turn is in progress.
  2. User queues a message.
  3. Reload happens.
  4. Turn continues after reload.
  5. Model naturally finishes the turn.
  6. The queued message is then sent.

Actual behavior

The queued message is sometimes dropped during/after the reload and never sent.

Notes

  • The dequeue should be tied to the turn naturally ending, not to the reload event itself.

Activity

  1. added
    bug
    fable-5
    triage: unclear
    autonomous: likely
    priority: medium
    on Jun 21, 2026
  2. 1jehuang commented on Jun 25, 2026

    @1jehuang
    OwnerAuthor

    Triage: triage: unclear (intermittent, not reproduced) / autonomous: likely / priority: medium.

    The queue-persist-across-reload infrastructure already exists and is well-developed:

    • Queue field is App.queued_messages (crates/jcode-tui/src/tui/app/state_ui.rs:11).
    • On reload, save_input_for_reload() (state_ui.rs:182) serializes queued_messages (and interleave/soft-interrupts) to ~/.jcode/client-input-<session>. It is invoked from the reload paths (tui_lifecycle_runtime.rs:551/570, state_ui_maintenance.rs:234, remote/reconnect.rs:624, remote/key_handling.rs:839/851).
    • On restore, restore_input_for_reload() (state_ui.rs:305) + apply_restored_reload_input() (tui_lifecycle.rs:6) re-populate queued_messages and explicitly keep them as a 'wait-until-turn-end' queue for remote sessions until the history/Done event proves the turn is idle (tui_lifecycle.rs:64+).

    So the expected behavior described in the issue is the intended design and the happy path is covered by tests (tests/remote_startup_input_03/part_01.rs, tests/remote_events_reload_*). The reported drop is intermittent ('sometimes'), pointing at a race in a specific reload path rather than a missing feature. Recommended next step: capture a repro with logs (the save/restore paths log Startup input restored: ... queued_messages=N) to identify which reload path skipped/clobbered the save (e.g. a save fired before the message was pushed to queued_messages, or a path that calls reload without save_input_for_reload). Cannot reproduce from a code read alone, hence unclear.

  3. 1jehuang commented on Jul 2, 2026

    @1jehuang
    OwnerAuthor

    Fixed in 155902e, regression tests in 81f5d13.

    Root cause: a queued follow-up that had already been dequeued into an in-flight send lives only in rate_limit_pending_message with the shape is_system && !auto_retry. That shape has no retry path: the tick resend requires a rate_limit_reset timestamp and the disconnect resend requires auto_retry. So whenever a reload/disconnect, stream stall, failed send, or a server "Already processing" rejection raced the turn-end dispatch, the message was silently dropped. This matches the reported intermittency: it only happened when the reload landed in the window between dequeue and turn completion.

    Fixes:

    • recover_undelivered_queued_continuation folds the in-flight continuation (and its hidden reminder) back onto the queue on disconnect and stream stall.
    • handle_tick / process_remote_followups restore dequeued messages to the queue when begin_remote_send fails instead of logging and dropping.
    • On "Already processing a message", the follow-up is re-queued and the running-turn state re-adopted.
    • save_input_for_reload persists the in-flight continuation at the front of the restored queue, and an empty save removes a stale restore file (>5 min old) so old state cannot resurrect, while preserving fresh files for multi-client safety.

    The queue still only dispatches after the turn is proven idle post-reconnect, per the queue's contract.

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

    @1jehuang
    OwnerAuthor

    Released in v0.34.0. Run jcode update to get it.

  6. removed
    triage: fixed-pending-release
    on Jul 2, 2026
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: likelybugfable-5priority: mediumtriage: unclear

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions