Skip to content

Feature Request: Auto-resume session context from state.db on Gateway startup #9286

@Xwm1234

Description

@Xwm1234

Problem or Use Case

The Gateway currently starts a completely fresh session upon restart, causing the AI to "forget" the immediate previous conversation. Although all history is safely stored in state.db, the new session has no mechanism to automatically load or resume context. This breaks conversational continuity and forces users to re-explain context after every restart or update.

Proposed Solution

Add an automatic session recovery hook during Gateway startup (gateway/run.py). The logic should:

  1. Query state.db to find the most recent non-cron session.
  2. Extract the last N (e.g., 30-50) user/assistant messages in chronological order.
  3. Automatically inject them into the prefill_messages list for the new session.
    This leverages existing infrastructure (state.db + prefill_messages) and requires minimal code changes while providing a seamless "wake-up" experience.

Alternatives Considered

The current workaround is using an external cron job to periodically export SQLite data to a JSON file, which the Gateway reads via prefill_messages_file. This has latency (up to 30 mins) and relies on external scheduling. The proposed native startup hook is instant (0 latency), requires no external dependencies, and is more reliable as it runs exactly when the session initializes.

Feature Type

Other

Scope

None

Contribution

  • I'd like to implement this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions