mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-30 09:05:15 +01:00
fix(runner): a sidecar session.open refusal keeps its code and reason
The live /swarm failure was undiagnosable: the Runner composed "classification=unclassified" and dropped the sidecar's code and message, so nothing in run events, logs or state said why. - The Runner classifies the typed /swarm refusals (antigravity_swarm_*), candidate_admission_invalid and sidecar_request_invalid instead of "unclassified". - A rejected command keeps the sidecar's own code, and its redacted, bounded message when no typed provider cause was sent, as `sidecarRejection` on the failed command result (run error). The rejection text stays closed; provider text still travels only in providerFailure. - The server settles a typed /swarm refusal at session.open as antigravity_swarm_unavailable (waits for the user, no same-run retry) and a request-contract or grant refusal as a startup rejection. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1a97dfe821
commit
3d4cf276fa
9 files changed
+178
-8
No files matched your search
@@ -1630,7 +1630,8 @@ impl AcpxCommandExecutor {
|
||||
let incompatible = recovering && saved_state_reload_refused(&error);
|
||||
let failure =
|
||||
DurableRunnerError::invalid(format!("failed to start ACPX provider: {error}"))
|
||||
.with_provider_failure(error.provider_failure());
|
||||
.with_provider_failure(error.provider_failure())
|
||||
.with_sidecar_rejection(error.sidecar_rejection());
|
||||
if incompatible {
|
||||
failure.with_classification(crate::durable::PROVIDER_STATE_INCOMPATIBLE)
|
||||
} else {
|
||||
|
||||
@@ -2042,7 +2042,8 @@ fn with_cleanup_error(
|
||||
"{error}; ACPX sidecar cleanup also failed: {cleanup}"
|
||||
))
|
||||
.with_provider_failure(error.provider_failure())
|
||||
.with_command_rejection(error.command_rejection()),
|
||||
.with_command_rejection(error.command_rejection())
|
||||
.with_sidecar_rejection(error.sidecar_rejection()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2544,6 +2545,15 @@ mod mode_tests {
|
||||
session_open_params(&cfg, &[])["candidateAdmission"],
|
||||
json!(admission)
|
||||
);
|
||||
// A granted /swarm turn keeps the same grant and names its provider mode;
|
||||
// the sidecar, not the Runner, decides which agent modes it accepts.
|
||||
let mut swarm = cfg.clone();
|
||||
swarm.mode = Some("swarm".to_owned());
|
||||
swarm.validate().unwrap();
|
||||
let open = session_open_params(&swarm, &[]);
|
||||
assert_eq!(open["candidateAdmission"], json!(admission));
|
||||
assert_eq!(open["mode"], json!("swarm"));
|
||||
assert_eq!(initialize_params(&swarm)["candidateAdmission"], json!(admission));
|
||||
for (field, value) in [
|
||||
("run", "different-run"),
|
||||
("session", "different-session"),
|
||||
|
||||
@@ -829,6 +829,7 @@ impl AcpxSidecarTransport {
|
||||
let tool_call_retired = command == GeneratedAcpxSidecarCommand::ToolResolve
|
||||
&& error.code == "ACPX_TOOL_CALL_STALE";
|
||||
let classification = response_error_classification(&error);
|
||||
let sidecar_rejection = sidecar_rejection_detail(command.as_str(), &error);
|
||||
return Ok(Some(CommandOutcome::Rejected { tool_call_retired, error: LocalRunnerError::invalid(
|
||||
format!(
|
||||
"ACPX sidecar command {} was rejected (retryable={}, classification={})",
|
||||
@@ -840,7 +841,8 @@ impl AcpxSidecarTransport {
|
||||
.with_command_rejection(Some(CommandRejection {
|
||||
command: command.as_str(),
|
||||
classification,
|
||||
})), resume_required }));
|
||||
}))
|
||||
.with_sidecar_rejection(Some(sidecar_rejection)), resume_required }));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1289,6 +1291,42 @@ fn typed_provider_classification(error: &ResponseError) -> Option<&'static str>
|
||||
pub(crate) const ANTIGRAVITY_SAVED_STATE_INCOMPATIBLE: &str =
|
||||
"antigravity_saved_state_incompatible";
|
||||
|
||||
const SIDECAR_REJECTION_MESSAGE_CHARS: usize = 512;
|
||||
|
||||
/// The sidecar's own code and, when it sent no typed provider cause, its
|
||||
/// (sidecar-redacted) message, for operators reading the failed command. The
|
||||
/// rejection text itself stays closed; a provider cause travels only in
|
||||
/// `providerFailure`, so its message is never copied here.
|
||||
fn sidecar_rejection_detail(command: &str, error: &ResponseError) -> Value {
|
||||
let code = if !error.code.is_empty()
|
||||
&& error.code.len() <= 96
|
||||
&& error
|
||||
.code
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'.' | b'-'))
|
||||
{
|
||||
error.code.as_str()
|
||||
} else {
|
||||
"invalid_code"
|
||||
};
|
||||
let mut detail = json!({ "command": command, "code": code });
|
||||
if validated_provider_failure(error.provider_failure.clone()).is_none() {
|
||||
let message: String = crate::durable::redact_sensitive_text_values(&error.message)
|
||||
.chars()
|
||||
.filter(|character| {
|
||||
!character.is_control()
|
||||
&& !matches!(character, '\u{202a}'..='\u{202e}' | '\u{2066}'..='\u{2069}')
|
||||
})
|
||||
.take(SIDECAR_REJECTION_MESSAGE_CHARS)
|
||||
.collect();
|
||||
let message = message.trim();
|
||||
if !message.is_empty() {
|
||||
detail["message"] = json!(message);
|
||||
}
|
||||
}
|
||||
detail
|
||||
}
|
||||
|
||||
fn response_error_classification(error: &ResponseError) -> &'static str {
|
||||
match error.code.as_str() {
|
||||
"GROK_EFFORT_ACKNOWLEDGEMENT_MISSING" => return "grok_effort_acknowledgement_missing",
|
||||
@@ -1359,6 +1397,15 @@ fn response_error_classification(error: &ResponseError) -> &'static str {
|
||||
"ACPX_MODEL_SELECTION_UNAVAILABLE" => return "model_selection_unavailable",
|
||||
"ACPX_EFFECTIVE_MODEL_MISMATCH" => return "effective_model_mismatch",
|
||||
"ANTIGRAVITY_SAVED_STATE_INCOMPATIBLE" => return ANTIGRAVITY_SAVED_STATE_INCOMPATIBLE,
|
||||
// A typed /swarm refusal: the request cannot run as sent, so it waits for the user.
|
||||
"ANTIGRAVITY_SWARM_UNAVAILABLE" => return "antigravity_swarm_unavailable",
|
||||
"ANTIGRAVITY_SWARM_SIGN_IN_REQUIRED" => return "antigravity_swarm_sign_in_required",
|
||||
"ANTIGRAVITY_SWARM_RECEIPT_MISMATCH" => return "antigravity_swarm_receipt_mismatch",
|
||||
"ANTIGRAVITY_SWARM_WORKSPACE_ESCAPE" => return "antigravity_swarm_workspace_escape",
|
||||
"ANTIGRAVITY_SWARM_HELPERS_TIMEOUT" => return "antigravity_swarm_helpers_timeout",
|
||||
"ACPX_CANDIDATE_ADMISSION_INVALID" => return "candidate_admission_invalid",
|
||||
// Runner and sidecar disagree on the request contract (a version skew or a missing field).
|
||||
"ACPX_SIDECAR_REQUEST_INVALID" => return "sidecar_request_invalid",
|
||||
_ => {}
|
||||
}
|
||||
match error.message.as_str() {
|
||||
|
||||
@@ -59,11 +59,26 @@ pub const PROVIDER_SIDE_EFFECT_PENDING: &str = "provider_side_effect_pending";
|
||||
pub const PROVIDER_SESSION_CLOSED: &str = "provider_session_closed";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct DurableRunnerError(String, Option<serde_json::Value>, Option<&'static str>);
|
||||
pub struct DurableRunnerError(
|
||||
String,
|
||||
Option<serde_json::Value>,
|
||||
Option<&'static str>,
|
||||
Option<serde_json::Value>,
|
||||
);
|
||||
|
||||
impl DurableRunnerError {
|
||||
pub fn invalid(message: impl Into<String>) -> Self {
|
||||
Self(message.into(), None, None)
|
||||
Self(message.into(), None, None, None)
|
||||
}
|
||||
|
||||
/// See [`crate::local_runner::LocalRunnerError::with_sidecar_rejection`].
|
||||
pub fn with_sidecar_rejection(mut self, detail: Option<serde_json::Value>) -> Self {
|
||||
self.3 = detail;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sidecar_rejection(&self) -> Option<serde_json::Value> {
|
||||
self.3.clone()
|
||||
}
|
||||
|
||||
pub fn with_provider_failure(mut self, value: Option<serde_json::Value>) -> Self {
|
||||
|
||||
@@ -2487,6 +2487,9 @@ fn process_command<E: CommandExecutor>(
|
||||
if let Some(provider_failure) = error.provider_failure() {
|
||||
failure["providerFailure"] = provider_failure;
|
||||
}
|
||||
if let Some(rejection) = error.sidecar_rejection() {
|
||||
failure["sidecarRejection"] = rejection;
|
||||
}
|
||||
let result = state.fail_command(command, failure)?;
|
||||
store.save(state)?;
|
||||
return Ok((result, CommandLifecycle::after_failure(command)));
|
||||
|
||||
@@ -22,7 +22,12 @@ const HARNESS_MESSAGE_SCHEMA: &str = "paperclip.fake_harness.message.v1";
|
||||
const CONTROLLER_COMMAND_QUEUE_CAPACITY: usize = 256;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct LocalRunnerError(String, Option<Value>, Option<CommandRejection>);
|
||||
pub struct LocalRunnerError(
|
||||
String,
|
||||
Option<Value>,
|
||||
Option<CommandRejection>,
|
||||
Option<Value>,
|
||||
);
|
||||
|
||||
/// A provider process rejected a named command with a closed failure class.
|
||||
/// Callers branch on this data, never on the error message.
|
||||
@@ -34,7 +39,7 @@ pub struct CommandRejection {
|
||||
|
||||
impl LocalRunnerError {
|
||||
pub fn invalid(message: impl Into<String>) -> Self {
|
||||
Self(message.into(), None, None)
|
||||
Self(message.into(), None, None, None)
|
||||
}
|
||||
|
||||
pub fn with_provider_failure(mut self, value: Option<Value>) -> Self {
|
||||
@@ -54,6 +59,17 @@ impl LocalRunnerError {
|
||||
pub fn command_rejection(&self) -> Option<CommandRejection> {
|
||||
self.2
|
||||
}
|
||||
|
||||
/// The provider process's own rejection, as `{command, code, message?}`:
|
||||
/// an operator diagnosis kept out of the error text, which stays closed.
|
||||
pub fn with_sidecar_rejection(mut self, detail: Option<Value>) -> Self {
|
||||
self.3 = detail;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sidecar_rejection(&self) -> Option<Value> {
|
||||
self.3.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for LocalRunnerError {
|
||||
|
||||
@@ -298,6 +298,58 @@ fn preserves_closed_admission_categories_over_the_sidecar_pipe() {
|
||||
transport.shutdown().unwrap();
|
||||
}
|
||||
|
||||
// Live /swarm runs failed with only "classification=unclassified": the sidecar's
|
||||
// own reason ("mode is supported only for Cursor") was dropped at this pipe.
|
||||
#[test]
|
||||
fn session_open_rejection_keeps_the_sidecar_code_and_reason_outside_the_error_text() {
|
||||
let mut sidecar = transport("remote-error", Duration::from_secs(1));
|
||||
for (code, classification) in [
|
||||
("ACPX_SIDECAR_REQUEST_INVALID", "sidecar_request_invalid"),
|
||||
("ANTIGRAVITY_SWARM_UNAVAILABLE", "antigravity_swarm_unavailable"),
|
||||
("ANTIGRAVITY_SWARM_SIGN_IN_REQUIRED", "antigravity_swarm_sign_in_required"),
|
||||
("ANTIGRAVITY_SWARM_RECEIPT_MISMATCH", "antigravity_swarm_receipt_mismatch"),
|
||||
("ANTIGRAVITY_SWARM_WORKSPACE_ESCAPE", "antigravity_swarm_workspace_escape"),
|
||||
("ANTIGRAVITY_SWARM_HELPERS_TIMEOUT", "antigravity_swarm_helpers_timeout"),
|
||||
("ACPX_CANDIDATE_ADMISSION_INVALID", "candidate_admission_invalid"),
|
||||
("acpx_sidecar_command_failed", "unclassified"),
|
||||
] {
|
||||
let error = sidecar
|
||||
.request(GeneratedAcpxSidecarCommand::SessionOpen, json!({ "errorCode": code }))
|
||||
.unwrap_err();
|
||||
let message = error.to_string();
|
||||
assert!(message.ends_with(&format!("retryable=false, classification={classification})")));
|
||||
assert!(!message.contains("violet-circuit-4821"));
|
||||
assert_eq!(
|
||||
error.sidecar_rejection(),
|
||||
Some(json!({ "command": "session.open", "code": code, "message": "violet-circuit-4821" }))
|
||||
);
|
||||
}
|
||||
// A provider cause has its own channel: the sidecar message is not copied.
|
||||
let cause = json!({ "schema": "paperclip.provider-failure.v1", "provider": "antigravity", "phase": "startup",
|
||||
"category": "unknown", "message": "Swarm is not available.", "providerCode": "ANTIGRAVITY_SWARM_UNAVAILABLE",
|
||||
"retryability": "unknown" });
|
||||
let error = sidecar
|
||||
.request(
|
||||
GeneratedAcpxSidecarCommand::SessionOpen,
|
||||
json!({ "errorCode": "ANTIGRAVITY_SWARM_UNAVAILABLE", "providerFailure": cause }),
|
||||
)
|
||||
.unwrap_err();
|
||||
assert_eq!(error.provider_failure(), Some(cause));
|
||||
assert_eq!(
|
||||
error.sidecar_rejection(),
|
||||
Some(json!({ "command": "session.open", "code": "ANTIGRAVITY_SWARM_UNAVAILABLE" }))
|
||||
);
|
||||
sidecar.shutdown().unwrap();
|
||||
// A code outside the closed identifier shape fails the frame contract and is never echoed.
|
||||
let mut invalid = transport("remote-error", Duration::from_secs(1));
|
||||
let error = invalid
|
||||
.request(GeneratedAcpxSidecarCommand::SessionOpen, json!({ "errorCode": "token=amber secret" }))
|
||||
.unwrap_err();
|
||||
assert!(error.sidecar_rejection().is_none());
|
||||
assert!(!error.to_string().contains("amber"));
|
||||
invalid.shutdown().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn session_ensure_rejection_carries_its_provider_cause_outside_the_error_text() {
|
||||
let mut transport = transport("remote-error", Duration::from_secs(1));
|
||||
|
||||
Reference in new issue
Block a user