we fixed the claude hook insight generation to update the title of the session after…
- User
we fixed the claude hook insight generation to update the title of the session after generating insights in background. but looks like it is not working.. http://localhost:7890/sessions?project=1966e21af7b0e4f4&session=cc9e8aa5-769d-41ea-98ce-ff5a905f2f04 has not got the title updated
Assistant
Let me investigate the issue. I'll look at the insight generation flow and the title update mechanism.
Assistant
Good findings from the explorer. Let me check the specific session and the current code to pinpoint the issue.
Assistant
Found it. The analysis failed via the hook — all 3 attempts failed with a
claude -perror. The insights that exist were likely generated from the dashboard, but thegenerated_titlewas never updated with the LLM summary title.Let me verify the current state and code.
Assistant
Interesting — the summary insight has the LLM title "Phase 12 native analysis: 5 PRs shipped, critical auth bug found in testing" but the session's
generated_titleis "We were working on core insights CLI command with --nativ...". Let me check how titles are set during sync and what the dashboard uses to display.Assistant
I think I see the issue. The sync upsert overwrites
generated_title. Let me check what the sync passes for that field.Assistant
Now let me see what value the sync passes for
generated_title.Assistant
Found the issue pattern. The sync upsert unconditionally overwrites
generated_title. Let me trace wheregeneratedTitlecomes from in the parser.Assistant
Now I have the full picture. Here's what's happening:
★ Insight ─────────────────────────────────────The root cause is a race between two title-setting paths:- Parser path (sync):
generateTitle()computes a heuristic title from user messages/session character → stored as on → written to DB via upsert
- Parser path (sync):
- User
fix it in a feature branch. not master directly
Assistant
Now let me also fix the existing session's title directly, and verify the build passes.
Assistant
Build passes, all 557 tests pass. Let me verify the session title was fixed.
Assistant
Done. Here's what was done:
The fix (
cli/src/db/write.ts:107):sql-- Before: unconditionally overwrites generated_title = excluded.generated_title, -- After: preserves existing title, only sets on first sync generated_title = COALESCE(sessions.generated_title, excluded.generated_title),The data fix: Updated the affected session's
generated_titledirectly from its existing summary insight — it now shows "Phase 12 native analysis: 5 PRs shipped, critical auth bug found in testing".★ Insight ─────────────────────────────────────SQLiteCOALESCEinON CONFLICT DO UPDATE— The key nuance here is the reference to (the row) vs (the row). In SQLite's upsert, refers to the values that would have been inserted, while the table name refers to the current row. is a common pattern to implement "write once, don't overwrite" semantics.- User
yes
Assistant
PR created: melagiri/code-insights#263
The uncommitted change warning is just the untracked
rerun-analysis.shfrom before — not related to this fix.