Skip to content

fix(tui): stabilize generated session titles - #39894

Merged
kitlangton merged 1 commit into
v2from
title-flap
Jul 31, 2026
Merged

fix(tui): stabilize generated session titles#39894
kitlangton merged 1 commit into
v2from
title-flap

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Keep generated TUI session titles stable when title generation overlaps initial hydration and when multiple TUI processes share persisted tabs.

Before / After

Before

  1. A TUI starts loading an untitled session.
  2. session.renamed delivers the generated title while the initial session read is still in flight.
  3. The untitled response wins, leaving that TUI with a synthetic New session fallback.
  4. Another TUI with the generated title and the stale TUI both write shared tabs.json.
  5. Their filesystem watchers repeatedly reload and overwrite each other, visibly alternating tabs between the generated title and New session.

After

Rename events reapply their title after initial hydration. Persisted titles are also treated as hints that an untitled local snapshot cannot downgrade, and tab normalization reruns against the latest file contents after acquiring the storage lock.

How

  • packages/tui/src/context/data.tsx waits for session hydration before applying session.renamed.
  • packages/tui/src/context/session-tabs.tsx prefers authoritative session titles, then persisted titles, then synthetic fallbacks.
  • Tab and unread normalization use one shared path for reactive comparisons and locked persistence updates.
  • Lifecycle coverage holds an untitled session response across a rename event.
  • Concurrent-TUI coverage mounts two clients against one state directory and watches for title alternation.

Scope

This supersedes the TUI hydration fix proposed in #39051 and adds coverage for the separate shared-tab persistence feedback loop. It does not redesign session sync keys or generic storage no-op handling.

Testing

  • bun run test from packages/tui: 578 passed, 5 skipped
  • bun typecheck from packages/tui
  • Push hook workspace typecheck: 33 packages passed
  • bunx prettier --check packages/tui/src/context/data.tsx packages/tui/src/context/session-tabs.tsx packages/tui/test/app-lifecycle.test.tsx packages/tui/test/context/session-tabs.test.tsx

Demo

The deterministic concurrent-TUI regression reproduced repeated generated-title/default-title writes before the fix. After the fix, the shared file remains on Generated title for the full observation window.

Flow

sequenceDiagram
  participant Server
  participant Titled as TUI with generated title
  participant Stale as TUI with untitled snapshot
  participant Tabs as shared tabs.json

  Server-->>Titled: session.renamed
  Titled->>Tabs: persist generated title
  Tabs-->>Stale: filesystem reload
  Stale->>Stale: preserve persisted title
  Note over Stale,Tabs: synthetic fallback cannot downgrade generated title
Loading

@kitlangton
kitlangton merged commit dc3c996 into v2 Jul 31, 2026
6 of 7 checks passed
@kitlangton
kitlangton deleted the title-flap branch July 31, 2026 15:13
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