Skip to content

fix: persist session renames through state.db sync#865

Open
dataguybobby wants to merge 2 commits into
fathah:mainfrom
dataguybobby:fix/session-rename-persistence
Open

fix: persist session renames through state.db sync#865
dataguybobby wants to merge 2 commits into
fathah:mainfrom
dataguybobby:fix/session-rename-persistence

Conversation

@dataguybobby

Copy link
Copy Markdown

Summary

  • Persist chat renames to Hermes state.db before updating the local sessions.json cache, so syncSessionCache cannot resurrect the old title
  • Surface duplicate/invalid title failures (Hermes unique titles + 100-char cap) instead of swallowing DB errors with no UI feedback
  • Share title normalization and rename confirm UX between the sidebar and Sessions modal to keep both screens lean and consistent

Test plan

  • Rename a conversation in the sidebar; switch chats / wait for refresh — name should stick
  • Rename to a title already used by another session — toast shows duplicate error; editor stays open; list rolls back
  • Rename with extra internal spaces — persisted title matches collapsed whitespace in the list after sync
  • npm test -- tests/session-cache-sync.test.ts src/shared/session-title.test.ts
  • npm run typecheck

Made with Cursor

dataguybobby and others added 2 commits July 21, 2026 23:23
Renames previously updated the local sessions.json cache first and
swallowed state.db errors, so the UI looked successful until the next
syncSessionCache restored the old Hermes title. Write the durable DB
row first (honoring unique titles and the 100-char cap), only then
mirror into the cache, and toast/rollback when the write fails.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pull title policy into src/shared/session-title and the optimistic
rename UX into confirmSessionRename so the sidebar and Sessions modal
stop duplicating toast/rollback/refocus logic. Keeps both screens under
the 1k-line ceiling and prevents UI/DB whitespace drift on rename.

Co-authored-by: Cursor <cursoragent@cursor.com>
@greptile-apps

greptile-apps Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes session renames durable and shares the rename flow across both session lists. The main changes are:

  • Writes normalized titles to state.db before updating sessions.json.
  • Adds duplicate, invalid, oversized, unavailable, and missing-session errors.
  • Shares optimistic rename, rollback, toast, and refocus behavior.
  • Adds title-policy and cache-sync tests.

Confidence Score: 4/5

Cache-write failures and overlapping modal renames can leave the displayed title out of sync with durable state.

  • Database-first persistence fixes the original cache-only rename problem.
  • A failed cache mirror is reported as success and may not be repaired by later syncs.
  • An older failed request can roll back a newer successful rename in the modal.

src/main/session-cache.ts and src/renderer/src/screens/Sessions/Sessions.tsx

Important Files Changed

Filename Overview
src/main/session-cache.ts Adds database-first rename persistence and validation, but a suppressed cache-write failure can leave the two stores inconsistent.
src/renderer/src/screens/Sessions/confirmSessionRename.ts Adds the shared optimistic rename, rollback, toast, and refocus flow.
src/renderer/src/screens/Sessions/Sessions.tsx Uses the shared helper for modal and search state, but rollback snapshots are not protected from overlapping requests.
src/renderer/src/screens/Layout/SidebarRecentSessions.tsx Moves sidebar renames to the shared flow while reading the previous title from the current sessions ref.
src/shared/session-title.ts Centralizes title normalization, length validation, and SQLite uniqueness-error detection.
tests/session-cache-sync.test.ts Covers durable renames, duplicate titles, invalid input, and unknown sessions, but not cache-write failures.

Sequence Diagram

sequenceDiagram
    participant UI as Renderer
    participant Main as Main process
    participant DB as state.db
    participant Cache as sessions.json
    UI->>UI: Apply normalized title
    UI->>Main: updateSessionTitle(id, title)
    Main->>DB: Check uniqueness and update
    DB-->>Main: Commit
    Main->>Cache: Mirror title
    Main-->>UI: Resolve or reject
    alt Success
        UI->>UI: Close editor
    else Failure
        UI->>UI: Roll back and show toast
    end
Loading

Reviews (1): Last reviewed commit: "refactor: share session title normalize ..." | Re-trigger Greptile

Comment thread src/main/session-cache.ts
if (idx >= 0) {
cache.sessions[idx].title = title;
cache.sessions[idx].title = normalized;
writeCache(cache);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Cache Mirror Failure Is Hidden

The database has already committed when writeCache runs, but that function suppresses every write error. If disk access fails, this call still reports success while sessions.json keeps the old title; later incremental syncs do not repair established sessions because they select by unchanged started_at and refresh only message counts in the stale-entry pass.

Comment on lines +397 to +400
const oldSessionTitle =
sessions.find((s) => s.id === sessionId)?.title ?? "";
const oldSearchResultTitle =
searchResults.find((r) => r.sessionId === sessionId)?.title ?? "";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Older Rollback Overwrites Newer Rename

Two submissions for the same session can overlap while persistence is pending. If rename B succeeds before rename A fails, A's snapshot rollback runs last and restores the original title over B's optimistic title, leaving the modal inconsistent with the title persisted by B until another refresh.

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