Skip to content

Commit

Permalink
Handle agent symbol resolution panics (#1227)
Browse files Browse the repository at this point in the history
* handle agent symbol resolution panics

* fix compile errors

* revert clippy allows
  • Loading branch information
ggordonhall authored Feb 12, 2024
1 parent 35e8401 commit 0c1203f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
22 changes: 13 additions & 9 deletions server/bleep/src/agent/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ impl Agent {
&symbol_metadata.repo_path.path,
None,
)
.await
.unwrap()
.unwrap();
.await?
.context("Document is None")?;

let all_docs = {
let associated_langs =
Expand Down Expand Up @@ -252,8 +251,7 @@ impl Agent {
Some(0),
Some(NUMBER_CHUNK_LINES),
)
.await
.unwrap()
.await?
.into_iter()
.filter(|file_symbol| {
file_symbol.file != symbol_metadata.repo_path.path
Expand All @@ -266,7 +264,7 @@ impl Agent {
}
}

pub async fn get_related_chunks(&mut self, chunks: Vec<CodeChunk>) -> Vec<CodeChunk> {
pub async fn get_related_chunks(&mut self, chunks: Vec<CodeChunk>) -> Result<Vec<CodeChunk>> {
const MAX_CHUNKS: usize = 3;

// get symbols with ref/defs for each chunk
Expand All @@ -282,7 +280,11 @@ impl Agent {
.collect();

// get original user query
let user_query = self.last_exchange().query.target().unwrap();
let user_query = self
.last_exchange()
.query
.target()
.context("Query has no target")?;

// select one symbol
let selected_symbol = match self.filter_symbols(&user_query, chunks_with_symbols).await {
Expand All @@ -292,7 +294,7 @@ impl Agent {
}
Err(e) => {
info!("Returning no extra chunks: {}", e);
return Vec::new();
return Ok(Vec::new());
}
};

Expand All @@ -317,7 +319,7 @@ impl Agent {
})
.collect::<Vec<_>>();

extra_chunks
Ok(extra_chunks)
}
}

Expand All @@ -337,4 +339,6 @@ pub enum SymbolError {
ListEmpty,
#[error("Selected symbol out of bounds")]
OutOfBounds,
#[error("anyhow: {0:?}")]
Anyhow(#[from] anyhow::Error),
}
8 changes: 7 additions & 1 deletion server/bleep/src/agent/tools/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ impl Agent {
.push(chunk.clone())
}

let extra_chunks = self.get_related_chunks(chunks.clone()).await;
let extra_chunks = match self.get_related_chunks(chunks.clone()).await {
Ok(chunks) => chunks,
Err(e) => {
info!(?e, "failed to get related chunks");
vec![]
}
};

chunks.extend(extra_chunks);

Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/agent/tools/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Agent {
.push(chunk.clone())
}

let extra_chunks = self.get_related_chunks(chunks.clone()).await;
let extra_chunks = self.get_related_chunks(chunks.clone()).await?;

chunks.extend(extra_chunks);

Expand Down

0 comments on commit 0c1203f

Please sign in to comment.