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:
DottaandClaude Opus 5.5 committed 2026-11-24 13:21:08 -06:00
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));
@@ -16089,6 +16089,21 @@ describe("native session bounded recovery", () => {
});
});
it("settles a typed swarm or request-contract refusal at session.open without same-run retries", () => {
const rejected = (classification: string, extra = "") => new Error(`PRP command session.open failed: {"commandId":"command_prp_00000002","commandType":"session.open","controllerSeq":2,"result":{"code":"command_execution_failed","message":"failed to start ACPX provider: ACPX sidecar command session.open was rejected (retryable=false, classification=${classification})"${extra}},"status":"failed"}`);
for (const classification of ["antigravity_swarm_unavailable", "antigravity_swarm_sign_in_required", "antigravity_swarm_receipt_mismatch"]) {
expect(nativeSessionFailureSourceCode(rejected(classification))).toBe("antigravity_swarm_unavailable");
expect(nativeSessionFailureDisposition(1, new Date(), "antigravity_swarm_unavailable")).toEqual({
phase: "terminal_failure", failureCode: "antigravity_swarm_unavailable", nextAttemptAt: null });
}
// The live /swarm failure: the provider process refused the request by its own contract.
const skew = rejected("sidecar_request_invalid", `,"sidecarRejection":{"command":"session.open","code":"ACPX_SIDECAR_REQUEST_INVALID","message":"mode is supported only for Cursor"}`);
expect(nativeSessionFailureSourceCode(skew)).toBe(NATIVE_PROVIDER_STARTUP_REJECTED);
expect(skew.message).toContain("mode is supported only for Cursor");
expect(nativeSessionFailureSourceCode(rejected("candidate_admission_invalid"))).toBe(NATIVE_PROVIDER_STARTUP_REJECTED);
expect(nativeSessionFailureSourceCode(rejected("unclassified"))).toBe("provider_session_open_rejected");
});
it("rests a run whose Runner refused its commands as out of sequence with a precise code and a Retry", () => {
const refused = new Error(`PRP command session.open rejected: {"commandId":"c","controllerSeq":11,"commandType":"session.open","status":"rejected","result":{"code":"controller_sequence_mismatch","message":"controller sequence must be contiguous: expected 13, received 11","expectedControllerSeq":13,"receivedControllerSeq":11}}`);
expect(nativeSessionFailureSourceCode(refused)).toBe(NATIVE_CONTROLLER_JOURNAL_BEHIND_RUNNER);
@@ -118,6 +118,7 @@ import { readLocalAiCredentialFile } from "../local-ai-credential-file.js";
import { prepareGrokRunnerCredentials } from "./grok-runner-credentials.js";
import { AntigravityConnectionConfigurationError } from "./antigravity-connection-policy.js";
import { antigravityCandidateTarget, antigravityForcesSameSessionRecovery, antigravityReleasePending, antigravityUsesRunScopedState, assertAntigravityExecutionAdmissible } from "./antigravity-release.js";
import { ANTIGRAVITY_SWARM_UNAVAILABLE } from "../antigravity-swarm-refusal.js";
import { bindAntigravityCredentialTurn, bindAntigravityTransportRetirement, prepareAntigravityRunnerCredentials } from "./antigravity-runner-credentials.js";
import { copyBackGrokAuth } from "@paperclipai/adapter-grok-local/server";
@@ -9090,7 +9091,8 @@ export function nativeSessionFailureDisposition(
sourceFailureCode === NATIVE_PROVIDER_STARTUP_REJECTED ||
sourceFailureCode === NATIVE_CONTROLLER_JOURNAL_BEHIND_RUNNER ||
sourceFailureCode === NATIVE_SANDBOX_DISK_FULL ||
sourceFailureCode === NATIVE_RUN_PAYLOAD_TOO_LARGE;
sourceFailureCode === NATIVE_RUN_PAYLOAD_TOO_LARGE ||
sourceFailureCode === ANTIGRAVITY_SWARM_UNAVAILABLE;
const permissionDeclined = sourceFailureCode === "native_permission_declined";
const exhausted = permanentFailure || permissionDeclined || attempt >= 3;
return {
@@ -9324,6 +9326,7 @@ function classifyNativeSessionFailure(
| typeof NATIVE_CURRENT_WAKE_COMMENTS_UNREAD
| typeof NATIVE_CURRENT_WAKE_COMMENTS_CHANGED_AFTER_READ
| "provider_session_open_rejected"
| typeof ANTIGRAVITY_SWARM_UNAVAILABLE
| "provider_session_open_timeout"
| "runner_task_admission_rejected"
| "runner_ingress_access_rejected"
@@ -9453,6 +9456,14 @@ function classifyNativeSessionFailure(
if (/classification=(?:requested_model_unsupported|grok_model_mismatch)\)/.test(message)) {
return "native_provider_model_rejected";
}
// The swarm route refused this /swarm (typed, with its own plain message).
// Every automatic attempt would refuse the same way, so it waits for the user.
if (/classification=antigravity_swarm_[a-z_]+\)/.test(message)) return ANTIGRAVITY_SWARM_UNAVAILABLE;
// The Runner and its provider process disagree on the request contract, or the
// operator grant does not cover this execution: the same run cannot open again.
if (/classification=(?:sidecar_request_invalid|candidate_admission_invalid)\)/.test(message)) {
return NATIVE_PROVIDER_STARTUP_REJECTED;
}
if (deterministicProviderStartupFailure(error)) return NATIVE_PROVIDER_STARTUP_REJECTED;
return "provider_session_open_rejected";
}