mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-02 10:44:52 +01:00
test(e2e): retain failed agent-settings task identity (#23371)
## Thinking Path > - Paperclip lets people manage agents and their saved work. > - Product E2E tests check whether saved agent instructions affect the next task. > - A failed work run must keep a failed test result. > - The observer currently saves task identity only after the task completes. > - A failed run leaves no task or run ID in its retained settings evidence. > - This change saves the observed identity before the failure check. > - Engineers can then find the failed run without storing raw instruction or provider data. ## Linked Issues or Issue Description **What happened?** The saved-instructions journey reads a failed native run and throws `agent_settings_native_run_failed`. Its private report then writes `issueId: null` and `runIds: []`. The observer already read the task and run, but loses their identity because it fills completed evidence only after a successful wait. **Expected behavior** Keep the created task ID, requested run IDs and observed status/native phase. Keep the test failed. Do not record instruction text, raw errors, output excerpts, account configuration or provider payloads. **Steps to reproduce** Run the existing agent-settings flow fixture with a failed native run. Read `agent-settings-observations.json`. Before this change its task ID is null. The new regression fails on that value. A denied run-detail read also loses its requested identity. Related work: #23041 retains question-journey failure evidence. #23108 adds Skill Studio browser-step codes. #23288 changes reset and repository observation waits. None covers the saved-instructions observer. This change does not repair the underlying native run failure. ## What Changed - Keep the created task identity before the first task observation. - Save requested run IDs before detail reads. Keep status and native phase from each completed read. - Keep this diagnostic separate from completed evidence and all grading checks. - Test failed runs, denied detail reads, successful completion and raw-data exclusion. - Document the private evidence fields. ## Verification - The new failed-run assertion failed before the fix: expected task ID `task`, received null. The other nine flow checks passed. - After the fix, 89 checks pass in `agent-settings-flow.test.ts`, `agent-settings-evidence.test.ts` and `observation-read.test.ts`. - Command: `pnpm exec vitest run --config tests/runner-e2e/vitest.config.ts` with those three files. - `pnpm test:e2e:runner:typecheck` passes on the final source. - The real observer and private file writer ran on Linux with simulated browser/API boundaries. Failed work still fails. A denied detail read keeps an empty observed-runs list. No second settings save occurs after either failure. - `pnpm verify` could not select tests because the managed Git guard rejects `git ls-files`. This is not a pass. Preflight installed dependencies and built required packages, then could not find Cargo. Focused checks ran directly. - No hosted provider rerun or deployment was made. Local evidence does not establish a staging pass. Hosted acceptance requires approved harness adoption. - Final-head CI and automated reviews are pending. ## Risks The new record contains private task/run IDs and lifecycle fields. It uses an explicit field projection and does not copy the full run object. It cannot make a pending or failed run pass. The change adds no work runs, retries, requests, settings edits or budget. Existing grading, cleanup and public projection remain in place. This is a reporting repair; the underlying provider or infrastructure cause remains open. ## Model Used OpenAI Codex, GPT-6 family, with reasoning, tool use and code execution. The runtime does not expose an exact model ID or 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 (a) linked existing issues with `Fixes: #` / `Closes: #` / `Refs: #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [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 any risks above - [ ] All Paperclip CI gates are green - [ ] 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>
This commit is contained in:
1 parent
3f80675409
commit
00a792999c
3 files changed
+61
-4
No files matched your search
@@ -60,5 +60,9 @@ The first contains closed IDs, hashes, the synthetic reference, checks, and both
|
||||
matched board-save receipts. Each receipt includes its audit ID, actor, agent
|
||||
entity, entry path, content hash, and save source. It
|
||||
does not contain raw instruction files, account bindings, or provider payloads.
|
||||
The last task observation retains the created task ID, requested run IDs and
|
||||
observed run status/native phase before checking for a failed run. It survives
|
||||
a failed run or detail read without satisfying any result check. Missing run
|
||||
details remain absent; the diagnostic does not invent a completed run or output.
|
||||
Discovery and local controls do not qualify a staging run. The daily plan may
|
||||
admit this case only after a genuine staging pass and reviewed source merge.
|
||||
@@ -5,6 +5,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { JourneyContext, JourneyEvidence, TargetSession } from "./types.js";
|
||||
import { settingsEvidenceFixture } from "./agent-settings-test-fixture.js";
|
||||
import { settingsTaskPrompt } from "./agent-settings-evidence.js";
|
||||
import { ConnectionFailure } from "../connection-config.js";
|
||||
|
||||
const controls = vi.hoisted(() => ({ createTask: vi.fn(), openDocument: vi.fn() }));
|
||||
vi.mock("../user-actions.js", () => ({ createTaskThroughUi: controls.createTask }));
|
||||
@@ -113,7 +114,7 @@ async function fixture(nativeFailure = false, unscopedActivity = false, delayedR
|
||||
const session = { async own(resource: any) { owns.push(resource); } } as TargetSession;
|
||||
const evidence: JourneyEvidence = { outcome: "passed", startingState: "recipe", phases: [], checks: [], resourceDisposition: "retained", privacy: "private" };
|
||||
const directory = await mkdtemp(path.join(os.tmpdir(), "qa-settings-flow-")); directories.push(directory);
|
||||
return { context, session, evidence, directory, saves, savedPaths, selectedPaths, availablePaths, owns, apiWrites, activityReads, unrelatedActivity, original: f.original,
|
||||
return { context, session, evidence, directory, api, saves, savedPaths, selectedPaths, availablePaths, owns, apiWrites, activityReads, unrelatedActivity, original: f.original,
|
||||
currentContent: () => content, options: { directory, deadlineAt: Date.now() + 30000 } };
|
||||
}
|
||||
|
||||
@@ -146,6 +147,8 @@ describe("agent settings production-surface orchestration", () => {
|
||||
expect(artifact).not.toContain(f.original); expect(artifact).not.toContain("adapterConfig");
|
||||
expect(artifact).not.toContain("must-not-be-retained");
|
||||
const saved = JSON.parse(artifact); expect(saved.checks.every((row: any) => row.passed)).toBe(true);
|
||||
expect(saved.taskObservation).toEqual({ issueId: "task", runIds: ["run"],
|
||||
runs: [{ id: "run", status: "succeeded", nativePhase: "committed" }] });
|
||||
expect(saved.checkpoints.original.contentHash).toBe(saved.checkpoints.restored.contentHash);
|
||||
expect(saved.saveAudits).toEqual({ saved: { id: "save", companyId: "company", actorType: "user", actorId: "user",
|
||||
agentId: null, runId: null, action: "agent.files_updated", entityType: "agent", entityId: "agent", path: "AGENTS.md",
|
||||
@@ -174,7 +177,48 @@ describe("agent settings production-surface orchestration", () => {
|
||||
const f = await fixture(true);
|
||||
await expect(runAgentSettings(f.context, f.session, "campaign-1", f.evidence, f.options)).rejects.toThrow("agent_settings_native_run_failed");
|
||||
expect(f.saves).toHaveLength(1); expect(f.currentContent()).not.toBe(f.original);
|
||||
expect(JSON.parse(await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8")).checks.every((row: any) => row.passed)).toBe(false);
|
||||
const artifact = await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8");
|
||||
const saved = JSON.parse(artifact);
|
||||
expect(saved.issueId).toBe("task");
|
||||
expect(saved.runIds).toEqual(["run"]);
|
||||
expect(saved.taskObservation).toMatchObject({ issueId: "task", runs: [{ id: "run", status: "failed", nativePhase: "committed" }] });
|
||||
expect(saved.documentId).toBeNull();
|
||||
expect(saved.checks.every((row: any) => row.passed)).toBe(false);
|
||||
expect(artifact).not.toContain(f.original);
|
||||
expect(artifact).not.toContain("runnerProfileJson");
|
||||
expect(artifact).not.toContain("resultJson");
|
||||
expect(f.apiWrites).toEqual([]);
|
||||
});
|
||||
it("retains the requested run identity if its detail read fails without claiming a completed task", async () => {
|
||||
const f = await fixture();
|
||||
const get = f.api.get.bind(f.api);
|
||||
f.api.get = async route => {
|
||||
if (route === "/api/heartbeat-runs/run") throw new ConnectionFailure("api_status_403");
|
||||
return get(route);
|
||||
};
|
||||
await expect(runAgentSettings(f.context, f.session, "campaign-1", f.evidence, f.options)).rejects.toThrow("api_status_403");
|
||||
const saved = JSON.parse(await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8"));
|
||||
expect(saved.taskObservation).toEqual({ issueId: "task", runIds: ["run"], runs: [] });
|
||||
expect(saved.issueId).toBe("task"); expect(saved.runIds).toEqual(["run"]);
|
||||
expect(saved.documentId).toBeNull(); expect(saved.documentRevisionId).toBeNull();
|
||||
expect(saved.checks.filter((row: any) => row.passed).map((row: any) => row.id))
|
||||
.toEqual(["agent-settings-browser-save", "agent-settings-reload-persisted"]);
|
||||
expect(f.saves).toHaveLength(1); expect(f.apiWrites).toEqual([]);
|
||||
});
|
||||
it("keeps failure identity while excluding raw run data from the retained file", async () => {
|
||||
const f = await fixture(true);
|
||||
const get = f.api.get.bind(f.api);
|
||||
f.api.get = async route => {
|
||||
const value = await get(route);
|
||||
return route === "/api/heartbeat-runs/run" ? { ...value, error: "private-error-marker",
|
||||
stdoutExcerpt: "private-output-marker", contextSnapshot: { instructions: "private-instructions-marker" },
|
||||
resultJson: { privatePayload: "private-result-marker" } } : value;
|
||||
};
|
||||
await expect(runAgentSettings(f.context, f.session, "campaign-1", f.evidence, f.options)).rejects.toThrow("agent_settings_native_run_failed");
|
||||
const artifact = await readFile(path.join(f.directory, "agent-settings-observations.json"), "utf8");
|
||||
for (const marker of ["private-error-marker", "private-output-marker", "private-instructions-marker", "private-result-marker"])
|
||||
expect(artifact).not.toContain(marker);
|
||||
expect(JSON.parse(artifact).taskObservation.runs).toEqual([{ id: "run", status: "failed", nativePhase: "committed" }]);
|
||||
expect(f.saves).toHaveLength(1); expect(f.apiWrites).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -24,6 +24,7 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS
|
||||
agentId: agent.id, agentName: agent.name, provider: agent.provider, model: agent.model,
|
||||
environmentId: context.environmentId, reference: randomBytes(16).toString("hex") };
|
||||
const observations: AgentSettingsEvidence = {};
|
||||
let taskObservation: { issueId: string; runIds: string[]; runs: Array<{ id: string; status: string; nativePhase: string | null }> } | null = null;
|
||||
const read = createObservedReader(context.api, options.deadlineAt), agentRoute = `/api/agents/${agent.id}`;
|
||||
const agentRunsRoute = `/api/companies/${scope.companyId}/heartbeat-runs?agentId=${agent.id}&limit=100`;
|
||||
const activityRoute = `/api/companies/${scope.companyId}/activity?entityType=agent&entityId=${agent.id}&limit=200`;
|
||||
@@ -113,6 +114,7 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS
|
||||
const task = await createTaskThroughUi({ page: context.page, origin: context.api.origin, issuePrefix: context.company.issuePrefix,
|
||||
agentName: agent.name, title, prompt: settingsTaskPrompt, workMode: "standard", requireExplicitTitle: true,
|
||||
beforeDispatch: () => session.own({ kind: "issue", name: title, journeyId: id }) });
|
||||
taskObservation = { issueId: task.issueId, runIds: [], runs: [] };
|
||||
await session.own({ kind: "issue", name: title, id: task.issueId, journeyId: id });
|
||||
const route = `/api/issues/${task.issueId}`, documentRoute = `${route}/documents/${settingsDocumentKey}`;
|
||||
const state = await waitFor(options.deadlineAt, async () => {
|
||||
@@ -120,7 +122,14 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS
|
||||
read.get<Row>(route), read.get<Row[]>(`${route}/runs`), read.get<Row[]>(`${route}/interactions`),
|
||||
]);
|
||||
if (!Array.isArray(summaries) || summaries.length > 1 || !Array.isArray(interactions)) throw new JourneyError("failed", "agent_settings_run_coverage_mismatch");
|
||||
const runs = await Promise.all(summaries.map(row => read.get<Row>(`/api/heartbeat-runs/${row.runId}`)));
|
||||
const point = taskObservation!;
|
||||
point.runIds = summaries.map(row => row.runId);
|
||||
point.runs = [];
|
||||
const runs = await Promise.all(summaries.map(async row => {
|
||||
const run = await read.get<Row>(`/api/heartbeat-runs/${row.runId}`);
|
||||
point.runs.push({ id: row.runId, status: run.status, nativePhase: run.nativePhase ?? null });
|
||||
return run;
|
||||
}));
|
||||
if (runs.some(run => ["failed", "cancelled", "timed_out"].includes(run.status))) throw new JourneyError("failed", "agent_settings_native_run_failed");
|
||||
return { issue, runs, interactions };
|
||||
}, point => point.issue.status === "done" && point.runs.length === 1 && point.runs[0]!.status === "succeeded"
|
||||
@@ -163,7 +172,7 @@ export async function runAgentSettings(context: JourneyContext, session: TargetS
|
||||
independentlyComputedHash: typeof point.file.content === "string" ? instructionDigest(point.file.content) : null,
|
||||
revisionId: point.file.revision?.id ?? null, runIds: point.runs.map(row => row.id ?? row.runId) } : null];
|
||||
})),
|
||||
issueId: observations.task?.issue.id ?? null, runIds: observations.task?.runs.map(row => row.id) ?? [],
|
||||
issueId: taskObservation?.issueId ?? null, runIds: taskObservation?.runIds ?? [], taskObservation,
|
||||
documentId: observations.task?.document.id ?? null, documentRevisionId: observations.task?.revision.id ?? null,
|
||||
saveAudits: { saved: matchedBoardSaveAudit(observations.saved, observations.original, scope),
|
||||
restored: matchedBoardSaveAudit(observations.restored, observations.afterWork, scope) },
|
||||
|
||||
Reference in new issue
Block a user