A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
free the acp prompt slot before the response leaves (#3347)
ktae8f653ff60e
diff --git a/crates/pa-cli/tests/acp_mode_e2e.rs b/crates/pa-cli/tests/acp_mode_e2e.rsindex d53e3c3959..52fdf4e1b7 100644--- a/crates/pa-cli/tests/acp_mode_e2e.rs+++ b/crates/pa-cli/tests/acp_mode_e2e.rs@@ -287,6 +287,17 @@ fn initialize_params() -> Value {const TIMEOUT: Duration = Duration::from_mins(1);+/// Assert a settled turn's stop reason, printing the whole response+/// envelope on mismatch: an `internal_error`'s failure text (the+/// `prime-agent turn failed: <failure>` message) is otherwise lost — the+/// `stopReason: null` arms of `assert_eq!` show only the null.+fn assert_end_turn(response: &Value) {+ assert_eq!(+ response["result"]["stopReason"], "end_turn",+ "the turn's response envelope: {response}"+ );+}+/// The TS initialize response shape (capture `ts-happy_path.jsonl`), with the/// version and sessionId-class fields normalized as volatile.#[test]@@ -1850,7 +1861,7 @@ fn acp_threshold_auto_compaction_publishes_the_compaction_meta() {}),);let (prompt_response, updates) = client.wait_response(prompt, TIMEOUT);- assert_eq!(prompt_response["result"]["stopReason"], "end_turn");+ assert_end_turn(&prompt_response);let metas = compaction_metas(&updates);assert!(!metas.is_empty(), "the threshold arm ran: {updates:?}");assert!(@@ -1870,7 +1881,7 @@ fn acp_threshold_auto_compaction_publishes_the_compaction_meta() {}),);let (prompt_response, updates) = client.wait_response(prompt, TIMEOUT);- assert_eq!(prompt_response["result"]["stopReason"], "end_turn");+ assert_end_turn(&prompt_response);let metas = compaction_metas(&updates);let ran = metas.iter()@@ -1883,6 +1894,45 @@ fn acp_threshold_auto_compaction_publishes_the_compaction_meta() {assert!(ran["tokensBefore"].as_u64().unwrap() > 0);}+/// A settled turn's response implies the next prompt is admissible: the+/// turn releases the session's single-prompt slot before its reply+/// leaves, so a client that prompts again the instant it reads the+/// response is admitted. Twenty back-to-back prompts keep every+/// settle-to-next-admission window covered.+#[test]+fn acp_settled_prompt_immediately_admits_the_next_prompt() {+ let script = json!({+ "engine": "faux",+ "contextWindow": 128_000,+ "responses": (0..30)+ .map(|index| json!({ "text": format!("settled turn reply {index}") }))+ .collect::<Vec<_>>(),+ });+ let mut client = AcpChild::spawn(&["--mode", "acp", "--no-session"], &script);+ let init = client.request("initialize", &initialize_params());+ let _ = client.wait_response(init, TIMEOUT);+ let new = client.request("session/new", &json!({ "mcpServers": [] }));+ let (new_response, _) = client.wait_response(new, TIMEOUT);+ let session_id = new_response["result"]["sessionId"]+ .as_str()+ .unwrap()+ .to_string();+ for turn in 0..20 {+ let prompt = client.request(+ "session/prompt",+ &json!({+ "sessionId": session_id,+ "prompt": [{ "type": "text", "text": format!("settled turn {turn}") }],+ }),+ );+ let (prompt_response, _) = client.wait_response(prompt, TIMEOUT);+ assert_eq!(+ prompt_response["result"]["stopReason"], "end_turn",+ "turn {turn}: the settled turn raced the next prompt's admission: {prompt_response}"+ );+ }+}+/// The overflow arm on the ACP turn path: a provider context-overflow/// error runs one compact-and-retry at the boundary and the retried turn/// settles the prompt with `end_turn` instead of the error (TSdiff --git a/crates/pa-daemon/src/acp/daemon.rs b/crates/pa-daemon/src/acp/daemon.rsindex 7457679df8..341e0c0b6d 100644--- a/crates/pa-daemon/src/acp/daemon.rs+++ b/crates/pa-daemon/src/acp/daemon.rs@@ -1149,6 +1149,10 @@ async fn prompt_turn(let failure = response.error.unwrap_or_else(|| "unknown error".to_string());+ // The failure text rides the internal_error reply, where a test+ // asserting only the stop reason loses it: echo it to stderr so+ // every harness's child-stderr dump shows WHY the turn failed.+ eprintln!("pa-daemon: acp turn failed: {failure}");publish_error_boundary(&producer, turn_id).await;producer.finish_prompt(turn_id).await;return super::internal_error(&id, &format!("prime-agent turn failed: {failure}"));