Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src-tauri/src/agent/cancel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ fn cancel_key(project_id: &str, session_id: &str, run_id: &str) -> String {
}

fn normalize_key(value: &str) -> String {
value.replace(['\\', '/'], "_")
// `:` must be neutralized too, not just path separators: cancel_key joins
// fields with `::`, so an unescaped `:` in one field can shift the split and
// collide with a different (session_id, run_id) pair's key.
value.replace(['\\', '/', ':'], "_")
}

#[cfg(test)]
Expand Down Expand Up @@ -151,6 +154,18 @@ mod tests {
assert!(r2.is_cancelled());
}

#[test]
fn cancellation_registry_does_not_collide_on_embedded_delimiter() {
let registry = AgentCancellationRegistry::default();
// (session "a::b", run "c") and (session "a", run "b::c") must not
// collapse to the same key just because "::" is also the field delimiter.
let target = registry.start("p1", "a::b", "c");
let unrelated = registry.start("p1", "a", "b::c");
assert!(registry.cancel("p1", "a::b", Some("c")));
assert!(target.is_cancelled());
assert!(!unrelated.is_cancelled());
}

#[test]
fn cancellation_token_drop_removes_registry_entry() {
let registry = AgentCancellationRegistry::default();
Expand Down
Loading