Skip to content

feat(sessions): sort session list by filesystem modTime#2972

Merged
qin-ctx merged 2 commits into
mainfrom
feat/session-recency-sort
Jul 3, 2026
Merged

feat(sessions): sort session list by filesystem modTime#2972
qin-ctx merged 2 commits into
mainfrom
feat/session-recency-sort

Conversation

@ZaynJarvis

Copy link
Copy Markdown
Collaborator

Summary

Session lists in the web studio (sidebar + playground history) were sorted by name order with a .reverse() hack. This PR adds proper recency sorting using the session directory's filesystem mtime.

Changes

Backend (openviking/service/session_service.py)

  • sessions() list API now includes mod_time from viking_fs.ls() stat output — zero extra I/O since the entry already carries it

Frontend types (web-studio/types/ov-server/api/v1/sessions.ts)

  • SessionListItem gains mod_time: string

Frontend hooks (web-studio/src/lib/sessions/use-sessions.ts)

  • useSessionListByRecency simplified: sorts by mod_time directly from the list response instead of issuing N per-session detail requests via useQueries

Frontend consumers

  • app-shell.tsx: sidebar uses useSessionListByRecency, removes .reverse() hack
  • agent-panel.tsx: playground history filters from the recency-sorted list

File tree (web-studio/src/routes/playground/-lib/utils.ts)

  • sortTreeEntries sorts directories by modTimestamp descending (newest first), fallback to name

Impact

Metric Before After
Requests to load session list 1 + N (detail per session) 1
Sort basis name reversed → updated_at from .meta.json directory mtime from filesystem
Time to sorted render waits for all detail queries immediate

@ZaynJarvis ZaynJarvis left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Codex Review

Verdict: LGTM — no blocking issues

Structure: Single commit, 6 files, all changes are on-topic (session recency sorting + file tree modTime sort). No unrelated changes.

Design: The approach is correct. mod_time is already present in viking_fs.ls() output, so adding it to the list response is zero extra I/O. Frontend simplification from 1+N requests to 1 is a clear win.

One design note (non-blocking, already discussed with author):

  • Directory mtime ≠ last-activity time. On Unix filesystems, a directory's mtime only updates when entries are created/deleted/renamed inside it — not when an existing file (like messages.jsonl or .meta.json) is written in-place. So a session receiving new messages may not bubble to the top of the list. This is a trade-off vs. the previous approach of reading .meta.json's updated_at per session. Acceptable for the 1-request simplification; revisit if users report stale ordering.

Fix applied during review: Renamed reversedSessionsplaygroundSessions in agent-panel.tsx — the variable no longer reverses anything, it just filters from the recency-sorted list.

Compatibility: mod_time is an additive field. Existing callers (Python SDK, bot) use .get() to access dict fields, so no breakage.

The AgentPanel used to call POST /sessions on every page load (via a
useEffect gated on botHealth.isSuccess), creating empty UUID sessions
even when the user never sent a message. These orphan sessions cluttered
the session list.

Fix: generate a client-side UUID as the initial sessionId instead of an
empty string. The session is lazily created on the backend by the first
addMessage call (POST /sessions/{id}/messages uses auto_create=True).

- Remove startSession() and its auto-create useEffect
- Always have a sessionId (createRandomUuid fallback)
- Simplify useChat params (persistMessages always true, no preview fallback)
- Remove dead isCreating UI branch
- Call onSessionChange on mount so the URL stays in sync
- Error retry button now uses handleNewSession()

Closes: orphan empty sessions created on playground page load
- Backend: add mod_time to session list API response (from viking_fs.ls stat)
- Frontend: useSessionListByRecency sorts by mod_time instead of N detail fetches
- Frontend: sidebar and playground history use recency-sorted list
- Frontend: sortTreeEntries sorts directories by modTime descending

Reduces session list load from 1+N requests to 1 request.
@ZaynJarvis ZaynJarvis force-pushed the feat/session-recency-sort branch from 02a1eac to dc5ee7f Compare July 2, 2026 20:04
@qin-ctx qin-ctx merged commit 6f97624 into main Jul 3, 2026
3 checks passed
@qin-ctx qin-ctx deleted the feat/session-recency-sort branch July 3, 2026 03:05
@github-project-automation github-project-automation Bot moved this from Backlog to Done in OpenViking project Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants