Skip to content

The open-source app everyone uses to manage agents at work

fix(skills): honor the current run harness checkout (#15548)

Dotta71cd0a262161
diff --git a/packages/adapter-utils/src/server-utils.test.ts b/packages/adapter-utils/src/server-utils.test.ts
index 3b6a5ab0af..068486bc9f 100644
--- a/packages/adapter-utils/src/server-utils.test.ts
+++ b/packages/adapter-utils/src/server-utils.test.ts
@@ -935,6 +935,20 @@ describe("runChildProcess", () => {
});
describe("renderPaperclipWakePrompt", () => {
+ it.each([false, true])("renders the runtime checkout flag for ordinary task wakes (resume=%s)", resumedSession => {
+ const payload = { reason: "issue_assigned", issue: { id: "issue-1", status: "in_progress" },
+ comments: [], commentWindow: { requestedCount: 0, includedCount: 0, missingCount: 0 },
+ fallbackFetchNeeded: false };
+ const claimed = renderPaperclipWakePrompt({ ...payload, checkedOutByHarness: true }, { resumedSession });
+ expect(claimed).toContain(resumedSession ? "checkout: already claimed by the harness for this run" :
+ "The harness already checked out this issue for the current run.");
+ for (const checkedOutByHarness of [false, undefined]) {
+ const unclaimed = renderPaperclipWakePrompt({ ...payload, checkedOutByHarness }, { resumedSession });
+ expect(unclaimed).not.toContain("checkout: already claimed");
+ expect(unclaimed).not.toContain("The harness already checked out this issue for the current run.");
+ }
+ });
+
it("leaves conversation disposition and accepted-plan handoff to the injected chat policy", () => {
const payload = {
reason: "issue_commented",
diff --git a/server/src/__tests__/heartbeat-auto-checkout.test.ts b/server/src/__tests__/heartbeat-auto-checkout.test.ts
index 51edb14dc3..035d1456ae 100644
--- a/server/src/__tests__/heartbeat-auto-checkout.test.ts
+++ b/server/src/__tests__/heartbeat-auto-checkout.test.ts
@@ -4,6 +4,19 @@ import {
} from "../services/heartbeat.ts";
describe("shouldAutoCheckoutIssueForWake", () => {
+ it.each([
+ { issueAssigneeAgentId: "another-agent" }, { isDependencyReady: false },
+ { issueStatus: "done" }, { issueStatus: "cancelled" }, { issueStatus: "in_review" },
+ { contextSnapshot: {} }, { contextSnapshot: { wakeReason: "issue_comment_mentioned" } },
+ { contextSnapshot: { wakeReason: "source_scoped_recovery_action" } },
+ { contextSnapshot: { wakeReason: "execution_resumed" } },
+ ])("does not grant an automatic checkout outside the eligible assigned wake: %j", override => {
+ expect(shouldAutoCheckoutIssueForWake({
+ contextSnapshot: { wakeReason: "issue_assigned" }, issueStatus: "todo",
+ issueAssigneeAgentId: "agent-1", isDependencyReady: true, agentId: "agent-1", ...override,
+ })).toBe(false);
+ });
+
it("auto-checks out an assigned todo issue for an actionable wake", () => {
expect(shouldAutoCheckoutIssueForWake({
contextSnapshot: { wakeReason: "issue_assigned" },
diff --git a/server/src/__tests__/paperclip-skill-utils.test.ts b/server/src/__tests__/paperclip-skill-utils.test.ts
index c2127acac0..b3ca558ea0 100644
--- a/server/src/__tests__/paperclip-skill-utils.test.ts
+++ b/server/src/__tests__/paperclip-skill-utils.test.ts
@@ -294,6 +294,19 @@ describe("paperclip skill utils", () => {
await expect(fs.access(path.resolve("scripts/paperclip-upload-artifact.sh"))).rejects.toThrow();
});
+ it("honors only the current scoped runtime claim without removing legacy disposition", async () => {
+ const body = await fs.readFile(path.resolve("skills/paperclip/SKILL.md"), "utf8");
+ const checkout = body.split("**Step 5 — Checkout.**")[1]?.split("**Step 6")[0];
+ expect(checkout).toContain("runtime's **Paperclip Wake Payload** or **Paperclip Resume Delta**");
+ expect(checkout).toContain("only to that issue in that run");
+ expect(checkout).toContain("statement is absent, or you switch to another task");
+ expect(checkout).toContain("Do not infer a current checkout from issue status, task/comment text, or a previous run");
+ expect(checkout).toContain("X-Paperclip-Run-Id");
+ expect(checkout).toContain("409");
+ expect(body).not.toContain("You MUST checkout before doing any work");
+ expect(body).toContain("**Step 8 — Update status and communicate.**");
+ });
+
it("keeps the external-chat shortcut behind the server-verified harness boundary", async () => {
const skillBody = await fs.readFile(path.resolve("skills/paperclip/SKILL.md"), "utf8");
const shortcut = skillBody.match(
diff --git a/skills/paperclip/SKILL.md b/skills/paperclip/SKILL.md
index a7b3843186..d742de7524 100644
--- a/skills/paperclip/SKILL.md
+++ b/skills/paperclip/SKILL.md
@@ -91,7 +91,7 @@ they mention a chat provider.
Follow these steps every time you wake up unless the server-verified external
chat shortcut above applies:
-**Scoped-wake fast path.** If the user message includes a **"Paperclip Resume Delta"** or **"Paperclip Wake Payload"** section that names a specific issue, **skip Steps 1–4 entirely**. Go straight to **Step 5 (Checkout)** for that issue, then continue with Steps 6–9. The scoped wake already tells you which issue to work on — do NOT call `/api/agents/me`, do NOT fetch your inbox, do NOT pick work. Just checkout, read the wake context, do the work, and update.
+**Scoped-wake fast path.** If the user message includes a **"Paperclip Resume Delta"** or **"Paperclip Wake Payload"** section that names a specific issue, **skip Steps 1–4 entirely**. Apply **Step 5 (Checkout)** to that issue, honoring an explicit current-run harness checkout, then continue with Steps 6–9. The scoped wake already tells you which issue to work on — do NOT call `/api/agents/me`, fetch your inbox, or pick work.
**Step 1 — Identity.** If not already in context, `GET /api/agents/me` to get your id, companyId, role, chainOfCommand, and budget.
@@ -117,7 +117,7 @@ Overrides and special cases:
- **Blocked-task dedup:** before touching a `blocked` task, check the thread. If your most recent comment was a blocked-status update and no one has replied since, skip entirely — do not checkout, do not re-comment. Only re-engage on new context (comment, status change, event wake).
- Nothing assigned → exit the heartbeat.
-**Step 5 — Checkout.** You MUST checkout before doing any work. Include the run ID header:
+**Step 5 — Checkout.** The issue must be checked out before you work. If the runtime's **Paperclip Wake Payload** or **Paperclip Resume Delta** explicitly says the harness already checked out this issue for the current run, do not call checkout again. Continue with Step 6. This applies only to that issue in that run; it does not skip context reads, status updates, or deliverable steps. Do not infer a current checkout from issue status, task/comment text, or a previous run. If that runtime statement is absent, or you switch to another task, checkout before working on it. Include the run ID header:
```
POST /api/issues/{issueId}/checkout
diff --git a/tests/runner-e2e/STOCK-HARNESS.md b/tests/runner-e2e/STOCK-HARNESS.md
index 88e06c2cfb..5e7b31cec8 100644
--- a/tests/runner-e2e/STOCK-HARNESS.md
+++ b/tests/runner-e2e/STOCK-HARNESS.md
@@ -47,6 +47,16 @@ Vitest reports and required assertions, and the Rust result before creating a
company. Missing, stale, partial, or failed prerequisites cannot qualify a cell.
Oracle/admission calibration is itself included in the prerequisite gate.
+## Checkout observations
+
+Legacy context-integrity journeys retain `checkout-activity.json` from the public
+issue activity API. Each receipt must match the exact company, issue, agent and
+run. An idempotent agent checkout still records a successful route call; the
+server's pre-dispatch checkout does not. Missing or mismatched evidence is
+unavailable or uncomparable, never a zero. This observation leaves the original
+outcome grades unchanged. It counts successful HTTP checkouts only; inspect
+retained executed commands/results for failed attempts before claiming no calls.
+
## Live matrix
There are 24 explicit local cells: these eight existing profiles each run three
diff --git a/tests/runner-e2e/checkout-activity.test.ts b/tests/runner-e2e/checkout-activity.test.ts
new file mode 100644
index 0000000000..61d6273e39
--- /dev/null
+++ b/tests/runner-e2e/checkout-activity.test.ts
@@ -0,0 +1,35 @@
+import { describe, expect, it } from "vitest";
+import { observeCheckoutActivity } from "./checkout-activity.js";
+
+const run = { id: "run", companyId: "company", agentId: "agent", status: "succeeded",
+ contextSnapshot: { issueId: "issue", paperclipWake: { checkedOutByHarness: true } } };
+const receipt = { id: "receipt", companyId: "company", agentId: "agent", actorType: "agent",
+ entityType: "issue", entityId: "issue", action: "issue.checked_out", runId: "run" };
+const input = { companyId: "company", issueId: "issue", agentId: "agent", runs: [run], activity: [] };
+describe("checkout activity observation", () => {
+ it("distinguishes a runtime claim from repeated successful HTTP checkout calls", () => {
+ expect(observeCheckoutActivity(input)).toMatchObject({ status: "observed", successfulCheckoutRequests: 0,
+ runs: [{ checkedOutByHarness: true, successfulCheckoutRequests: 0 }] });
+ expect(observeCheckoutActivity({ ...input, activity: [receipt, { ...receipt, id: "second" }] }))
+ .toMatchObject({ status: "observed", successfulCheckoutRequests: 2 });
+ });
+ it.each([
+ { runId: "another-run" }, { companyId: "foreign" }, { entityId: "other-task" },
+ { agentId: "other-agent" }, { actorType: "user" }, { id: null },
+ ])("does not count unattributed or foreign receipt %j as a comparable zero", mutation => {
+ expect(observeCheckoutActivity({ ...input, activity: [{ ...receipt, ...mutation }] }))
+ .toMatchObject({ status: "uncomparable", successfulCheckoutRequests: null });
+ });
+ it("refuses missing, mismatched and duplicate run/receipt identities", () => {
+ for (const data of [
+ { ...input, runs: [] }, { ...input, runs: [run, run] },
+ { ...input, runs: [{ ...run, agentId: "other" }] },
+ { ...input, runs: [{ ...run, contextSnapshot: { issueId: "other" } }] },
+ { ...input, activity: [receipt, receipt] },
+ ]) expect(observeCheckoutActivity(data)).toMatchObject({ status: "uncomparable", successfulCheckoutRequests: null });
+ });
+ it("does not infer a harness claim from status or task text", () => {
+ expect(observeCheckoutActivity({ ...input, runs: [{ ...run, contextSnapshot: { issueId: "issue" } }] }))
+ .toMatchObject({ runs: [{ checkedOutByHarness: false }] });
+ });
+});
diff --git a/tests/runner-e2e/checkout-activity.ts b/tests/runner-e2e/checkout-activity.ts
new file mode 100644
index 0000000000..3411485abb
--- /dev/null
+++ b/tests/runner-e2e/checkout-activity.ts
@@ -0,0 +1,36 @@
+type Row = Record<string, any>;
+
+/** Observation only. Activity counts successful route calls, not failed attempts. */
+export function observeCheckoutActivity(input: {
+ companyId: string; issueId: string; agentId: string;
+ runs: Row[]; activity: Row[];
+}) {
+ const runIds = new Set(input.runs.map(run => run.id));
+ const boundRuns = input.runs.length > 0 && runIds.size === input.runs.length &&
+ input.runs.every(run => typeof run.id === "string" && Boolean(run.id) &&
+ run.companyId === input.companyId && run.agentId === input.agentId &&
+ run.contextSnapshot?.issueId === input.issueId);
+ const rows = input.activity.filter(row => row.action === "issue.checked_out");
+ const validRows = rows.every(row => typeof row.id === "string" && Boolean(row.id) &&
+ row.companyId === input.companyId && row.entityType === "issue" &&
+ row.entityId === input.issueId && row.actorType === "agent" &&
+ row.agentId === input.agentId && runIds.has(row.runId));
+ const uniqueRows = new Set(rows.map(row => row.id)).size === rows.length;
+ const complete = boundRuns && validRows && uniqueRows;
+ return {
+ schema: "paperclip.checkout-activity.v1",
+ status: complete ? "observed" : "uncomparable",
+ companyId: input.companyId, issueId: input.issueId, agentId: input.agentId,
+ scope: "successful checkout HTTP calls only; failed attempts require run-log inspection",
+ successfulCheckoutRequests: complete ? rows.length : null,
+ runs: input.runs.map(run => ({
+ runId: run.id, status: run.status,
+ checkedOutByHarness: run.contextSnapshot?.paperclipWake?.checkedOutByHarness === true,
+ successfulCheckoutRequests: complete ? rows.filter(row => row.runId === run.id).length : null,
+ })),
+ receipts: rows.map(row => ({
+ id: row.id, runId: row.runId, companyId: row.companyId,
+ issueId: row.entityId, agentId: row.agentId, actorType: row.actorType,
+ })),
+ };
+}
diff --git a/tests/runner-e2e/context-integrity-flow.ts b/tests/runner-e2e/context-integrity-flow.ts
index 1fe6a9d4c3..77a0e2363b 100644
--- a/tests/runner-e2e/context-integrity-flow.ts
+++ b/tests/runner-e2e/context-integrity-flow.ts
@@ -1,3 +1,4 @@
+import { observeCheckoutActivity } from "./checkout-activity.js";
import type { Page } from "@playwright/test";
import { randomUUID } from "node:crypto";
import { contextIntegrityScenario, isAssignedSkillContext } from "./context-integrity-cases.js";
@@ -221,6 +222,21 @@ export async function runContextIntegrityFlow(input: {
await snapshot("initial");
}
await snapshot("final");
+ if (execution.suite.id === "stock-harness" && execution.profile.generation === "legacy") {
+ // Successful checkout HTTP calls emit activity even for an idempotent
+ // same-run claim. Server pre-dispatch checkout does not use that route.
+ // Keep this observation separate from the unchanged task-outcome oracle.
+ let checkoutActivity: unknown;
+ try {
+ checkoutActivity = observeCheckoutActivity({
+ companyId: fixtures.company.id, issueId: issue.id, agentId: fixtures.agent.id,
+ runs, activity: await api.get<Row[]>(`/api/issues/${issue.id}/activity`),
+ });
+ } catch {
+ checkoutActivity = { schema: "paperclip.checkout-activity.v1", status: "unavailable" };
+ }
+ await input.evidence("checkout-activity.json", checkoutActivity);
+ }
const checks = gradeContextIntegrity({ id: scenario.id, marker: scenario.marker, comments: scenario.comments, checkpoints });
const failures = checks.filter((check) => !check.passed);
if (failures.length) throw new Error(`Context-integrity matcher failures: ${failures.map((failure) => `${failure.id}: ${failure.detail}`).join("; ")}`);
diff --git a/tests/runner-e2e/stock-harness-checks.mjs b/tests/runner-e2e/stock-harness-checks.mjs
index 949593873f..9b6c4e975f 100644
--- a/tests/runner-e2e/stock-harness-checks.mjs
+++ b/tests/runner-e2e/stock-harness-checks.mjs
@@ -45,9 +45,9 @@ export const stockHarnessGates = [
{ id: "SH-eval", name: "Independent oracle and qualification admission", cwd: ".",
config: "tests/runner-e2e/vitest.config.ts",
files: ["tests/runner-e2e/stock-harness-manifest.test.ts", "tests/runner-e2e/paperclip-document.test.ts", "tests/runner-e2e/stock-harness.test.ts", "tests/runner-e2e/stock-harness-checks.test.mjs",
- "tests/runner-e2e/stock-harness-admission.test.ts", "tests/runner-e2e/stock-harness-digest.test.ts",
+ "tests/runner-e2e/stock-harness-admission.test.ts", "tests/runner-e2e/stock-harness-digest.test.ts", "tests/runner-e2e/checkout-activity.test.ts",
"tests/runner-e2e/select-rerun-artifacts.test.ts", "tests/runner-e2e/stock-harness-instruction-variant.test.mjs", "tests/runner-e2e/automatic-retry.test.ts"],
- required: ["requires generated capability manifests for the current skill sources", "the shipped recipe delivers the current", "the shipped recipe supports an unnumbered issue", "rejects old SHA before providers", "allows toolchain paths and excludes every present or future credential",
+ required: ["distinguishes a runtime claim from repeated successful HTTP checkout calls", "refuses missing, mismatched and duplicate run/receipt identities", "requires generated capability manifests for the current skill sources", "the shipped recipe delivers the current", "the shipped recipe supports an unnumbered issue", "rejects old SHA before providers", "allows toolchain paths and excludes every present or future credential",
"changes when the evaluated server/src/onboarding-assets/default/AGENTS.md changes",
"changes when the evaluated packages/adapter-utils/src/server-utils.ts changes",
"changes when the evaluated packages/shared/src/connection-intent-guidance.ts changes",
@@ -85,7 +85,7 @@ export function sourceFingerprint() {
const hash = createHash("sha256");
const sources = new Set([
...stockHarnessGates.flatMap(gate => gate.files.map(file => join(gate.cwd, file))),
- "tests/runner-e2e/stock-harness.ts", "tests/runner-e2e/stock-harness-checks.mjs", "tests/runner-e2e/catalog.ts",
+ "tests/runner-e2e/stock-harness.ts", "tests/runner-e2e/checkout-activity.ts", "tests/runner-e2e/stock-harness-checks.mjs", "tests/runner-e2e/catalog.ts",
"tests/runner-e2e/stock-harness-admission.ts", "tests/runner-e2e/launch.ts", "tests/runner-e2e/runner.spec.ts",
"tests/runner-e2e/stock-harness-instruction-variant.mjs", "tests/runner-e2e/stock-harness-instruction-variant.d.mts", "tests/runner-e2e/fixtures/stock-harness/historical-default-agents.md",
"tests/runner-e2e/automatic-retry.ts", "tests/runner-e2e/types.ts",
diff --git a/tests/runner-e2e/stock-harness-digest.test.ts b/tests/runner-e2e/stock-harness-digest.test.ts
index 6fbfd3597a..3f7a4a0810 100644
--- a/tests/runner-e2e/stock-harness-digest.test.ts
+++ b/tests/runner-e2e/stock-harness-digest.test.ts
@@ -1,11 +1,23 @@
import { describe, expect, it, vi } from "vitest";
import { readFileSync } from "node:fs";
+import { sourceFingerprint } from "./stock-harness-checks.mjs";
import { stockHarnessSourceDigest, stockHarnessSkillSources } from "./stock-harness.js";
vi.mock("node:fs", async importOriginal => ({ ...await importOriginal<typeof import("node:fs")>(), readFileSync: vi.fn() }));
describe("stock harness instruction revision", () => {
- it.each(["server/src/onboarding-assets/default/AGENTS.md", "packages/adapter-utils/src/server-utils.ts", "packages/shared/src/connection-intent-guidance.ts", "skills/paperclip/SKILL.md", "skills/paperclip/references/issue-documents.md", "packages/paperclip-runner/generated/capability/capabilities.yaml", "packages/paperclip-runner/spec/capability/capabilities.yaml", "tests/runner-e2e/stock-harness-manifest.ts", "packages/adapter-utils/src/acpx-engine/execute.ts", "packages/adapter-utils/src/acpx-engine/ephemeral-session-environment.ts", "tests/runner-e2e/stock-harness-instruction-variant.mjs", "tests/runner-e2e/automatic-retry.ts", "tests/runner-e2e/catalog.ts"])(
+ it("invalidates the prerequisite fingerprint when checkout observation changes", () => {
+ vi.mocked(readFileSync).mockImplementation(() => Buffer.from("unchanged"));
+ const original = sourceFingerprint();
+ vi.mocked(readFileSync).mockImplementation(file => Buffer.from(
+ String(file).endsWith("tests/runner-e2e/checkout-activity.ts") ? "changed accounting" : "unchanged"));
+ const changed = sourceFingerprint();
+ expect(original.sourceErrors).toEqual([]);
+ expect(changed.sourceErrors).toEqual([]);
+ expect(changed.fingerprint).not.toBe(original.fingerprint);
+ });
+
+ it.each(["tests/runner-e2e/checkout-activity.ts", "server/src/onboarding-assets/default/AGENTS.md", "packages/adapter-utils/src/server-utils.ts", "packages/shared/src/connection-intent-guidance.ts", "skills/paperclip/SKILL.md", "skills/paperclip/references/issue-documents.md", "packages/paperclip-runner/generated/capability/capabilities.yaml", "packages/paperclip-runner/spec/capability/capabilities.yaml", "tests/runner-e2e/stock-harness-manifest.ts", "packages/adapter-utils/src/acpx-engine/execute.ts", "packages/adapter-utils/src/acpx-engine/ephemeral-session-environment.ts", "tests/runner-e2e/stock-harness-instruction-variant.mjs", "tests/runner-e2e/automatic-retry.ts", "tests/runner-e2e/catalog.ts"])(
"changes when the evaluated %s changes", source => {
vi.mocked(readFileSync).mockImplementation(() => Buffer.from("unchanged"));
const original = stockHarnessSourceDigest();
diff --git a/tests/runner-e2e/stock-harness.ts b/tests/runner-e2e/stock-harness.ts
index 7e7fd1dac1..f4830cf077 100644
--- a/tests/runner-e2e/stock-harness.ts
+++ b/tests/runner-e2e/stock-harness.ts
@@ -155,7 +155,7 @@ export async function captureStockHarness(input: {
export function stockHarnessSourceDigest() {
const hash = createHash("sha256");
for (const source of [
- "stock-harness.ts", "context-integrity-cases.ts", "context-integrity-scoring.ts",
+ "stock-harness.ts", "checkout-activity.ts", "context-integrity-cases.ts", "context-integrity-scoring.ts",
"context-integrity-flow.ts", "chat-cases.ts", "chat-flow.ts", "live-fixtures.ts", "runner.spec.ts",
"stock-harness-checks.mjs", "stock-harness-admission.ts", "stock-harness-manifest.ts",
"stock-harness-instruction-variant.mjs", "stock-harness-instruction-variant.d.mts", "stock-harness-instruction-variant.test.mjs",