Skip to content

Commit 54003c6

Browse files
committed
Prefer two-segment Codex session ids
1 parent 5166c47 commit 54003c6

1 file changed

Lines changed: 40 additions & 9 deletions

File tree

src/ai.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,6 +3693,24 @@ fn display_session_id(session_id: &str) -> String {
36933693
truncate_recover_id(session_id)
36943694
}
36953695

3696+
fn display_session_id_two_segments(session_id: &str) -> String {
3697+
let mut segments = session_id.split('-');
3698+
let Some(first) = segments.next() else {
3699+
return display_session_id(session_id);
3700+
};
3701+
let Some(second) = segments.next() else {
3702+
return display_session_id(session_id);
3703+
};
3704+
if first.len() == 8
3705+
&& second.len() == 4
3706+
&& first.chars().all(|ch| ch.is_ascii_hexdigit())
3707+
&& second.chars().all(|ch| ch.is_ascii_hexdigit())
3708+
{
3709+
return format!("{first}-{second}");
3710+
}
3711+
display_session_id(session_id)
3712+
}
3713+
36963714
fn display_session_ids(rows: &[ProviderSessionListRow]) -> HashMap<String, String> {
36973715
let mut prefix_counts: HashMap<String, usize> = HashMap::new();
36983716
for row in rows {
@@ -3707,16 +3725,18 @@ fn display_session_ids(rows: &[ProviderSessionListRow]) -> HashMap<String, Strin
37073725

37083726
let mut display = HashMap::with_capacity(rows.len());
37093727
for row in rows {
3710-
if row.id.chars().count() <= 8 {
3728+
let base = display_session_id_two_segments(&row.id);
3729+
let base_len = base.chars().count();
3730+
if row.id.chars().count() <= base_len {
37113731
display.insert(row.id.clone(), row.id.clone());
37123732
continue;
37133733
}
37143734

37153735
let mut prefix = String::new();
3716-
let mut candidate = row.id.clone();
3736+
let mut candidate = base.clone();
37173737
for (index, ch) in row.id.chars().enumerate() {
37183738
prefix.push(ch);
3719-
if index + 1 < 8 {
3739+
if index + 1 < base_len {
37203740
continue;
37213741
}
37223742
candidate = prefix.clone();
@@ -16254,7 +16274,7 @@ values (?1, ?2, ?3, ?4, ?5, ?6, 0)
1625416274
}
1625516275

1625616276
#[test]
16257-
fn display_session_ids_extend_prefixes_only_when_needed() {
16277+
fn display_session_ids_prefer_two_segments_and_extend_when_needed() {
1625816278
let rows = vec![
1625916279
ProviderSessionListRow {
1626016280
index: 1,
@@ -16267,7 +16287,7 @@ values (?1, ?2, ?3, ?4, ?5, ?6, 0)
1626716287
index: 2,
1626816288
updated_relative: "1h".to_string(),
1626916289
updated_at: None,
16270-
id: "019d3a66-f3ae-7801-a8d2-7d505d8c8627".to_string(),
16290+
id: "019d3a66-219d-7801-a8d2-7d505d8c8627".to_string(),
1627116291
preview: "second".to_string(),
1627216292
},
1627316293
ProviderSessionListRow {
@@ -16277,20 +16297,31 @@ values (?1, ?2, ?3, ?4, ?5, ?6, 0)
1627716297
id: "019d3b29-d5b9-75c1-b69b-3136abc3d922".to_string(),
1627816298
preview: "third".to_string(),
1627916299
},
16300+
ProviderSessionListRow {
16301+
index: 4,
16302+
updated_relative: "3h".to_string(),
16303+
updated_at: None,
16304+
id: "019d3c00-abcd-75c1-b69b-3136abc3d922".to_string(),
16305+
preview: "fourth".to_string(),
16306+
},
1628016307
];
1628116308

1628216309
let display = display_session_ids(&rows);
1628316310
assert_eq!(
1628416311
display.get("019d3b29-d5b9-75c1-b69b-3136abc3d922"),
16285-
Some(&"019d3b29".to_string())
16312+
Some(&"019d3b29-d5b9".to_string())
1628616313
);
1628716314
assert_eq!(
1628816315
display.get("019d3a66-219d-7a03-a91e-cd3de17ffeca"),
16289-
Some(&"019d3a66-2".to_string())
16316+
Some(&"019d3a66-219d-7a".to_string())
16317+
);
16318+
assert_eq!(
16319+
display.get("019d3a66-219d-7801-a8d2-7d505d8c8627"),
16320+
Some(&"019d3a66-219d-78".to_string())
1629016321
);
1629116322
assert_eq!(
16292-
display.get("019d3a66-f3ae-7801-a8d2-7d505d8c8627"),
16293-
Some(&"019d3a66-f".to_string())
16323+
display.get("019d3c00-abcd-75c1-b69b-3136abc3d922"),
16324+
Some(&"019d3c00-abcd".to_string())
1629416325
);
1629516326
}
1629616327

0 commit comments

Comments
 (0)