forked from NousResearch/hermes-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(agent): persist messages by intrinsic marker to stop id() reuse data loss (salvage #50372) #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hashbender
wants to merge
1
commit into
main
Choose a base branch
from
mirror/pr-56284
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Exception handler does not clear _flushed_db_message_ids seed, risking stale-id dedup error across retry paths (bug)
In
_flush_messages_to_session_db(run_agent.py), the one-shot seed_flushed_db_message_idsis intended to be reset to an empty set after every flush. However, the reset at line 1835 is inside thetryblock. If an exception occurs during the flush loop — e.g., a transient DB lock timeout onappend_message(line 1816) — control jumps to theexceptat line 1837, which only logs and falls through. The stale seed survives on the agent object. On a subsequent flush call in the same session,_last_flushed_db_idx > 0andflushed_session_idmatches, soseed_idsis read from the uncleared_flushed_db_message_ids. If that stale set contains an id matching a new message (address reuse in CPython), the new message is stamped_db_persistedand silently skipped — data loss. No current production code populates_flushed_db_message_idswith non-empty values (only tests do), but the invariant violation makes the code fragile to any future production seeder.💡 Suggestion: Clear
_flushed_db_message_idsbefore the message loop (immediately after capturingseed_idsat line 1763) rather than after, so the seed is consumed instantly and cannot survive an exception.📋 Prompt for AI Agents
In run_agent.py
_flush_messages_to_session_db, move theself._flushed_db_message_ids = set()to immediately after line 1763 (afterseed_ids = set()in both branches), so the seed is consumed before the flush loop begins. This ensures an exception during the loop cannot leave stale IDs on the agent object. The_last_flushed_db_idxupdate can stay at line 1836 since it's only needed for successful flushes.