mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-30 09:05:15 +01:00
Preserve ACP turn ordering when negotiated controls are unchanged
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
851c60a1fb
commit
04b88a97f5
3 files changed
+118
-16
No files matched your search
@@ -1253,12 +1253,18 @@ impl AcpxCommandExecutor {
|
||||
.as_mut()
|
||||
.expect("ACPX state exists after turn start");
|
||||
state.lifecycle = "turn_active".to_owned();
|
||||
let previous_turn_controls = state.turn_controls;
|
||||
state.turn_controls = self
|
||||
.session
|
||||
.as_ref()
|
||||
.expect("live ACPX session")
|
||||
.turn_control_capabilities();
|
||||
let capabilities = json!({"sessionGoals": state.goal_projection["sessionGoals"], "turnControls":state.turn_controls});
|
||||
// session.open already published these capabilities. Preserve legacy
|
||||
// turn ordering when nothing changed, while exposing lazy discovery
|
||||
// and capability loss after a provider process replacement.
|
||||
let capabilities = (state.turn_controls != previous_turn_controls).then(|| {
|
||||
json!({"sessionGoals": state.goal_projection["sessionGoals"], "turnControls":state.turn_controls})
|
||||
});
|
||||
self.save_state()?;
|
||||
let mut events = Vec::with_capacity(if provider_process_will_be_replaced {
|
||||
2
|
||||
@@ -1281,11 +1287,13 @@ impl AcpxCommandExecutor {
|
||||
),
|
||||
));
|
||||
}
|
||||
events.push((
|
||||
"session.capabilities.updated".to_owned(),
|
||||
EventPriority::P0,
|
||||
capabilities,
|
||||
));
|
||||
if let Some(capabilities) = capabilities {
|
||||
events.push((
|
||||
"session.capabilities.updated".to_owned(),
|
||||
EventPriority::P0,
|
||||
capabilities,
|
||||
));
|
||||
}
|
||||
events.push((
|
||||
"turn.started".to_owned(),
|
||||
EventPriority::P0,
|
||||
|
||||
@@ -208,6 +208,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
| "controls"
|
||||
| "controls-wrong-ack"
|
||||
| "controls-lazy"
|
||||
| "controls-downgrade"
|
||||
| "turns"
|
||||
| "turns-wrong-turn"
|
||||
| "turns-wrong-cancel"
|
||||
@@ -732,7 +733,7 @@ fn bootstrap_success(
|
||||
"providerLifetimeFenceCandidates": [60001, 60002, 60003],
|
||||
},
|
||||
"status": {},
|
||||
"turnControls": {"steering": matches!(mode, "controls" | "controls-wrong-ack"), "queuedFollowUp":matches!(mode, "controls" | "controls-wrong-ack")},
|
||||
"turnControls": {"steering": matches!(mode, "controls" | "controls-wrong-ack" | "controls-downgrade"), "queuedFollowUp":matches!(mode, "controls" | "controls-wrong-ack" | "controls-downgrade")},
|
||||
})
|
||||
}
|
||||
"run.attach" => json!({
|
||||
|
||||
+102
-9
@@ -16,6 +16,8 @@ use sha2::{Digest, Sha256};
|
||||
|
||||
const CODEX_ACPX_DIGEST: &str =
|
||||
"sha256:c4538599d1ab767db5dff50934f13bb5ba313a59d9c4a83e993fac4617ea63d3";
|
||||
const PI_ACPX_DIGEST: &str =
|
||||
"sha256:8c696f38296d53d0061fa11534570c5ddd951b63532aed30e0f1fcc676dc169f";
|
||||
|
||||
fn temporary_directory(label: &str) -> PathBuf {
|
||||
let nonce = SystemTime::now()
|
||||
@@ -76,6 +78,18 @@ fn acpx_config(state_dir: &Path, mode: &str) -> DurableRunnerConfig {
|
||||
config
|
||||
}
|
||||
|
||||
fn pi_acpx_config(state_dir: &Path, mode: &str) -> DurableRunnerConfig {
|
||||
let mut config = acpx_config(state_dir, mode);
|
||||
*config
|
||||
.acpx_launch_profile
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.args
|
||||
.last_mut()
|
||||
.unwrap() = PI_ACPX_DIGEST.to_owned();
|
||||
config
|
||||
}
|
||||
|
||||
fn qualified_artifact(path: PathBuf) -> QualifiedLaunchArtifact {
|
||||
QualifiedLaunchArtifact {
|
||||
sha256: format!("sha256:{:x}", Sha256::digest(fs::read(&path).unwrap())),
|
||||
@@ -211,6 +225,20 @@ fn prepare_payload_with_mode(directory: &Path, agent: &str, mode: &str) -> Value
|
||||
})
|
||||
}
|
||||
|
||||
fn pi_prepare_payload(directory: &Path, mode: &str) -> Value {
|
||||
let mut payload = prepare_payload_with_mode(directory, "pi", mode);
|
||||
let provider = &mut payload["provider"];
|
||||
provider["model"] = json!("openrouter/deepseek/deepseek-v4-flash-0731");
|
||||
provider["agentServerPackage"] = json!("pi-acp");
|
||||
provider["agentServerVersion"] = json!("0.0.33");
|
||||
provider["agentRuntimePackage"] = json!("@earendil-works/pi-coding-agent");
|
||||
provider["agentRuntimeVersion"] = json!("0.84.2");
|
||||
provider["commandDigest"] = json!(PI_ACPX_DIGEST);
|
||||
provider["sidecarArgs"][3] = json!(PI_ACPX_DIGEST);
|
||||
provider["providerPolicy"] = json!({"readOnly":true});
|
||||
payload
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserves_acpx_semantic_disposition_in_the_run_terminal() {
|
||||
let directory = temporary_directory("acpx-blocked");
|
||||
@@ -820,18 +848,83 @@ fn rejects_opencode_launch_profile_drift_across_fresh_recovery() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_pi_before_starting_a_sidecar() {
|
||||
let directory = temporary_directory("pi");
|
||||
let config = config(&directory);
|
||||
fn rejects_pi_with_an_unqualified_model_before_starting_a_sidecar() {
|
||||
let directory = temporary_directory("pi-model");
|
||||
let config = pi_acpx_config(&directory, "bootstrap");
|
||||
let mut payload = pi_prepare_payload(&directory, "bootstrap");
|
||||
// All Pi distribution and policy fields are correct. Admission must reject
|
||||
// the model itself, not rely on the old blanket exclusion of this harness.
|
||||
payload["provider"]["model"] = json!("gpt-5.6-sol");
|
||||
let mut executor = NativeProviderCommandExecutor::with_runner_config(&directory, &config);
|
||||
let error = executor
|
||||
.execute(&command(
|
||||
1,
|
||||
"run.prepare",
|
||||
prepare_payload(&directory, "pi"),
|
||||
))
|
||||
.execute(&command(1, "run.prepare", payload))
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().contains("agent pi is not executable"));
|
||||
assert!(error
|
||||
.to_string()
|
||||
.contains("does not match a qualified immutable profile"));
|
||||
assert!(!directory.join("acpx-runtime").exists());
|
||||
assert!(!directory.join("acpx-provider-state.json").exists());
|
||||
fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn publishes_only_changed_pi_controls_before_the_new_turn() {
|
||||
for (mode, initially_available, turn_available) in [
|
||||
("controls-lazy", false, true),
|
||||
("controls-downgrade", true, false),
|
||||
("controls", true, true),
|
||||
] {
|
||||
let directory = temporary_directory(mode);
|
||||
let config = pi_acpx_config(&directory, mode);
|
||||
let mut executor = NativeProviderCommandExecutor::with_runner_config(&directory, &config);
|
||||
executor
|
||||
.execute(&command(
|
||||
1,
|
||||
"run.prepare",
|
||||
pi_prepare_payload(&directory, mode),
|
||||
))
|
||||
.unwrap();
|
||||
let opened = executor
|
||||
.execute(&command(2, "session.open", json!({})))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
opened.events[0].2["providerDescriptor"]["turnControls"],
|
||||
json!({"steering":initially_available, "queuedFollowUp":initially_available})
|
||||
);
|
||||
|
||||
let started = executor
|
||||
.execute(&command(
|
||||
3,
|
||||
"turn.start",
|
||||
json!({
|
||||
"text":"Work", "turnId":"provider-turn-controls"
|
||||
}),
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(started.result["providerTurnId"], "provider-turn-controls");
|
||||
let expected_types = if initially_available != turn_available {
|
||||
vec!["session.capabilities.updated", "turn.started"]
|
||||
} else {
|
||||
vec!["turn.started"]
|
||||
};
|
||||
assert_eq!(
|
||||
started
|
||||
.events
|
||||
.iter()
|
||||
.map(|event| event.0.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
expected_types
|
||||
);
|
||||
if initially_available != turn_available {
|
||||
assert_eq!(
|
||||
started.events[0].2["turnControls"],
|
||||
json!({"steering":turn_available, "queuedFollowUp":turn_available})
|
||||
);
|
||||
}
|
||||
let turn = &started.events.last().unwrap().2;
|
||||
assert_eq!(turn["providerTurnId"], "provider-turn-controls");
|
||||
assert_eq!(turn["turn"]["id"], "provider-turn-controls");
|
||||
executor.shutdown().unwrap();
|
||||
fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user