Skip to content

fix(desktop): retry auto-title when first user message is not yet persisted#5120

Open
HUQIANTAO wants to merge 4 commits into
esengine:main-v2from
HUQIANTAO:fix/auto-title-retry
Open

fix(desktop): retry auto-title when first user message is not yet persisted#5120
HUQIANTAO wants to merge 4 commits into
esengine:main-v2from
HUQIANTAO:fix/auto-title-retry

Conversation

@HUQIANTAO

Copy link
Copy Markdown
Contributor

Problem

All session titles remain as the default "新的会话" (New Session) indefinitely. The .jsonl.meta sidecar files have an empty topic_title field, and the auto-title mechanism silently gives up after the first failed attempt.

Reproduction (Issue #5017):

  1. Open Reasonix Desktop
  2. Start a new conversation and send a message
  3. The session title stays as "新的会话" instead of updating

Root Cause

The auto-title flow in desktop/tabs.go:

  1. tabSnapshotLoop calls maybeAutoTitleTopic after each successful ctrl.Snapshot()
  2. maybeAutoTitleTopic calls autoTitleTopicFromSession
  3. autoTitleTopicFromSession calls topicTitleFromSession(sessionPath) which opens the JSONL file and reads messages until it finds role: "user"
  4. If no user message is found yet (the first message hasn't been persisted to disk at the time of the snapshot), topicTitleFromSession returns ""
  5. The function returns "", false with no retry signal — the title stays as default forever

The race condition: the first Snapshot() can complete before the user's first message is fully written to the JSONL file. The auto-title mechanism reads an empty file, gets no result, and never tries again.

Fix

Modify autoTitleTopicFromSession to return a retry flag as a third return value. When the title extraction fails but the current title is still the default (meaning no title has ever been successfully set), signal the caller to retry on the next snapshot loop iteration instead of giving up permanently.

Changes in desktop/tabs.go:

// Before
func autoTitleTopicFromSession(workspaceRoot, topicID, sessionPath string) (string, bool) {
    // ...
    if nextTitle == "" || nextTitle == loadTopicTitle(workspaceRoot, topicID) {
        return "", false  // gives up permanently
    }
    // ...
}

// After
func autoTitleTopicFromSession(workspaceRoot, topicID, sessionPath, currentTitle string) (title string, updated bool, retry bool) {
    // ...
    if nextTitle == "" || nextTitle == currentTitle {
        if currentTitle == "" || currentTitle == defaultTopicTitle {
            return "", false, true  // retry on next snapshot
        }
        return "", false, false
    }
    // ...
}

The caller maybeAutoTitleTopic now uses the retry flag:

nextTitle, updated, retry := autoTitleTopicFromSession(titleRoot, tab.TopicID, sessionPath, ...)
if !updated {
    return retry  // true → snapshot loop will emit and continue; false → no change
}

Testing

  1. Create a new topic, send a message
  2. Verify the title updates from "新的会话" to a truncated version of the first message
  3. Verify manually-renamed topics are not overwritten
  4. Verify the retry doesn't cause excessive emissions (only retries while title is still default)

@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 23, 2026
…sisted

When a new topic is created, the auto-title mechanism reads the JSONL
session file to extract the first user message as the topic title. If
the first snapshot occurs before the user message is written to disk,
topicTitleFromSession returns an empty string and the title stays as
the default '新的会话' indefinitely — the function never retries.

Fix autoTitleTopicFromSession to return a retry flag. When the title
extraction fails but the current title is still the default (meaning no
title has ever been set), signal the caller to try again on the next
snapshot loop iteration instead of giving up permanently.

Fixes esengine#5017
@HUQIANTAO HUQIANTAO force-pushed the fix/auto-title-retry branch from c2c768f to 59cb156 Compare June 23, 2026 05:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant