fix(runner): expose repairable completion and recovery failures

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-09-19 09:44:47 -05:00
1 parent c1f6c3310a
commit 18e7018ddc
7 files changed
+166 -16

No files matched your search

@@ -4834,7 +4834,7 @@ mod tests {
}
#[test]
fn invalid_tool_results_expose_only_reserved_static_schema_guidance() {
fn invalid_tool_results_expose_only_reserved_schema_guidance() {
let finish_result = schema_rejection(
"paperclip_finish",
json!({"secretSubmittedValue": "must-not-appear"}),
@@ -4844,6 +4844,9 @@ mod tests {
let finish_message = finish_result.result["error"]["message"].as_str().unwrap();
assert!(finish_message
.contains("continuation must include kind=response_wake, summary, and idempotencyKey"));
assert!(finish_message.contains("/required (missing \"requiredField\")"));
assert!(finish_message.contains("/additionalProperties"));
assert!(!finish_message.contains("secretSubmittedValue"));
assert!(finish_message.len() <= 512);
assert!(!finish_message.chars().any(char::is_control));
assert!(!finish_result.result.to_string().contains("must-not-appear"));
@@ -223,7 +223,7 @@ pub struct ProviderToolBridge {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ProviderBridgeError {
message: String,
safe_provider_message: Option<&'static str>,
safe_provider_message: Option<String>,
}
impl ProviderBridgeError {
@@ -242,10 +242,48 @@ impl ProviderBridgeError {
};
Self {
message: format!("provider arguments for {operation_id} failed JSON Schema validation"),
safe_provider_message,
safe_provider_message: safe_provider_message.map(str::to_owned),
}
}
fn with_schema_locations(mut self, validator: &jsonschema::Validator, input: &Value) -> Self {
// Only completion tools have a provider-safe hint. Report bounded paths
// into the authorized schema, never the submitted values or unknown keys.
if let Some(message) = self.safe_provider_message.as_mut() {
let locations = validator
.iter_errors(input)
.take(3)
.map(|error| {
let location = error
.schema_path()
.to_string()
.chars()
.filter(|c| c.is_ascii_alphanumeric() || "/_~.-".contains(*c))
.take(128)
.collect::<String>();
match error.kind() {
jsonschema::error::ValidationErrorKind::Required { property } => {
// Required property names come from the authorized schema.
let name = property
.to_string()
.chars()
.filter(|c| c.is_ascii_graphic() || *c == ' ')
.take(64)
.collect::<String>();
format!("{location} (missing {name})")
}
_ => location,
}
})
.collect::<Vec<_>>();
message.push_str(" Check these input schema locations: ");
message.push_str(&locations.join(", "));
message.push('.');
message.truncate(message.len().min(512));
}
self
}
fn active_turn_receipt_limit() -> Self {
Self::invalid(ACTIVE_TURN_RECEIPT_LIMIT_MESSAGE)
}
@@ -254,8 +292,8 @@ impl ProviderBridgeError {
self.message == ACTIVE_TURN_RECEIPT_LIMIT_MESSAGE
}
pub fn safe_provider_message(&self) -> Option<&'static str> {
self.safe_provider_message
pub fn safe_provider_message(&self) -> Option<&str> {
self.safe_provider_message.as_deref()
}
}
@@ -612,7 +650,8 @@ impl ProviderToolBridge {
))
})?;
if !validator.is_valid(&input) {
return Err(ProviderBridgeError::input_schema_validation(&operation_id));
return Err(ProviderBridgeError::input_schema_validation(&operation_id)
.with_schema_locations(&validator, &input));
}
if matches!(
operation_id.as_str(),
@@ -1522,6 +1561,65 @@ mod tests {
assert!(!over_limit.has_call_receipt("call-over-limit"));
}
#[test]
fn completion_validation_identifies_schema_location_without_echoing_input() {
let mut bridge = completion_bridge();
let error = bridge
.begin_call(
"bad-summary".to_owned(),
"paperclip_finish".to_owned(),
json!({"summary": {"PRIVATE_FIELD": "PRIVATE_VALUE"}}),
)
.unwrap_err();
let message = error.safe_provider_message().unwrap();
assert!(message.contains("/properties/summary/type"), "{message}");
assert!(!message.contains("PRIVATE_FIELD"));
assert!(!message.contains("PRIVATE_VALUE"));
assert!(!bridge.has_call_receipt("bad-summary"));
bridge
.begin_call(
"corrected-summary".to_owned(),
"paperclip_finish".to_owned(),
json!({"summary": "Saved the requested output."}),
)
.unwrap();
}
#[test]
fn completion_validation_names_missing_fields_and_bounds_feedback() {
let mut bridge = completion_bridge();
let error = bridge
.begin_call(
"missing-summary".to_owned(),
"paperclip_finish".to_owned(),
json!({}),
)
.unwrap_err();
assert!(error
.safe_provider_message()
.unwrap()
.contains("/required (missing \"summary\")"));
let schema = json!({"type": "object", "properties": {
"a": {"type": "string"}, "b": {"type": "string"},
"c": {"type": "string"}, "d": {"type": "string"},
}});
let validator = jsonschema::validator_for(&schema).unwrap();
let error = ProviderBridgeError::input_schema_validation("paperclip_finish")
.with_schema_locations(&validator, &json!({"a": 1, "b": 2, "c": 3, "d": 4}));
assert_eq!(
error
.safe_provider_message()
.unwrap()
.matches("/properties/")
.count(),
3
);
let other = ProviderBridgeError::input_schema_validation("some_other_tool")
.with_schema_locations(&validator, &json!({"a": 1}));
assert_eq!(other.safe_provider_message(), None);
}
#[test]
fn canonical_number_uses_decimal_notation_at_javascript_lower_boundary() {
for encoded in ["1e-6", "0.000001"] {
+7
View File
@@ -784,3 +784,10 @@ with the test flow. Native provider runs do not require an unrelated host
Changes to privileged worker setup must reach the default branch before a
branch-targeted paid campaign can exercise them. The report job resolves its
lockfile from its own trusted checkout, never from the tested branch.
### Injected interruption diagnostics
Everyday restart and Stop scenarios exempt only their recorded cancellation,
graceful-shutdown interruption, or process-loss outcome. A later adapter error
on that same run still fails immediately and fails the lifecycle grader. The
run ID alone is not an exemption from recovery failures.
+4 -6
View File
@@ -22,6 +22,8 @@ import { LATE_REQUIREMENT, SLUGIFY_REVISION, requiresEverydayArtifactOracle } fr
import {
isActiveStoryRun,
isStoryWorkspaceDeferral,
isExpectedStoryInterruption,
storyUnexpectedRunFailure,
storyLifecycleChecks,
storyRepliesConsumed,
storyHasAgentReply,
@@ -304,11 +306,7 @@ export async function runEverydayFlow(input: Input) {
)),
reject: (state) => {
if (state.runs.length > 12) return "bounded execution count exceeded";
const bad = state.runs.find(
(r) =>
["failed", "timed_out"].includes(r.status) &&
!ev.allowedInterruptedRuns.includes(r.id),
);
const bad = storyUnexpectedRunFailure(state.runs, ev.allowedInterruptedRuns);
if (bad)
return `native execution failed ${bad.errorCode ?? ""}: ${bad.error ?? bad.status}`;
if (
@@ -1387,7 +1385,7 @@ export async function runEverydayFlow(input: Input) {
.filter(
(r) =>
!isStoryWorkspaceDeferral(r) &&
!ev.allowedInterruptedRuns.includes(r.id),
!isExpectedStoryInterruption(r, ev.allowedInterruptedRuns),
)
.every(
(r) =>
+24 -3
View File
@@ -208,6 +208,27 @@ export function isStoryWorkspaceDeferral(run: StoryRun) {
!run.processPid
);
}
/** Exempt the injected stop itself, never a later recovery/provider failure on that run. */
export function isExpectedStoryInterruption(
run: StoryRun,
allowedRunIds: readonly string[],
): boolean {
if (!allowedRunIds.includes(run.id)) return false;
return (
(run.status === "cancelled" && (!run.errorCode || run.errorCode === "cancelled")) ||
(run.status === "interrupted" && run.errorCode === "server_shutdown_interrupted") ||
(run.status === "failed" && run.errorCode === "process_lost")
);
}
export function storyUnexpectedRunFailure(runs: StoryRun[], allowedRunIds: readonly string[]) {
return runs.find((run) =>
["failed", "timed_out", "cancelled", "interrupted"].includes(run.status) &&
!isStoryWorkspaceDeferral(run) &&
!isExpectedStoryInterruption(run, allowedRunIds),
);
}
export function storyLifecycleChecks(input: {
issues: StoryIssue[];
runs: StoryRun[];
@@ -216,7 +237,7 @@ export function storyLifecycleChecks(input: {
allowedInterruptedRuns?: string[];
}): StoryCheck[] {
const executed = input.runs.filter((r) => !isStoryWorkspaceDeferral(r));
const allowed = new Set(input.allowedInterruptedRuns ?? []);
const allowed = input.allowedInterruptedRuns ?? [];
const check = (id: string, passed: boolean, detail: string): StoryCheck => ({
id,
passed,
@@ -244,8 +265,8 @@ export function storyLifecycleChecks(input: {
),
check(
"successful-runs",
executed.every((r) => r.status === "succeeded" || allowed.has(r.id)),
"Only explicitly interrupted runs may have a non-success terminal state.",
executed.every((r) => r.status === "succeeded" || isExpectedStoryInterruption(r, allowed)),
"Only the expected stop or process-loss outcome of an injected interruption is exempt.",
),
check(
"bounded-work",
+23
View File
@@ -4,6 +4,7 @@ import { parseRunnerSelectors, selectRunnerExecutions } from "./selectors.js";
import { everydayTasks, productionStoryProfile } from "./everyday-cases.js";
import {
isStoryWorkspaceDeferral,
storyUnexpectedRunFailure,
storyLifecycleChecks,
storyRepliesConsumed,
storyHasAgentReply,
@@ -274,6 +275,28 @@ describe("lifecycle oracle calibrated failures", () => {
);
expect(checks.find((c) => c.id === "successful-runs")?.passed).toBe(false);
});
it.each(["adapter_failed", "tool_validation_error", "timed_out"])(
"does not excuse a later %s on the same deliberately interrupted run",
(errorCode) => {
const checks = score(
[{ ...run, status: "failed", errorCode }],
[parent],
[run.id],
);
expect(checks.find((c) => c.id === "successful-runs")?.passed).toBe(false);
const failed = { ...run, status: "failed", errorCode };
expect(storyUnexpectedRunFailure([failed], [run.id])).toBe(failed);
},
);
it.each([
["cancelled", "cancelled"],
["interrupted", "server_shutdown_interrupted"],
["failed", "process_lost"],
])("accepts an injected interruption with %s / %s", (status, errorCode) => {
const checks = score([{ ...run, status, errorCode }], [parent], [run.id]);
expect(checks.find((c) => c.id === "successful-runs")?.passed).toBe(true);
expect(storyUnexpectedRunFailure([{ ...run, status, errorCode }], [run.id])).toBeUndefined();
});
it("excludes a proven pre-dispatch workspace deferral without hiding executed failures", () => {
const deferred: StoryRun = {
id: "deferred",
+1 -1
View File
@@ -19,7 +19,7 @@ it("lets Playwright reap a restarted server through the production bounded shutd
const pidsPath = path.join(root, "pids.json");
const configPath = path.join(root, "playwright.config.cjs");
const testModule = require.resolve("@playwright/test");
const cli = path.join(path.dirname(require.resolve("playwright/package.json")), "cli.js");
const cli = require.resolve("@playwright/test/cli");
let child: ReturnType<typeof spawn> | undefined;
let timer: ReturnType<typeof setTimeout> | undefined;
let reservationReleased = false;