diff --git a/tests/runner-e2e/PRODUCT-JOURNEYS.md b/tests/runner-e2e/PRODUCT-JOURNEYS.md index 30858434c29..ac51dd4e3b7 100644 --- a/tests/runner-e2e/PRODUCT-JOURNEYS.md +++ b/tests/runner-e2e/PRODUCT-JOURNEYS.md @@ -571,3 +571,9 @@ The recovery wait gates the shared task snapshot before it reaches any journey consumer. Plan revision, Plan approval and protected-action decisions cannot use a pending card while its producing run is still recovering. A recovery that outlives the original campaign deadline fails without making a decision. + +The hire-delegate-reuse observer applies the same exact-session retry wait to +lead and hired-agent runs. Its idle check still requires every run to succeed. +A journey failure from a hosted API call keeps its fixed code, such as +`api_status_500` or `api_request_failed`; other errors stay +`journey_operation_failed`. diff --git a/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts b/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts index eb10aeefe09..a9ad5c57fbf 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-evidence.test.ts @@ -146,6 +146,25 @@ describe("deployment hiring qualification", () => { expect(() => assertHireRuns(scope, f.agent.id, [f.task], [f.taskRun, f.taskRun])).toThrow(); expect(() => assertHireRuns(scope, f.agent.id, [f.task], [f.leadRun, f.taskRun], 5)).toThrow(); }); + it("keeps observing a hired task run while its exact-session retry is scheduled inside the deadline", () => { + const f = fixture(), now = Date.now(), deadline = now + 60_000; + const pending = { ...f.taskRun, status: "failed", nativeIssueId: f.task.id, nativePhase: "retryable_failure", errorCode: "native_session_interrupted", + finishedAt: new Date(now - 1_000).toISOString(), execution: { phase: "retry_scheduled", cause: "native_session_interrupted", attempt: 1, + maxAttempts: 3, recoveryOwner: "agent", retryAt: new Date(now + 1_000).toISOString() } }; + expect(() => assertHireRuns(scope, f.agent.id, [f.task], [f.leadRun, pending], undefined, undefined, undefined, deadline)).not.toThrow(); + // A pending retry is never completion, and the deadline is required to wait at all. + expect(() => assertHireRuns(scope, f.agent.id, [f.task], [f.leadRun, pending], 2, undefined, undefined, deadline)).not.toThrow(); + expect(() => assertHireRuns(scope, f.agent.id, [f.task], [f.leadRun, pending])).toThrow("hire_native_run_failed"); + for (const change of [{ execution: { ...pending.execution, attempt: 3 } }, { execution: { ...pending.execution, recoveryOwner: "user" } }, + { execution: { ...pending.execution, retryAt: new Date(deadline + 1_000).toISOString() } }, { nativePhase: "terminal_failure" }, + { execution: { ...pending.execution, successorRunId: "other-run" } }]) { + expect(() => assertHireRuns(scope, f.agent.id, [f.task], [f.leadRun, { ...pending, ...change }], undefined, undefined, undefined, deadline)) + .toThrow("hire_native_run_failed"); + } + // Recovery never relaxes the task, agent and company bindings. + expect(() => assertHireRuns(scope, f.agent.id, [f.task], [f.leadRun, { ...pending, agentId: scope.leadId }], undefined, undefined, undefined, deadline)) + .toThrow("hire_run_scope_mismatch"); + }); it("rejects a lead task run from create-self-then-reassign even after the saved assignee is correct", () => { const f = fixture(); const delegation = { ...f.run("delegate-chat", scope.chatId, scope.leadId), status: "running" }; diff --git a/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts b/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts index 93ae767e4b0..242bcd5c65e 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-evidence.ts @@ -3,6 +3,7 @@ import { createRequire } from "node:module"; import { applyCompanyPrefix } from "../../../ui/src/lib/company-routes.js"; import { parseIssueReferenceFromHref, remarkLinkIssueReferences } from "../../../ui/src/lib/issue-reference.js"; import { JourneyError } from "./types.js"; +import { isPendingNativeRecovery } from "./workspace-deferral.js"; type Row = Record; const uiRequire = createRequire(new URL("../../../ui/package.json", import.meta.url)); @@ -134,7 +135,9 @@ export function hireResultLinkMatches(scope: Pick [task.id, hiredId] as [string, string | undefined])]); if (runs.length > 7 || count !== undefined && runs.length !== count || new Set(runs.map(run => run.id)).size !== runs.length) { throw new JourneyError("failed", "hire_run_limit_mismatch"); @@ -180,7 +183,8 @@ export function assertHireRuns(scope: HireScope, hiredId: string | undefined, ta requests.add(context.wakeCommentId); } } - if (!["queued", "running", "succeeded"].includes(run.status)) throw new JourneyError("failed", "hire_native_run_failed"); + const recovering = deadlineAt !== undefined && isPendingNativeRecovery(run, deadlineAt); + if (!recovering && !["queued", "running", "succeeded"].includes(run.status)) throw new JourneyError("failed", "hire_native_run_failed"); if (run.status === "succeeded" && (run.runtimeMode !== "native" || provider?.kind !== scope.provider || provider?.model !== scope.model || run.contextSnapshot?.paperclipEnvironment?.id !== scope.environmentId)) throw new JourneyError("failed", "hire_run_runtime_mismatch"); if (run.status === "succeeded" && scope.connectionChoice) { diff --git a/tests/runner-e2e/product-journeys/hire-delegate-flow.ts b/tests/runner-e2e/product-journeys/hire-delegate-flow.ts index af231adb320..4fc18a92542 100644 --- a/tests/runner-e2e/product-journeys/hire-delegate-flow.ts +++ b/tests/runner-e2e/product-journeys/hire-delegate-flow.ts @@ -148,8 +148,8 @@ export async function hireDelegateReuse(context: JourneyContext, session: Target const runs = [...canonical.values()]; const comments = await readObserved(`/api/issues/${chat.id}/comments?order=asc`); const requestIds = comments.filter(row => row.authorUserId === context.user.id).map(row => row.id); - const completionRepliesReady = assertHireRuns(scope, hiredId, owned.tasks, runs, undefined, requestIds, comments); - for (const run of projectedRuns) assertHireRuns(scope, hiredId, owned.tasks, [run], undefined, requestIds, comments); + const completionRepliesReady = assertHireRuns(scope, hiredId, owned.tasks, runs, undefined, requestIds, comments, options.deadlineAt); + for (const run of projectedRuns) assertHireRuns(scope, hiredId, owned.tasks, [run], undefined, requestIds, comments, options.deadlineAt); await retain("hire-delegate-observation.json", { scope: { ...scope, connectionBinding: undefined, connectionChoice: undefined }, chat, project, agents: owned.agents.map(row => ({ id: row.id, name: row.name, reportsTo: row.reportsTo })), tasks: owned.tasks, runs: runs.map(run => ({ id: run.id, issueId: hireRunIssueId(run), agentId: run.agentId, status: run.status })) }); diff --git a/tests/runner-e2e/product-journeys/journey-failure.test.ts b/tests/runner-e2e/product-journeys/journey-failure.test.ts new file mode 100644 index 00000000000..1f103302d2a --- /dev/null +++ b/tests/runner-e2e/product-journeys/journey-failure.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from "vitest"; +import { ConnectionFailure } from "../connection-config.js"; +import { journeyFailure } from "./launch.js"; + +describe("journeyFailure", () => { + it("keeps the controlled HTTP status code from a failed API request", () => { + expect(journeyFailure(new ConnectionFailure("api_status_500"))).toEqual({ outcome: "failed", code: "api_status_500" }); + expect(journeyFailure(new ConnectionFailure("api_status_409"))).toEqual({ outcome: "failed", code: "api_status_409" }); + }); + + it("keeps the controlled transport failure codes", () => { + for (const code of ["api_request_failed", "sensitive_api_request_failed", "invalid_api_route", "invalid_api_timeout"]) { + expect(journeyFailure(new ConnectionFailure(code))).toEqual({ outcome: "failed", code }); + } + }); + + it("matches a connection failure loaded from another module instance by its class name", () => { + class ConnectionFailure extends Error {} + expect(journeyFailure(new ConnectionFailure("api_status_502"))).toEqual({ outcome: "failed", code: "api_status_502" }); + }); + + it("never retains free-form messages", () => { + expect(journeyFailure(new ConnectionFailure("api_status_500 https://example.test/?token=secret"))).toEqual({ outcome: "failed", code: "journey_operation_failed" }); + expect(journeyFailure(new Error("api_status_500"))).toEqual({ outcome: "failed", code: "journey_operation_failed" }); + expect(journeyFailure(new Error("page.click: Timeout 30000ms exceeded"))).toEqual({ outcome: "failed", code: "journey_operation_failed" }); + }); +}); diff --git a/tests/runner-e2e/product-journeys/launch.ts b/tests/runner-e2e/product-journeys/launch.ts index e96a990d03f..66d47f78df5 100644 --- a/tests/runner-e2e/product-journeys/launch.ts +++ b/tests/runner-e2e/product-journeys/launch.ts @@ -29,6 +29,7 @@ import { companyAccessIsolation } from "./company-access-flow.js"; import { inboxTriage } from "./inbox-triage-flow.js"; import { JourneyError, type JourneyContext, type JourneyEvidence, type JourneyOutcome, type TargetLifecycleInput, type TargetProvider, type TargetSession } from "./types.js"; import type { RunnerE2EResult } from "../types.js"; +import { ConnectionFailure } from "../connection-config.js"; import { regenerateRunnerDashboard } from "../dashboard-regenerate.js"; import { resolveRunnerE2ESource } from "../source.js"; import { validateRetainedRunnerResult } from "../result-validation.js"; @@ -75,6 +76,12 @@ export function journeyFailure(error: unknown): { outcome: Exclude, code: candidate.code! }; } + // ConnectionApi failures carry only these fixed codes. Providers may load + // their own copy of the class, so match the name as well as the instance. + if ((error instanceof ConnectionFailure || error instanceof Error && error.constructor?.name === "ConnectionFailure") + && /^(api_status_[1-5][0-9]{2}|(sensitive_)?api_request_failed|invalid_api_route|invalid_api_timeout)$/.test(error.message)) { + return { outcome: "failed", code: error.message }; + } // Browser errors may contain keys, codes, URLs and form values. Never retain them. return { outcome: "failed", code: "journey_operation_failed" }; }