diff --git a/crates/application/src/agent/lifecycle.rs b/crates/application/src/agent/lifecycle.rs index 85a1dad..786d246 100644 --- a/crates/application/src/agent/lifecycle.rs +++ b/crates/application/src/agent/lifecycle.rs @@ -2645,6 +2645,31 @@ fn mcp_server_wiring( /// /// The MCP server is named `idea`; OpenCode therefore exposes IdeA tools as /// `idea_idea_*` (`_`), matching the observed contract. +/// Default MCP request timeout (milliseconds) injected into the OpenCode agent +/// config (`opencode.json` → `mcp.idea.timeout`). OpenCode applies this **per +/// `tools/call`** to its MCP servers; the original hardcoded `15_000` (15 s) was +/// far too short for `idea_ask_agent`, which blocks while the target agent works +/// (potentially minutes). Aligning on the rendezvous ceiling (4 h) ensures +/// OpenCode's client never kills an in-flight delegation before the server-side +/// watchdog resolves. +/// +/// **Must stay ≥ `DEFAULT_RENDEZVOUS_CEILING`** so the MCP client timeout and the +/// server-side absolute ceiling expire together — never the client first. +/// Overridable via `IDEA_OPENCODE_MCP_TIMEOUT_MS`. +pub const DEFAULT_OPENCODE_MCP_TIMEOUT_MS: u64 = 4 * 60 * 60 * 1000; + +/// Resolves the effective OpenCode MCP request timeout (ms) from the +/// `IDEA_OPENCODE_MCP_TIMEOUT_MS` env var, falling back to +/// [`DEFAULT_OPENCODE_MCP_TIMEOUT_MS`]. Parse failure or `0` ⇒ default, so a +/// misconfigured value never collapses the timeout to an instant kill. +pub fn resolve_opencode_mcp_timeout_ms() -> u64 { + std::env::var("IDEA_OPENCODE_MCP_TIMEOUT_MS") + .ok() + .and_then(|v| v.trim().parse::().ok()) + .filter(|&ms| ms > 0) + .unwrap_or(DEFAULT_OPENCODE_MCP_TIMEOUT_MS) +} + fn opencode_config_json( config: &domain::profile::OpenCodeConfig, project_root: &str, @@ -2725,7 +2750,7 @@ fn opencode_config_json( "command": command_array, "cwd": project_root, "enabled": true, - "timeout": 15000 + "timeout": resolve_opencode_mcp_timeout_ms() } }), ); @@ -2808,7 +2833,7 @@ fn opencode_provider_config_json( "command": command_array, "cwd": project_root, "enabled": true, - "timeout": 15000 + "timeout": resolve_opencode_mcp_timeout_ms() } }), ); diff --git a/crates/application/src/agent/mod.rs b/crates/application/src/agent/mod.rs index 02f7bf5..944394f 100644 --- a/crates/application/src/agent/mod.rs +++ b/crates/application/src/agent/mod.rs @@ -40,7 +40,8 @@ pub use lifecycle::{ ListAgentsOutput, LiveStateLeanProvider, McpRuntime, PermissionProjectorRegistry, ProviderSessionProvider, ReadAgentContext, ReadAgentContextInput, ReadAgentContextOutput, StructuredRoutingMode, StructuredSessionDescriptor, UpdateAgentContext, - UpdateAgentContextInput, AGENT_MEMORY_RECALL_BUDGET, LIVE_STATE_INJECT_MAX, + UpdateAgentContextInput, DEFAULT_OPENCODE_MCP_TIMEOUT_MS, AGENT_MEMORY_RECALL_BUDGET, + LIVE_STATE_INJECT_MAX, resolve_opencode_mcp_timeout_ms, }; pub use resume::{ ListResumableAgents, ListResumableAgentsInput, ListResumableAgentsOutput, ResumableAgent, diff --git a/crates/infrastructure/src/assistant/mod.rs b/crates/infrastructure/src/assistant/mod.rs index 7540f7a..c357bef 100644 --- a/crates/infrastructure/src/assistant/mod.rs +++ b/crates/infrastructure/src/assistant/mod.rs @@ -407,7 +407,7 @@ fn opencode_config_json( "command": command_array, "cwd": project_root, "enabled": true, - "timeout": 15000 + "timeout": application::agent::resolve_opencode_mcp_timeout_ms() } }), ); @@ -492,7 +492,7 @@ fn opencode_provider_config_json( "command": command_array, "cwd": project_root, "enabled": true, - "timeout": 15000 + "timeout": application::agent::resolve_opencode_mcp_timeout_ms() } }), );