Skip to content

fix(todo): filter completed/cancelled items when restoring from history - #7595

Closed
johnhom1024 wants to merge 1 commit into
NousResearch:mainfrom
johnhom1024:fix/todo-cancelled-items-revival
Closed

fix(todo): filter completed/cancelled items when restoring from history#7595
johnhom1024 wants to merge 1 commit into
NousResearch:mainfrom
johnhom1024:fix/todo-cancelled-items-revival

Conversation

@johnhom1024

@johnhom1024 johnhom1024 commented Apr 11, 2026

Copy link
Copy Markdown

Closes #7599

Bug Description

Cancelled (or completed) todo items spontaneously resurrect and get executed after subsequent tasks complete. When a user explicitly cancels a task (e.g. says 'don't do that'), the task should remain cancelled permanently. However, after completing another task, the cancelled task reappears and Hermes silently executes it.

Root Cause

In run_agent.py, _hydrate_todo_store() (~line 2883) restores all todo items from conversation history without filtering out completed/cancelled ones. This contradicts format_for_injection() in tools/todo_tool.py which intentionally excludes them during context compression — causing a mismatch where cancelled items are excluded from compression but resurrected on hydration.

Fix

Filter to only pending/in_progress items before writing to the todo store, matching format_for_injection():

Before:

if last_todo_response:
    self._todo_store.write(last_todo_response, merge=False)
    self._vprint(f"Restored {len(last_todo_response)} todo item(s) from history")

After:

if last_todo_response:
    active_items = [
        item for item in last_todo_response
        if item.get("status") in ("pending", "in_progress")
    ]
    self._todo_store.write(active_items, merge=False)
    self._vprint(f"Restored {len(active_items)} todo item(s) from history ({len(last_todo_response) - len(active_items)} filtered)")

Testing

  • Syntax verified with python3 -m py_compile
  • Bug reproduced and root cause identified via conversation history analysis
  • Fix applied to local Hermes and fork

Hydrating the TodoStore from conversation history would resurrect
cancelled items that format_for_injection() had intentionally excluded
during context compression. This caused previously cancelled tasks to
reappear after subsequent agent turns.

Now _hydrate_todo_store() only restores pending/in_progress items,
matching the behavior of format_for_injection().
@johnhom1024

Copy link
Copy Markdown
Author

find the relative issue may not cause by this code

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]: Cancelled tasks resurrect after subsequent agent turns

1 participant