Skip to content

fix(core): delete legacy V1 session rows when a session is removed - #50270

Open
holny wants to merge 1 commit into
anomalyco:v2from
holny:fix-50260-legacy-rows
Open

holny wants to merge 1 commit into
anomalyco:v2from
holny:fix-50260-legacy-rows

Conversation

@holny

@holny holny commented Sep 21, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #50260

Type of change

  • Bug fix

What does this PR do?

Deleting a session only removed its session_v2 row, so databases that came in through the V1→V2 migration kept the legacy session / message / part / todo copies forever — unreachable from the UI but still holding space that VACUUM can't reclaim. The Deleted projection in packages/core/src/session/projector.ts now also deletes the legacy parent row when the legacy session table exists, and the legacy foreign keys cascade the child rows from there. Fresh and renamed-lineage V2 databases have no legacy table, so the delete is guarded by a sqlite_master lookup.

How did you verify your code works?

Added a regression test in packages/core/test/session-remove.test.ts that materializes the legacy store, installs matching legacy rows, runs Session.remove, and asserts every legacy table is empty afterwards. bun test test/session (612 pass) and bun typecheck are green. Workaround from the report (DELETE FROM session WHERE id NOT IN (SELECT id FROM session_v2); VACUUM;) still applies for rows orphaned before this fix.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Databases migrated from V1 keep the legacy session/message/part/todo store alongside session_v2, but the Deleted projection only removed the V2 row, orphaning the legacy copy forever. Guard a legacy delete on a schema lookup so fresh and renamed-lineage databases skip it, and let the legacy foreign keys cascade the child rows.
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

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