Skip to content

fix(chat): restore user prompts in session message history#57

Merged
dimakis merged 1 commit intomainfrom
fix/restore-user-prompts
Apr 4, 2026
Merged

fix(chat): restore user prompts in session message history#57
dimakis merged 1 commit intomainfrom
fix/restore-user-prompts

Conversation

@dimakis
Copy link
Copy Markdown
Owner

@dimakis dimakis commented Apr 4, 2026

Summary

  • User prompts were completely missing from restored session histories. The SDK stores user messages with content as a plain string, while assistant messages use an array of content blocks. The getMessages API had if (!Array.isArray(content)) continue; which skipped every user prompt.
  • Now handles both formats: plain strings (user prompts) and content block arrays (assistant turns, tool results).

Root Cause

// Before — skips all user prompts
if (!Array.isArray(content)) continue;

// After — handles string content for user messages
if (typeof content === 'string') { /* build text block */ }
else if (Array.isArray(content)) { /* existing logic */ }

Test plan

  • Open any previous session — verify user prompts now appear
  • Check a session with image attachments — user message text should show
  • Check a multi-turn session — all user messages present between assistant turns
  • Verify tool result messages (SDK-injected user type with only tool_result blocks) are still filtered out

Made with Cursor

The SDK stores user prompts as plain strings (content: "text") while
assistant messages use content block arrays. The getMessages API
skipped any message where content was not an array, so all user
prompts were missing from restored sessions.

Made-with: Cursor
@dimakis dimakis merged commit fae815c into main Apr 4, 2026
1 check passed
@dimakis dimakis deleted the fix/restore-user-prompts branch April 4, 2026 11:52
dimakis added a commit that referenced this pull request Apr 4, 2026
Extracts reconstructMessages() from getMessages() as a pure function
so it can be tested without SDK/disk dependencies. 10 new tests cover:
- User prompts stored as plain strings (the PR #57 fix)
- Assistant messages with text and tool_use blocks
- Tool result attachment from SDK user-type messages
- Filtering of tool-result-only user messages
- Empty/undefined content handling
- Full multi-turn conversation round-trip
- Block ID uniqueness across messages

Made-with: Cursor
dimakis added a commit that referenced this pull request Apr 4, 2026
Extracts reconstructMessages() from getMessages() as a pure function
so it can be tested without SDK/disk dependencies. 10 new tests cover:
- User prompts stored as plain strings (the PR #57 fix)
- Assistant messages with text and tool_use blocks
- Tool result attachment from SDK user-type messages
- Filtering of tool-result-only user messages
- Empty/undefined content handling
- Full multi-turn conversation round-trip
- Block ID uniqueness across messages

Made-with: Cursor
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