Skip to content

fix(session): retry failed title generation - #39748

Merged
kitlangton merged 7 commits into
v2from
retry-session-title
Jul 31, 2026
Merged

fix(session): retry failed title generation#39748
kitlangton merged 7 commits into
v2from
retry-session-title

Conversation

@kitlangton

@kitlangton kitlangton commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

What

Automatic title generation now retries after a failed first execution step and still uses the session's original user prompt even when later prompts have been admitted. Explicit titles and manual renames remain authoritative.

Closes #39529.

Before / After

Before: if the first model step failed, title generation never started. After a second user message arrived, the history lookup rejected the session because it no longer had exactly one user message; a process-local latch then prevented useful recovery, leaving the fallback title indefinitely.

After: each later successful execution can start one coalesced title attempt while the session remains untitled. The attempt reads the first user message, retries after provider failure, and publishes only if the title is still absent or the exact historical fallback for that session.

A manual rename that lands during generation, including between the final read and event publication, wins: the generated rename uses the durable session event sequence as an atomic commit guard and rolls back if another session event committed first.

How

  • session/history.ts returns the first user message regardless of later user-message count.
  • session/runner/llm.ts replaces the permanent process latch with in-flight request coalescing, clearing it after every attempt so later executions can retry.
  • session/title.ts checks durable title state before the request and again before publication, recognizes only the exact legacy fallback derived from the session creation time, and sequence-guards the rename transaction.
  • Direct and runner-level regressions cover first-of-many history, provider failure and recovery, explicit titles, legacy rows, and in-flight manual renames.

Scope

This PR depends on #39747 for optional title storage and display fallbacks. It does not alter title prompts, model selection, or generated title formatting.

Testing

  • packages/core: bun typecheck
  • packages/core: bun run test -- test/session-title.test.ts (8 passed)
  • packages/core: bun run test -- test/session-runner.test.ts --test-name-pattern "retries title generation" (1 passed, 136 filtered)
  • packages/core: bun run migration --check
  • Full Core run: 1,526 passed, 6 skipped; one unrelated local-environment failure because plugin discovery included ~/.config/opencode/plugins/voice.ts in a fixture expecting only its two invalid plugins

Flow

sequenceDiagram
  participant Runner
  participant Title as SessionTitle
  participant Store as Session store
  participant LLM
  participant Bus

  Runner->>Title: start after successful step
  Title->>Store: title still absent/legacy fallback?
  Title->>LLM: generate from first user prompt
  alt generation fails
    Title-->>Runner: finish without title
    Note over Runner,Title: in-flight marker clears; later execution retries
  else generation succeeds
    Title->>Bus: snapshot session sequence
    Title->>Store: recheck title
    Title->>Bus: publish rename with sequence guard
    Bus-->>Store: commit only if no intervening event
  end
Loading

@kitlangton
kitlangton force-pushed the optional-session-title branch from 5f8e8b8 to 8eb2231 Compare July 31, 2026 00:44
@kitlangton
kitlangton force-pushed the retry-session-title branch from 018f111 to 9ffe221 Compare July 31, 2026 00:44
Base automatically changed from optional-session-title to v2 July 31, 2026 01:24
@kitlangton
kitlangton merged commit 0a6a5d3 into v2 Jul 31, 2026
18 of 22 checks passed
@kitlangton
kitlangton deleted the retry-session-title branch July 31, 2026 01:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant