Skip to content

fix(sessions): stop chat-title regeneration on every view remount#3315

Open
tatoalo wants to merge 2 commits into
mainfrom
posthog-code/fix-title-regen-on-remount
Open

fix(sessions): stop chat-title regeneration on every view remount#3315
tatoalo wants to merge 2 commits into
mainfrom
posthog-code/fix-title-regen-on-remount

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Opening or switching to a task chat view re-fired the LLM title/summary generation even when nothing had changed.

~14,000–21,000 eliminated LLM calls/week
~15–20M gateway tokens/week that stop counting against users' metered LLM usage
Per user roughly one fewer 2.2s background gateway request + IPC round trip on most task-view

Changes

  • move title generation state into a shared Zustand store keyed by task ID, preserving generation state across remounts and preventing concurrent generation.

  • skip catch-up title generation when the title is locked and a summary already exists, while continuing normal generation triggers so summaries stay up to date.

  • clamp prompt counts to prevent newer task runs with shorter event logs from resetting generation state.

Title/summary generation bookkeeping lived in refs inside
useChatTitleGenerator, so it reset on every mount: reopening a task whose
conversation had 1 or REGENERATE_INTERVAL+ prompts re-fired an LLM gateway
call per view switch, and two simultaneously mounted views of the same task
could double-fire. Move the bookkeeping into a shared zustand store keyed by
task id, and skip catch-up fires entirely when the user has renamed the task
and a conversation summary is already stored (both outputs would be unused).

Generated-By: PostHog Code
Task-Id: 40590239-d05a-487c-9e49-d2209ffa93c7
@trunk-io

trunk-io Bot commented Jul 9, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 7e1b305.

@tatoalo tatoalo self-assigned this Jul 9, 2026
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 9, 2026
@tatoalo tatoalo marked this pull request as ready for review July 9, 2026 17:02
Make the title-lock check lazy so the query-cache scan only runs when a
stale first fire is actually being suppressed, collapse the suppression
into one condition, drop the no-op prompt-count clamp and the test-only
store reset API, and trim comments.

Generated-By: PostHog Code
Task-Id: 40590239-d05a-487c-9e49-d2209ffa93c7
github-actions[bot]
github-actions Bot previously approved these changes Jul 9, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well-targeted bug fix with solid test coverage. Moving from per-mount refs to a shared Zustand store correctly follows the project's architecture conventions, and the new titleLocked/hasSummary logic is simple, well-tested, and backward-compatible. No data, API, or security concerns.

@github-actions github-actions Bot dismissed their stale review July 9, 2026 17:04

New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Focused, well-tested bug fix that correctly moves per-mount refs to a shared Zustand store in the right architectural layer; no API contracts, data models, or security concerns touched.

@greptile-apps

greptile-apps Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "refactor(sessions): simplify title-gener..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant