mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
fix(acp): use SessionDB.replace_messages for atomic history rewrite
ACP's save_session() did a non-atomic clear_messages() + append_message() loop. If any message hit an exception mid-loop (bad tool_call shape, etc.), the DELETE had already committed and the persisted conversation was lost. SessionDB.replace_messages() wraps DELETE + bulk INSERT in a single BEGIN IMMEDIATE transaction that rolls back on any exception, so a bad message can no longer clobber previously-persisted history. Salvages @Awsh1's PR #13675 — uses the existing replace_messages() helper (which covers more message fields than the PR's own copy) instead of adding a duplicate.
This commit is contained in:
parent
e805380b82
commit
5795b3be4e
1 changed files with 4 additions and 11 deletions
|
|
@ -466,17 +466,10 @@ class SessionManager:
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.debug("Failed to update ACP session metadata", exc_info=True)
|
logger.debug("Failed to update ACP session metadata", exc_info=True)
|
||||||
|
|
||||||
# Replace stored messages with current history.
|
# Replace stored messages with current history atomically so a
|
||||||
db.clear_messages(state.session_id)
|
# mid-rewrite failure rolls back and the previously persisted
|
||||||
for msg in state.history:
|
# conversation is preserved (salvaged from #13675).
|
||||||
db.append_message(
|
db.replace_messages(state.session_id, state.history)
|
||||||
session_id=state.session_id,
|
|
||||||
role=msg.get("role", "user"),
|
|
||||||
content=msg.get("content"),
|
|
||||||
tool_name=msg.get("tool_name") or msg.get("name"),
|
|
||||||
tool_calls=msg.get("tool_calls"),
|
|
||||||
tool_call_id=msg.get("tool_call_id"),
|
|
||||||
)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning("Failed to persist ACP session %s", state.session_id, exc_info=True)
|
logger.warning("Failed to persist ACP session %s", state.session_id, exc_info=True)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue