Skip to content

Prompt is lost entirely when a turn's first response never completes (stall or client disconnect) #45110

Closed

Description

@jffuree

Summary

Hermes appears to commit the user's prompt to state.db together with the
first completed model response — not on receipt. If that first response never
completes, nothing from the turn is persisted: not the prompt, not the
partial response. The turn vanishes as if it never happened.

Environment

  • hermes-agent v0.16.0 (rolling main), macOS 15 (Apple Silicon)
  • Model: GPT-5.5 via openai-codex provider
  • Reproduced on both CLI chat and the gateway's OpenAI-compatible
    /v1/chat/completions (streaming)

Reproduction (gateway streaming variant)

  1. POST a streaming request to the gateway /v1/chat/completions with a
    prompt that takes a while to answer.
  2. Disconnect the client mid-generation (e.g. curl -m 3 ..., or a mobile
    browser tab being suspended — that's how we hit it in practice).
  3. Inspect state.db for the session.

Expected: the user message is persisted on receipt; the aborted/partial
assistant response is either persisted partially or marked aborted.
Actual: no record of the user message or the response. The session's
message history skips the turn entirely.

The CLI variant is the same with a turn whose first model response stalls
indefinitely: the prompt is never stored.

Impact

Two user-facing failure modes, both observed in real use:

  1. Silent data loss on mobile. Ask a question, background the browser
    while the agent is thinking, return: no answer, and no record the question
    was ever asked.
  2. Confabulation in later turns. Because the turn is missing from the
    session store, follow-up questions hit an agent with a hole in its own
    history. With session_search available, the model fills the gap by
    guessing from older sessions — in our case it confidently conflated two
    different hardware chipsets after losing its own (correct) prior answer.
    The data loss converts into wrong answers downstream.

Suggested direction

Persist the user message at receipt (with the turn opened in a pending
state), and finalize/mark-aborted when the response settles. That keeps the
transcript truthful even when streams die — which on mobile clients is
routine, not exceptional.

Activity

  1. added
    type/bugSomething isn't working
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    P1High — major feature broken, no workaround
    on Jun 12, 2026
  2. teknium1 commented on Jun 28, 2026

    @teknium1
    Collaborator

    Closing — the data-loss bug here is fixed on current main.

    The inbound user message is now persisted to state.db on receipt, before any model call, in agent/turn_context.py:

    # Crash-resilience: persist the inbound user turn as soon as the session row exists.
    try:
        agent._persist_session(messages, conversation_history)
    except Exception:
        logger.warning("Early turn-start session persistence failed ...")

    That flows through _flush_messages_to_session_db, which writes the row via identity-tracked append_message — so a stall, a streaming client disconnect, or a crash during the first response can no longer erase the prompt. This is exactly the "persist on receipt" direction suggested in the report.

    I verified the disconnect-before-response scenario end-to-end against a real SessionDB: create session → append_message(role="user", ...) → no assistant response → the prompt survives (state.db holds the user row). The turn no longer vanishes.

    Three PRs (#45887, #48578, #52985) targeted this and were closed as implemented-on-main; the data-loss path each addressed is already covered. The one genuinely new piece — a gateway "Retry / Discard" prompt for an abandoned turn (mitigating downstream confabulation in follow-up turns) — is a separate enhancement and would be welcome as a focused follow-up PR scoped to just that UX, reviewed on its own merits.

    Thanks @jffuree for the clear repro and the confabulation analysis — it made the root cause easy to confirm.

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

    P1High — major feature broken, no workaroundcomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointtype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions