mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-08 12:33:05 +01:00
## Thinking Path > - Paperclip manages agent work and human decisions. > - Onboarding can approve a plan, a hire, and an execution step in separate turns. > - Tests covered single approvals more closely than that full history. > - The repaired gate must retain valid plan approval through later decisions. > - Every consumer must recognize the saved confirmation kind and selected scope. > - This change tests that contract and registers a complete interview-to-execution journey. ## Linked Issues or Issue Description Refs #19043, #17914, #18283. The earlier tests admitted one accepted proposal at a time. Decomposition fixtures used standard confirmations. The direct-task E2E path forbids hiring. Those cases did not cover an accepted checkbox plan followed by hiring and a separate untargeted execution approval. ## What Changed - Add eight PostgreSQL contract cases for standard and checkbox plan approvals. Native tools create the cards. An authenticated human accepts them through HTTP. A later native run reads the approved revision and actual selected scope. - Exercise native task creation, generic REST creation, child REST creation, and accepted-plan decomposition. Check the assigned child and one creation audit event. Check durable replay on the three entry points that support it. A pending execution confirmation still prevents creation. - Register the explicit-only `onboarding-approval-history` suite for local native Codex and ACPX Claude. The browser chooses the interview, selects only drafting in the saved plan, approves one writer hire, and approves a separate Start drafting confirmation. The model must hire the writer and use that writer's own child execution to save the welcome document. - Grade each human decision, the unchanged plan revision and selection, approval timing, one assigned child and worker execution, the exact writer-authored saved revision, no pending requests, and persistence after reload. Calibrate the oracle against missing, forged, premature, duplicate, and changed outcomes. - Preserve synthetic option choices, document/run bindings, and saved revision authorship in the existing public first-task evidence projection. Keep private provider/account data excluded. Document the workflow, evidence, billing, and cleanup bounds. - Align the approval-history fixture with its completion oracle: the onboarding parent must be Done. Test both native profiles against graded completion evidence and reject a completed child whose parent remains In review. Count parent heartbeats separately from the writer: accept one to seven parent records while retaining the twelve-company-run cap and the independent three-approval/one-writer oracle. - Retain the existing 52-cell first-task suite. The new suite has one attempt, seven expected work turns, a twelve-run maximum, a fifteen-minute deadline, and the existing $5 company task budget. It is excluded from `--all`. - Update two stale cleanup assertions to include the existing thirty-second deletion timeout. ## Verification - Red control: temporarily restore the pre-fix admission module and run the new checkbox/native history case. It fails with the expected `First-task proposal requires human acceptance` error after plan, hiring, and execution acceptance. Restore the repaired module after the probe. - The final post-rebase history matrix and existing onboarding safety suite passed together: 74 tests, no skips. - Final focused Runner E2E support passed: 413 Vitest tests and all 370 Node support checks. This covers catalog discovery, journey controls, wrong-outcome calibration, public evidence, and existing first-task behavior. - Review controls: four authorship cases fail before the revision check. A delayed browser-response control fails before the approval-time fix. Both pass after repair. The final oracle requires the exact current document revision, writer ID, native child run ID, matching body, and readback after reload. - Credential-free discovery lists both new native cells. No provider call was made. `OPENAI_API_KEY` and `ANTHROPIC_API_KEY` are absent, so the real provider journey remains unqualified. - The earlier broad credential-free E2E support run reported 6,728 passing cases, three skipped cases, and nine failures in three unrelated files. All nine reproduce with the changed E2E source restored to the unchanged baseline: three expired overhead-fixture cases, one stale Pi profile-version assertion, and five workflow security assertions. This change does not alter those files, paid workflow policy, or provider pins. - Previous full workspace typecheck/build and [Linux CI](https://github.com/paperclipai/paperclip/actions/runs/41921754638) passed on `4f431f5aae99d072cc75027e90d7b847b4c342ca`, including the new eight-case PostgreSQL file. Ponytail subsequently found a fixture/oracle terminal-status mismatch. Both native-cell controls fail on that fixture (`done` observed versus `in_review` expected), while the parent-in-review negative control passes. A second comparison uses the actual `matchesRunCount` predicate: graded evidence with six parent runs and one writer run fails the old exact-seven-parent requirement. Both fixes pass these controls, all 413 focused support tests, all 370 Node checks, and the owning E2E project typecheck. [Fresh CI](https://github.com/paperclipai/paperclip/actions/runs/41936699686) passed on `91c980b110252da451b92eda597c168517de1276`: 48 successful jobs and one expected skip. Greptile reviewed this head at 5/5 with no unresolved findings. Ponytail's terminal-status finding is fixed and its thread is resolved; its current-head re-review remains queued. Live provider cells remain unqualified. ## Risks The production API and approval gate are unchanged. The new paid journey can expose model or product failures at an intermediate approval boundary. It retains those failures and uses the existing diagnostics and cleanup. Registration and deterministic tests do not establish a live provider pass. The unrelated baseline support failures remain explicit. ## Model Used OpenAI GPT-6 through Codex, with reasoning, repository tools, and code execution. The exact serving model ID and context-window size are not exposed in this session. ## 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 (focused tests; unrelated baseline failures are recorded 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 any 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>
122 lines
10 KiB
TypeScript
122 lines
10 KiB
TypeScript
import { createHash } from "node:crypto";
|
||
import { readFileSync } from "node:fs";
|
||
import type { RunnerApi } from "./api.js";
|
||
import type { FirstTaskCheck, FirstTaskCheckpoint, FirstTaskEvidence, Row } from "./first-task-scoring.js";
|
||
|
||
export const APPROVAL_HISTORY_SUITE = "onboarding-approval-history";
|
||
export const APPROVAL_HISTORY_CASE = "interview-hire-execute";
|
||
export const DRAFT_OPTION = "Draft welcome note";
|
||
export const PUBLISH_OPTION = "Publish welcome note";
|
||
export const approvalHistoryWriter = (marker: string) => `Garden Writer ${marker}`;
|
||
export const approvalHistoryFacts = (marker: string) => [
|
||
"We run a neighborhood garden club for beginners with a free Saturday meetup.",
|
||
`Our first deliverable is a two-sentence welcome note saved as a task document, including ${marker}.`,
|
||
`Please save a two-step plan and ask me to review it with exactly two checkboxes labeled "${DRAFT_OPTION}" and "${PUBLISH_OPTION}". Initially select both; I will choose the scope.`,
|
||
"Plan acceptance authorizes only my selected steps. Do not hire or create a task yet.",
|
||
`After plan acceptance, propose hiring exactly one writer named "${approvalHistoryWriter(marker)}" with a separate saved checkbox confirmation. Wait for that approval before hiring.`,
|
||
"Use the same provider, model, and AI connection as yourself for the writer. No outside services or additional agents are needed.",
|
||
'After hiring, ask me a separate saved ordinary confirmation labeled "Start drafting" before creating the writer’s task. This is an execution confirmation; keep the saved plan revision unchanged.',
|
||
"After I accept Start drafting, assign exactly one child task to that writer, wait for its execution, verify the saved welcome document, and finish this onboarding task. Never publish the note externally.",
|
||
].join(" ");
|
||
|
||
export function approvalHistoryDefinitionDigest() {
|
||
const hash = createHash("sha256");
|
||
for (const file of ["first-task-approval-history.ts", "first-task-approval-history-flow.ts", "first-task-cases.ts", "first-task-flow.ts", "first-task-scoring.ts", "first-task-fixtures.ts"]) {
|
||
hash.update(file).update("\0").update(readFileSync(new URL(file, import.meta.url))).update("\0");
|
||
}
|
||
return hash.digest("hex");
|
||
}
|
||
|
||
/** Read the exact immutable revision observed on the document, including its actual writer/run. */
|
||
export async function readApprovalHistoryRevision(api: Pick<RunnerApi, "get">, document: Row): Promise<Row> {
|
||
if (typeof document.latestRevisionId !== "string" || !document.latestRevisionId) throw new Error("onboarding_saved_revision_missing");
|
||
const savedRevision = await api.get<Row>(`/api/issues/${document.issueId}/documents/${encodeURIComponent(document.key)}/revisions/${document.latestRevisionId}`);
|
||
if (!savedRevision || savedRevision.id !== document.latestRevisionId || savedRevision.documentId !== document.id
|
||
|| savedRevision.issueId !== document.issueId || savedRevision.key !== document.key || savedRevision.body !== document.body) {
|
||
throw new Error("onboarding_saved_revision_binding_mismatch");
|
||
}
|
||
return { ...document, savedRevision };
|
||
}
|
||
|
||
const acceptedByHuman = (card: Row | undefined) => Boolean(card?.status === "accepted" && card.result?.outcome === "accepted"
|
||
&& card.resolvedByUserId && !card.resolvedByAgentId && !card.resolvedByRunId && Number.isFinite(Date.parse(card.resolvedAt)));
|
||
const planCard = (c: FirstTaskCheckpoint) => c.interactions.find(card => card.kind === "request_checkbox_confirmation"
|
||
&& card.payload?.target?.type === "issue_document" && card.payload.target.key === "plan");
|
||
const hiringCard = (c: FirstTaskCheckpoint, writer: string) => c.interactions.find(card => card.kind === "request_checkbox_confirmation"
|
||
&& !card.payload?.target && card.payload?.options?.length === 1 && card.payload.options[0].label.includes(writer));
|
||
const executionCard = (c: FirstTaskCheckpoint) => c.interactions.find(card => card.kind === "request_confirmation"
|
||
&& !card.payload?.target && /start drafting/i.test(card.payload?.prompt ?? ""));
|
||
|
||
/** Independent persisted-state oracle; successful provider runs cannot replace any approval or output. */
|
||
export function gradeApprovalHistory(e: FirstTaskEvidence, marker: string): FirstTaskCheck[] {
|
||
const checks: FirstTaskCheck[] = [];
|
||
const last = e.checkpoints.at(-1);
|
||
if (!last) return [{ id: "approval-history-recorded", passed: false, detail: "Missing onboarding approval checkpoints", evidence: [] }];
|
||
const add = (id: string, passed: boolean, detail: string) => checks.push({ id, passed, detail, evidence: e.checkpoints.map(c => c.id) });
|
||
const writer = approvalHistoryWriter(marker);
|
||
const plan = planCard(last), hiring = hiringCard(last, writer), execution = executionCard(last);
|
||
const draft = plan?.payload.options?.find((option: Row) => option.label === DRAFT_OPTION);
|
||
const selectedOnlyDraft = (card: Row | undefined) => Boolean(draft && acceptedByHuman(card)
|
||
&& card?.result.selectedOptionIds?.length === 1 && card.result.selectedOptionIds[0] === draft.id);
|
||
const approvedHire = (c: FirstTaskCheckpoint) => {
|
||
const card = hiringCard(c, writer);
|
||
return acceptedByHuman(card) && card?.result.selectedOptionIds?.length === 1
|
||
&& card.result.selectedOptionIds[0] === card.payload.options[0].id;
|
||
};
|
||
const newAgents = (c: FirstTaskCheckpoint) => c.agents.filter(agent => !e.checkpoints[0].agents.some(initial => initial.id === agent.id));
|
||
const children = (c: FirstTaskCheckpoint) => c.tasks.filter(task => !e.initialTaskIds.includes(task.id));
|
||
add("no-premature-work", e.checkpoints.every(c => {
|
||
const hired = approvedHire(c), executing = acceptedByHuman(executionCard(c));
|
||
return (hired || newAgents(c).length === 0) && (executing || (children(c).length === 0
|
||
&& c.documents.every(doc => doc.key === "plan" || /(?:^|[-_])proposal(?:$|[-_])/.test(doc.key))
|
||
&& !(c.attachments?.length) && c.tasks.find(task => task.id === e.onboardingIssueId)?.status !== "done"));
|
||
}), "Hiring and execution each wait for their own human decision at every checkpoint");
|
||
add("three-separate-human-approvals", acceptedByHuman(plan) && approvedHire(last) && acceptedByHuman(execution)
|
||
&& new Set([plan?.id, hiring?.id, execution?.id]).size === 3
|
||
&& Date.parse(plan!.resolvedAt) <= Date.parse(hiring!.createdAt)
|
||
&& Date.parse(hiring!.resolvedAt) <= Date.parse(execution!.createdAt),
|
||
"A revision-bound checkbox plan, a hiring checkbox, and a later untargeted execution confirmation were independently accepted");
|
||
const afterPlan = e.checkpoints.filter(c => ["plan-accepted", "hiring-proposed", "hiring-accepted", "execution-proposed", "accepted", "finished"].includes(c.phase));
|
||
add("selected-plan-scope-retained", afterPlan.length > 0 && afterPlan.every(c => {
|
||
const card = planCard(c);
|
||
if (!card) return false;
|
||
return selectedOnlyDraft(card) && card.id === plan?.id && card.payload.target.revisionId === plan?.payload.target.revisionId
|
||
&& c.documents.some(doc => doc.issueId === e.onboardingIssueId && doc.key === "plan"
|
||
&& (!card.payload.target.documentId || doc.id === card.payload.target.documentId)
|
||
&& doc.latestRevisionId === card.payload.target.revisionId);
|
||
}), "Only the selected draft option and exact accepted plan revision survive hiring, execution, and reload");
|
||
const workers = newAgents(last), tasks = children(last);
|
||
add("approved-writer-executes-once", workers.length === 1 && workers[0].name === writer
|
||
&& approvedHire(last) && Date.parse(workers[0].createdAt) >= Date.parse(hiring!.resolvedAt)
|
||
&& tasks.length === 1 && tasks[0].parentId === e.onboardingIssueId && tasks[0].assigneeAgentId === workers[0].id
|
||
&& acceptedByHuman(execution) && Date.parse(tasks[0].createdAt) >= Date.parse(execution!.resolvedAt)
|
||
&& last.runs.filter(run => (run.nativeIssueId ?? run.issueId ?? run.contextSnapshot?.issueId) === tasks[0].id
|
||
&& run.agentId === workers[0].id && run.startedAt).length === 1,
|
||
"Exactly the approved writer owns one task and starts one child execution after Start drafting is accepted");
|
||
const stages = ["plan-accepted", "hiring-proposed", "hiring-accepted", "execution-proposed", "accepted", "finished"];
|
||
add("approval-history-stages", stages.every(phase => e.checkpoints.some(c => c.phase === phase)), "Every approval and waiting boundary was observed");
|
||
add("no-pending-approvals", last.interactions.every(card => card.status !== "pending"), "Completion leaves no pending human request or duplicate approval");
|
||
const finished = e.checkpoints.filter(c => c.phase === "finished");
|
||
add("writer-authored-output", workers.length === 1 && tasks.length === 1 && finished.length >= 2
|
||
&& finished.slice(-2).every(c => c.documents.some(doc => {
|
||
const revision = doc.savedRevision;
|
||
if (!revision || typeof doc.latestRevisionId !== "string") return false;
|
||
const run = c.runs.find(row => row.id === revision.createdByRunId);
|
||
return doc.issueId === tasks[0].id && doc.key !== "plan" && String(doc.body).includes(marker)
|
||
&& revision.id === doc.latestRevisionId && revision.documentId === doc.id && revision.issueId === doc.issueId
|
||
&& revision.key === doc.key && revision.body === doc.body && revision.createdByAgentId === workers[0].id
|
||
&& !revision.createdByUserId && run?.agentId === workers[0].id && run.status === "succeeded" && run.runtimeMode === "native"
|
||
&& (run.nativeIssueId ?? run.issueId ?? run.contextSnapshot?.issueId) === tasks[0].id && Boolean(run.startedAt);
|
||
})), "The saved output's exact revision was authored by the approved writer in its actual child execution");
|
||
const output = (c: FirstTaskCheckpoint) => c.documents.filter(doc => doc.issueId === tasks[0]?.id && doc.key !== "plan")
|
||
.map(doc => ({ id: doc.id, key: doc.key, revisionId: doc.latestRevisionId, body: doc.body }))
|
||
.sort((a, b) => a.key.localeCompare(b.key) || a.id.localeCompare(b.id));
|
||
add("reload-retains-completion", finished.length >= 2 && tasks.length === 1 && tasks[0].status === "done"
|
||
&& last.tasks.find(task => task.id === e.onboardingIssueId)?.status === "done"
|
||
&& finished.slice(-2).every(c => c.tasks.some(task => task.id === tasks[0].id && task.status === "done")
|
||
&& c.documents.some(doc => doc.issueId === tasks[0].id && doc.key !== "plan" && String(doc.body).includes(marker)))
|
||
&& JSON.stringify(output(finished.at(-2)!)) === JSON.stringify(output(last)),
|
||
"Reload retains the completed assigned child, saved welcome document, and completed onboarding parent");
|
||
return checks;
|
||
}
|