Skip to content

Commit 9dc7fb2

Browse files
szguptaoz-agent
andcommitted
Fix race condition causing permanent loss of active rule files
When a repository update arrives, the stream handler removes rules from the path_to_rules HashMap and re-inserts them asynchronously after processing. If a second update arrives during this async gap (e.g. from a git checkout or atomic file save), the remove returns None and the update is silently dropped. If the first update was a deletion and the dropped second update was the corresponding addition, the rules are permanently lost until client restart. Fix: clone the rules instead of removing them, so they remain available in the HashMap during async processing. Queries see slightly stale (pre-update) rules during the gap instead of no rules at all. Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 2f84587 commit 9dc7fb2

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

crates/ai/src/project_context/model.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct ProjectRule {
2525
pub content: String,
2626
}
2727

28-
#[derive(Debug, Default)]
28+
#[derive(Debug, Default, Clone)]
2929
struct RuleAtPath {
3030
parent_path: PathBuf,
3131
warp_md: Option<ProjectRule>,
@@ -69,7 +69,7 @@ fn matches_rules_pattern(file_name_str: &str) -> bool {
6969
false
7070
}
7171

72-
#[derive(Debug, Default)]
72+
#[derive(Debug, Default, Clone)]
7373
struct ProjectRules {
7474
rules: Vec<RuleAtPath>,
7575
}
@@ -345,7 +345,7 @@ impl ProjectContextModel {
345345
return;
346346
}
347347

348-
let existing_rules = me.path_to_rules.remove(&path_clone);
348+
let existing_rules = me.path_to_rules.get(&path_clone).cloned();
349349
let repo_path = path_clone.clone();
350350
if let Some(rules) = existing_rules {
351351
let repo_path_for_closure = repo_path.clone();

0 commit comments

Comments
 (0)