Skip to content

fix(session): make /clear reset middleware state without losing initial context - #69

Open
imMamdouhaboammar wants to merge 12 commits into
MagicCube:mainfrom
imMamdouhaboammar:fix/session-reset-state
Open

fix(session): make /clear reset middleware state without losing initial context#69
imMamdouhaboammar wants to merge 12 commits into
MagicCube:mainfrom
imMamdouhaboammar:fix/session-reset-state

Conversation

@imMamdouhaboammar

Copy link
Copy Markdown

Summary

Make /clear start a genuinely fresh agent session instead of clearing only the visible/message transcript.

Root causes

Helixent has session state both inside and outside agent.messages:

  • repo AGENTS.md is loaded into the Agent as an initial user-context message
  • todo_write keeps its task list and reminder counters inside middleware closure state
  • the TUI scrollback flusher keeps a numeric cursor into the previous message array

The TUI /clear command called agent.clearMessages(). That removed the initial AGENTS.md context for the rest of the process, while leaving todo middleware state alive. A later prompt could therefore lose repository instructions yet still receive reminders from tasks that belonged to the cleared conversation.

The scrollback cursor also remained at the old session's message index. After history shrank to zero, new messages could be skipped from terminal scrollback until the new session grew past the previous cursor.

Changes

  • add Agent.reset() as a separate API from clearMessages()
  • snapshot constructor-provided initial messages and restore them on reset
  • add an optional middleware onReset lifecycle hook for session state not represented in messages
  • prevent reset while the Agent is actively streaming
  • clear requested-skill state during reset
  • make todo middleware clear its store and reminder counters on reset
  • make TUI /clear await agent.reset() instead of deleting every internal message
  • reset the TUI scrollback flush cursor when visible history shrinks
  • keep clearMessages() unchanged for existing library callers that explicitly want an empty transcript

Regression coverage

  • Agent reset restores constructor-provided context and preserves the original messages array reference
  • middleware reset hooks run after requested-skill state is cleared
  • todo reminders from a previous session disappear after reset

This aligns the visible /clear behavior with the actual agent session boundary while preserving repository context such as AGENTS.md.

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.

1 participant