Skip to content

fix(sessions): preserve ambiguous legacy titles during upgrade - #1848

Merged
vastsa merged 2 commits into
vastsa:mainfrom
ShawTim:fix/session-title-placeholder-case
Oct 25, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
ShawTim:fix/session-title-placeholder-case

Conversation

@ShawTim

@ShawTim ShawTim commented Oct 23, 2026 •

Copy link
Copy Markdown

What

Historical schema-v22 sessions lack provenance metadata to distinguish whether a stored title was an untouched placeholder or a deliberate user rename to that same text (e.g. new task). The v22→v23 migration originally attempted a heuristic reclassification by matching title strings, which was case-sensitive and risked overwriting user-chosen titles on subsequent prompts.

Fix

  • Rather than guessing user intent from title text alone, the v22→v23 migration leaves all pre-existing v22 sessions classified as legacy (the column's default), keeping migration impact minimal and safely protecting deliberate renames from being overwritten by first-prompt title derivation or title plugins.
  • Newly created sessions after upgrade continue to set default (for placeholders) or manual (for user titles), preserving normal title derivation and plugin workflows.
  • Existing v23/v24 database rows remain untouched.

Tests

  • v22_database_migrates_session_title_sources_without_losing_titles sets up a v22 database, reproduces a deliberate v22 title-only rename to lowercase new task, runs the real migration, and verifies:
    1. All pre-existing titles receive title_source = 'legacy' and their exact title strings are preserved.
    2. First-prompt derivation (derive_session_title) refuses to overwrite the renamed session.
    3. Plugin title CAS writes (set_automatic_session_title) refuse to overwrite legacy sessions.
    4. Newly created sessions after upgrade correctly receive default and derive titles normally.
  • Verified in isolated Docker container running cargo test -p host-core.
  • Specs updated in docs/spec/03-runtime/04-data-storage.md, 06-delivery/04-e2e-test-plan.md, and the zh-CN mirror.

@ShawTim
ShawTim force-pushed the fix/session-title-placeholder-case branch from 3dc2522 to de250f3 Compare October 23, 2026 14:11

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for tracing the migration bug to the shared placeholder matcher and adding coverage for existing v24 databases. I found a user-data preservation case the migration currently changes: rename_session() records any user-selected title as manual, including a deliberate title such as New task. The v24→v25 migration selects every manual row and reclassifies any matching placeholder as default. After upgrade, derive_session_title() may then overwrite that explicit title on the next prompt. The current test uses only an ordinary manual title, so it does not cover this case. Please address this ambiguity conservatively and add a regression that manually renames a session to a placeholder and proves the upgrade cannot overwrite it. Thanks.

@ShawTim
ShawTim force-pushed the fix/session-title-placeholder-case branch 5 times, most recently from bb9b962 to f6e4ee0 Compare October 23, 2026 16:30
@ShawTim

ShawTim commented Oct 23, 2026

Copy link
Copy Markdown
Author

Thanks for the catch! Addressed conservatively:

  1. Rather than reclassifying existing databases (which would introduce ambiguity with deliberate renames), the migration fix simply normalizes LOWER(TRIM(title)) in place in the v22->v23 migration, keeping existing manual rows untouched and preserved.
  2. Added the regression test manual_placeholder_title_is_never_overwritten_after_upgrade verifying that a session manually renamed to a placeholder (New task) remains manual across reopen/upgrade and derive_session_title refuses to overwrite it.

@ShawTim
ShawTim requested a review from vastsa October 23, 2026 16:38

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for addressing the manual-rename preservation case. I found a separate coverage gap: this changes only the historical v22→v23 migration, while current main is at schema v24 and runs that migration only for databases whose stored version is below 23. Users who already opened a build that applied v22→v23 keep the misclassified title_source = 'manual', so derive_session_title() continues to reject their placeholder sessions. The new migration test resets a fixture to v22; the manual-placeholder test starts from a current database and renames after migration, so neither covers an already-migrated v23/v24 database containing the bad row.

Please address the affected existing databases or narrow the fix's scope and explain that the already-migrated users remain affected. There is a real data-safety constraint here: rename_session() stores only the title and manual source, so a deliberate rename to New task is indistinguishable from a placeholder misclassified by the old migration. A repair must preserve that explicit rename. Until the existing-user path is resolved, this doesn't fully fix the reported root cause. Thanks!

@ShawTim
ShawTim force-pushed the fix/session-title-placeholder-case branch from f6e4ee0 to a4654b9 Compare October 24, 2026 17:57

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for narrowing the already-migrated database claim and preserving manual titles in v23/v24. I found one remaining data-safety ambiguity in the newly covered v22 path, plus a compile error in the added test. Please address both before landing.

Comment thread crates/host-core/src/db/tests.rs Resolved
Historical schema-v22 sessions lack provenance metadata to distinguish
whether a stored title is an untouched placeholder or a deliberate manual
rename to the same text. The v22 to v23 migration originally attempted a
heuristic reclassification by matching title text, which was both case-
sensitive and risked overwriting user-chosen titles on subsequent prompts.

Removing the ambiguous heuristic UPDATE leaves all pre-existing v22
sessions with title_source = 'legacy', safely protecting deliberate
renames from being overwritten by first-prompt title derivation or title
plugins. Existing v23/v24 databases and newly created sessions retain
their standard behavior.

A regression test verifies that historical v22 titles (including deliberate
renames to lowercase 'new task') remain 'legacy' and refuse automatic
derivation, while new sessions created after upgrade correctly receive
'default' and derive titles normally.
@ShawTim
ShawTim force-pushed the fix/session-title-placeholder-case branch from a4654b9 to ce10ef2 Compare October 25, 2026 12:30
@ShawTim ShawTim changed the title fix(sessions): classify placeholder titles case-insensitively fix(sessions): preserve ambiguous legacy titles during upgrade Oct 25, 2026
@vastsa
vastsa merged commit c099b6a into vastsa:main Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants