mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-08 22:13:59 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Rolling tests must exercise the lifecycle they claim to cover.
> - The warm lane selected a warm environment.
> - Its profiles also set an explicit per-turn agent policy, which took
precedence.
> - The test then waited for a live workspace that per-turn cleanup had
correctly retired.
> - This pull request sets warm agent policy for providers admitted by
the production warm capability.
> - The matrix now checks effective lifecycle and preserves per-turn
coverage for every qualified native profile.
## Linked Issues or Issue Description
Builds on merged #18982 for the source controller dependency link. This
PR now targets master.
**What happened?**
The warm rolling fixture built a Codex agent with `lifecycleMode:
per_turn` and an environment with `runnerLifecycleMode: warm`. The
explicit agent policy won. The initial task completed, its disposable
workspace retired, and the fixture waited for a live file before it
reached deployment.
**Expected behavior**
Warm rolling, legacy migration, remote-file and controller-outage cells
must create actual warm agents. Only providers supported by the
production managed warm-session capability belong in that lane. All
qualified native profiles retain per-turn coverage.
**Steps to reproduce**
Build the old warm Codex cell's agent and environment and compare their
lifecycle policies. The new effective-policy regression fails on the old
catalog and passes on this branch. No duplicate exact-scope warm-fixture
PR was found.
## What Changed
- Share the production managed warm capability filter and explicit warm
agent policy across rolling, legacy migration, remote-file and
controller-outage suites.
- Check effective agent and environment policies and update matrix
coverage/counts.
- Read completed warm turns from the exact saved snapshot while
independently requiring the retained, bound workspace location.
- Keep both rolling lanes separate from the outage simulation and
exercise their assembled supervisor requests.
- Version the corrected definitions and keep every qualified native
profile in the per-turn lanes.
## Verification
- Baseline regression: failed against the unchanged catalog; retained
before the fix.
- Fixed catalog/controller selection: 39 checks passed.
- The first real warm-policy attempt completed and saved its workspace
but timed out because the file oracle demanded live content; retained
trace responses prove the API returned the correct saved snapshot with a
retained lease.
- A new regression fails on the previous reader and passes after
separating saved file source from retained versus released location.
Focused catalog, reader and rolling checks: 81 passed.
- The next warm attempt reached replacement and exposed a second fixture
defect: warm also selected a SIGKILL outage, which the supervisor
rejected alongside rolling mode. The failure remains retained; its four
owned sandboxes, temporary key and local bucket were deleted.
- An outage-selection regression failed before the fix; 57
outage/supervisor checks pass afterward, including assembled requests
for both rolling lanes. The fresh warm Codex run passed all 56 checks in
8.5 minutes: original run/session/runner/lease retained, authenticated
takeover, both predecessor homes removed, later native continuation and
saved file readback. Two replacement receipts recorded 742 ordinary
reads and 75 writes, all 75 read back, with zero HTTP probe failures. A
transient `native_workspace_sync_out_failed` phase recovered before
successful finalization and remains retained. This source-lane result
does not claim released-image or hosted Railway qualification.
- The invalid earlier attempt was interrupted before deployment. Its
four archived disposable sandboxes were deleted and verified absent; its
temporary key and local bucket were removed.
- Broad local typecheck reached stale shared database declarations in
this checkout's linked build dependencies. The fixture's own type error
was corrected; clean-head CI remains required. No full build is claimed
locally.
- An incidental report-catalog test selected by a substring filter
failed to generate its normalized output. That failure is retained
separately; the focused catalog/controller checks pass.
- Review follow-up: fixed the same policy conflict in the base
file-storage, legacy migration and controller-outage suites. The roster
now has 822 valid cells; unsupported warm combinations remain covered
per-turn. Updated the explicit supervisor-request control to use a
supported warm provider. Focused catalog, file-reader, migration,
rolling and supervisor checks pass (133 checks).
- Earlier full CI passed at dd5aa71 using the built-in GitHub-hosted
fallback after self-hosted runner shutdowns. That result does not
qualify this new head; fresh CI and review are required. The final head
now has a 5/5 review and passing full CI (run 41901807639, attempt 2).
Attempt 1 hit two unrelated port collisions: the unchanged managed Codex
credential lease test and CLI company-server startup on a busy requested
port. Both passed on one failed-job retry. Those failures remain
retained.
## Risks
This changes test setup and coverage. It does not change agent runtime
defaults or provider capabilities. Warm cells use the production
capability boundary, while every qualified native profile keeps its
per-turn cell.
## Model Used
OpenAI Codex, exact model ID `gpt-6.1-sol`, with reasoning, tool use and
code execution. The host does not expose context window size.
## Checklist
- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either linked existing issues or described the issue in-PR
following the relevant issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links
- [x] My branch name describes the change and contains no internal
ticket id or instance-derived details
- [x] I have run the relevant tests locally; failures and limits are
retained above
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
---------
Co-authored-by: Paperclip <noreply@paperclip.ing>
1778 lines
80 KiB
TypeScript
1778 lines
80 KiB
TypeScript
import { stopAndRedirectThroughUi } from "./stop-redirect-flow.js";
|
|
import { downloadStoryArtifact } from "./story-artifact.js";
|
|
import { editCreatedSkillThroughStudio } from "./skill-studio-flow.js";
|
|
import { decideProtectedActionThroughUi, readServiceBriefing, serviceBriefingChecks } from "./protected-action-flow.js";
|
|
import { gradeAgentmailSetup } from "./agentmail-setup-evidence.js";
|
|
import { CONNECTION_GUIDANCE_SUITE, CONNECTION_GUIDANCE_BUDGET_CENTS } from "./connection-guidance-cases.js";
|
|
import { gradeConnectionGuidanceDecline, hasConnectionGuidanceDeclineReply, explainsConnectionUnavailable, type ConnectionGuidanceDeclineInput } from "./connection-guidance-evidence.js";
|
|
import { expect, type Page } from "@playwright/test";
|
|
import { runnerApiToolsEnabled } from "../../server/src/services/native-runtime/runner-api-rollout.js";
|
|
import { spawn } from "node:child_process";
|
|
import { createHash, randomUUID } from "node:crypto";
|
|
import { mkdir, readFile, readdir } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { isDeepStrictEqual } from "node:util";
|
|
import { pollUntil, type RunnerApi } from "./api.js";
|
|
import {
|
|
latestStoryDelivery,
|
|
type StoryDelivery,
|
|
} from "./everyday-delivery.js";
|
|
import type { LiveFixtureValues } from "./live-fixtures.js";
|
|
import type { MatrixExecution } from "./types.js";
|
|
import { submitTaskReply } from "./user-actions.js";
|
|
import { createTaskFromPromptThroughUi } from "./plan-task-ui.js";
|
|
import { waitForTaskChatRendered, waitForTaskIdentity } from "./continuation-screenshot.js";
|
|
import { hasPersistedSource, isSavedSourceCheckpoint } from "./everyday-interruption.js";
|
|
import { collectRunEvents } from "./run-observations.js";
|
|
import { gradeRemoteRestart, observeRemoteRestartBoundary, projectRemoteRestartEvents, projectRemoteRestartRun, waitForRemoteRestartBoundary, type RemoteRestartEvidence } from "./everyday-remote-restart.js";
|
|
import { controllerOutageForExecution } from "./controller-outage.js";
|
|
import type { ControllerReplacementReceipt } from "./controller-replacement.js";
|
|
import { isRollingWebDeployment } from "./controller-rolling-deployment.js";
|
|
import { gradeRemoteWorkspaceStorage, isRemoteWorkspaceStorageExecution, readRemoteWorkspaceStorageCheckpoint,
|
|
REMOTE_WORKSPACE_PROOF_FILE, type RemoteWorkspaceStorageEvidence } from "./remote-workspace-storage.js";
|
|
import { gradeRetainedControllerContinuation, retainedControllerRun, retainedControllerFollowupTransport, submitRetainedControllerComment, onePersistedRetainedControllerComment } from "./retained-controller-continuation.js";
|
|
import { setupAggregatorFixture } from "./aggregator-fixture.js";
|
|
import { gradeProviderChoice, gradeProviderOutcome, requireProviderAccessCard } from "./connection-routing-evidence.js";
|
|
import { setupConnectionReview } from "./connection-reviews.js";
|
|
import {
|
|
pendingStoryDecision,
|
|
StoryDecisionError,
|
|
type StoryInteraction,
|
|
} from "./everyday-decisions.js";
|
|
import { LATE_REQUIREMENT, SLUGIFY_REVISION, SLUGIFY_DEPLOYMENT_SOAK, requiresEverydayArtifactOracle } from "./everyday-cases.js";
|
|
import {
|
|
isActiveStoryRun,
|
|
isStoryWorkspaceDeferral,
|
|
isExpectedStoryInterruption,
|
|
storyUnexpectedRunFailure,
|
|
storyUnexercisedReviewBoundary,
|
|
storyLifecycleChecks,
|
|
storyRepliesConsumed,
|
|
storyHasAgentReply,
|
|
storyAgentReplyMatches,
|
|
retainedControllerReplyMatcher,
|
|
storyHasPendingHumanInteraction,
|
|
storyReviewContinuationTimeoutDetail,
|
|
storyHasStrandedBlockedLeaf,
|
|
storyHasDurableAgentReviewContinuation,
|
|
storyHasDurableServiceContinuation,
|
|
storyIssueHasBlockedTimelineBefore,
|
|
storyIssueHasUnresolvedDependency,
|
|
storyRunReportsDependencyBlock,
|
|
storyParentFinishedAfterChildren,
|
|
storyAcceptedAgentReview,
|
|
artifactGradeModeForPhase,
|
|
storyParentCompletionPrecedesReview,
|
|
type StoryCheck,
|
|
type StoryIssue,
|
|
type StoryRun,
|
|
type StoryReplyExpectation,
|
|
} from "./everyday-observations.js";
|
|
|
|
type Row = Record<string, any>;
|
|
export interface EverydayEvidence {
|
|
schema: "paperclip.everyday-workflow.v1";
|
|
caseId: string;
|
|
prompt: string;
|
|
harnessDigest?: string;
|
|
sourceRevision?: string;
|
|
providerVersion?: string;
|
|
fixtureConfiguration?: {
|
|
apiToolsEnabled: boolean;
|
|
aiConnection?: LiveFixtureValues["aiConnection"];
|
|
connectionGuidanceBudgets?: { companyMonthlyCents: unknown; agentMonthlyCents: unknown };
|
|
};
|
|
documents?: Row[];
|
|
declineGradeEvidence?: { capturedAt: string; input: ConnectionGuidanceDeclineInput; checks: StoryCheck[] };
|
|
checks: StoryCheck[];
|
|
timeline: Array<{ at: string; action: string; detail?: unknown }>;
|
|
issues: Array<StoryIssue & Row>;
|
|
runs: StoryRun[];
|
|
agents: Row[];
|
|
downloads: Row[];
|
|
allowedInterruptedRuns: string[];
|
|
remoteRestart?: RemoteRestartEvidence;
|
|
remoteWorkspaceStorage?: RemoteWorkspaceStorageEvidence;
|
|
}
|
|
interface Input {
|
|
page: Page;
|
|
api: RunnerApi;
|
|
fixtures: LiveFixtureValues;
|
|
execution: MatrixExecution;
|
|
nonce: string;
|
|
workspacePath: string;
|
|
privateDir: string;
|
|
deadlineAt: number;
|
|
restartCount?: number;
|
|
restart(binding?: import("./controller-recovery-observer.js").RecoveryBinding, controllerDowntimeMs?: number): Promise<ControllerReplacementReceipt | void>;
|
|
observe(issue: StoryIssue, runs: StoryRun[]): void;
|
|
capture(id: string, label: string, file: string): Promise<void>;
|
|
evidence(name: string, value: unknown): Promise<void>;
|
|
}
|
|
|
|
function runCommand(
|
|
command: string,
|
|
args: string[],
|
|
timeout = 20_000,
|
|
): Promise<{ code: number; stdout: string }> {
|
|
return new Promise((resolve, reject) => {
|
|
const env = Object.fromEntries(
|
|
Object.entries(process.env).filter(([key]) =>
|
|
["PATH", "SYSTEMROOT", "TMPDIR"].includes(key),
|
|
),
|
|
);
|
|
const child = spawn(command, args, {
|
|
env,
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
let stdout = "";
|
|
let stderr = "";
|
|
const timer = setTimeout(() => child.kill("SIGKILL"), timeout);
|
|
child.stdout.on("data", (chunk) => {
|
|
stdout += String(chunk);
|
|
if (stdout.length > 1_000_000) child.kill("SIGKILL");
|
|
});
|
|
child.stderr.on("data", (chunk) => {
|
|
stderr += String(chunk);
|
|
});
|
|
child.on("error", (error) => {
|
|
clearTimeout(timer);
|
|
reject(error);
|
|
});
|
|
child.on("exit", (code) => {
|
|
clearTimeout(timer);
|
|
if (code === null)
|
|
reject(new Error("Bounded evaluator command timed out"));
|
|
else resolve({ code, stdout: stdout || stderr });
|
|
});
|
|
});
|
|
}
|
|
|
|
/** No DB writes, fabricated tool receipts, or corrective messages after a failed check. */
|
|
export async function runEverydayFlow(input: Input) {
|
|
const { page, api, fixtures, execution, nonce } = input;
|
|
const prefix = fixtures.company.issuePrefix!;
|
|
const ev: EverydayEvidence = {
|
|
schema: "paperclip.everyday-workflow.v1",
|
|
caseId: execution.task.id,
|
|
prompt: execution.task.buildPrompt(nonce),
|
|
fixtureConfiguration: {
|
|
apiToolsEnabled: runnerApiToolsEnabled(fixtures.company.id),
|
|
aiConnection: fixtures.aiConnection,
|
|
},
|
|
checks: [],
|
|
timeline: [],
|
|
issues: [],
|
|
runs: [],
|
|
agents: [],
|
|
downloads: [],
|
|
allowedInterruptedRuns: [],
|
|
};
|
|
const note = (action: string, detail?: unknown) =>
|
|
ev.timeline.push({
|
|
at: new Date().toISOString(),
|
|
action,
|
|
...(detail === undefined ? {} : { detail }),
|
|
});
|
|
const check = (id: string, passed: boolean, detail: string) => {
|
|
ev.checks.push({ id, passed, detail });
|
|
};
|
|
let parent: StoryIssue | undefined;
|
|
let lastSubmissionAt = 0;
|
|
const submittedCommentIds: string[] = [];
|
|
let review: Awaited<ReturnType<typeof setupConnectionReview>> | undefined;
|
|
let project = fixtures.project;
|
|
const caseId = execution.task.id;
|
|
const controllerOutage = controllerOutageForExecution(execution, process.env);
|
|
const requireRemoteRestart = controllerOutage !== undefined || isRollingWebDeployment(execution);
|
|
const remoteWorkspaceStorage = isRemoteWorkspaceStorageExecution(execution);
|
|
if (remoteWorkspaceStorage) {
|
|
const perTurn = execution.suite.definitionMetadata?.lifecycleCoverage === "per-turn-disposable";
|
|
ev.remoteWorkspaceStorage = { browserReadPhases: [],
|
|
expectedFileSource: perTurn || execution.suite.definitionMetadata?.lifecycleCoverage === "warm-reusable" ? "saved" : "live",
|
|
expectedLocation: perTurn ? "released" : "retained" };
|
|
}
|
|
const providerChoice = caseId === "provider-decline" || caseId === "provider-second";
|
|
const nativeProviderCase = caseId === "provider-native";
|
|
let aggregatorFixture: Awaited<ReturnType<typeof setupAggregatorFixture>> | undefined;
|
|
const agentmailSetup = caseId === "agentmail-setup";
|
|
const decliningConnection = caseId === "connection-decline" || nativeProviderCase || agentmailSetup;
|
|
const declining = decliningConnection || caseId === "service-decline";
|
|
let decisionId: string | undefined;
|
|
let decisionResolvedAt: string | undefined;
|
|
let initialConnections: string[] = [];
|
|
let providerAccessDecision: { id: string; connectionId: string } | undefined;
|
|
let stoppedWorkspace: Record<string, string> | undefined;
|
|
let settledAgentReply: Row | undefined;
|
|
let postControllerApiFollowup = false;
|
|
let retainedFollowupCommentId: string | undefined;
|
|
let reviewHandoffBoundary: {
|
|
childId: string;
|
|
assigneeAgentId: string | null | undefined;
|
|
interactionId: string;
|
|
interactionCreatedAt?: string;
|
|
parentRunId?: string;
|
|
parentBlockedObserved: boolean;
|
|
} | undefined;
|
|
async function workspaceFiles() {
|
|
const workspaceRoot = input.workspacePath;
|
|
const files: Record<string, string> = {};
|
|
for (const entry of await readdir(workspaceRoot, {
|
|
withFileTypes: true,
|
|
})) {
|
|
if (entry.isFile() && /\.(py|md|zip)$/.test(entry.name))
|
|
files[entry.name] = createHash("sha256")
|
|
.update(await readFile(path.join(workspaceRoot, entry.name)))
|
|
.digest("hex");
|
|
}
|
|
return files;
|
|
}
|
|
async function runnerStopped(run: StoryRun) {
|
|
if (!run.processPid) return false;
|
|
const identity = await runCommand("ps", [
|
|
"-p",
|
|
String(run.processPid),
|
|
"-o",
|
|
"command=",
|
|
]);
|
|
return (
|
|
identity.code !== 0 || !identity.stdout.includes(`--run-id ${run.id} `)
|
|
);
|
|
}
|
|
async function refresh() {
|
|
const listed = await api.get<StoryRun[]>(
|
|
`/api/companies/${fixtures.company.id}/heartbeat-runs?limit=100`,
|
|
);
|
|
ev.runs = await Promise.all(
|
|
listed.map((r) => api.get<StoryRun>(`/api/heartbeat-runs/${r.id}`)),
|
|
);
|
|
const issues = await api.get<StoryIssue[]>(
|
|
`/api/companies/${fixtures.company.id}/issues`,
|
|
);
|
|
ev.issues = await Promise.all(
|
|
issues.map(async (issue) => ({
|
|
...issue,
|
|
comments: await api.get<Row[]>(
|
|
`/api/issues/${issue.id}/comments?order=asc`,
|
|
),
|
|
queuedComments: await api.get<Row>(
|
|
`/api/issues/${issue.id}/queued-comments`,
|
|
),
|
|
interactions: await api.get<Row[]>(
|
|
`/api/issues/${issue.id}/interactions`,
|
|
),
|
|
wakeDiagnostics: await api.get<Row>(
|
|
`/api/issues/${issue.id}/diagnostics/wakes`,
|
|
),
|
|
activity: await api.get<Row[]>(`/api/issues/${issue.id}/activity`),
|
|
})),
|
|
);
|
|
if (parent) {
|
|
parent = ev.issues.find((i) => i.id === parent!.id) as StoryIssue;
|
|
input.observe(parent!, ev.runs);
|
|
}
|
|
return ev;
|
|
}
|
|
const taskUrl = (issue: StoryIssue) =>
|
|
`/${prefix}/issues/${issue.identifier ?? issue.id}`;
|
|
async function openTask(issue: StoryIssue) {
|
|
await page.goto(taskUrl(issue), { waitUntil: "domcontentloaded" });
|
|
await waitForTaskIdentity(page, taskUrl(issue), issue.identifier ?? issue.id);
|
|
if (providerChoice || nativeProviderCase) {
|
|
await expect(page.locator('[data-testid="task-chat-thread"], [data-testid="thread-root"]').first()).toBeVisible({timeout:30_000});
|
|
await expect(page.getByTestId("issue-chat-skeleton")).toHaveCount(0);
|
|
} else await waitForTaskChatRendered(page);
|
|
}
|
|
async function openParent() {
|
|
await openTask(parent!);
|
|
}
|
|
function observableAgentIds(state: EverydayEvidence) {
|
|
return [
|
|
fixtures.agent.id,
|
|
...state.issues.flatMap((issue) =>
|
|
[
|
|
issue.assigneeAgentId,
|
|
...(issue.interactions ?? []).map(
|
|
(interaction) => interaction.addresseeAgentId,
|
|
),
|
|
].filter((agentId): agentId is string => Boolean(agentId)),
|
|
),
|
|
];
|
|
}
|
|
async function reply(message: string, target: StoryIssue = parent!, transport: "browser" | "task_comment_api" = "browser") {
|
|
const priorFailures = ev.checks.filter((c) => !c.passed);
|
|
if (priorFailures.length)
|
|
throw new Error(
|
|
`Story prerequisite failed before the next user request: ${priorFailures.map((c) => c.id).join(", ")}`,
|
|
);
|
|
const before = await api.get<Row[]>(`/api/issues/${target.id}/comments`);
|
|
lastSubmissionAt = Date.now();
|
|
const submitted = transport === "task_comment_api"
|
|
? await submitRetainedControllerComment(api, target.id, message, randomUUID())
|
|
: (await submitTaskReply(page, message), undefined);
|
|
const after = await pollUntil({
|
|
label: "one persisted user reply",
|
|
deadlineAt: Date.now() + 30_000,
|
|
load: () => api.get<Row[]>(`/api/issues/${target.id}/comments`),
|
|
accept: (rows) =>
|
|
rows.filter(
|
|
(c) => !c.authorAgentId && !before.some((old) => old.id === c.id),
|
|
).length > 0,
|
|
});
|
|
const added = after.filter(
|
|
(c) => !c.authorAgentId && !before.some((old) => old.id === c.id),
|
|
);
|
|
check(
|
|
`reply-${ev.timeline.length}-stored-once`,
|
|
transport === "task_comment_api" ? onePersistedRetainedControllerComment({ added, commentId: submitted?.id ?? "", body: message }) : added.length === 1,
|
|
transport === "task_comment_api" ? "The production comment API creates exactly one matching user message." : "A composer submission creates exactly one user message.",
|
|
);
|
|
submittedCommentIds.push(...added.map((c) => c.id));
|
|
if (submitted) retainedFollowupCommentId = submitted.id;
|
|
note(transport === "task_comment_api" ? "task-api-message-persisted" : "composer-message-persisted", {
|
|
issueId: target.id,
|
|
commentIds: added.map((c) => c.id),
|
|
});
|
|
}
|
|
function declineInput(state: Pick<EverydayEvidence, "issues" | "runs">): ConnectionGuidanceDeclineInput | undefined {
|
|
if (execution.suite.id !== CONNECTION_GUIDANCE_SUITE ||
|
|
(caseId !== "service-decline" && caseId !== "connection-decline" && caseId !== "provider-decline")) return;
|
|
const issue = state.issues.find(i => i.id === parent?.id);
|
|
return {
|
|
caseId, decisionId: decisionId ?? "", decisions: issue?.interactions as any ?? [],
|
|
leadAgentId: fixtures.agent.id, issueId: parent?.id ?? "", replies: issue?.comments ?? [],
|
|
runs: state.runs, marker: (caseId === "provider-decline" ? "CONTACTS_" : "SERVICE_") + nonce,
|
|
// Readiness never grades these external observations. They are filled at the grading boundary below.
|
|
sameConnections: false,
|
|
};
|
|
}
|
|
async function settled(expectedAgentReply?: StoryReplyExpectation, readback: "browser" | "api" = "browser") {
|
|
const settledState = await pollUntil({
|
|
label: `everyday ${caseId} settled`,
|
|
deadlineAt: input.deadlineAt,
|
|
timeoutDetail: (state) => state && (
|
|
storyReviewContinuationTimeoutDetail(
|
|
state.issues, parent?.id ?? "", fixtures.agent.id, state.runs,
|
|
observableAgentIds(state),
|
|
) ?? (storyHasDurableServiceContinuation(state.issues, parent?.id ?? "", fixtures.agent.id, state.runs)
|
|
? "task is Blocked without an active continuation after resolved service approval" : undefined)),
|
|
intervalMs: 1000,
|
|
load: refresh,
|
|
accept: (state) =>
|
|
state.issues.length > 0 &&
|
|
state.issues.every(
|
|
(i) => i.status === "done" && i.queuedComments.entries.length === 0,
|
|
) &&
|
|
storyRepliesConsumed(state.runs, submittedCommentIds) &&
|
|
state.runs.length > 0 &&
|
|
!state.runs.some(isActiveStoryRun) &&
|
|
state.runs.some(
|
|
(r) => Date.parse(r.finishedAt ?? "") >= lastSubmissionAt,
|
|
) &&
|
|
(!declineInput(state) || hasConnectionGuidanceDeclineReply(declineInput(state)!)) &&
|
|
(!expectedAgentReply ||
|
|
storyHasAgentReply(
|
|
state.issues.find((issue) => issue.id === parent?.id),
|
|
fixtures.agent.id,
|
|
expectedAgentReply,
|
|
)),
|
|
reject: (state) => {
|
|
if (state.runs.length > 12) return "bounded execution count exceeded";
|
|
const bad = storyUnexpectedRunFailure(state.runs, ev.allowedInterruptedRuns);
|
|
if (bad)
|
|
return `native execution failed ${bad.errorCode ?? ""}: ${bad.error ?? bad.status}`;
|
|
if (
|
|
state.runs.some(isActiveStoryRun) ||
|
|
state.issues.some((i) => i.scheduledRetry || i.activeRecoveryAction)
|
|
)
|
|
return;
|
|
if (
|
|
state.runs.length &&
|
|
storyHasStrandedBlockedLeaf(state.issues, observableAgentIds(state)) &&
|
|
!storyHasDurableAgentReviewContinuation(
|
|
state.issues,
|
|
parent?.id ?? "",
|
|
fixtures.agent.id,
|
|
state.runs,
|
|
) &&
|
|
!storyHasDurableServiceContinuation(state.issues, parent?.id ?? "", fixtures.agent.id, state.runs)
|
|
)
|
|
return "task is Blocked without an active continuation";
|
|
if (
|
|
state.issues.some(
|
|
(i) =>
|
|
i.status === "in_review" &&
|
|
storyHasPendingHumanInteraction(i, observableAgentIds(state)),
|
|
)
|
|
)
|
|
return "unexpected human interaction: task did not finish autonomously";
|
|
},
|
|
});
|
|
if (expectedAgentReply) {
|
|
const issue = settledState.issues.find((candidate) => candidate.id === parent?.id);
|
|
const reply = issue?.comments?.find(
|
|
(comment) => storyAgentReplyMatches(comment, fixtures.agent.id, expectedAgentReply),
|
|
);
|
|
if (reply) {
|
|
// Keep the exact snapshot that satisfied the readiness predicate. A
|
|
// later refresh may return a newer projection and must not change the
|
|
// evidence used by the assertion below.
|
|
settledAgentReply = { ...reply };
|
|
note(readback === "api" ? "expected-agent-reply-persisted-at-settlement" : "expected-agent-reply-visible-at-settlement", {
|
|
issueId: issue?.id,
|
|
commentId: reply.id,
|
|
authorAgentId: reply.authorAgentId,
|
|
createdAt: reply.createdAt,
|
|
body: reply.body,
|
|
});
|
|
}
|
|
}
|
|
if (readback === "browser") {
|
|
await openParent();
|
|
await expect(
|
|
page.getByTestId("issue-detail-header").getByRole("button", {
|
|
name: "Change status (current: Done)",
|
|
exact: true,
|
|
}),
|
|
).toBeVisible();
|
|
}
|
|
note("all-tasks-done", { readback });
|
|
}
|
|
async function downloadDelegated(
|
|
mode: "base" | "separator" | "max-length",
|
|
phase: string,
|
|
after?: number,
|
|
) {
|
|
const related = ev.issues.filter(
|
|
(issue) => issue.id === parent!.id || issue.parentId === parent!.id,
|
|
);
|
|
const attachments = (
|
|
await Promise.all(
|
|
related.map(async (issue) =>
|
|
(await api.get<Row[]>(`/api/issues/${issue.id}/attachments`)).map(
|
|
(a) => ({ ...a, issueId: issue.id }) as StoryDelivery,
|
|
),
|
|
),
|
|
)
|
|
).flat();
|
|
const delivery = latestStoryDelivery(
|
|
attachments,
|
|
related.map((issue) => issue.id),
|
|
after,
|
|
after === undefined ? [] : ev.downloads.map((d) => d.sha256),
|
|
);
|
|
if (!delivery) {
|
|
check(
|
|
`${phase}.zip-delivered`,
|
|
false,
|
|
"No new downloadable ZIP was delivered on the parent or its child tasks.",
|
|
);
|
|
return;
|
|
}
|
|
note("delivery-selected", { attachmentId: delivery.id, issueId: delivery.issueId, sha256: delivery.sha256, after });
|
|
await download(delivery.issueId, mode, phase, delivery.id);
|
|
}
|
|
|
|
async function download(
|
|
issueId: string,
|
|
mode: "base" | "separator" | "max-length",
|
|
phase: string,
|
|
selectedAttachmentId?: string,
|
|
) {
|
|
const attachments = await api.get<Row[]>(
|
|
`/api/issues/${issueId}/attachments`,
|
|
);
|
|
const zips = attachments
|
|
.filter(
|
|
(a) =>
|
|
String(a.originalFilename ?? a.filename ?? "").endsWith(".zip") ||
|
|
a.contentType === "application/zip",
|
|
)
|
|
.sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)));
|
|
if (!zips.length) {
|
|
check(
|
|
`${phase}.zip-delivered`,
|
|
false,
|
|
"No downloadable ZIP attachment was delivered.",
|
|
);
|
|
return;
|
|
}
|
|
const attachment = selectedAttachmentId
|
|
? zips.find((a) => a.id === selectedAttachmentId)
|
|
: zips[zips.length - 1];
|
|
if (!attachment) throw new Error("Selected delivery is no longer available");
|
|
const issue = ev.issues.find((i) => i.id === issueId)!;
|
|
await openTask(issue);
|
|
const delivered = await downloadStoryArtifact({ page, attachmentId: attachment.id,
|
|
directory: path.join(input.privateDir, "snapshots"), phase, mode, deadlineAt: input.deadlineAt });
|
|
ev.checks.push(...delivered.checks.map(c => ({ ...c, id: `${phase}.${c.id}` })));
|
|
const { checks: _checks, ...receipt } = delivered;
|
|
ev.downloads.push({ phase, issueId, mode, ...receipt });
|
|
note("download-verified", {
|
|
phase,
|
|
attachmentId: attachment.id,
|
|
sha256: delivered.sha256,
|
|
});
|
|
await openParent();
|
|
}
|
|
async function recordSource(
|
|
label = "source-saved-before-interruption",
|
|
evidenceName = "source-before-interruption.json",
|
|
requireActive = false,
|
|
maxWaitMs = 180_000,
|
|
) {
|
|
const filePath = path.join(input.workspacePath, "slugify.py");
|
|
const bytes = await pollUntil({
|
|
label: requireActive ? "active run with saved source" : "saved source after interruption",
|
|
deadlineAt: Math.min(input.deadlineAt, Date.now() + maxWaitMs),
|
|
intervalMs: 500,
|
|
load: async () => {
|
|
await refresh();
|
|
const source = await readFile(filePath).catch(() => undefined);
|
|
return { active: ev.runs.some(isActiveStoryRun), source };
|
|
},
|
|
accept: ({ active, source }) =>
|
|
requireActive
|
|
? isSavedSourceCheckpoint(active, source)
|
|
: hasPersistedSource(source),
|
|
});
|
|
if (!bytes.source) throw new Error("Saved source was not available at the controlled boundary");
|
|
await input.evidence(evidenceName, {
|
|
body: bytes.source.toString("utf8"),
|
|
sha256: createHash("sha256").update(bytes.source).digest("hex"),
|
|
});
|
|
note(label, {
|
|
sha256: createHash("sha256").update(bytes.source).digest("hex"),
|
|
bytes: bytes.source.length,
|
|
active: bytes.active,
|
|
});
|
|
}
|
|
async function sourceReady() {
|
|
await recordSource("source-saved-before-interruption", "source-before-interruption.json", true);
|
|
}
|
|
async function remoteRestartBoundary(runId?: string, recovered = false) {
|
|
await refresh();
|
|
const active = ev.runs.filter(run => (run.status === "running" || (recovered && run.status === "succeeded")) && run.nativeIssueId === parent!.id
|
|
&& (!runId || run.id === runId));
|
|
if (active.length !== 1) throw new Error("Remote restart boundary unexercised: the original run is not active");
|
|
const run = active[0]!;
|
|
const [rows, leases] = await Promise.all([
|
|
collectRunEvents<Row>((afterSeq, limit) => api.get(`/api/heartbeat-runs/${run.id}/events?afterSeq=${afterSeq}&limit=${limit}`)),
|
|
api.get<Row[]>(`/api/environments/${fixtures.environment.id}/leases`),
|
|
]);
|
|
return observeRemoteRestartBoundary(run, rows, leases, { companyId: fixtures.company.id,
|
|
agentId: fixtures.agent.id, issueId: parent!.id, environmentId: fixtures.environment.id }, recovered);
|
|
}
|
|
async function remoteWorkspaceStorageCheckpoint(phase: "initial" | "final") {
|
|
const point = await pollUntil({
|
|
label: `remote workspace ${phase} saved version`, deadlineAt: input.deadlineAt,
|
|
load: () => readRemoteWorkspaceStorageCheckpoint({ api, companyId: fixtures.company.id,
|
|
agentId: fixtures.agent.id, issueId: parent!.id, environmentId: fixtures.environment.id,
|
|
expectedFileSource: ev.remoteWorkspaceStorage!.expectedFileSource,
|
|
expectedLocation: ev.remoteWorkspaceStorage!.expectedLocation }),
|
|
accept: observed => Boolean(observed.point),
|
|
});
|
|
ev.remoteWorkspaceStorage![phase] = point.point!;
|
|
await input.evidence(`remote-workspace-${phase}.json`, point.point);
|
|
const browserPhase = phase === "initial" ? "before-restart" : "after-restart";
|
|
await page.goto(`${taskUrl(parent!)}?browse=1&q=${REMOTE_WORKSPACE_PROOF_FILE}`);
|
|
await expect(page.getByRole("combobox", { name: "Search workspace files" })).toBeVisible();
|
|
await expect(page.getByLabel("Workspace file source", { exact: true })).toHaveText(
|
|
ev.remoteWorkspaceStorage!.expectedFileSource === "saved" ? /^Saved copy(?: from .+)?$/ : "Live workspace");
|
|
await page.getByRole("treeitem").filter({ hasText: REMOTE_WORKSPACE_PROOF_FILE }).last().click();
|
|
await expect(page.getByText(point.content!.trim(), { exact: true })).toBeVisible();
|
|
await input.capture(`remote-workspace-${browserPhase}`, `Remote workspace file ${browserPhase}`, `remote-workspace-${browserPhase}.png`);
|
|
ev.remoteWorkspaceStorage!.browserReadPhases.push(browserPhase);
|
|
await openParent();
|
|
}
|
|
async function prepareStopBoundary() {
|
|
// Providers can finish a short first turn before the browser can click
|
|
// Stop. If that happens, submit one ordinary user follow-up through the
|
|
// composer and use that fresh run as the controlled interruption boundary.
|
|
// Save the checkpoint even if a fast provider has already finished. Do
|
|
// not shorten the normal source-creation budget to manufacture a timeout.
|
|
await recordSource("source-saved-before-interruption", "source-before-interruption.json");
|
|
await refresh();
|
|
if (ev.runs.some(isActiveStoryRun)) return;
|
|
await submitTaskReply(page, `${SLUGIFY_REVISION}\nContinue working until the source file is saved.`);
|
|
note("stop-boundary-continuation-submitted");
|
|
await recordSource(
|
|
"source-saved-before-interruption",
|
|
"source-before-interruption.json",
|
|
true,
|
|
);
|
|
}
|
|
try {
|
|
await mkdir(path.join(input.privateDir, "snapshots"), { recursive: true });
|
|
const revision = await runCommand("git", ["rev-parse", "HEAD"]);
|
|
if (revision.code === 0) ev.sourceRevision = revision.stdout.trim();
|
|
// Native providers run the packaged runtime (possibly remotely). A host
|
|
// `claude`/`codex` binary is neither required nor its observed version.
|
|
const harnessFiles = [
|
|
"everyday-flow.ts",
|
|
"everyday-cases.ts",
|
|
"everyday-decisions.ts",
|
|
"aggregator-fixture.ts",
|
|
"connection-routing-evidence.ts",
|
|
"agentmail-setup-evidence.ts",
|
|
"everyday-delivery.ts",
|
|
"everyday-observations.ts",
|
|
"everyday-remote-restart.ts",
|
|
"retained-controller-continuation.ts",
|
|
"controller-outage.ts",
|
|
"controller-rolling-deployment.ts",
|
|
"controller-replacement.ts",
|
|
"rolling-deployment-supervisor.ts",
|
|
"controller-recovery-observer.ts",
|
|
"upgrade-artifacts.ts",
|
|
"server.ts",
|
|
"server-stop.ts",
|
|
"native-event-envelope.ts",
|
|
"run-observations.ts",
|
|
"everyday-artifact.py",
|
|
"user-actions.ts",
|
|
"runner.spec.ts",
|
|
"api.ts",
|
|
"harness-env.ts",
|
|
"failure-classifier.ts",
|
|
"live-fixtures.ts",
|
|
"connection-reviews.ts",
|
|
"catalog.ts",
|
|
"remote-workspace-storage.ts",
|
|
];
|
|
if (execution.suite.id === CONNECTION_GUIDANCE_SUITE) {
|
|
harnessFiles.push("connection-guidance-cases.ts", "connection-guidance-evidence.ts");
|
|
const [company, agent] = await Promise.all([
|
|
api.get<Row>("/api/companies/" + fixtures.company.id),
|
|
api.get<Row>("/api/agents/" + fixtures.agent.id),
|
|
]);
|
|
ev.fixtureConfiguration!.connectionGuidanceBudgets = {
|
|
companyMonthlyCents: company.budgetMonthlyCents, agentMonthlyCents: agent.budgetMonthlyCents,
|
|
};
|
|
const budgetsMatch = company.budgetMonthlyCents === CONNECTION_GUIDANCE_BUDGET_CENTS &&
|
|
agent.budgetMonthlyCents === CONNECTION_GUIDANCE_BUDGET_CENTS;
|
|
check("guidance-budget-hard-stops", budgetsMatch, "Public company and lead records retain both 1,000-cent hard stops before task creation.");
|
|
if (!budgetsMatch) throw new Error("Connection guidance budget admission failed before task creation");
|
|
}
|
|
ev.harnessDigest = createHash("sha256")
|
|
.update(
|
|
(
|
|
await Promise.all(
|
|
harnessFiles.map((f) =>
|
|
readFile(path.join(import.meta.dirname, f)),
|
|
),
|
|
)
|
|
)
|
|
.map((b) => b.toString())
|
|
.join("\n"),
|
|
)
|
|
.digest("hex");
|
|
if (requiresEverydayArtifactOracle(caseId)) {
|
|
try {
|
|
const sandbox = await runCommand(process.env.PYTHON ?? "python3", [
|
|
path.join(import.meta.dirname, "everyday-artifact.py"), "--preflight",
|
|
]);
|
|
if (sandbox.code !== 0) throw new Error(sandbox.stdout);
|
|
note("artifact-sandbox-qualified", { isolation: "docker", network: "none" });
|
|
} catch (error) {
|
|
throw new Error(`Artifact sandbox qualification failed before task creation: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
}
|
|
}
|
|
if (remoteWorkspaceStorage) {
|
|
if (project) throw new Error("Remote workspace storage qualification requires a projectless task");
|
|
const settings = await api.get<Row>("/api/instance/settings/experimental");
|
|
check("remote-workspace-feature-enabled", settings.remoteWorkspaceStorageEnabled === true,
|
|
"The ordinary instance settings API resolves remote workspace storage as enabled by default before task creation.");
|
|
if (settings.remoteWorkspaceStorageEnabled !== true) throw new Error("Remote workspace storage was not enabled by default");
|
|
const viewer = await api.patch<Row>("/api/instance/settings/experimental", { enableExperimentalFileViewer: true });
|
|
const viewerReady = viewer.enableExperimentalFileViewer === true && viewer.remoteWorkspaceStorageEnabled === true;
|
|
check("remote-workspace-file-viewer-enabled", viewerReady, "The ordinary instance API enables the existing Files viewer while remote storage uses its default setting.");
|
|
if (!viewerReady) throw new Error("Remote workspace Files viewer prerequisite did not retain the storage default");
|
|
}
|
|
if (!remoteWorkspaceStorage && !project && !caseId.startsWith("service-") && !decliningConnection && !providerChoice) {
|
|
project = await api.post(
|
|
`/api/companies/${fixtures.company.id}/projects`,
|
|
{
|
|
name: `Studio project ${nonce}`,
|
|
description: "Small software project",
|
|
executionWorkspacePolicy: {
|
|
enabled: true,
|
|
defaultMode: "shared_workspace",
|
|
sharedWorkspaceConcurrency: "serialize",
|
|
allowIssueOverride: false,
|
|
environmentId: fixtures.environment.id,
|
|
workspaceStrategy: { type: "project_primary" },
|
|
},
|
|
workspace: {
|
|
name: "Primary",
|
|
sourceType: "local_path",
|
|
cwd: input.workspacePath,
|
|
isPrimary: true,
|
|
},
|
|
},
|
|
);
|
|
}
|
|
await api.patch(`/api/agents/${fixtures.agent.id}/permissions`, {
|
|
canCreateAgents: true,
|
|
canAssignTasks: true,
|
|
});
|
|
if (caseId === "delegate-feedback" || caseId === "agent-review-handoff") {
|
|
const config = execution.profile.buildAgent({
|
|
environmentId: fixtures.environment.id,
|
|
environmentFixtureId: execution.environment.id,
|
|
workspacePath: input.workspacePath,
|
|
secretRefs: fixtures.secretRefs,
|
|
executionId: nonce,
|
|
});
|
|
await api.post(`/api/companies/${fixtures.company.id}/agents`, {
|
|
...config,
|
|
name: "Riley Builder",
|
|
role: "engineer",
|
|
title: "Engineer",
|
|
reportsTo: fixtures.agent.id,
|
|
instructionsBundle: {
|
|
entryFile: "AGENTS.md",
|
|
files: {
|
|
"AGENTS.md":
|
|
"You implement small software projects and verify your work. Follow task feedback and deliver usable files.",
|
|
},
|
|
},
|
|
});
|
|
}
|
|
if (caseId.startsWith("service-"))
|
|
review = await setupConnectionReview({
|
|
page,
|
|
api,
|
|
prefix,
|
|
companyId: fixtures.company.id,
|
|
agentId: fixtures.agent.id,
|
|
marker: `Pages: Roadmap, Meeting notes. Verification code: SERVICE_${nonce}`,
|
|
authenticated: true,
|
|
});
|
|
if (providerChoice || nativeProviderCase || (execution.suite.id === CONNECTION_GUIDANCE_SUITE && Boolean(review))) {
|
|
if (caseId === "provider-second" || (execution.suite.id === CONNECTION_GUIDANCE_SUITE && caseId === "provider-decline")) aggregatorFixture = await setupAggregatorFixture(api, fixtures.company.id, fixtures.agent.id, `CONTACTS_${nonce}`, execution.suite.id === CONNECTION_GUIDANCE_SUITE);
|
|
const state = await api.get<{connections:Row[]}>(`/api/companies/${fixtures.company.id}/tools/connections`);
|
|
initialConnections = state.connections.map(c=>c.id);
|
|
if (aggregatorFixture && execution.suite.id === CONNECTION_GUIDANCE_SUITE) {
|
|
await input.evidence("provider-initial-access.json", aggregatorFixture.initialAccess);
|
|
check("provider-not-installed-before-choice", !aggregatorFixture.initialAccess.installed && aggregatorFixture.initialAccess.allowedToolIds.length === 0,
|
|
"The company connection is configured, but this agent has no installed or allowed HubSpot tool before the decision.");
|
|
}
|
|
}
|
|
if (agentmailSetup) await api.patch("/api/instance/settings/experimental", { enableChatConnectors: true });
|
|
if (decliningConnection) {
|
|
const state = await api.get<{ connections: Row[] }>(
|
|
`/api/companies/${fixtures.company.id}/tools/connections`,
|
|
);
|
|
initialConnections = state.connections.map((c) => c.id);
|
|
check(
|
|
"connection-starts-unconfigured",
|
|
state.connections.length === 0,
|
|
"This isolated company has no service connection before the request.",
|
|
);
|
|
if (state.connections.length)
|
|
throw new Error("New-connection story requires an unconnected company");
|
|
}
|
|
const created = await createTaskFromPromptThroughUi({
|
|
page,
|
|
companyId: fixtures.company.id,
|
|
issuePrefix: prefix,
|
|
agentName: fixtures.agent.name,
|
|
prompt: ev.prompt,
|
|
projectName: project?.name,
|
|
});
|
|
parent = await api.get<StoryIssue>(`/api/issues/${created.id}`);
|
|
input.observe(parent!, []);
|
|
note("task-submitted", { issueId: parent!.id });
|
|
await openParent();
|
|
if (caseId === "agent-review-handoff") {
|
|
const boundary = await pollUntil({
|
|
label: "blocked parent with agent review wake",
|
|
deadlineAt: input.deadlineAt,
|
|
load: refresh,
|
|
accept: (state) => {
|
|
const child = state.issues.find((issue) => issue.parentId === parent!.id);
|
|
const interaction = child?.interactions?.find(
|
|
(candidate) =>
|
|
["pending", "accepted"].includes(String(candidate.status)) &&
|
|
candidate.addresseeAgentId === fixtures.agent.id &&
|
|
candidate.effectiveResolverPolicy !== "human_only",
|
|
);
|
|
const parentIssue = state.issues.find((issue) => issue.id === parent!.id);
|
|
const reviewRun = interaction?.resolvedByRunId
|
|
? state.runs.find((run) => run.id === interaction.resolvedByRunId)
|
|
: undefined;
|
|
const parentRun = state.runs.find(
|
|
(run) =>
|
|
(run.nativeIssueId === parent!.id ||
|
|
run.contextSnapshot?.issueId === parent!.id ||
|
|
run.contextSnapshot?.taskId === parent!.id) &&
|
|
run.status === "succeeded" &&
|
|
run.finishedAt &&
|
|
(reviewRun?.startedAt
|
|
? Date.parse(run.finishedAt) <= Date.parse(reviewRun.startedAt)
|
|
: parentIssue?.status === "blocked"),
|
|
);
|
|
const parentBlockedEvidence =
|
|
Boolean(
|
|
parentIssue && storyIssueHasUnresolvedDependency(parentIssue),
|
|
) ||
|
|
Boolean(
|
|
parentIssue &&
|
|
storyIssueHasBlockedTimelineBefore(
|
|
parentIssue,
|
|
reviewRun?.startedAt ?? undefined,
|
|
),
|
|
) ||
|
|
Boolean(parentRun && storyRunReportsDependencyBlock(parentRun));
|
|
return Boolean(
|
|
parentIssue &&
|
|
["blocked", "done"].includes(parentIssue.status) &&
|
|
["in_review", "done"].includes(String(child?.status)) &&
|
|
interaction &&
|
|
parentBlockedEvidence &&
|
|
parentRun &&
|
|
(parentIssue.status === "blocked" || reviewRun),
|
|
);
|
|
},
|
|
reject: (state) => {
|
|
const failed = state.runs.find((run) =>
|
|
["failed", "timed_out"].includes(run.status),
|
|
);
|
|
return failed
|
|
? `Review handoff prerequisite failed: ${failed.errorCode}: ${failed.error}`
|
|
: storyUnexercisedReviewBoundary(state.issues, state.runs, parent!.id, fixtures.agent.id);
|
|
},
|
|
});
|
|
const child = boundary.issues.find((issue) => issue.parentId === parent!.id)!;
|
|
const interaction = child.interactions!.find(
|
|
(candidate) =>
|
|
["pending", "accepted"].includes(String(candidate.status)) &&
|
|
candidate.addresseeAgentId === fixtures.agent.id,
|
|
)!;
|
|
const reviewRun = interaction.resolvedByRunId
|
|
? boundary.runs.find((run) => run.id === interaction.resolvedByRunId)
|
|
: undefined;
|
|
const parentAtBoundary = boundary.issues.find(
|
|
(issue) => issue.id === parent!.id,
|
|
);
|
|
const parentRun = boundary.runs.find(
|
|
(run) =>
|
|
(run.nativeIssueId === parent!.id ||
|
|
run.contextSnapshot?.issueId === parent!.id ||
|
|
run.contextSnapshot?.taskId === parent!.id) &&
|
|
run.status === "succeeded" &&
|
|
run.finishedAt &&
|
|
storyParentCompletionPrecedesReview(
|
|
run.finishedAt,
|
|
reviewRun?.startedAt,
|
|
parentAtBoundary?.status === "blocked",
|
|
),
|
|
);
|
|
reviewHandoffBoundary = {
|
|
childId: child.id,
|
|
assigneeAgentId: child.assigneeAgentId,
|
|
interactionId: interaction.id!,
|
|
interactionCreatedAt: interaction.createdAt,
|
|
parentRunId: parentRun?.id,
|
|
parentBlockedObserved: boundary.issues.some(
|
|
(issue) =>
|
|
issue.id === parent!.id && storyIssueHasUnresolvedDependency(issue),
|
|
),
|
|
};
|
|
check(
|
|
"parent-blocked-before-agent-review",
|
|
reviewHandoffBoundary.parentBlockedObserved || Boolean(parentRun),
|
|
"The completed lead run and durable dependency projection precede the child review card.",
|
|
);
|
|
note("agent-review-requested", {
|
|
childId: child.id,
|
|
childAssigneeAgentId: child.assigneeAgentId,
|
|
interactionId: interaction.id,
|
|
parentStatus: boundary.issues.find((issue) => issue.id === parent!.id)?.status,
|
|
parentRunId: parentRun?.id,
|
|
parentRunFinishedAt: parentRun?.finishedAt,
|
|
interactionCreatedAt: interaction.createdAt,
|
|
});
|
|
await openParent();
|
|
}
|
|
if (caseId === "delegate-feedback") {
|
|
await pollUntil({
|
|
label: "active delegated child",
|
|
deadlineAt: input.deadlineAt,
|
|
load: refresh,
|
|
accept: (state) =>
|
|
state.issues.some(
|
|
(i) =>
|
|
i.parentId === parent!.id &&
|
|
state.runs.some(
|
|
(r) =>
|
|
isActiveStoryRun(r) &&
|
|
(r.contextSnapshot?.issueId === i.id ||
|
|
r.contextSnapshot?.taskId === i.id),
|
|
),
|
|
),
|
|
reject: (state) => {
|
|
const failed = state.runs.find((run) =>
|
|
["failed", "timed_out"].includes(run.status),
|
|
);
|
|
return failed
|
|
? `Delegation prerequisite failed before feedback: ${failed.errorCode}: ${failed.error}`
|
|
: undefined;
|
|
},
|
|
});
|
|
const child = ev.issues.find((i) => i.parentId === parent!.id)!;
|
|
note("late-feedback-boundary", {
|
|
childId: child.id,
|
|
activeRunIds: ev.runs.filter(isActiveStoryRun).map((r) => r.id),
|
|
});
|
|
await openTask(child);
|
|
await reply(LATE_REQUIREMENT, child);
|
|
note("late-feedback-delivered-to-child", { childId: child.id });
|
|
await openParent();
|
|
}
|
|
if (
|
|
caseId === "recover-controller" ||
|
|
caseId === "stop-redirect"
|
|
) {
|
|
if (execution.environment.id === "daytona") {
|
|
// A completed, downloaded first version is an observable remote persistence checkpoint.
|
|
await settled();
|
|
await download(parent!.id, "base", "before-restart");
|
|
if (remoteWorkspaceStorage) await remoteWorkspaceStorageCheckpoint("initial");
|
|
if (!ev.downloads.length || ev.checks.some((c) => !c.passed))
|
|
throw new Error(
|
|
"Remote fault boundary unexercised: no verified saved project",
|
|
);
|
|
await reply(isRollingWebDeployment(execution) ? `${SLUGIFY_REVISION}\n\n${SLUGIFY_DEPLOYMENT_SOAK}` : SLUGIFY_REVISION);
|
|
note("remote-revision-submitted");
|
|
await pollUntil({
|
|
label: "remote revision executing",
|
|
deadlineAt: input.deadlineAt,
|
|
load: refresh,
|
|
accept: (s) => s.runs.some(isActiveStoryRun),
|
|
});
|
|
} else if (caseId === "stop-redirect") await prepareStopBoundary();
|
|
else await sourceReady();
|
|
const active = ev.runs.find((r) => r.status === "running");
|
|
if (!active)
|
|
throw new Error(
|
|
"Fault boundary was not exercised: no active execution",
|
|
);
|
|
if (caseId === "stop-redirect") {
|
|
ev.allowedInterruptedRuns.push(active.id);
|
|
await stopAndRedirectThroughUi({ page, nonce,
|
|
awaitRetirement: async () => {
|
|
note("stop-clicked", { runId: active.id });
|
|
await pollUntil({ label: "owned runner stopped", deadlineAt: input.deadlineAt,
|
|
load: () => runnerStopped(active), accept: Boolean, intervalMs: 250 });
|
|
},
|
|
beforeRedirect: async () => {
|
|
await recordSource("source-saved-after-interruption", "source-after-interruption.json");
|
|
stoppedWorkspace = await workspaceFiles();
|
|
note("stopped-workspace-snapshot", stoppedWorkspace);
|
|
},
|
|
reply: async message => { await reply(message); note("new-direction-submitted"); },
|
|
});
|
|
} else {
|
|
await reply(LATE_REQUIREMENT);
|
|
note("followup-submitted-before-interruption");
|
|
for (let restartIndex = 0; restartIndex < (requireRemoteRestart ? input.restartCount ?? 1 : 1); restartIndex += 1) {
|
|
let currentBefore: RemoteRestartEvidence["before"];
|
|
if (requireRemoteRestart) {
|
|
const before = await waitForRemoteRestartBoundary({
|
|
deadlineAt: input.deadlineAt, load: async () => {
|
|
await refresh();
|
|
const original = ev.runs.find(run => run.id === active.id);
|
|
if (!original || original.status !== "running") return { run: original };
|
|
const rows = await collectRunEvents<Row>((afterSeq, limit) => api.get(`/api/heartbeat-runs/${active.id}/events?afterSeq=${afterSeq}&limit=${limit}`));
|
|
if (!rows.some(row => row.payload?.prpEvent?.eventType === "tool.execution.completed" && row.payload.prpEvent.payload?.status === "completed")) return { run: original };
|
|
return { run: original, boundary: await remoteRestartBoundary(active.id) };
|
|
} });
|
|
currentBefore = before;
|
|
ev.remoteRestart ??= { before, expectedReplacements: input.restartCount ?? 1, replacements: [] };
|
|
await input.evidence(`remote-restart-${restartIndex + 1}-before.json`, before);
|
|
} else ev.allowedInterruptedRuns.push(active.id);
|
|
if (remoteWorkspaceStorage && restartIndex === 0) {
|
|
const probe = await api.get<{ upgradeReadiness: NonNullable<RemoteWorkspaceStorageEvidence["upgradeReadiness"]> }>("/api/instance/task-drain?upgradeReadiness=1");
|
|
const { version, activeRuns, recoverableRuns, truncated } = probe.upgradeReadiness;
|
|
ev.remoteWorkspaceStorage!.upgradeReadiness = { version, activeRuns, recoverableRuns, truncated };
|
|
await input.evidence("remote-workspace-upgrade-readiness.json", ev.remoteWorkspaceStorage!.upgradeReadiness);
|
|
const upgrade = gradeRemoteWorkspaceStorage(ev.remoteWorkspaceStorage!).find(item => item.id === "remote-workspace-upgrade-recoverable")!;
|
|
if (!upgrade.passed) throw new Error(upgrade.detail);
|
|
}
|
|
const outage = await input.restart(requireRemoteRestart ? { companyId: fixtures.company.id, issueId: parent!.id, runId: active.id } : undefined, controllerOutage?.holdMs);
|
|
if (requireRemoteRestart) ev.remoteRestart!.outage = outage || undefined;
|
|
note("controller-restarted");
|
|
await openParent();
|
|
if (requireRemoteRestart) {
|
|
const after = await remoteRestartBoundary(active.id, true);
|
|
ev.remoteRestart!.after = after;
|
|
if (!outage || !currentBefore) throw new Error("Missing replacement fault evidence");
|
|
ev.remoteRestart!.replacements!.push({ before: currentBefore, after, outage });
|
|
await input.evidence(`remote-restart-${restartIndex + 1}-after.json`, { after, outage });
|
|
if (!gradeRemoteRestart(ev.remoteRestart)[0]!.passed) throw new Error("Remote restart changed the original native process, lease or receipt prefix");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (providerChoice) {
|
|
const rows = await pollUntil({
|
|
label: "external-provider choice", deadlineAt: input.deadlineAt,
|
|
load: async () => {
|
|
const runs = await api.get<StoryRun[]>(`/api/issues/${parent!.id}/runs`);
|
|
const failure = runs.find(run => ["failed", "timed_out"].includes(run.status));
|
|
if (failure) throw new Error(`Stopped waiting for external-provider choice: agent failed before selection: ${failure.error ?? failure.status}`);
|
|
const rows = await api.get<Row[]>(`/api/issues/${parent!.id}/interactions`);
|
|
const issue = await api.get<StoryIssue>(`/api/issues/${parent!.id}`);
|
|
if (!rows.some(row=>row.status==="pending") && ["done", "blocked", "cancelled"].includes(issue.status)) throw new Error(`Stopped waiting for external-provider choice: task reached ${issue.status} without asking the user`);
|
|
return rows;
|
|
},
|
|
accept: rows => rows.some(row=>row.status==="pending"),
|
|
});
|
|
const decision = gradeProviderChoice(rows as any, aggregatorFixture?.invocationCount() ?? 0);
|
|
decisionId = decision.interaction.id;
|
|
check("provider-disclosed-before-choice", true, "Ranked external providers and None were offered before any call.");
|
|
// Exercise durable selection across a real controller restart and browser reload.
|
|
await input.restart();
|
|
await openParent();
|
|
const choice = page.getByRole("radio", {name: caseId === "provider-decline" ? /None for now/ : /^Arcade/});
|
|
await expect(choice).toBeVisible();
|
|
await input.capture("provider-choice", "External service choice after restart", "provider-choice.png");
|
|
await choice.click();
|
|
await page.getByRole("button", {name:"Submit answers",exact:true}).click();
|
|
await pollUntil({label:"provider choice saved", deadlineAt:input.deadlineAt,
|
|
load:()=>api.get<Row[]>(`/api/issues/${parent!.id}/interactions`),
|
|
accept:rows=>rows.some(row=>row.id===decisionId && row.status==="answered"),
|
|
});
|
|
note("provider-choice-submitted", {interactionId:decisionId, selected:caseId === "provider-decline" ? "none" : "via:arcade:hubspot"});
|
|
if (execution.suite.id === CONNECTION_GUIDANCE_SUITE && caseId === "provider-second") {
|
|
const rows = await pollUntil({
|
|
label: "selected Arcade access request", deadlineAt: input.deadlineAt,
|
|
load: async () => ({
|
|
rows: await api.get<Row[]>(`/api/issues/${parent!.id}/interactions`),
|
|
issue: await api.get<StoryIssue>(`/api/issues/${parent!.id}`),
|
|
calls: aggregatorFixture!.invocationCount(),
|
|
runs: await api.get<StoryRun[]>(`/api/issues/${parent!.id}/runs`),
|
|
}),
|
|
accept: state => state.rows.some(row => row.id !== decisionId && row.status === "pending"),
|
|
reject: state => state.calls > 0 ? "Provider ran before tool-access approval"
|
|
: state.runs.some(run => ["failed", "timed_out"].includes(run.status)) ? "Agent failed before tool-access approval"
|
|
: ["done", "blocked", "cancelled"].includes(state.issue.status) ? "Task ended without the required access request" : undefined,
|
|
});
|
|
const card = requireProviderAccessCard({ rows: rows.rows as any, decisionId: decisionId!, connectionId: aggregatorFixture!.connectionId,
|
|
agentId: fixtures.agent.id, catalogEntryIds: aggregatorFixture!.catalogEntryIds, calls: rows.calls });
|
|
providerAccessDecision = { id: card.id, connectionId: aggregatorFixture!.connectionId };
|
|
await openParent();
|
|
const accessCard = page.getByTestId("connection-intent-access-request");
|
|
await expect(accessCard).toHaveCount(1);
|
|
await expect(accessCard.getByText("Hubspot_ListContacts", { exact: true })).toBeVisible();
|
|
await input.capture("provider-access", "Separate HubSpot tool-access approval", "provider-access.png");
|
|
check("no-call-before-provider-access", aggregatorFixture!.invocationCount() === 0, "Selecting a provider alone did not expose or execute its tool.");
|
|
await accessCard.getByRole("button", { name: "Grant access", exact: true }).click();
|
|
await pollUntil({ label: "Arcade access grant saved", deadlineAt: input.deadlineAt,
|
|
load: () => api.get<Row[]>(`/api/issues/${parent!.id}/interactions`),
|
|
accept: rows => rows.some(row => row.id === card.id && row.status === "accepted"
|
|
&& row.result?.connectionId === aggregatorFixture!.connectionId),
|
|
});
|
|
note("provider-access-granted", { interactionId: card.id, connectionId: aggregatorFixture!.connectionId });
|
|
}
|
|
}
|
|
if (review || decliningConnection) {
|
|
const interactions = await pollUntil({
|
|
label: "story decision request",
|
|
deadlineAt: input.deadlineAt,
|
|
load: async () => {
|
|
const [interactions, issue] = await Promise.all([
|
|
api.get<StoryInteraction[]>(
|
|
`/api/issues/${parent!.id}/interactions`,
|
|
),
|
|
api.get<StoryIssue>(`/api/issues/${parent!.id}`),
|
|
]);
|
|
return { interactions, issue, calls: review?.invocationCount() ?? 0 };
|
|
},
|
|
accept: (state) =>
|
|
state.interactions.some((i) => i.status === "pending"),
|
|
reject: (state) =>
|
|
state.calls > 0
|
|
? `The provider received ${state.calls} call(s) before approval.`
|
|
: ["done", "blocked", "cancelled"].includes(state.issue.status)
|
|
? `Task reached ${state.issue.status} without requesting the expected decision.`
|
|
: undefined,
|
|
});
|
|
await openParent();
|
|
await expect(
|
|
page
|
|
.locator(
|
|
'[data-testid="task-chat-thread"], [data-testid="thread-root"]',
|
|
)
|
|
.first(),
|
|
).toBeVisible();
|
|
await expect(page.getByTestId("issue-chat-skeleton")).toHaveCount(0);
|
|
const pendingInteraction = pendingStoryDecision(
|
|
interactions.interactions,
|
|
review
|
|
? { kind: "tool", connectionId: review.connectionId }
|
|
: { kind: "connection", serviceSlug: agentmailSetup ? "agentmail" : nativeProviderCase ? "jira" : "notion" },
|
|
);
|
|
await expect(
|
|
page.getByRole("button", {
|
|
name: decliningConnection ? "Not now" : "Review request",
|
|
exact: true,
|
|
}),
|
|
).toBeVisible();
|
|
await input.capture(
|
|
"decision-pending",
|
|
"Request before the user decision",
|
|
"decision-pending.png",
|
|
);
|
|
decisionId = pendingInteraction.id;
|
|
check(
|
|
"decision-request-matches-story",
|
|
true,
|
|
review
|
|
? "Tool approval belongs to the installed page service."
|
|
: `New connection request is for ${agentmailSetup ? "AgentMail" : nativeProviderCase ? "Jira" : "Notion"}, without an external-provider question.`,
|
|
);
|
|
if (agentmailSetup) {
|
|
// Reload proves the card is durable, rather than a transient model UI.
|
|
await page.reload();
|
|
const form = page.getByTestId("agentmail-inline-setup");
|
|
await expect(form).toBeVisible();
|
|
const card = page.getByTestId("connection-intent-focus-target").filter({ has: form });
|
|
const rows = await api.get<Parameters<typeof gradeAgentmailSetup>[0]["interactions"]>(`/api/issues/${parent!.id}/interactions`);
|
|
const checks = gradeAgentmailSetup({
|
|
// This harness boots a dedicated local_trusted instance.
|
|
interactions: rows, agentId: fixtures.agent.id, userId: "local-board",
|
|
visible: await form.isVisible(),
|
|
inputTypes: await card.locator("input").evaluateAll(inputs => inputs.map(input => input.getAttribute("type") ?? "text")),
|
|
keyLink: await form.getByRole("link", { name: "Get an AgentMail API key" }).getAttribute("href"),
|
|
accessSelectorCount: await card.locator('[role="radiogroup"], [role="combobox"], select').count(),
|
|
dialogCount: await page.getByRole("dialog").count(),
|
|
});
|
|
ev.checks.push(...checks);
|
|
await input.capture("agentmail-inline-key", "AgentMail API-key card after reload", "agentmail-inline-key.png");
|
|
if (checks.some(result => !result.passed)) throw new Error("AgentMail inline setup evidence failed");
|
|
}
|
|
if (review)
|
|
check(
|
|
"no-call-before-approval",
|
|
review.invocationCount() === 0,
|
|
"Service must not execute before the user decides.",
|
|
);
|
|
if (decliningConnection) {
|
|
await page
|
|
.getByRole("button", { name: "Not now", exact: true })
|
|
.click();
|
|
} else {
|
|
if (review) await decideProtectedActionThroughUi({ page,
|
|
rows: [pendingInteraction], connectionId: review.connectionId, decline: declining,
|
|
invocationCount: review.invocationCount });
|
|
else {
|
|
const dismiss = page.getByRole("button", {
|
|
name: "Dismiss Approve tool action",
|
|
});
|
|
if (await dismiss.isVisible()) await dismiss.click();
|
|
await page
|
|
.getByRole("button", { name: "Review request", exact: true })
|
|
.click();
|
|
await page
|
|
.getByRole("button", {
|
|
name: declining ? "Decline" : "Approve & run",
|
|
exact: true,
|
|
})
|
|
.click();
|
|
}
|
|
}
|
|
const decisionStatus = declining ? "rejected" : "accepted";
|
|
const decided = await pollUntil({
|
|
label: "connection decision persisted",
|
|
deadlineAt: Math.min(input.deadlineAt, Date.now() + 30_000),
|
|
load: () => api.get<Row[]>(`/api/issues/${parent!.id}/interactions`),
|
|
accept: (rows) =>
|
|
rows.some(
|
|
(interaction) =>
|
|
interaction.id === pendingInteraction.id &&
|
|
interaction.status === decisionStatus,
|
|
),
|
|
});
|
|
decisionResolvedAt = decided.find((i) => i.id === decisionId)?.resolvedAt;
|
|
check(
|
|
"user-decision-persisted",
|
|
true,
|
|
`Interaction ${decisionId} saved as ${decisionStatus}.`,
|
|
);
|
|
note("connection-decision", {
|
|
decision: caseId,
|
|
interactionId: pendingInteraction.id,
|
|
status: decisionStatus,
|
|
});
|
|
}
|
|
await settled(
|
|
caseId === "stop-redirect" ? `Reference ${nonce}`
|
|
: caseId === "provider-second" ? `CONTACTS_${nonce}` : undefined,
|
|
);
|
|
if (caseId === "create-skill-studio") {
|
|
const createdSkills = await api.get<Row[]>(
|
|
`/api/companies/${fixtures.company.id}/skills`,
|
|
);
|
|
const created = createdSkills.find(
|
|
(skill) => skill.slug === "release-readiness-checklist",
|
|
);
|
|
check(
|
|
"skill-persisted",
|
|
Boolean(created && String(created.name) === "release-readiness-checklist"),
|
|
"The runner-created skill is present in the company library after the run.",
|
|
);
|
|
if (created) {
|
|
await openParent();
|
|
await editCreatedSkillThroughStudio({ page, skillId: created.id, skillName: created.name,
|
|
marker: "Studio edit marker: verified", deadlineAt: input.deadlineAt,
|
|
read: () => api.get(`/api/companies/${fixtures.company.id}/skills/${created.id}`) });
|
|
check("feed-card-opened", true, "The task activity card opens the created skill.");
|
|
check("studio-opened", true, "The skill opens in Skill Studio.");
|
|
check("studio-edit-persisted", true, "The Studio edit persists across reload.");
|
|
check("return-content-persisted", true, "The saved edit is readable from the task card.");
|
|
}
|
|
}
|
|
if (providerChoice) {
|
|
const issue = ev.issues.find(i=>i.id===parent!.id)!;
|
|
const state = await api.get<{connections:Row[]}>(`/api/companies/${fixtures.company.id}/tools/connections`);
|
|
ev.checks.push(...gradeProviderOutcome({rows:issue.interactions as any, decisionId:decisionId!, accessDecision:providerAccessDecision,
|
|
selected:caseId === "provider-decline" ? "none" : "via:arcade:hubspot", calls:aggregatorFixture?.invocationCount() ?? 0,
|
|
response: (issue.comments ?? []).filter((c:Row)=>c.authorAgentId).map((c:Row)=>c.body).join("\n"), marker:`CONTACTS_${nonce}`,
|
|
sameConnections:isDeepStrictEqual(state.connections.map(c=>c.id).sort(), initialConnections.sort()),
|
|
}));
|
|
}
|
|
if (execution.suite.id === CONNECTION_GUIDANCE_SUITE &&
|
|
(caseId === "service-decline" || caseId === "connection-decline" || caseId === "provider-decline")) {
|
|
const state = await api.get<{ connections: Row[] }>("/api/companies/" + fixtures.company.id + "/tools/connections");
|
|
const gradeInput = structuredClone({
|
|
...declineInput(ev)!,
|
|
calls: review?.invocationCount() ?? aggregatorFixture?.invocationCount(),
|
|
sameConnections: isDeepStrictEqual(state.connections.map(c => c.id).sort(), initialConnections.sort()),
|
|
});
|
|
const checks = gradeConnectionGuidanceDecline(gradeInput);
|
|
// Keep the actual assertion input independent of the later final/cleanup refreshes.
|
|
ev.declineGradeEvidence = { capturedAt: new Date().toISOString(), input: gradeInput, checks: structuredClone(checks) };
|
|
await input.evidence("connection-guidance-decline-grade.json", ev.declineGradeEvidence);
|
|
ev.checks.push(...checks);
|
|
}
|
|
if (declining) {
|
|
const issue = ev.issues.find((i) => i.id === parent!.id)!;
|
|
const requests = issue.interactions as Row[];
|
|
check(
|
|
"decline-not-repeated",
|
|
requests.length === 1 &&
|
|
requests[0]?.id === decisionId &&
|
|
requests[0]?.status === "rejected",
|
|
"The saved decline remains rejected and no replacement request appears.",
|
|
);
|
|
const replies = (issue.comments ?? []).filter(
|
|
(c: Row) =>
|
|
c.authorAgentId &&
|
|
Date.parse(c.createdAt) >= Date.parse(decisionResolvedAt ?? ""),
|
|
);
|
|
const text = replies.map((c: Row) => String(c.body ?? "")).join("\n");
|
|
check(
|
|
"decline-visible-explanation",
|
|
replies.length > 0 &&
|
|
explainsConnectionUnavailable(text),
|
|
"A new agent response explains the missing access after the saved decline.",
|
|
);
|
|
check(
|
|
"decline-no-fabricated-result",
|
|
!text.includes(`SERVICE_${nonce}`),
|
|
"The fallback does not claim the private verification code.",
|
|
);
|
|
if (decliningConnection) {
|
|
const state = await api.get<{ connections: Row[] }>(
|
|
`/api/companies/${fixtures.company.id}/tools/connections`,
|
|
);
|
|
check(
|
|
"decline-no-connection-created",
|
|
isDeepStrictEqual(
|
|
state.connections.map((c) => c.id).sort(),
|
|
initialConnections.sort(),
|
|
),
|
|
"Not now did not create a service connection.",
|
|
);
|
|
}
|
|
}
|
|
if (caseId === "build-revise") {
|
|
await download(parent!.id, "base", "initial");
|
|
await reply(SLUGIFY_REVISION);
|
|
note("revision-requested");
|
|
await settled();
|
|
await download(parent!.id, "separator", "revised");
|
|
check(
|
|
"new-artifact-revision",
|
|
ev.downloads.length === 2 &&
|
|
ev.downloads[0]!.sha256 !== ev.downloads[1]!.sha256,
|
|
"The follow-up must deliver a new version.",
|
|
);
|
|
if (ev.downloads[0]) {
|
|
const response = await api.request.get(
|
|
`/api/attachments/${ev.downloads[0].attachmentId}/content`,
|
|
);
|
|
check(
|
|
"prior-download-preserved",
|
|
response.ok() &&
|
|
createHash("sha256")
|
|
.update(await response.body())
|
|
.digest("hex") === ev.downloads[0].sha256,
|
|
"The first delivered version remains retrievable.",
|
|
);
|
|
}
|
|
} else if (caseId === "hire-reuse") {
|
|
let agents = await api.get<Row[]>(
|
|
`/api/companies/${fixtures.company.id}/agents`,
|
|
);
|
|
const hires = agents.filter((a) => a.name === "Morgan QA");
|
|
check(
|
|
"exactly-one-hire",
|
|
hires.length === 1,
|
|
"One Morgan QA must be hired.",
|
|
);
|
|
check(
|
|
"manager-correct",
|
|
hires.length === 1 && hires[0]!.reportsTo === fixtures.agent.id,
|
|
"The hired agent reports to the lead.",
|
|
);
|
|
const lead = agents.find((a) => a.id === fixtures.agent.id);
|
|
check(
|
|
"hire-native-connection",
|
|
hires.length === 1 &&
|
|
hires[0]!.adapterType === "paperclip_runner" &&
|
|
hires[0]!.adapterConfig?.model === lead?.adapterConfig?.model &&
|
|
isDeepStrictEqual(
|
|
hires[0]!.runtimeConfig?.aiConnection,
|
|
fixtures.aiConnection?.binding,
|
|
),
|
|
"The hire keeps the native model and inherits the managed AI account binding.",
|
|
);
|
|
const children = ev.issues.filter((i) => i.parentId === parent!.id);
|
|
check(
|
|
"hired-agent-executed",
|
|
hires.length === 1 &&
|
|
ev.runs.some(
|
|
(r) =>
|
|
r.agentId === hires[0]!.id &&
|
|
r.status === "succeeded" &&
|
|
(r.contextSnapshot?.aiConnection as Row | undefined)
|
|
?.connectionId === fixtures.aiConnection?.connectionId,
|
|
),
|
|
"The new hire must complete a run using the fixture managed account.",
|
|
);
|
|
await downloadDelegated("base", "hired-delivery");
|
|
const reuseRequestedAt = Date.now();
|
|
await reply(
|
|
`Have the existing Morgan QA add --separator support to the delivered project. Use the same agent; do not hire another. ${SLUGIFY_REVISION}`,
|
|
);
|
|
note("reuse-requested");
|
|
await settled();
|
|
agents = await api.get<Row[]>(
|
|
`/api/companies/${fixtures.company.id}/agents`,
|
|
);
|
|
check(
|
|
"hire-reused",
|
|
agents.filter((a) => a.name === "Morgan QA").length === 1 &&
|
|
agents.some((a) => a.id === hires[0]?.id),
|
|
"The original hired identity remains unique.",
|
|
);
|
|
check(
|
|
"hired-agent-executed-revision",
|
|
ev.runs.some(
|
|
(r) =>
|
|
r.agentId === hires[0]?.id &&
|
|
r.status === "succeeded" &&
|
|
Date.parse(r.finishedAt ?? "") >= reuseRequestedAt,
|
|
),
|
|
"The same hired agent performs the follow-up work.",
|
|
);
|
|
await downloadDelegated("separator", "reused-delivery", reuseRequestedAt);
|
|
} else if (caseId === "delegate-feedback") {
|
|
const children = ev.issues.filter((i) => i.parentId === parent!.id);
|
|
check(
|
|
"one-child",
|
|
children.length === 1,
|
|
"Exactly one delegated child task.",
|
|
);
|
|
check(
|
|
"child-consumed-feedback",
|
|
Boolean(children[0]) &&
|
|
storyRepliesConsumed(
|
|
ev.runs.filter(
|
|
(run) =>
|
|
run.contextSnapshot?.issueId === children[0]?.id ||
|
|
run.contextSnapshot?.taskId === children[0]?.id,
|
|
),
|
|
submittedCommentIds,
|
|
),
|
|
"A completed child execution consumed the delivered user feedback.",
|
|
);
|
|
if (children[0])
|
|
await downloadDelegated(
|
|
artifactGradeModeForPhase("delegated-delivery"),
|
|
"delegated-delivery",
|
|
);
|
|
check(
|
|
"feedback-delivered-to-child",
|
|
Boolean(
|
|
children[0]?.comments?.some((c: Row) =>
|
|
String(c.body).includes("--max-length"),
|
|
),
|
|
),
|
|
"The child history contains the late requirement.",
|
|
);
|
|
} else if (caseId === "agent-review-handoff") {
|
|
const children = ev.issues.filter((i) => i.parentId === parent!.id);
|
|
const child = children.find((candidate) =>
|
|
candidate.id === reviewHandoffBoundary?.childId,
|
|
);
|
|
const interaction = storyAcceptedAgentReview(
|
|
child,
|
|
reviewHandoffBoundary?.interactionId,
|
|
fixtures.agent.id,
|
|
ev.runs,
|
|
) as Row | undefined;
|
|
const reviewRun = interaction?.resolvedByRunId
|
|
? ev.runs.find((run) => run.id === interaction.resolvedByRunId)
|
|
: undefined;
|
|
const parentContinuationRun = ev.runs.find(
|
|
(run) =>
|
|
run.agentId === fixtures.agent.id &&
|
|
run.status === "succeeded" &&
|
|
run.id !== reviewHandoffBoundary?.parentRunId &&
|
|
(run.nativeIssueId === parent!.id ||
|
|
run.contextSnapshot?.issueId === parent!.id ||
|
|
run.contextSnapshot?.taskId === parent!.id) &&
|
|
interaction?.resolvedAt &&
|
|
run.startedAt &&
|
|
Date.parse(run.startedAt) >= Date.parse(interaction.resolvedAt),
|
|
);
|
|
check(
|
|
"agent-review-one-child",
|
|
children.length === 1 && Boolean(child),
|
|
"Exactly one child remains attached to the lead task.",
|
|
);
|
|
check(
|
|
"agent-review-child-completed",
|
|
child?.status === "done" && interaction?.status === "accepted",
|
|
"The named agent review is accepted and the child reaches Done.",
|
|
);
|
|
check(
|
|
"agent-review-assignee-preserved",
|
|
child?.assigneeAgentId === reviewHandoffBoundary?.assigneeAgentId,
|
|
"Review resolution preserves the child task assignee.",
|
|
);
|
|
check(
|
|
"agent-review-run-scoped",
|
|
reviewRun?.status === "succeeded" &&
|
|
reviewRun.agentId === fixtures.agent.id &&
|
|
reviewRun.contextSnapshot?.nativeReviewInteractionId ===
|
|
interaction?.id &&
|
|
typeof reviewRun.contextSnapshot?.nativeReviewDecisionId === "string",
|
|
"The lead resolves the review from a successful review-scoped native run.",
|
|
);
|
|
check(
|
|
"agent-review-parent-resumed",
|
|
parent?.status === "done" &&
|
|
Boolean(parentContinuationRun) &&
|
|
Boolean(
|
|
parentContinuationRun?.finishedAt &&
|
|
parentContinuationRun.startedAt &&
|
|
Date.parse(parentContinuationRun.finishedAt) >=
|
|
Date.parse(parentContinuationRun.startedAt),
|
|
),
|
|
"The parent continuation starts after review acceptance and finishes successfully.",
|
|
);
|
|
note("agent-review-accepted", {
|
|
childId: child?.id,
|
|
childAssigneeAgentId: child?.assigneeAgentId,
|
|
interactionId: interaction?.id,
|
|
interactionStatus: interaction?.status,
|
|
resolvedByRunId: interaction?.resolvedByRunId,
|
|
reviewRunId: reviewRun?.id,
|
|
reviewRunAgentId: reviewRun?.agentId,
|
|
parentContinuationRunId: parentContinuationRun?.id,
|
|
parentContinuationStartedAt: parentContinuationRun?.startedAt,
|
|
nativeReviewInteractionId:
|
|
reviewRun?.contextSnapshot?.nativeReviewInteractionId,
|
|
nativeReviewDecisionId:
|
|
reviewRun?.contextSnapshot?.nativeReviewDecisionId,
|
|
});
|
|
// The review handoff case uses the base slugify requirements. The
|
|
// max-length grader belongs to the later follow-up requirement cases.
|
|
if (child)
|
|
await downloadDelegated(
|
|
artifactGradeModeForPhase("reviewed-delivery"),
|
|
"reviewed-delivery",
|
|
);
|
|
} else if (caseId === "recover-controller") {
|
|
await download(
|
|
parent!.id,
|
|
artifactGradeModeForPhase("recovered-delivery"),
|
|
"recovered-delivery",
|
|
);
|
|
if (execution.suite.definitionMetadata?.retainedControllerContinuation === true) {
|
|
const prior = ev.runs.filter(run => run.status === "succeeded" && run.agentId === fixtures.agent.id)
|
|
.sort((a, b) => Date.parse(b.finishedAt ?? "") - Date.parse(a.finishedAt ?? ""))[0];
|
|
if (!prior) throw new Error("Retained continuation requires a completed source run");
|
|
const before = retainedControllerRun(prior), priorIds = new Set(ev.runs.map(run => run.id));
|
|
const outage = await input.restart();
|
|
const followupTransport = retainedControllerFollowupTransport(execution);
|
|
postControllerApiFollowup = followupTransport === "task_comment_api";
|
|
if (!postControllerApiFollowup) await openParent();
|
|
note("retained-controller-followup-entry", { transport: followupTransport,
|
|
browserNavigationVerified: !postControllerApiFollowup });
|
|
const requestedAt = new Date().toISOString(), marker = `CONTINUED_${nonce}`;
|
|
const expectedReply = retainedControllerReplyMatcher(marker);
|
|
const reportInstruction = remoteWorkspaceStorage
|
|
? `Reply with exactly one plain-text line: ${marker} followed by one space and the command's actual output. Add no Markdown, code fences, punctuation, labels, or explanatory prose.`
|
|
: `Report its output after the marker ${marker}.`;
|
|
await reply(`Run the existing delivered slugify.py on " Queue--Ready!! " with --separator _ and --max-length 7. ${reportInstruction} Use the saved project; do not rebuild it.`, parent!, followupTransport);
|
|
await settled(expectedReply, postControllerApiFollowup ? "api" : "browser");
|
|
const after = ev.runs.filter(run => !priorIds.has(run.id) && run.status === "succeeded" && run.agentId === fixtures.agent.id)
|
|
.sort((a, b) => Date.parse(b.finishedAt ?? "") - Date.parse(a.finishedAt ?? ""))[0];
|
|
if (!after) throw new Error("Retained continuation produced no new successful run");
|
|
const events = await collectRunEvents<Row>((afterSeq, limit) => api.get(`/api/heartbeat-runs/${after.id}/events?afterSeq=${afterSeq}&limit=${limit}`));
|
|
const evidence = { before, after: retainedControllerRun(after), outage: outage || undefined, requestedAt,
|
|
followupTransport, followupCommentId: retainedFollowupCommentId,
|
|
completedTool: events.some(row => row.payload?.prpEvent?.eventType === "tool.execution.completed" && row.payload.prpEvent.payload?.status === "completed"),
|
|
usefulReply: storyAgentReplyMatches(settledAgentReply, fixtures.agent.id, expectedReply) };
|
|
ev.checks.push(...gradeRetainedControllerContinuation(evidence));
|
|
await input.evidence("retained-controller-continuation.json", evidence);
|
|
}
|
|
} else if (caseId === "stop-redirect")
|
|
check(
|
|
"new-direction-delivered",
|
|
settledAgentReply?.authorAgentId === fixtures.agent.id &&
|
|
String(settledAgentReply.body ?? "").includes(`Reference ${nonce}`),
|
|
"The new request is answered after Stop and reload.",
|
|
);
|
|
if (stoppedWorkspace) {
|
|
check(
|
|
"stop.workspace-unchanged",
|
|
isDeepStrictEqual(stoppedWorkspace, await workspaceFiles()),
|
|
"Project files remain unchanged from verified runner stop through the new response.",
|
|
);
|
|
check(
|
|
"stop.no-old-run-active",
|
|
ev.runs
|
|
.filter((r) => ev.allowedInterruptedRuns.includes(r.id))
|
|
.every((r) => !isActiveStoryRun(r)),
|
|
"The stopped run is terminal after the new response.",
|
|
);
|
|
}
|
|
if (review) {
|
|
check(
|
|
"service-call-count",
|
|
review.invocationCount() === (caseId === "service-decline" ? 0 : 1),
|
|
"Exactly one approved service call; none after decline.",
|
|
);
|
|
if (caseId === "service-approve") {
|
|
const bodies = await readServiceBriefing({ page, api, issueId: parent!.id });
|
|
for (const result of serviceBriefingChecks(bodies, `SERVICE_${nonce}`)) check(result.id, result.passed, result.detail);
|
|
ev.documents = bodies;
|
|
ev.issues.find((i) => i.id === parent!.id)!.documents = bodies;
|
|
}
|
|
}
|
|
if (!postControllerApiFollowup) await page.reload();
|
|
await refresh();
|
|
check(
|
|
"submitted-replies-consumed",
|
|
storyRepliesConsumed(ev.runs, submittedCommentIds),
|
|
"Every submitted user message appears in a successfully completed native execution input.",
|
|
);
|
|
if (
|
|
caseId === "delegate-feedback" ||
|
|
caseId === "hire-reuse" ||
|
|
caseId === "agent-review-handoff"
|
|
) {
|
|
check(
|
|
"parent-finishes-after-child",
|
|
storyParentFinishedAfterChildren(
|
|
ev.runs,
|
|
parent!.id,
|
|
fixtures.agent.id,
|
|
ev.issues.filter((i) => i.parentId === parent!.id).map((i) => i.id),
|
|
),
|
|
"The lead completes only after the final child execution.",
|
|
);
|
|
}
|
|
const expectedModel = execution.profile.model;
|
|
check(
|
|
"native-model-config",
|
|
ev.runs.length > 0 &&
|
|
ev.runs
|
|
.filter((r) => !isStoryWorkspaceDeferral(r))
|
|
.every(
|
|
(r) =>
|
|
(r.runnerProfileJson?.nativeExecutionInput as Row | undefined)
|
|
?.provider?.model === expectedModel,
|
|
),
|
|
"Persisted native execution inputs use the selected model; this does not claim provider-side model identity.",
|
|
);
|
|
check(
|
|
"native-terminal-contract",
|
|
ev.runs
|
|
.filter(
|
|
(r) =>
|
|
!isStoryWorkspaceDeferral(r) &&
|
|
!isExpectedStoryInterruption(r, ev.allowedInterruptedRuns),
|
|
)
|
|
.every(
|
|
(r) =>
|
|
(r.resultJson?.nativeTerminal as Row | undefined)?.schema ===
|
|
"paperclip.prp.terminal.v1",
|
|
),
|
|
"Successful runs retain the native terminal contract.",
|
|
);
|
|
if (requireRemoteRestart) {
|
|
const runId = ev.remoteRestart?.before?.identity.runId;
|
|
if (!runId) throw new Error("Remote restart has no saved original run boundary");
|
|
const final = await pollUntil({ label: "original remote run committed with workspace receipt",
|
|
deadlineAt: input.deadlineAt, load: async () => {
|
|
const [run, rows, operationRows, recovery, issue] = await Promise.all([
|
|
api.get<StoryRun>(`/api/heartbeat-runs/${runId}`),
|
|
collectRunEvents<Row>((afterSeq, limit) => api.get(`/api/heartbeat-runs/${runId}/events?afterSeq=${afterSeq}&limit=${limit}`)),
|
|
api.get<Row[]>(`/api/heartbeat-runs/${runId}/workspace-operations`),
|
|
api.get<{ active: Row | null; actions: Row[] }>(`/api/issues/${parent!.id}/recovery-actions`),
|
|
api.get<StoryIssue>(`/api/issues/${parent!.id}`),
|
|
]);
|
|
if (!Array.isArray(operationRows) || !Array.isArray(recovery.actions) || !("active" in recovery)) throw new Error("Remote restart finalization evidence is incomplete");
|
|
const final = { observedAt: new Date().toISOString(), run: projectRemoteRestartRun(run), events: projectRemoteRestartEvents(run, rows),
|
|
operations: operationRows.map(operation => ({ companyId: operation.companyId, heartbeatRunId: operation.heartbeatRunId,
|
|
issueId: operation.issueId, executionWorkspaceId: operation.executionWorkspaceId, phase: operation.phase, status: operation.status })),
|
|
scheduledRetry: issue.scheduledRetry,
|
|
recoveryActions: [recovery.active, ...recovery.actions].filter((action): action is Row => action !== null).map(action => ({ status: action.status })) };
|
|
ev.remoteRestart!.final = final;
|
|
return final;
|
|
}, accept: final => gradeRemoteRestart({ ...ev.remoteRestart, final }).every(check => check.passed),
|
|
reject: final => ["failed", "cancelled", "timed_out"].includes(final.run.status) ? "Original remote run failed after restart"
|
|
: final.run.status === "succeeded" && final.run.nativePhase === "committed"
|
|
&& !gradeRemoteRestart({ ...ev.remoteRestart, final })[1]!.passed ? "Original remote turn completed with failed tools or conflicting/repeated execution receipts" : undefined });
|
|
await input.evidence("remote-restart-final.json", final);
|
|
}
|
|
if (remoteWorkspaceStorage) {
|
|
await remoteWorkspaceStorageCheckpoint("final");
|
|
ev.checks.push(...gradeRemoteWorkspaceStorage(ev.remoteWorkspaceStorage!));
|
|
await input.evidence("remote-workspace-storage.json", ev.remoteWorkspaceStorage);
|
|
}
|
|
ev.checks.push(
|
|
...storyLifecycleChecks({
|
|
issues: ev.issues as StoryIssue[],
|
|
runs: ev.runs,
|
|
parentId: parent!.id,
|
|
leadId: fixtures.agent.id,
|
|
allowedInterruptedRuns: ev.allowedInterruptedRuns,
|
|
requireRemoteRestart,
|
|
remoteRestart: ev.remoteRestart,
|
|
}),
|
|
);
|
|
check(
|
|
"no-pending-bookkeeping",
|
|
ev.issues.every((i) =>
|
|
(i.interactions ?? []).every((x: Row) => x.status !== "pending"),
|
|
),
|
|
"No completion confirmation or unanswered interaction remains.",
|
|
);
|
|
if (!postControllerApiFollowup) {
|
|
if (providerChoice || nativeProviderCase) await openParent();
|
|
else {
|
|
await waitForTaskIdentity(page, taskUrl(parent!), parent!.identifier ?? parent!.id);
|
|
await waitForTaskChatRendered(page);
|
|
}
|
|
const latestAgentComment = ev.issues
|
|
.find((i) => i.id === parent!.id)
|
|
?.comments?.filter((c: Row) => c.authorAgentId)
|
|
.at(-1);
|
|
if (latestAgentComment && !providerChoice && !nativeProviderCase) {
|
|
const response = page.locator(`[id="comment-${latestAgentComment.id}"]`);
|
|
await expect(response).toBeVisible();
|
|
await response.scrollIntoViewIfNeeded();
|
|
}
|
|
await input.capture(
|
|
"final-state",
|
|
"Finished everyday workflow",
|
|
"final-state.png",
|
|
);
|
|
} else {
|
|
note("final-state-api-readback", { browserNavigationVerified: false, renderedStatusVerified: false });
|
|
await input.capture("final-state", "Browser state retained after API-verified native continuation; browser reconnection unqualified", "final-state.png");
|
|
}
|
|
const failed = ev.checks.filter((c) => !c.passed);
|
|
if (failed.length)
|
|
throw new Error(
|
|
`Everyday outcome checks failed: ${failed.map((c) => c.id).join(", ")}`,
|
|
);
|
|
return { issue: parent!, runs: ev.runs, evidence: ev };
|
|
} catch (error) {
|
|
check(
|
|
error instanceof StoryDecisionError
|
|
? error.checkId
|
|
: "workflow-completed",
|
|
false,
|
|
error instanceof Error ? error.message : String(error),
|
|
);
|
|
throw error;
|
|
} finally {
|
|
try {
|
|
await refresh();
|
|
ev.agents = await api.get<Row[]>(
|
|
`/api/companies/${fixtures.company.id}/agents`,
|
|
);
|
|
if (ev.documents && parent)
|
|
ev.issues.find((i) => i.id === parent!.id)!.documents = ev.documents;
|
|
} catch (error) {
|
|
note("evidence-capture-error", String(error));
|
|
}
|
|
if (caseId === "recover-controller") {
|
|
note("recovery-final-observation", {
|
|
taskStatus: parent?.status,
|
|
pendingCommentIds: ev.issues.flatMap((i) =>
|
|
(i.queuedComments?.entries ?? []).map((e: Row) => e.comment.id),
|
|
),
|
|
failureCodes: ev.runs
|
|
.filter((r) => r.errorCode)
|
|
.map((r) => ({ runId: r.id, code: r.errorCode })),
|
|
});
|
|
if (execution.environment.id === "local") {
|
|
try {
|
|
const source = await readFile(
|
|
path.join(input.workspacePath, "slugify.py"),
|
|
"utf8",
|
|
);
|
|
await input.evidence("source-after-interruption.json", {
|
|
body: source,
|
|
sha256: createHash("sha256").update(source).digest("hex"),
|
|
});
|
|
} catch {
|
|
note("saved-source-unavailable-at-final-capture");
|
|
}
|
|
}
|
|
}
|
|
if (review) {
|
|
note("service-final-observation", {
|
|
invocationCount: review.invocationCount(),
|
|
requests: review.captures,
|
|
decisionTaken: ev.timeline.some(
|
|
(entry) => entry.action === "connection-decision",
|
|
),
|
|
});
|
|
}
|
|
try {
|
|
await input.evidence("everyday-workflow.json", ev);
|
|
await input.evidence("api-state.json", {
|
|
capturePhase: "everyday-final", issue: parent, runs: ev.runs,
|
|
issues: ev.issues, checks: ev.checks,
|
|
});
|
|
if (aggregatorFixture) await input.evidence("aggregator-provider-calls.json", { calls: aggregatorFixture.captures });
|
|
} finally {
|
|
try { await aggregatorFixture?.close(); }
|
|
finally { await review?.close(); }
|
|
}
|
|
}
|
|
}
|