Skip to content

Commit cae158c

Browse files
wpfleger96AliaHayt
authored
fix(dev-mcp): extend shell timeout cap to 20 minutes and align outer budgets (#7185)
Raise the `buzz-dev-mcp` shell timeout ceiling to 1,200,000 ms (20 minutes) while keeping the omitted-value default at 120,000 ms (2 minutes), and align the two outer timeout layers that bound every MCP tool call. ## What changed **`crates/buzz-dev-mcp`** — shell timeout cap raised to 1,200,000 ms; tool and parameter descriptions updated to match. **`crates/buzz-agent`** — `BUZZ_AGENT_TOOL_TIMEOUT_SECS` default raised from 660 s to 1,260 s (20-min cap + 60 s cleanup headroom). The old 660 s default would have killed the MCP server at 11 min, before a 20-min shell call could finish. README updated. **`crates/buzz-acp`** — `DEFAULT_IDLE_TIMEOUT_SECS` raised from 900 s to 1,500 s and its doc comment updated (1,200 s max shell + 300 s breathing room). The old value was documented as "600 s max shell + 300 s" — stale arithmetic. ## Tests - Existing boundary tests in `buzz-dev-mcp` (default, exact-cap, over-cap, `u64::MAX`) all pass. - `default_idle_timeout_is_1500_seconds` — pinned constant replaces old 900 s assertion. - `default_tool_timeout_is_1260_seconds` — new pinned constant in `buzz-agent`. - `budget_ordering_invariant_shell_cap_plus_headroom_fits_within_idle_timeout` — new const assertion in `buzz-acp` that encodes the full three-layer ordering: shell cap (1,200 s) ≤ agent tool timeout (1,260 s) < ACP idle timeout (1,500 s) < max turn duration. A future edit that inverts any tier fails to compile. --------- Signed-off-by: Alia <d32955ad69077062930cc46cfe2df30ca9aaf6f8e76422681265e9e9af704d78@buzz.block.builderlab.xyz> Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: Alia <d32955ad69077062930cc46cfe2df30ca9aaf6f8e76422681265e9e9af704d78@buzz.block.builderlab.xyz> Co-authored-by: Hayt <9e1c23a3fd83f61da34420e4e88ff1b16e45cafcc0cd9019eb07d4ecfa8ca9b0@buzz.block.builderlab.xyz>
1 parent e17a0d4 commit cae158c

5 files changed

Lines changed: 84 additions & 15 deletions

File tree

‎crates/buzz-acp/src/config.rs‎

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use crate::filter::SubscriptionRule;
2020
///
2121
/// Sized for slow turns where the agent may go silent on its outer ACP channel
2222
/// while running long sub-tools (e.g. a buzz-agent running another agent, or
23-
/// codex/claude doing multi-minute single tool calls). 900s gives 300s of
24-
/// breathing room above the 600s max shell timeout, so legitimate long-running
23+
/// codex/claude doing multi-minute single tool calls). 1500s gives 300s of
24+
/// breathing room above the 1200s max shell timeout, so legitimate long-running
2525
/// tool calls don't race the idle deadline.
2626
/// Override via `--idle-timeout` / `BUZZ_ACP_IDLE_TIMEOUT`.
27-
pub(crate) const DEFAULT_IDLE_TIMEOUT_SECS: u64 = 900;
27+
pub(crate) const DEFAULT_IDLE_TIMEOUT_SECS: u64 = 1_500;
2828

2929
/// Default absolute wall-clock cap per agent turn (2 hours).
3030
/// Override via `--max-turn-duration` / `BUZZ_ACP_MAX_TURN_DURATION`.
@@ -2757,9 +2757,9 @@ channels = "ALL"
27572757
// ── Idle timeout constant + guard (PR #935) ───────────────────────────────
27582758

27592759
#[test]
2760-
fn default_idle_timeout_is_900_seconds() {
2760+
fn default_idle_timeout_is_1500_seconds() {
27612761
// Lock the constant value so accidental changes are caught.
2762-
assert_eq!(DEFAULT_IDLE_TIMEOUT_SECS, 900);
2762+
assert_eq!(DEFAULT_IDLE_TIMEOUT_SECS, 1_500);
27632763
}
27642764

27652765
#[test]
@@ -2779,6 +2779,45 @@ channels = "ALL"
27792779
}
27802780
}
27812781

2782+
#[test]
2783+
fn budget_ordering_invariant_shell_cap_plus_headroom_fits_within_idle_timeout() {
2784+
// Asserts the three-layer budget relationship introduced in PR #7185:
2785+
// buzz-dev-mcp MAX_TIMEOUT_MS (1 200 000 ms = 1 200s)
2786+
// ≤ buzz-agent BUZZ_AGENT_TOOL_TIMEOUT_SECS default (1 260s)
2787+
// < buzz-acp DEFAULT_IDLE_TIMEOUT_SECS (1 500s)
2788+
//
2789+
// The idle deadline must strictly outlast the agent tool timeout so a
2790+
// legitimately long-running tool call is killed by buzz-agent first (at
2791+
// 1 260s) rather than the ACP idle watchdog. The 240s gap gives the agent
2792+
// time to handle the timeout, emit a response, and reset the idle clock
2793+
// before the ACP connection dies.
2794+
//
2795+
// If any of these constants change the compiler catches the inversion here.
2796+
// Cross-crate constants are mirrored as literals; grep for PR #7185 to
2797+
// find the authoritative source if you need to update them.
2798+
const SHELL_CAP_MS: u64 = 1_200_000; // buzz-dev-mcp MAX_TIMEOUT_MS
2799+
const SHELL_CAP_SECS: u64 = SHELL_CAP_MS / 1_000;
2800+
const AGENT_TOOL_TIMEOUT_SECS: u64 = 1_260; // buzz-agent BUZZ_AGENT_TOOL_TIMEOUT_SECS default
2801+
2802+
const {
2803+
// Shell cap must not exceed the agent's per-tool-call timeout.
2804+
assert!(
2805+
SHELL_CAP_SECS <= AGENT_TOOL_TIMEOUT_SECS,
2806+
"shell cap must be <= agent tool timeout"
2807+
);
2808+
// Agent tool timeout must be strictly less than the ACP idle deadline.
2809+
assert!(
2810+
AGENT_TOOL_TIMEOUT_SECS < DEFAULT_IDLE_TIMEOUT_SECS,
2811+
"agent tool timeout must be < ACP idle timeout"
2812+
);
2813+
// ACP idle timeout must remain below the max turn duration.
2814+
assert!(
2815+
DEFAULT_IDLE_TIMEOUT_SECS < DEFAULT_MAX_TURN_DURATION_SECS,
2816+
"ACP idle timeout must be < max turn duration"
2817+
);
2818+
}
2819+
}
2820+
27822821
// --- BUZZ_ACP_ALLOWED_RESPOND_TO gate ---
27832822

27842823
fn parse_allowed_respond_to(raw: &[&str]) -> Result<HashSet<RespondTo>, ConfigError> {

‎crates/buzz-agent/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Everything is environment variables. No flags, no config files. (We are a subpro
159159
| `BUZZ_AGENT_MAX_CONTEXT_TOKENS` | `200000` | Provider context window used by the handoff gate. |
160160
| `BUZZ_AGENT_MAX_HANDOFFS` | `10` | Max context handoffs per session before falling back to truncation. |
161161
| `BUZZ_AGENT_LLM_TIMEOUT_SECS` | `240` | Max seconds with no response bytes before abandoning an LLM call (per-read inactivity, not wall-clock). |
162-
| `BUZZ_AGENT_TOOL_TIMEOUT_SECS` | `660` | Per-tool call timeout in seconds |
162+
| `BUZZ_AGENT_TOOL_TIMEOUT_SECS` | `1260` | Per-tool call timeout in seconds |
163163
| `BUZZ_AGENT_MAX_PARALLEL_TOOLS` | `8` | Max concurrent tool calls per turn (1 = sequential) |
164164
| `BUZZ_AGENT_MAX_SESSIONS` | unlimited | Max concurrent ACP sessions. Sessions are cheap; default has no cap. |
165165
| `BUZZ_AGENT_MAX_LINE_BYTES` | `4194304` | 4 MiB. Hard cap on inbound JSON-RPC frames. |
@@ -326,7 +326,7 @@ The trust boundary is **the operator who launched the agent**. The harness, MCP
326326
| Tool calls per turn | 64 | `MAX_TOOL_CALLS_PER_TURN` |
327327
| Loop rounds | 0 (unlimited) | `BUZZ_AGENT_MAX_ROUNDS` |
328328
| LLM read inactivity timeout | 240 s | `BUZZ_AGENT_LLM_TIMEOUT_SECS` |
329-
| Tool call timeout | 660 s | `BUZZ_AGENT_TOOL_TIMEOUT_SECS` |
329+
| Tool call timeout | 1260 s | `BUZZ_AGENT_TOOL_TIMEOUT_SECS` |
330330

331331
## What This Is NOT
332332

‎crates/buzz-agent/src/config.rs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ impl Config {
709709
max_output_tokens: parse_env("BUZZ_AGENT_MAX_OUTPUT_TOKENS", 65_536)?,
710710
max_token_recoveries: parse_env("BUZZ_AGENT_MAX_TOKEN_RECOVERIES", 3u32)?,
711711
llm_timeout: Duration::from_secs(parse_env("BUZZ_AGENT_LLM_TIMEOUT_SECS", 240)?),
712-
tool_timeout: Duration::from_secs(parse_env("BUZZ_AGENT_TOOL_TIMEOUT_SECS", 660)?),
712+
tool_timeout: Duration::from_secs(parse_env("BUZZ_AGENT_TOOL_TIMEOUT_SECS", 1_260)?),
713713
mcp_init_timeout: Duration::from_secs(parse_env(
714714
"BUZZ_AGENT_MCP_INIT_TIMEOUT_SECS",
715715
30,
@@ -2462,4 +2462,24 @@ mod tests {
24622462
assert_eq!(pricing_authority("https://api.databricks.com/v1"), None);
24632463
assert_eq!(pricing_authority("https://custom.llm.corp/v1"), None);
24642464
}
2465+
2466+
#[test]
2467+
fn default_tool_timeout_is_1260_seconds() {
2468+
// Lock the production default so accidental regressions are caught.
2469+
// This value must remain >= buzz-dev-mcp's MAX_TIMEOUT_MS (1_200s) to
2470+
// give every shell(timeout_ms=1_200_000) call time to complete before
2471+
// buzz-agent kills the MCP server. See PR #7185 for the full budget chain.
2472+
//
2473+
// 1_260s is the literal default passed to parse_env in Config::from_env().
2474+
// Update here if and only if you update that literal; the test name makes
2475+
// "grep for old value" reliable.
2476+
const DEFAULT_TOOL_TIMEOUT_SECS: u64 = 1_260;
2477+
const {
2478+
// Shell cap (1_200_000 ms = 1_200s) must fit inside the agent timeout.
2479+
assert!(
2480+
1_200u64 <= DEFAULT_TOOL_TIMEOUT_SECS,
2481+
"agent tool timeout must be >= dev-mcp shell cap (1200s)"
2482+
);
2483+
}
2484+
}
24652485
}

‎crates/buzz-dev-mcp/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl DevMcp {
3939

4040
#[tool(
4141
name = "shell",
42-
description = "Run a shell command (bash by default; set `BUZZ_SHELL` to use cmd, PowerShell, or another shell). Ephemeral process per call. Output tail-truncated to ~8KB for the LLM; full output (first 10MB) saved to artifact file. timeout_ms defaults to 120000 (2 min) if omitted; capped at 600000 (10 min). For long-running commands (git push with hooks, cargo build, test suites), use 300000+. On PATH: rg (prefer over grep; flags: -n -i -l -g <glob> -C <n> --files), tree (flags: -d <depth>; shows line counts), and buzz (Buzz relay CLI — run buzz --help for commands)."
42+
description = "Run a shell command (bash by default; set `BUZZ_SHELL` to use cmd, PowerShell, or another shell). Ephemeral process per call. Output tail-truncated to ~8KB for the LLM; full output (first 10MB) saved to artifact file. timeout_ms defaults to 120000 (2 min) if omitted; capped at 1,200,000 (20 min). For long-running commands (git push with hooks, cargo build, test suites), use 300000+. On PATH: rg (prefer over grep; flags: -n -i -l -g <glob> -C <n> --files), tree (flags: -d <depth>; shows line counts), and buzz (Buzz relay CLI — run buzz --help for commands)."
4343
)]
4444
async fn shell(
4545
&self,

‎crates/buzz-dev-mcp/src/shell.rs‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use tokio::process::Command;
1414
use tokio_util::sync::CancellationToken;
1515

1616
const DEFAULT_TIMEOUT_MS: u64 = 120_000;
17-
const MAX_TIMEOUT_MS: u64 = 600_000;
17+
const MAX_TIMEOUT_MS: u64 = 1_200_000;
1818
const MAX_COMMAND_BYTES: usize = 1_000_000;
1919
const CAPTURE_CAP: usize = 10 * 1024 * 1024;
2020
const MAX_BYTES: usize = 50 * 1024;
@@ -121,12 +121,16 @@ pub struct ShellParams {
121121
pub command: String,
122122
#[serde(default)]
123123
pub workdir: Option<String>,
124-
/// Defaults to 120000 ms (2 min) if omitted; capped at 600000 ms (10 min).
124+
/// Defaults to 120000 ms (2 min) if omitted; capped at 1,200,000 ms (20 min).
125125
/// For long-running commands (git push with hooks, cargo build, test suites), use 300000+.
126126
#[serde(default)]
127127
pub timeout_ms: Option<u64>,
128128
}
129129

130+
fn effective_timeout_ms(requested: Option<u64>) -> u64 {
131+
requested.unwrap_or(DEFAULT_TIMEOUT_MS).min(MAX_TIMEOUT_MS)
132+
}
133+
130134
pub async fn run(
131135
state: &SharedState,
132136
p: ShellParams,
@@ -138,10 +142,7 @@ pub async fn run(
138142
None,
139143
));
140144
}
141-
let timeout_ms = p
142-
.timeout_ms
143-
.unwrap_or(DEFAULT_TIMEOUT_MS)
144-
.min(MAX_TIMEOUT_MS);
145+
let timeout_ms = effective_timeout_ms(p.timeout_ms);
145146
let workdir: PathBuf = p
146147
.workdir
147148
.as_deref()
@@ -1002,6 +1003,15 @@ mod tests {
10021003
serde_json::from_str(&text).expect("json")
10031004
}
10041005

1006+
#[test]
1007+
fn timeout_bounds_preserve_default_and_cap_requests_at_twenty_minutes() {
1008+
assert_eq!(effective_timeout_ms(None), 120_000);
1009+
assert_eq!(effective_timeout_ms(Some(120_000)), 120_000);
1010+
assert_eq!(effective_timeout_ms(Some(1_200_000)), 1_200_000);
1011+
assert_eq!(effective_timeout_ms(Some(1_200_001)), 1_200_000);
1012+
assert_eq!(effective_timeout_ms(Some(u64::MAX)), 1_200_000);
1013+
}
1014+
10051015
#[tokio::test(flavor = "current_thread")]
10061016
async fn basic_echo() {
10071017
let dir = tempdir().expect("tempdir");

0 commit comments

Comments
 (0)