Skip to content

Session state is lost after free session expires or run is interrupted #1054

Description

@Utkarsh-X

Summary

When a free session expires mid-turn (or when a user interrupts with Esc), sending a follow-up message like "continue" loses all prior conversation history. The assistant restarts from scratch as if it were a new chat and re-runs initial repository exploration (git status, git log, file listings).

Steps to Reproduce

  1. Run Freebuff on a multi-turn task where several files are edited.
  2. Allow the session to hit the expiration limit (or press Esc to stop). The banner displays: "Your free session ended... Nothing is lost — send your message again to start a new session and pick up where it left off."
  3. Send a follow-up message such as continue.
  4. Observed: The assistant replies:

    "It looks like this is the start of a fresh conversation — there's no prior work to continue from."
    or starts exploring the workspace from scratch with git status and file tree queries.

Expected Behavior

The follow-up prompt should retain the full conversation history and prior tool results from the ended session.

Root Cause

In cli/src/hooks/use-send-message.ts, when a run fails or the session ends, the catch (error) block calls saveChatState(latestRunStateSnapshot, ...) to persist to disk, but does not update previousRunStateRef.current in React memory.

When the user sends the next message in the same running CLI session:

  • sendMessage reads previousRunStateRef.current, which is still unassigned or stale.
  • sdk/src/run.ts treats previousRun as undefined and instantiates a blank initialSessionState.
  • The model receives only the user's latest prompt with an empty history.

A similar race condition occurs on user cancellation (Esc) in registerActiveRun, where the input lock is released before client.run() resolves without updating previousRunStateRef.current synchronously.

(I have attached screenshots demonstrating the issue where sending "continue" after session expiration treats the thread as a fresh conversation.)

Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliThe Codebuff/Freebuff terminal clientbot:triagedClassified by the community triage bottype:bugA defect in the code with a reproducible failure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions