Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion scripts/benchmarks/git/benchmark_nasty_modes_vs_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,14 @@ def main() -> int:
prepare_main_worktree(repo_root, args.main_ref, main_worktree)
created_main_worktree = True
print("Building main branch binary...")
main_bin = build_release_binary(main_worktree, targets_dir / "main")
try:
main_bin = build_release_binary(main_worktree, targets_dir / "main")
except BenchmarkError as err:
print(
"::warning::Skipping nasty benchmark because the main baseline failed to build."
)
print(f"Baseline build error: {err}")
return 0
main_sha = git_output(main_worktree, ["rev-parse", "HEAD"])

print("Cloning seed repo snapshot...")
Expand Down
15 changes: 13 additions & 2 deletions src/commands/checkpoint_agent/presets/agent_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ impl AgentPreset for AgentV1Preset {
model,
conversation_id,
trace_id,
command,
command.clone(),
),
tool_use_id: tool_use_id.unwrap_or_else(|| "shell".to_string()),
command,
}),
AgentV1Payload::PostShellCommand {
repo_working_dir,
Expand All @@ -185,9 +186,10 @@ impl AgentPreset for AgentV1Preset {
model,
conversation_id,
trace_id,
command,
command.clone(),
),
tool_use_id: tool_use_id.unwrap_or_else(|| "shell".to_string()),
command,
stream_source: None,
}),
};
Expand Down Expand Up @@ -308,6 +310,10 @@ mod tests {
e.context.metadata.get("command").map(String::as_str),
Some("printf 'generated\\n' > output.txt")
);
assert_eq!(
e.command.as_deref(),
Some("printf 'generated\\n' > output.txt")
);
}
_ => panic!("Expected PreBashCall"),
}
Expand Down Expand Up @@ -339,6 +345,10 @@ mod tests {
e.context.metadata.get("command").map(String::as_str),
Some("printf 'generated\\n' > output.txt")
);
assert_eq!(
e.command.as_deref(),
Some("printf 'generated\\n' > output.txt")
);
assert!(e.stream_source.is_none());
}
_ => panic!("Expected PostBashCall"),
Expand All @@ -360,6 +370,7 @@ mod tests {
ParsedHookEvent::PreBashCall(e) => {
assert_eq!(e.tool_use_id, "shell");
assert!(e.context.metadata.is_empty());
assert!(e.command.is_none());
}
_ => panic!("Expected PreBashCall"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ mod tests {
.join("github.copilot-chat")
.join("agent-traces.db");
std::fs::create_dir_all(otel_db_path.parent().unwrap()).unwrap();
let conn = rusqlite::Connection::open(&otel_db_path).unwrap();
let conn = crate::sqlite::open_with_memory_limits(&otel_db_path).unwrap();
conn.execute_batch(
"CREATE TABLE spans (
span_id TEXT PRIMARY KEY,
Expand Down
53 changes: 42 additions & 11 deletions src/metrics/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,13 @@ impl MetricsDatabase {

/// Get or initialize the global database
pub fn global() -> Result<&'static Mutex<MetricsDatabase>, GitAiError> {
let db_mutex = METRICS_DB.get_or_init(|| {
match Self::new() {
Ok(db) => Mutex::new(db),
Err(e) => {
eprintln!("[Error] Failed to initialize metrics database: {}", e);
// Create a dummy connection that will fail on any operation
let temp_path = std::env::temp_dir().join("git-ai-metrics-db-failed");
let conn = crate::sqlite::open_with_memory_limits(&temp_path)
.expect("Failed to create temp DB");
Mutex::new(MetricsDatabase { conn })
}
let db_mutex = METRICS_DB.get_or_init(|| match Self::new() {
Ok(db) => Mutex::new(db),
Err(e) => {
eprintln!("[Error] Failed to initialize metrics database: {}", e);
Mutex::new(
Self::new_fallback().expect("Failed to create fallback metrics database"),
)
}
});

Expand Down Expand Up @@ -193,6 +189,26 @@ impl MetricsDatabase {
Ok(db)
}

fn new_fallback() -> Result<Self, GitAiError> {
let temp_path = std::env::temp_dir().join("git-ai-metrics-db-failed");
Self::new_fallback_at_path(&temp_path)
}

fn new_fallback_at_path(path: &std::path::Path) -> Result<Self, GitAiError> {
let conn = crate::sqlite::open_with_memory_limits(path)?;
conn.execute_batch(
r#"
PRAGMA journal_mode=WAL;
PRAGMA synchronous=NORMAL;
PRAGMA temp_store=MEMORY;
"#,
)?;

let mut db = Self { conn };
db.initialize_schema()?;
Ok(db)
}

#[cfg(test)]
pub(crate) fn new_temp_for_tests() -> Result<(Self, tempfile::TempDir), GitAiError> {
let temp_dir = tempfile::TempDir::new()?;
Expand Down Expand Up @@ -1670,6 +1686,21 @@ mod tests {
}
}

#[test]
fn test_fallback_database_initializes_schema() {
let temp_dir = TempDir::new().unwrap();
let db_path = temp_dir.path().join("fallback-metrics.db");
let mut db = MetricsDatabase::new_fallback_at_path(&db_path).unwrap();

db.insert_events(&[event_json(days_ago(1))]).unwrap();

let count: i64 = db
.conn
.query_row("SELECT COUNT(*) FROM metrics", [], |row| row.get(0))
.unwrap();
assert_eq!(count, 1);
}

#[test]
fn test_initialize_schema_handles_preexisting_agent_usage_table() {
let temp_dir = TempDir::new().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/streams/model_extraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod tests {
if let Some(parent) = path.parent() {
std::fs::create_dir_all(parent).unwrap();
}
let conn = rusqlite::Connection::open(path).unwrap();
let conn = crate::sqlite::open_with_memory_limits(path).unwrap();
conn.execute_batch(
"CREATE TABLE spans (
span_id TEXT PRIMARY KEY,
Expand Down
Loading