Skip to content

fix(tui): system prompt not loaded in interactive mode#218

Merged
avoidwork merged 2 commits into
mainfrom
fix/interactive-system-prompt
Jun 13, 2026
Merged

fix(tui): system prompt not loaded in interactive mode#218
avoidwork merged 2 commits into
mainfrom
fix/interactive-system-prompt

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

The Problem

In interactive mode (TUI), the system prompt was not being loaded correctly. The agent would fall back to its default identity instead of using the custom persona defined in prompts/SYSTEM_PROMPT.md.

Root Cause

The TUI's handleChat function was calling sessionState.addExchange({ role: 'user', content: text }) before calling dispatchProvider. This meant that when callProvider checked sessionState.getConversation().length === 0 to determine isNewThread, it was already false (the user message was already in the conversation).

Since isNewThread was false, the system prompt was never prepended to the conversation messages in callReactAgent.

The Fix

Move the sessionState.addExchange({ role: 'user' }) call to after dispatchProvider returns, matching the non-interactive flow where callProvider is called before the exchange is persisted.

Before (broken):

sessionState.addExchange({ role: 'user', content: text });  // <-- Too early!
const response = await dispatchProvider(text, ...);
sessionState.addExchange({ role: 'assistant', content: response.content });

After (fixed):

const response = await dispatchProvider(text, ...);  // isNewThread is now true
sessionState.addExchange({ role: 'user', content: text });  // <-- After dispatch
sessionState.addExchange({ role: 'assistant', content: response.content });

Testing

  • Non-interactive mode: node index.js "who are you?" - works correctly
  • Unit tests: 1117/1118 pass (1 pre-existing failure unrelated to this change)

The TUI was adding the user message to sessionState BEFORE calling
dispatchProvider, which caused isNewThread to be false. This prevented
the system prompt from being prepended to the conversation on the
first message.

Fix: Move sessionState.addExchange({ role: 'user' }) to AFTER
dispatchProvider returns, matching the non-interactive flow where
callProvider is called before the exchange is persisted.
@avoidwork avoidwork self-assigned this Jun 13, 2026
@avoidwork avoidwork enabled auto-merge (squash) June 13, 2026 23:09
@avoidwork avoidwork merged commit 08c99b5 into main Jun 13, 2026
3 checks passed
@avoidwork avoidwork deleted the fix/interactive-system-prompt branch June 13, 2026 23:10
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