From 23503f9689dd2aeb4dd9a63ee0683c56ed4e1abe Mon Sep 17 00:00:00 2001 From: Joah Gerstenberg Date: Wed, 24 Jun 2026 17:17:47 -0500 Subject: [PATCH] fix(agent): raise combined system prompt cap to 1 MiB The session/new handler rejects combined system prompts (harness prompt + persona + discovered AGENTS.md/skill hints) over MAX_SYSTEM_PROMPT_BYTES. At 512 KiB this falsely rejects sessions when a machine has a large skill library: buzz-agent inlines the full body of every SKILL.md found under ~/.agents/skills (and .goose/.claude skills + AGENTS.md), so a user with ~76 skills hits 'combined system prompt exceeds 512KB limit (533647 bytes)' and the agent cannot start a session. Raise MAX_SYSTEM_PROMPT_BYTES from 512 KiB to 1 MiB, matching the sibling MAX_PROMPT_BYTES. The cap is local to the buzz-acp<->buzz-agent stdio boundary, not the relay frame size, so this does not affect wire limits. Update the oversized-prompt integration test accordingly. Amp-Thread-ID: https://ampcode.com/threads/T-019efb67-0076-766e-be17-f563c0e12e01 Co-authored-by: Amp --- crates/buzz-agent/src/config.rs | 5 ++++- crates/buzz-agent/src/lib.rs | 2 +- crates/buzz-agent/tests/fake_llm.rs | 10 +++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/buzz-agent/src/config.rs b/crates/buzz-agent/src/config.rs index 1d5a3df3b..3d9557a1a 100644 --- a/crates/buzz-agent/src/config.rs +++ b/crates/buzz-agent/src/config.rs @@ -3,7 +3,10 @@ use std::time::Duration; pub const PROTOCOL_VERSION: u32 = 2; pub const MAX_PROMPT_BYTES: usize = 1024 * 1024; -pub const MAX_SYSTEM_PROMPT_BYTES: usize = 512 * 1024; +/// Ceiling on the combined system prompt (harness prompt + persona + hints). +/// Raised from 512 KiB to 1 MiB to fit large discovered skill/AGENTS.md hint +/// sections; matches `MAX_PROMPT_BYTES`. +pub const MAX_SYSTEM_PROMPT_BYTES: usize = 1024 * 1024; /// Total per-result byte ceiling (text + images). Sized for image-bearing /// results — view_image can legitimately return multi-MiB base64 payloads. /// Text is governed by the much smaller `BUZZ_AGENT_MAX_TOOL_RESULT_TEXT_BYTES`. diff --git a/crates/buzz-agent/src/lib.rs b/crates/buzz-agent/src/lib.rs index 5e4988b23..cec1cdc7a 100644 --- a/crates/buzz-agent/src/lib.rs +++ b/crates/buzz-agent/src/lib.rs @@ -285,7 +285,7 @@ async fn session_new(app: &Arc, id: Value, params: Value, wire_tx: &WireSen } else { format!("{base}\n\n{hints}") }; - // Reject combined prompts exceeding 512KB. + // Reject combined prompts exceeding MAX_SYSTEM_PROMPT_BYTES. if prompt.len() > MAX_SYSTEM_PROMPT_BYTES { return reject( wire_tx, diff --git a/crates/buzz-agent/tests/fake_llm.rs b/crates/buzz-agent/tests/fake_llm.rs index e3e83a6f0..4fcc5ae73 100644 --- a/crates/buzz-agent/tests/fake_llm.rs +++ b/crates/buzz-agent/tests/fake_llm.rs @@ -423,7 +423,7 @@ async fn rejects_oversized_line() { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn session_new_rejects_oversized_system_prompt() { - // A systemPrompt exceeding 512KB must produce a JSON-RPC error, not a panic. + // A systemPrompt exceeding 1 MiB must produce a JSON-RPC error, not a panic. let url = spawn_fake_llm(vec![]).await; let mut h = Harness::spawn(&url).await; h.send( @@ -434,8 +434,8 @@ async fn session_new_rejects_oversized_system_prompt() { let r = h.recv().await; assert_eq!(r["result"]["protocolVersion"], 2); - // 600KB payload — exceeds the 512KB limit. - let big_prompt = "x".repeat(600 * 1024); + // 1100KB payload — exceeds the 1 MiB limit. + let big_prompt = "x".repeat(1100 * 1024); let id = h .send( "session/new", @@ -449,8 +449,8 @@ async fn session_new_rejects_oversized_system_prompt() { ); let err_msg = r["error"]["message"].as_str().unwrap_or(""); assert!( - err_msg.contains("512KB limit"), - "error message should mention 512KB limit, got: {err_msg}" + err_msg.contains("1024KB limit"), + "error message should mention 1024KB limit, got: {err_msg}" ); h.shutdown().await; }