Skip to content

Persist chat and image history#69

Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1777320403-persist-chat-image-history
Open

Persist chat and image history#69
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1777320403-persist-chat-image-history

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot commented Apr 27, 2026

Summary

Adds AsyncStorage persistence for both chat and image history so conversations and generated images survive app restarts.

Chat history (chat.tsx):

  • Loads per-model chat states from rnai-chatStates on mount
  • Persists to AsyncStorage only at stream completion ([DONE]) and on clear — avoids excessive writes during SSE streaming
  • Guards chat() with chatLoaded flag to prevent race conditions during async load
  • Clearing a chat removes that model's entry from storage

Image history (images.tsx):

  • Loads image generation history from rnai-imageHistory on mount
  • Saves after each successful image generation
  • Guards generate() with imagesLoaded flag to prevent race conditions
  • Clearing prompts removes the persisted data

Uses the same AsyncStorage pattern already established in App.tsx for theme/model preferences.

Review & Testing Checklist for Human

  • Start a chat conversation, close the app, reopen — messages should be restored
  • Switch between models, verify each model's history persists independently
  • Generate an image, close the app, reopen — the image prompt and result should be restored
  • Use "Clear chat" / "Clear prompts" and verify the history is actually removed (doesn't reappear on restart)

Notes

  • Storage keys: rnai-chatStates (chat), rnai-imageHistory (images)

Link to Devin session: https://app.devin.ai/sessions/3ca51d55be7e4c4aa48cf5ab6ebcf95b
Requested by: @dabit3


Open in Devin Review

- Chat history (per-model conversation states) saved to AsyncStorage on every update
- Image generation history saved to AsyncStorage after each successful generation
- Both histories restored on component mount
- Clear chat/clear prompts properly cleans up persisted data

Co-Authored-By: Nader Dabit <dabit3@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

- Move saveChatHistory out of updateChatState to avoid writing on every SSE token
- Only persist at stream completion ([DONE]) and on clear
- Guard chat() and generate() with chatLoaded/imagesLoaded to prevent race conditions

Co-Authored-By: Nader Dabit <dabit3@gmail.com>
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