You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prompt is lost entirely when a turn's first response never completes (stall or client disconnect) #45110
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.
Reproduced on both CLI chat and the gateway's OpenAI-compatible /v1/chat/completions (streaming)
Reproduction (gateway streaming variant)
POST a streaming request to the gateway /v1/chat/completions with a
prompt that takes a while to answer.
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).
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:
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.
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.
Closing — the data-loss bug here is fixed on current main.
The inbound user message is now persisted to state.dbon 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)
exceptException:
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.
Activity
fix(agent): address review: ensure_db_session retry instead of dead p…
teknium1 commentedon Jun 28, 2026
Closing — the data-loss bug here is fixed on current
main.The inbound user message is now persisted to
state.dbon receipt, before any model call, inagent/turn_context.py:That flows through
_flush_messages_to_session_db, which writes the row via identity-trackedappend_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.dbholds 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.