Files
hermes-agent/tests
John Paul Soliva 3dd848f263 fix(sessions): repair-profiles moves a session whose title the target store already holds
`hermes sessions repair-profiles --apply` copied a stranded session into
its owning profile's store verbatim, title included. Titles are unique
per store only (idx_sessions_title_unique), so when the target profile
already held an unrelated session with the same title, which is common
for generic auto-titles, the insert raised IntegrityError.

_MoveBatch.run imported every row before deleting any and had no
per-row handling. The exception escaped before the delete phase and
before the result was memoised. Rows copied earlier in the batch were
left in both stores. Every later finding re-ran the whole batch and hit
the same error. Every row in the batch was reported failed on every
run, the command exited 1 forever, and a non-colliding row ended up
duplicated across two profiles.

- import_moved_session gives a colliding title the moved row's id tail,
  the same convention import_foreign_history uses, capped at
  MAX_TITLE_LENGTH. The resident row keeps its name, so resolving it by
  title is unchanged.
- _MoveBatch.run handles each row separately. A failed import or delete
  is that row's failure alone, reported through apply(). The rest of
  the batch still moves, and the batch runs once. The failed row's
  lineage waits with it: its descendants are not imported without it,
  and the parent it still points at in the source is not deleted. The
  next run moves the lineage whole.

Measured on main: with two stranded rows and one title collision, both
rows failed on every run and one was left in both stores. With the fix,
one run moves both, and a second run finds nothing.
2026-09-23 07:01:11 -07:00
..