Skip to content

feat(ai): List saved assistant sessions so past chats can be resumed#181

Merged
nfebe merged 1 commit into
mainfrom
feat/ai-session-list
Jul 19, 2026
Merged

feat(ai): List saved assistant sessions so past chats can be resumed#181
nfebe merged 1 commit into
mainfrom
feat/ai-session-list

Conversation

@nfebe

@nfebe nfebe commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Assistant conversations were already persisted per user, but nothing could enumerate them, so the UI could not show past chats or reopen one. This adds a listing of the caller's saved sessions (all of them for an admin), most recent first, each with a short title from its first message. It reuses the existing on-disk session store.

UI counterpart: flatrun/ui#88.

Assistant conversations were already persisted per user, but there was no way
to enumerate them, so the UI could not show past chats or reopen one. This adds
a listing of the caller's saved sessions (all of them for an admin), most recent
first, each with a short title taken from its first message.
@sourceant

sourceant Bot commented Jul 19, 2026

Copy link
Copy Markdown

Code Review Summary

This PR implements a feature to list saved AI sessions. It introduces a lightweight summary view, smart title generation from chat history, and an API handler that correctly filters sessions based on user identity and admin status.

🚀 Key Improvements

  • Added SessionSummary to avoid transferring full transcripts in list views.
  • Implemented intelligent title generation from the first visible user message.
  • Added unit tests for title generation and store listing logic.
  • Properly integrated admin/user visibility filtering in the API layer.

💡 Minor Suggestions

  • Consider passing a filter (e.g., UserID) to SessionStore.List to avoid loading all sessions from disk just to filter them in memory at the API handler level.
  • Use slices.SortFunc if the project uses Go 1.21+.

@sourceant sourceant Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review complete. See the overview comment for a summary.

Comment thread internal/ai/session.go
}
return nil, err
}
summaries := []SessionSummary{}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While functional, this implementation has a few performance and efficiency considerations:

  1. Performance: st.Get unmarshals the full session JSON, including potentially large transcripts (hundreds of messages). For a listing view, consider decoding into a 'metadata-only' struct that ignores the messages array to save memory and CPU.
  2. Optimization: Pre-allocate the summaries slice capacity to avoid repeated re-allocations during the loop.
  3. Modern Go: If using Go 1.21+, slices.SortFunc is preferred over sort.Slice for type safety and performance.
Suggested change
summaries := []SessionSummary{}
summaries := make([]SessionSummary, 0, len(entries))
for _, e := range entries {
if e.IsDir() || !strings.HasSuffix(e.Name(), ".json") {
continue
}
// Note: st.Get loads the full session. Optimization to load metadata only is recommended for scale.
sess, err := st.Get(strings.TrimSuffix(e.Name(), ".json"))
if err != nil {
continue
}
summaries = append(summaries, sess.Summary())
}
sort.Slice(summaries, func(i, j int) bool { return summaries[i].UpdatedAt.After(summaries[j].UpdatedAt) })

@nfebe
nfebe merged commit 1526048 into main Jul 19, 2026
6 checks passed
@nfebe
nfebe deleted the feat/ai-session-list branch July 19, 2026 18:47
@nfebe nfebe mentioned this pull request Jul 19, 2026
42 tasks
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