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
76 changes: 71 additions & 5 deletions src/runners/bifrost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1170,17 +1170,17 @@ fn run_declaration_to_usages(
};

// Bifrost rejects a per-request `max_duration_secs` and leaves deadline
// policy to the frontend, so the requested scan budget is applied here as
// a client-side deadline instead of being asked of the server.
session.set_request_timeout(Duration::from_secs(scan_usages_max_duration_secs));
let result = match session.call_tool(
// policy to the frontend, so the requested scan budget bounds this call
// without changing the timeout of later MCP requests.
let result = match session.call_tool_with_timeout(
"scan_usages_by_location",
json!({
"targets": [target],
"include_tests": true,
"include_same_owner": true,
"include_bindings": reference_policy != ReferencePolicy::ExternalUsages,
}),
Duration::from_secs(scan_usages_max_duration_secs),
) {
Ok(result) => result,
Err(error) => {
Expand Down Expand Up @@ -3560,6 +3560,57 @@ for line in sys.stdin:
);
}

#[test]
fn scan_timeout_becomes_an_explicit_case_error() {
struct ScanTimeoutClient {
calls: usize,
}

impl SearchToolsClient for ScanTimeoutClient {
fn call_tool(&mut self, name: &str, _arguments: Value) -> Result<Value> {
assert_eq!(name, "search_symbols");
self.calls += 1;
Ok(search_symbols_json(
"src/service.rs",
"example.build_service",
30,
))
}

fn call_tool_with_timeout(
&mut self,
name: &str,
_arguments: Value,
timeout: std::time::Duration,
) -> Result<Value> {
assert_eq!(name, "scan_usages_by_location");
assert_eq!(timeout, std::time::Duration::ZERO);
self.calls += 1;
Err(anyhow!("timed out waiting for Bifrost MCP response"))
}
}

let case = benchmark_case();
let mut client = ScanTimeoutClient { calls: 0 };
let mut diagnostics = Vec::new();
let report = run_declaration_to_usages(
&case,
case.declaration.as_ref().unwrap(),
PositionEncoding::Utf16,
ReferencePolicy::BindingsOptional,
None,
&mut client,
0,
&mut diagnostics,
);

assert_eq!(client.calls, 2);
assert_eq!(report.status, CaseStatus::Error);
assert_eq!(report.raw_statuses, vec!["scan_usages_failed"]);
assert_eq!(diagnostics[0].kind, "scan_usages_failed");
assert!(diagnostics[0].message.contains("timed out"));
}

#[test]
fn compatible_navigation_is_reported_without_replacing_canonical_status() {
let mut case = benchmark_case();
Expand Down Expand Up @@ -5287,8 +5338,14 @@ for line in sys.stdin:
}

impl SearchToolsClient for MockClient {
fn set_request_timeout(&mut self, timeout: std::time::Duration) {
fn call_tool_with_timeout(
&mut self,
name: &str,
arguments: Value,
timeout: std::time::Duration,
) -> Result<Value> {
self.request_timeouts.push(timeout);
self.call_tool(name, arguments)
}

fn call_tool(&mut self, name: &str, arguments: Value) -> Result<Value> {
Expand All @@ -5307,6 +5364,15 @@ for line in sys.stdin:
fn call_tool(&mut self, _name: &str, _arguments: Value) -> Result<Value> {
Err(anyhow!(self.message.clone()))
}

fn call_tool_with_timeout(
&mut self,
_name: &str,
_arguments: Value,
_timeout: std::time::Duration,
) -> Result<Value> {
Err(anyhow!(self.message.clone()))
}
}

fn tool(name: &str, value: Value) -> (String, Value) {
Expand Down
Loading