Skip to content

Fix tag stream ordering when entries have different org values#1326

Open
jrray wants to merge 1 commit intomainfrom
tag-time-order
Open

Fix tag stream ordering when entries have different org values#1326
jrray wants to merge 1 commit intomainfrom
tag-time-order

Conversation

@jrray
Copy link
Collaborator

@jrray jrray commented Feb 21, 2026

insert_tag_in_namespace used Tag::cmp() to determine insertion order, but Tag::cmp() compares org/name before time. When a tag file is renamed for version normalization (e.g. 1.0.0.0 -> 1.0.0), existing entries retain the old org while new entries get the normalized org. The lexicographic comparison of org then dominates over the time comparison, causing older entries to appear at position 0 (current) instead of newer ones.

Fix by comparing time first, falling back to Tag::cmp() only as a tiebreaker for same-time entries. This matches the documented contract that insertion must sort by datetime.

@jrray jrray requested a review from Copilot February 21, 2026 01:42
@jrray jrray self-assigned this Feb 21, 2026
@jrray jrray added the bug Something isn't working label Feb 21, 2026
insert_tag_in_namespace used Tag::cmp() to determine insertion order,
but Tag::cmp() compares org/name before time. When a tag file is
renamed for version normalization (e.g. 1.0.0.0 -> 1.0.0), existing
entries retain the old org while new entries get the normalized org.
The lexicographic comparison of org then dominates over the time
comparison, causing older entries to appear at position 0 (current)
instead of newer ones.

Fix by comparing time first, falling back to Tag::cmp() only as a
tiebreaker for same-time entries. This matches the documented contract
that insertion must sort by datetime.

Signed-off-by: J Robert Ray <jrray@jrray.org>
Copy link

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

Fixes incorrect tag stream ordering when tag entries within the same stream differ in org (e.g., after filesystem “version normalization” renames), by ensuring insertion order is primarily determined by tag timestamp.

Changes:

  • Update insert_tag_in_namespace to compare tag time before falling back to Tag::cmp() as a tiebreaker.
  • Add a regression test that simulates renaming a tag directory and inserting a newer tag with a different org.

Reviewed changes

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

File Description
crates/spfs/src/storage/tag_test.rs Adds regression coverage for tag ordering when older entries retain a legacy org but newer inserts use a normalized org.
crates/spfs/src/storage/fs/tag.rs Adjusts insertion comparator to sort by time first (then Tag::cmp()), preventing org differences from dominating ordering.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +327 to +331
if next == *tag {
// this tag already exists in the stream,
// and will be dropped
return Ok(());
}
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

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

if next == *tag attempts to move a tracking::Tag out of &tracking::Tag (Tag is not Copy), so this won’t compile. Compare by reference instead (e.g., &next == tag) or compare next to tag.clone() if you truly need an owned value.

Copilot uses AI. Check for mistakes.
@jrray jrray requested a review from rydrman February 21, 2026 01:58
@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jrray
Copy link
Collaborator Author

jrray commented Feb 21, 2026

One might question impl std::cmp::Ord for Tag and the decision to not order by time there first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants