feat!(sessions): newtype session ID, refactor store index - #275
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughIntroduces a SessionId newtype and replaces raw Uuid session identifiers with SessionId across the sessions store API and disk loader, sessions manager, exported RPC schema, SFTP subsystem, test harness, and unit tests. ChangesSessionId Type Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/sessions/src/lib.rs (1)
33-37: ⚡ Quick winInherent
to_stringshadowsDisplaytrait method.The inherent
to_string()returns the raw UUID string (self.0.to_string()), butDisplayformats asSessionId(uuid). This inconsistency triggers Clippy'sinherent_to_string_shadow_displaylint and may confuse callers expecting consistent behavior betweenformat!("{}", id)andid.to_string().Consider removing the inherent method and relying on
Display, or aligning both to return the same format.Option A: Remove inherent method, use Display for plain UUID
- /// Constructs a string representing the given UUID. - #[must_use] - pub fn to_string(&self) -> String { - self.0.to_string() - } } impl AsRef<Uuid> for SessionId { fn as_ref(&self) -> &Uuid { &self.0 } } impl fmt::Display for SessionId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "SessionId({})", self.0) + write!(f, "{}", self.0) } }Option B: Keep both, rename inherent method
- /// Constructs a string representing the given UUID. + /// Returns the underlying UUID as a hyphenated string. #[must_use] - pub fn to_string(&self) -> String { + pub fn as_uuid_string(&self) -> String { self.0.to_string() }Also applies to: 46-50
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/sessions/src/lib.rs` around lines 33 - 37, The inherent pub fn to_string(&self) on SessionId shadows the Display trait's to_string and triggers clippy; fix by removing or renaming it so behavior is consistent—either delete the inherent to_string and rely on the Display impl for string conversion, or rename the inherent method (e.g., as_uuid or to_uuid_string) and update all call sites; ensure the Display impl for SessionId remains unchanged and adjust the other similar method at lines 46-50 the same way to avoid duplicate shadowing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/sessions/src/lib.rs`:
- Around line 33-37: The inherent pub fn to_string(&self) on SessionId shadows
the Display trait's to_string and triggers clippy; fix by removing or renaming
it so behavior is consistent—either delete the inherent to_string and rely on
the Display impl for string conversion, or rename the inherent method (e.g.,
as_uuid or to_uuid_string) and update all call sites; ensure the Display impl
for SessionId remains unchanged and adjust the other similar method at lines
46-50 the same way to avoid duplicate shadowing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0a3758de-065a-45ae-b687-5d766602275a
📒 Files selected for processing (6)
crates/minimald/src/rpc.rscrates/minimald/src/sessions.rscrates/minimald/src/sftp.rscrates/minimald/src/test_harness.rscrates/sessions/src/lib.rscrates/sessions/src/store.rs
|
|
||
| /// Constructs a string representing the given UUID. | ||
| #[must_use] | ||
| pub fn to_string(&self) -> String { |
There was a problem hiding this comment.
FYI: when you implement Display, ToString is implemented automatically (and is actually the preferred way to implement ToString over manually doing a impl ToString for MyType.
There was a problem hiding this comment.
Made Display be a transparent impl of UUID's display, and removed to_string()
af1026e to
0bf5f85
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/sessions/src/lib.rs (1)
20-20: ⚡ Quick winConsider deriving Hash alongside Eq.
The
SessionIdtype derivesEqbut notHash. It's a Rust best practice to deriveHashwheneverEqis derived to maintain the invariant that equal values must have equal hashes. AddingHashalso future-proofs the type for use inHashMaporHashSetas keys.♻️ Add Hash to the derive list
-#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SessionId(Uuid);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/sessions/src/lib.rs` at line 20, The SessionId struct currently derives Eq but not Hash; update its derive annotation (the line with #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]) to also include Hash so SessionId implements std::hash::Hash and can be used reliably as a key in HashMap/HashSet while preserving the Eq/Hash invariant.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/sessions/src/lib.rs`:
- Line 20: The SessionId struct currently derives Eq but not Hash; update its
derive annotation (the line with #[derive(Debug, Clone, Copy, Serialize,
Deserialize, PartialEq, Eq, PartialOrd, Ord)]) to also include Hash so SessionId
implements std::hash::Hash and can be used reliably as a key in HashMap/HashSet
while preserving the Eq/Hash invariant.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8936dba2-6ef3-4658-86eb-fa7061bc3f56
📒 Files selected for processing (6)
crates/minimald/src/rpc.rscrates/minimald/src/sessions.rscrates/minimald/src/sftp.rscrates/minimald/src/test_harness.rscrates/sessions/src/lib.rscrates/sessions/src/store.rs
🚧 Files skipped from review as they are similar to previous changes (5)
- crates/minimald/src/test_harness.rs
- crates/minimald/src/rpc.rs
- crates/minimald/src/sessions.rs
- crates/minimald/src/sftp.rs
- crates/sessions/src/store.rs
0bf5f85 to
ea874c6
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
crates/sessions/src/store.rs (2)
266-271: ⚡ Quick winVariable name
uuidshould beidfor consistency.The pattern variable is named
uuidbut the type is&SessionId, which is inconsistent with the refactoring's naming conventions used elsewhere in this file.✨ Suggested fix
fn find_by_name<S: AsRef<str>>(&self, name: S) -> Result<Option<Self::Key>, std::io::Error> { - match self.index.find_by_name(name) { - Some(uuid) => self.find_by_id(uuid), + match self.index.find_by_name(name) { + Some(id) => self.find_by_id(id), None => Ok(None), } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/sessions/src/store.rs` around lines 266 - 271, The match binding in find_by_name uses the variable name `uuid` while the type is &SessionId and other code uses `id`; rename the pattern variable to `id` to match the refactoring conventions: update the match arm from `Some(uuid) => self.find_by_id(uuid)` to `Some(id) => self.find_by_id(id)` and adjust any related local uses in the find_by_name implementation (symbols: find_by_name, self.index.find_by_name, find_by_id, SessionId, Self::Key).
139-145: 💤 Low valueConsider a reverse index for O(1) ID-to-short lookups.
short_by_idperforms a linear scan throughshort_to_id, makingfind_by_idO(n) in the number of sessions. For typical session counts this is fine, but if session volume grows, a reverseBTreeMap<SessionId, String>(id_to_short) maintained alongsideshort_to_idwould provide O(log n) lookups.This is acceptable as-is for now given expected usage patterns.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/sessions/src/store.rs` around lines 139 - 145, short_by_id currently scans self.short_to_id linearly making lookups O(n); add a reverse index (e.g., a BTreeMap<SessionId, String> named id_to_short) and change short_by_id to consult id_to_short for O(log n) lookups. Maintain id_to_short wherever short_to_id is mutated: on insert/update populate id_to_short.insert(session_id.clone(), short.clone()), and on remove delete id_to_short.remove(session_id). Update any constructors, insert/remove helpers, and tests that touch short_to_id to keep both maps consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/sessions/src/store.rs`:
- Around line 266-271: The match binding in find_by_name uses the variable name
`uuid` while the type is &SessionId and other code uses `id`; rename the pattern
variable to `id` to match the refactoring conventions: update the match arm from
`Some(uuid) => self.find_by_id(uuid)` to `Some(id) => self.find_by_id(id)` and
adjust any related local uses in the find_by_name implementation (symbols:
find_by_name, self.index.find_by_name, find_by_id, SessionId, Self::Key).
- Around line 139-145: short_by_id currently scans self.short_to_id linearly
making lookups O(n); add a reverse index (e.g., a BTreeMap<SessionId, String>
named id_to_short) and change short_by_id to consult id_to_short for O(log n)
lookups. Maintain id_to_short wherever short_to_id is mutated: on insert/update
populate id_to_short.insert(session_id.clone(), short.clone()), and on remove
delete id_to_short.remove(session_id). Update any constructors, insert/remove
helpers, and tests that touch short_to_id to keep both maps consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8202a674-96df-48fc-b72a-10a3a6ccac29
📒 Files selected for processing (6)
crates/minimald/src/rpc.rscrates/minimald/src/sessions.rscrates/minimald/src/sftp.rscrates/minimald/src/test_harness.rscrates/sessions/src/lib.rscrates/sessions/src/store.rs
🚧 Files skipped from review as they are similar to previous changes (5)
- crates/minimald/src/sftp.rs
- crates/minimald/src/rpc.rs
- crates/minimald/src/test_harness.rs
- crates/sessions/src/lib.rs
- crates/minimald/src/sessions.rs
ea874c6 to
08d0019
Compare
Implements some followups from #265, most notably a newtype for session IDs.
Summary by CodeRabbit