Skip to content

fix: flush_memories history destruction, OpenClaw overwrite, set dedup, chat_id guard - #6687

Closed
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/flush-memories-destruction-overwrite-dedup-chatid
Closed

fix: flush_memories history destruction, OpenClaw overwrite, set dedup, chat_id guard#6687
aaronlab wants to merge 1 commit into
NousResearch:mainfrom
aaronlab:fix/flush-memories-destruction-overwrite-dedup-chatid

Conversation

@aaronlab

@aaronlab aaronlab commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • run_agent.py (HIGH): Fix a latent bug in flush_memories where messages.pop() removes the sentinel before the finally block runs. When memory_tool_def is None (no memory tool registered), the finally while-loop fails to find the sentinel and keeps popping until the entire messages list is empty — destroying all conversation history. Fix: let the finally block handle cleanup as designed.
  • hermes_cli/setup.py: The comment on line 2624 says "no overwrite" but code passes overwrite=True. This silently overwrites existing Hermes configuration with stale OpenClaw data when setup wizard is run again. Fix: align code with comment (overwrite=False).
  • hermes_cli/model_switch.py: Remove duplicate "opencode-go" entry from set literal on line 665 (copy-paste error).
  • tools/send_message_tool.py: Wrap int(chat_id) and int(thread_id) in try/except to prevent unhandled ValueError when Telegram channel name resolution returns non-numeric values (e.g., "@channelname" format).

Test plan

  • Verify flush_memories with no memory tool registered does not corrupt messages list
  • Verify OpenClaw migration preserves existing Hermes config files
  • Verify switch_model with all three OpenCode provider variants
  • Verify _send_telegram with non-numeric chat_id returns clean error

🤖 Generated with Claude Code

…p, chat_id crash

1. run_agent.py: Remove premature messages.pop() in flush_memories when
   memory_tool_def is None. The pop removed the sentinel before the
   finally block ran, causing the while loop to strip ALL remaining
   messages — destroying the entire conversation history. Let the
   finally block handle sentinel cleanup as designed.

2. hermes_cli/setup.py: Change overwrite=True to overwrite=False in
   OpenClaw migration. The comment says "no overwrite" but the code
   contradicts it, silently overwriting existing Hermes configuration
   with stale OpenClaw data on repeated setup wizard runs.

3. hermes_cli/model_switch.py: Remove duplicate "opencode-go" from the
   set literal. The set {"opencode-zen", "opencode-go", "opencode",
   "opencode-go"} contains "opencode-go" twice (copy-paste error).

4. tools/send_message_tool.py: Wrap int(chat_id) and int(thread_id) in
   try/except to handle non-numeric values from channel name resolution
   instead of letting ValueError propagate as a raw traceback.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard platform/telegram Telegram bot adapter labels Apr 29, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the thorough multi-part fix, @aaronlab — closing as redundant. All four changes are dead or already-fixed on current main:

  1. flush_memories history destruction — the entire flush_memories function was removed in PR refactor(memory): remove flush_memories entirely #15696 (merged Apr 25). The code path your fix targeted no longer exists.
  2. hermes_cli/setup.py overwrite=Truemain already passes overwrite=False (with the explanatory comment your fix wanted): the OpenClaw migration was hardened in PR feat(claw-migrate): harden OpenClaw import with plan-first apply, redaction, and pre-migration backup #16911.
  3. hermes_cli/model_switch.py duplicate "opencode-go" — the set literal is already {"opencode-zen", "opencode-go", "opencode"} with no duplicate.
  4. tools/send_message_tool.py int(chat_id) guard — the bare int(chat_id) was replaced with normalize_telegram_chat_id(), which handles the exact @username case you flagged even better than a try/except: it passes the username through to the Bot API (which accepts it) instead of returning an error, so the send still succeeds.

Good catches on real issues — they just all got resolved independently in the weeks since you opened this. Appreciate the contribution.

@teknium1 teknium1 closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants