Skip to content

fix: session restore crash — getMessages returns v2 format, guard stale caches#35

Merged
dimakis merged 1 commit into
mainfrom
fix/session-restore-v2
Apr 2, 2026
Merged

fix: session restore crash — getMessages returns v2 format, guard stale caches#35
dimakis merged 1 commit into
mainfrom
fix/session-restore-v2

Conversation

@dimakis
Copy link
Copy Markdown
Owner

@dimakis dimakis commented Apr 2, 2026

Summary

  • Server getMessages() was returning v1-format objects ({ role, text, toolCalls }) while the v2 frontend expects FinishedMessage ({ messageId, role, blocks: FinishedBlock[] }). Navigating to an existing session caused groupBlocks() to iterate undefined, crashing with "undefined is not an object (evaluating 'n')" in the minified build.
  • RESTORE reducer now filters out messages missing messageId/blocks, so stale pre-v2 localStorage caches degrade gracefully.
  • ChatView validates localStorage shape, evicts stale caches, and falls through to the API. groupBlocks() guards non-array input.

Test plan

  • 205 tests pass (5 new: RESTORE guard x3, groupBlocks undefined/null guard x2)
  • tsc --noEmit clean
  • Pre-commit hooks (eslint + prettier) pass
  • Navigate to an existing session from home screen on iOS — should render messages instead of crashing
  • New chat sessions still stream correctly
  • Reattach after iOS background still works

Made with Cursor

…le caches

The /api/sessions/:id/messages endpoint still returned v1-format objects
({ role, text, toolCalls }) while the v2 frontend expects FinishedMessage
({ messageId, role, blocks: FinishedBlock[] }). Navigating to an existing
session restored shapeless objects — groupBlocks() iterated undefined
blocks, crashing with "undefined is not an object (evaluating 'n')".

Three fixes:
1. Server getMessages() now converts SDK history to v2 FinishedMessage[]
   with messageId, role, and blocks array.
2. RESTORE reducer action filters out messages missing messageId/blocks,
   so stale v1 localStorage caches degrade gracefully instead of crashing.
3. ChatView invalidates pre-v2 localStorage caches and falls through to
   the API. groupBlocks() guards against non-array input.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Made-with: Cursor
@dimakis dimakis merged commit 2504659 into main Apr 2, 2026
1 check passed
@dimakis dimakis deleted the fix/session-restore-v2 branch April 2, 2026 23:52
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