fix: use get_work_path() instead of get_stack_path()+data/system for work dir, add etag check for PROMPT.md downloads
All checks were successful
BotServer CI/CD / build (push) Successful in 3m37s

This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-11 18:42:09 -03:00
parent a4a3837c4c
commit f4c99030aa
3 changed files with 49 additions and 41 deletions

View file

@ -144,15 +144,11 @@ fn associate_tool_with_session(
use crate::core::shared::models::schema::session_tool_associations;
// Check if tool's .mcp.json file exists in work directory
// Use relative path from botserver binary current directory
let gb_dir =
std::path::PathBuf::from(crate::core::shared::utils::get_stack_path()).join("data/system");
let work_root = crate::core::shared::utils::get_work_path();
// Get bot name to construct the path
let bot_name = get_bot_name_from_id(state, &user.bot_id)?;
let work_path = Path::new(&gb_dir)
.join("work")
.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
let work_path = Path::new(&work_root).join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
let mcp_path = work_path.join(format!("{}.mcp.json", tool_name));
trace!("Checking for tool .mcp.json at: {:?}", mcp_path);

View file

@ -35,19 +35,16 @@ pub fn get_session_tools(
}
// Build path to work/{bot_name}.gbai/{bot_name}.gbdialog directory
// Use relative path from botserver binary location
let gb_dir =
std::path::PathBuf::from(crate::core::shared::utils::get_stack_path()).join("data/system");
let work_root = std::path::PathBuf::from(crate::core::shared::utils::get_work_path());
// Ensure work directory exists (create if not)
let work_base = gb_dir.join("work");
if !work_base.exists() {
std::fs::create_dir_all(&work_base)
.map_err(|e| format!("Failed to create work directory {:?}: {}", work_base, e))?;
info!("Created work directory at: {:?}", work_base);
if !work_root.exists() {
std::fs::create_dir_all(&work_root)
.map_err(|e| format!("Failed to create work directory {:?}: {}", work_root, e))?;
info!("Created work directory at: {:?}", work_root);
}
let work_path = work_base.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
let work_path = work_root.join(format!("{}.gbai/{}.gbdialog", bot_name, bot_name));
info!(
"Loading {} tools for session {} from {:?}",

View file

@ -600,7 +600,17 @@ impl DriveMonitor {
}
if is_prompt_file {
// Download prompt file to work directory
// Check etag to avoid re-downloading unchanged prompt files
let etag = obj.e_tag().unwrap_or_default().to_string();
let prompt_state_key = format!("__prompt__{}", path);
let should_download = {
let states = self.file_states.read().await;
match states.get(&prompt_state_key) {
Some(prev) => prev.etag != etag,
None => true,
}
};
if should_download {
match client.get_object().bucket(&self.bucket_name).key(&path).send().await {
Ok(response) => {
let bytes = response.body.collect().await?.into_bytes();
@ -630,6 +640,11 @@ impl DriveMonitor {
log::error!("Failed to download prompt file {}: {}", path, e);
}
}
let mut states = self.file_states.write().await;
states.insert(prompt_state_key, FileState { etag, indexed: false });
} else {
trace!("Prompt file {} unchanged (etag match), skipping download", path);
}
continue;
}