Skip to content

fix(reset): clean up lane history entries when resetting snaps#10270

Merged
davidfirst merged 6 commits intomasterfrom
fix/reset-cleanup-lane-history
Apr 6, 2026
Merged

fix(reset): clean up lane history entries when resetting snaps#10270
davidfirst merged 6 commits intomasterfrom
fix/reset-cleanup-lane-history

Conversation

@davidfirst
Copy link
Copy Markdown
Member

When bit reset removes snapped versions from a lane, the corresponding lane history entries
were left behind — referencing version objects that no longer exist. These orphaned entries
would get exported to remotes and persist forever.

Fix: use the snap operation's batchId as the lane history entry key. During reset, load the
version objects being removed, collect their batchIds, and delete the matching lane history
entries before persisting.

Changes

  • LaneHistory.addHistory() accepts optional historyKey (defaults to v4())
  • LaneHistory.removeHistoryEntries() deletes entries by key
  • Lanes.updateLaneHistory() / saveLane() thread the key through
  • VersionMaker.addLaneObject() passes batchId as the history key
  • removeLocalVersion() extracts batchIds from versions being removed
  • reset() removes matching lane history entries before persist()
  • Updated e2e test to verify orphaned entries no longer exist after reset

Use the snap operation's batchId as the lane history entry key so that
`bit reset` can identify and remove the corresponding entries when it
deletes snapped versions. This prevents orphaned lane history entries
from being exported to remotes.
Copilot AI review requested due to automatic review settings April 3, 2026 15:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an issue where bit reset could delete snapped Version objects on a lane while leaving behind lane-history entries that still reference those removed versions, resulting in orphaned lane-history entries that can get exported and persist on remotes.

Changes:

  • Allow LaneHistory.addHistory() to accept an optional historyKey, and add LaneHistory.removeHistoryEntries() to delete entries by key.
  • Use the snap operation batchId as the lane-history entry key so reset can deterministically delete the corresponding history entry.
  • During reset(), collect batchIds from removed Version objects and remove matching lane-history entries; update e2e coverage to verify no orphaned entries remain.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
scopes/scope/objects/models/lane-history.ts Adds support for caller-provided history keys and removal of history entries by key.
components/legacy/scope/lanes/lanes.ts Threads the optional historyKey through lane history update/save flows.
scopes/component/snapping/version-maker.ts Keys lane-history “snap” entries by the snap operation batchId.
scopes/component/snapping/reset-component.ts Extracts batchIds from Version objects being removed so reset can clean history.
scopes/component/snapping/snapping.main.runtime.ts Removes lane-history entries matching the removed versions’ batchIds during reset.
e2e/harmony/lanes/lane-history-diff.e2e.ts Updates the scenario test to assert no orphaned lane-history entry remains after reset.

Copilot AI review requested due to automatic review settings April 3, 2026 15:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings April 6, 2026 12:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

const versionObjects = await Promise.all(
versionsToRemoveStr.map((ver) => component.loadVersion(ver, consumer.scope.objects, false))
);
batchIds = [...new Set(compact(compact(versionObjects).map((v) => v.batchId)))];
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

batchIds extraction uses nested compact(compact(...)) plus new Set(...), which is redundant and makes the intent harder to read. Consider simplifying to a single compact pass for missing version objects and using uniq (or a single Set) consistently for de-duping.

Suggested change
batchIds = [...new Set(compact(compact(versionObjects).map((v) => v.batchId)))];
const loadedVersions = compact(versionObjects);
batchIds = [...new Set(compact(loadedVersions.map((v) => v.batchId)))];

Copilot uses AI. Check for mistakes.
@davidfirst davidfirst merged commit d09a6b6 into master Apr 6, 2026
16 checks passed
@davidfirst davidfirst deleted the fix/reset-cleanup-lane-history branch April 6, 2026 13:11
davidfirst added a commit that referenced this pull request Apr 6, 2026
…10273)

Follow-up to #10270.

- Replace `compact(compact(versionObjects).map(...))` with a clearer
two-step: first `compact` to filter missing version objects, then
`compact` on the mapped batchIds
- Rewrite the e2e test doc and naming to use simple A/B/C labels instead
of "local snap"/"first snap"/"final snap" — makes the snap→reset→snap
flow easier to follow
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.

3 participants