Skip to content

fix(agent): persist repaired-turn responses - #46071

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-82ce03d4
Jun 14, 2026
Merged

fix(agent): persist repaired-turn responses#46071
teknium1 merged 1 commit into
mainfrom
hermes/hermes-82ce03d4

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

SessionDB flushing now persists newly appended assistant responses even when message-sequence repair has shortened the live messages list below conversation_history length.

Changes

  • run_agent.py: replace positional flush slicing with per-session message identity tracking, so history dicts are skipped by identity and newly appended dicts are written once.
  • tests/run_agent/test_identity_flush.py: cover repair-shrunk history, stale cached-agent cursor, same-turn dedup, and cached-agent turn reset.
  • tests/run_agent/test_compression_persistence.py: flip the stale-history regression from documenting the drop to asserting persistence.

Validation

Check Result
python3 -m py_compile run_agent.py tests/run_agent/test_identity_flush.py tests/run_agent/test_compression_persistence.py pass
scripts/run_tests.sh tests/run_agent/test_identity_flush.py tests/run_agent/test_compression_persistence.py tests/run_agent/test_860_dedup.py 18 passed

Fixes #46053.

Infographic

Repaired Turns Now Persist

@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-82ce03d4 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10895 on HEAD, 10893 on base (🆕 +2)

🆕 New issues (2):

Rule Count
unresolved-attribute 2
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:2920: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`

✅ Fixed issues (1):

Rule Count
invalid-assignment 1
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`

Unchanged: 5724 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@liuhao1024

Copy link
Copy Markdown
Contributor

Verification: LGTM — solid identity-based flush fix

Reviewed the full diff. The positional-slice approach (messages[flush_from:]) was fragile when repair_message_sequence merged/shrunk the history — len(conversation_history) > len(messages) made the slice empty, silently dropping assistant responses (#46053).

The replacement using id(msg) identity tracking is correct:

Test coverage is thorough — 4 new tests in test_identity_flush.py covering the exact regression scenario (stale cursor, repeated flush, cursor reset on new turn). The existing test_flush_with_stale_history_loses_messages is updated from "verifies the bug exists" to "verifies the fix works" — clean transition.

One note: _last_flushed_db_idx is still set to len(messages) at the end (line ~1633), but it's no longer used for slicing — only for the session-id reset gate. This is harmless but could be cleaned up in a follow-up if desired.

@teknium1

Copy link
Copy Markdown
Contributor Author

Live testing added after CI because this touches the core persistence path:

Scenario Result
Direct real SessionDB + real AIAgent._flush_messages_to_session_db with len(conversation_history)=8, len(messages)=3 Old positional flush_from=8 would be empty; PR persisted the new user + assistant rows and repeat flush kept row count stable at 11
Headless real Hermes CLI from this worktree with isolated HERMES_HOME Provider returned LIVE_PERSISTENCE_OK; state.db contained both user and assistant rows, assistant finish_reason=stop
Real AIAgent.run_conversation() with poisoned DB-style history of 7 consecutive persisted user rows repair_message_sequence merged the history path, model returned LIVE_REPAIR_FLOW_OK, state.db persisted the assistant row; repeat _persist_session kept row count stable at 9

The repair-flow test is the sensitive case from #46053: persisted conversation_history is longer than the repaired working messages list. The assistant row still landed in state.db.

@teknium1
teknium1 merged commit 2b4873f into main Jun 14, 2026
28 checks passed
@teknium1
teknium1 deleted the hermes/hermes-82ce03d4 branch June 14, 2026 10:20
AIalliAI pushed a commit to AIalliAI/Hermes that referenced this pull request Jun 14, 2026
loongfay pushed a commit to YuanbaoTeam/hermes-agent that referenced this pull request Jun 15, 2026
loongfay pushed a commit to YuanbaoTeam/hermes-agent that referenced this pull request Jun 15, 2026
T02200059 pushed a commit to T02200059/hermes-agent that referenced this pull request Jun 18, 2026
teknium1 pushed a commit that referenced this pull request Jul 1, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to #46071 / #46053, but covers the adjacent case where the assistant message was never appended before persistence.
teknium1 pushed a commit that referenced this pull request Jul 1, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to #46071 / #46053, but covers the adjacent case where the assistant message was never appended before persistence.
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
waefrebeorn pushed a commit to waefrebeorn/slermes that referenced this pull request Jul 2, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to NousResearch#46071 / NousResearch#46053, but covers the adjacent case where the assistant message was never appended before persistence.
caozuohua pushed a commit to caozuohua/hermes-agent that referenced this pull request Jul 2, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to NousResearch#46071 / NousResearch#46053, but covers the adjacent case where the assistant message was never appended before persistence.

(cherry picked from commit 59e7e9d)
Methodician added a commit to Methodician/hermes-agent that referenced this pull request Jul 4, 2026
Jasper6439 pushed a commit to Jasper6439/hermes-agent that referenced this pull request Jul 5, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to NousResearch#46071 / NousResearch#46053, but covers the adjacent case where the assistant message was never appended before persistence.
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to NousResearch#46071 / NousResearch#46053, but covers the adjacent case where the assistant message was never appended before persistence.
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to NousResearch#46071 / NousResearch#46053, but covers the adjacent case where the assistant message was never appended before persistence.
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to NousResearch#46071 / NousResearch#46053, but covers the adjacent case where the assistant message was never appended before persistence.
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
Close a recovery/fallback final_response with an assistant transcript entry before session persistence so durable history cannot end at a tool/user message after the caller receives a final answer.

Adds a regression for a tool-tail transcript with a non-empty final_response. Related to NousResearch#46071 / NousResearch#46053, but covers the adjacent case where the assistant message was never appended before persistence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: assistant responses silently dropped after repair_message_sequence (conversation_history vs messages mismatch)

2 participants