Files
PaperClipAI/tests/runner-e2e/operating-overhead.test.ts
T
DottaandClaude Opus 5.5 7e6d882558 fix(runner-e2e): require Daytona image lock digest; name expired overhead allowance (#19467)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Runner qualification uses a Daytona runner image and a nightly
Runner Full-Stack E2E workflow
> - The nightly workflow fails at "Validate catalog and select cells",
and a local image build fails at `sha256sum -c`
> - Operators cannot build a current Daytona image for restart tests
until both failures are understood
> - This pull request removes a stale Dockerfile lock digest default,
fixes the local recipes, and makes the nightly failure name its real
cause
> - The benefit is that a local build fails clearly when the digest is
missing, and an expired overhead allowance is obvious from the log

## Linked Issues or Issue Description

**What happened?**
1. The nightly `Runner Full-Stack E2E` runs 41997383733 and 42190298486
fail in "Validate catalog and select cells". The log shows
`digest-mismatch: error`, but that line is only the input list of
`actions/download-artifact`. The real error is `Operating overhead
allowance needs review before paid admission`. The repository variable
`RUNNER_E2E_OPERATING_OVERHEAD_JSON` has `expiresAt:
2026-11-03T19:49:53Z`. `scheduledOperatingOverhead` rejects an allowance
that expires within 4 hours. Manual dispatch (run 42046147744) does not
use the scheduled overhead path, so it passed this job.
2. `docker/daytona-runner/Dockerfile` set `ARG
PAPERCLIP_RUNNER_LOCK_SHA256=342a01e4…`. That value went stale when
`pnpm-lock.yaml` changed (#19443). The local recipes in
`tests/runner-e2e/README.md` and `docker/daytona-runner/README.md` did
not pass the argument, so local builds failed with a confusing checksum
mismatch.

**Expected behavior**
A local build computes and passes the lockfile digest. A missing digest
fails by name. An expired overhead allowance tells the operator which
allowance expired and which variable to renew.

**Steps to reproduce**
1. Run `gh run view 42190298486 --log` and read the "Validate catalog
and select cells" job.
2. Follow the old "## Daytona image" recipe in
`tests/runner-e2e/README.md` on current master.

## What Changed

- `docker/daytona-runner/Dockerfile`: remove the fixed
`PAPERCLIP_RUNNER_LOCK_SHA256` default. Reject a missing or non-SHA-256
value by name before `sha256sum -c` and before installation. CI already
passes the real value.
- `tests/runner-e2e/README.md` and `docker/daytona-runner/README.md`:
compute `shasum -a 256 pnpm-lock.yaml` and pass
`PAPERCLIP_RUNNER_LOCK_SHA256` in the local build recipes. Replace the
text about a "fixed Dockerfile default".
- `tests/runner-e2e/daytona-image.test.ts`: new test. It requires a
default-free `ARG`, the shape check before the checksum, and the
argument in every documented local recipe.
- `tests/runner-e2e/operating-overhead.ts`: the scheduled admission
error now names the allowance reference, its validity window, the 4-hour
margin, and `RUNNER_E2E_OPERATING_OVERHEAD_JSON`. The check itself is
unchanged.

## Verification

- `node node_modules/vitest/vitest.mjs run --config
tests/runner-e2e/vitest.config.ts
tests/runner-e2e/operating-overhead.test.ts
tests/runner-e2e/daytona-image.test.ts
tests/runner-e2e/scheduled-operations.test.ts
tests/runner-e2e/cost-ledger.test.ts`: 55 passed.
- `pnpm test:e2e:runner:typecheck`: passed.
- `pnpm verify`: exit 2 (README is a global CI input). Required CI
supplies broad coverage.
- `tests/runner-e2e/workflow-security.test.ts` has 5 local failures on
files that this PR does not touch (`pr-trusted.yml`,
`chat-catalog-testops-case.yml`). They are not caused by this change.
- I did not run a Docker build or a paid campaign.

## Risks

- Low risk. Any external script that builds this Dockerfile without
`PAPERCLIP_RUNNER_LOCK_SHA256` now fails with a clear message. Before,
it failed with a checksum mismatch whenever the lockfile changed. Both
CI build paths already pass the argument.
- The Dockerfile is an image content-ID input, so the next image gets a
new content tag. Current master needs a new image anyway.
- The nightly workflow stays red until an operator reviews and renews
`RUNNER_E2E_OPERATING_OVERHEAD_JSON`. This PR does not renew the
allowance, because that is a reviewed spend decision.
- Scheduled runs set `needs_daytona=false`, so the nightly run does not
publish a Daytona image even when the catalog passes. A current image
comes from a manual dispatch that selects Daytona cells.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude
Code with tool use (shell, file edits, GitHub CLI).

## 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
- [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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 09:08:59 -06:00

172 lines
13 KiB
TypeScript

import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
import { expect, it } from "vitest";
import { EvalSpendState, openEvalCostLedger, readEvalCostLedger, type EvalSpendLimits } from "./cost-ledger.js";
import { EVAL_OVERHEAD_COMPONENTS, operatingReservationBound, scheduledOperatingOverhead, validateOperatingOverhead, type EvalOperatingOverhead } from "./operating-overhead.js";
import { evalAccountingStatus, evalReadinessStatus, readEvalOperationsReport, renderEvalOperationsReport } from "./operations-report.js";
import { costBoundConfigurationSha256 } from "./cost-bound-evidence.js";
const now = Date.parse("2026-10-21T00:00:00Z");
const allowance = (): EvalOperatingOverhead => ({ version: 1, reference: "fixture-only", runner: "aws-fleet",
verifiedAt: "2026-10-20T00:00:00Z", expiresAt: "2026-11-19T00:00:00Z",
components: EVAL_OVERHEAD_COMPONENTS.map(component => ({ component, maxUsd: "1", reference: `fixture-${component}` })) });
const currentAllowance = (time = Date.now()): EvalOperatingOverhead => ({ ...allowance(),
verifiedAt: new Date(time - 86_400_000).toISOString(), expiresAt: new Date(time + 30 * 86_400_000).toISOString() });
const runner = "ubuntu-latest";
const modelIdentity = { executionId: "claude.local.fixture", attemptId: "attempt-1", phase: "agent" as const };
it.each(["aws-fleet", "local"] as const)("keeps %s overhead inside the same cap through model completion and a journal restart", async runnerKind => {
const directory = await mkdtemp(path.join(tmpdir(), "eval-overhead-"));
const file = path.join(directory, "ledger.jsonl");
const limits: EvalSpendLimits = { campaignId: "fixture", maxUsd: "20", deadlineAt: "2099-01-01T00:00:00Z",
maxRequests: 10, maxConcurrent: 1, maxAttemptsPerExecution: 1, overhead: { ...currentAllowance(), runner: runnerKind } };
try {
const ledger = await openEvalCostLedger(file, limits);
try {
expect((await readEvalCostLedger(file)).state.snapshot()).toMatchObject({ knownUsd: "0.000000000", heldUsd: "4.000000000", inflight: 0, unknownRequests: 4 });
await ledger.admitAttempt(modelIdentity.executionId, modelIdentity.attemptId);
await expect(ledger.reserve("too-large", modelIdentity, "17")).rejects.toThrow("spending cap");
await ledger.reserve("model", modelIdentity, "16");
await ledger.observe({ observationId: "model-receipt", requestId: "model", source: "provider", provider: "anthropic",
currency: "USD", route: "direct", classification: "reported", costUsd: "1", final: true });
await ledger.finish("model", "succeeded");
expect(ledger.snapshot()).toMatchObject({ knownUsd: "1.000000000", heldUsd: "4.000000000", committedUsd: "5.000000000" });
} finally { await ledger.close(); }
const changed = structuredClone(limits); changed.overhead!.components[0]!.maxUsd = "0";
await expect(openEvalCostLedger(file, changed)).rejects.toThrow("limits changed");
const resumed = await openEvalCostLedger(file, limits);
try {
await resumed.finish("overhead:ci_compute", "cancelled");
expect(resumed.snapshot().heldUsd).toBe("4.000000000");
await resumed.observe({ observationId: "ci-partial", requestId: "overhead:ci_compute", source: "infrastructure", provider: "aws",
currency: "USD", route: "infrastructure", classification: "estimated", pricingVersion: "fixture", costUsd: "0.2", final: false });
expect(resumed.snapshot()).toMatchObject({ knownUsd: "1.200000000", heldUsd: "3.800000000", committedUsd: "5.000000000", unknownRequests: 4 });
await resumed.observe({ observationId: "ci-invoice", requestId: "overhead:ci_compute", source: "invoice", provider: "aws",
currency: "USD", route: "infrastructure", classification: "reconciled", costUsd: "0.5", final: true });
expect(resumed.snapshot()).toMatchObject({ knownUsd: "1.500000000", heldUsd: "3.000000000", committedUsd: "4.500000000", unknownRequests: 3 });
} finally { await resumed.close(); }
const report = await readEvalOperationsReport(file);
expect(report).toMatchObject({ requests: 5, unresolvedRequests: 3, knownUsd: "1.500000000", heldUsd: "3.000000000" });
expect(renderEvalOperationsReport(report)).toContain("campaign-overhead");
expect(renderEvalOperationsReport(report)).toContain("Held reservations are not charges");
} finally { await rm(directory, { recursive: true, force: true }); }
});
it("stops further model admission when a later infrastructure receipt exceeds the shared cap", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "eval-overhead-overrun-"));
try {
const ledger = await openEvalCostLedger(path.join(directory, "ledger.jsonl"), { campaignId: "overrun", maxUsd: "20",
deadlineAt: "2099-01-01T00:00:00Z", maxRequests: 10, maxConcurrent: 1, maxAttemptsPerExecution: 1, overhead: currentAllowance() });
try {
await ledger.admitAttempt(modelIdentity.executionId, modelIdentity.attemptId);
await ledger.observe({ observationId: "late-invoice", requestId: "overhead:ci_compute", source: "invoice", provider: "aws",
currency: "USD", route: "infrastructure", classification: "reconciled", costUsd: "21", final: true });
expect(ledger.snapshot()).toMatchObject({ overBudget: true, committedUsd: "24.000000000" });
await expect(ledger.reserve("next", modelIdentity, "0.1")).rejects.toThrow("spending cap");
} finally { await ledger.close(); }
} finally { await rm(directory, { recursive: true, force: true }); }
});
it("requires each cost category once and rejects unknown policy fields or missing provenance", () => {
expect(validateOperatingOverhead(allowance(), "20")).toBe(4_000_000_000n);
expect(() => validateOperatingOverhead({ ...allowance(), components: allowance().components.slice(1) }, "20")).toThrow("Incomplete");
const duplicate = allowance(); duplicate.components[0] = duplicate.components[1]!;
expect(() => validateOperatingOverhead(duplicate, "20")).toThrow("component");
expect(() => validateOperatingOverhead({ ...allowance(), apiKey: "never-allowed" } as never, "20")).toThrow("fields");
const missing = allowance(); missing.components[0]!.reference = "";
expect(() => validateOperatingOverhead(missing, "20")).toThrow("component");
expect(() => validateOperatingOverhead(null as never, "20")).toThrow("fields");
expect(() => validateOperatingOverhead({ ...allowance(), expiresAt: "2027-10-20T00:00:00Z" }, "20")).toThrow("Incomplete");
expect(() => validateOperatingOverhead(allowance(), "4")).toThrow("no model allowance");
});
it("requires fresh reviewed allowances tied to the actual CI runner before scheduled work", () => {
const hosted = { ...allowance(), runner: "github-hosted" as const };
const raw = JSON.stringify(hosted);
expect(scheduledOperatingOverhead(raw, runner, "20", now)).toEqual(hosted);
expect(() => scheduledOperatingOverhead(undefined, runner, "20", now)).toThrow("Missing reviewed");
expect(() => scheduledOperatingOverhead("not json", runner, "20", now)).toThrow("JSON");
expect(() => scheduledOperatingOverhead(JSON.stringify(allowance()), runner, "20", now)).toThrow("runner");
expect(() => scheduledOperatingOverhead(JSON.stringify({ ...hosted, runner: "local" }), runner, "20", now)).toThrow("runner");
expect(() => scheduledOperatingOverhead(raw, "runs-on/fleet=paperclip-public-pr-x64/env=public-ci", "20", now)).toThrow("runner");
expect(() => scheduledOperatingOverhead(raw, "unrecognized", "20", now)).toThrow("runner");
expect(() => scheduledOperatingOverhead(raw, runner, "20", Date.parse("2026-10-19T23:59:59Z"))).toThrow("needs review");
expect(() => scheduledOperatingOverhead(raw, runner, "20", Date.parse("2026-11-18T20:00:00Z"))).toThrow("needs review");
expect(() => scheduledOperatingOverhead(raw, runner, "20", Date.parse("2026-11-18T20:00:00Z"))).toThrow(/until \S+ less a 4-hour campaign margin; renew the reviewed RUNNER_E2E_OPERATING_OVERHEAD_JSON/);
});
it("does not turn a zero allowance into an observed zero charge", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "eval-overhead-zero-"));
const overhead = allowance(); overhead.components[0]!.maxUsd = "0";
try {
const ledger = await openEvalCostLedger(path.join(directory, "ledger.jsonl"), { campaignId: "zero", maxUsd: "20",
deadlineAt: "2099-01-01T00:00:00Z", maxRequests: 10, maxConcurrent: 1, maxAttemptsPerExecution: 1, overhead });
try {
expect(ledger.snapshot().requests.find(row => row.requestId === "overhead:ci_compute"))
.toMatchObject({ costUsd: null, classification: "unknown", receiptComplete: false, reservedUsd: "0.000000000" });
} finally { await ledger.close(); }
} finally { await rm(directory, { recursive: true, force: true }); }
});
it("stops new admission after allowance expiry while preserving late invoice reconciliation", () => {
const state = new EvalSpendState({ campaignId: "expired", maxUsd: "20", deadlineAt: "2099-01-01T00:00:00Z",
maxRequests: 10, maxConcurrent: 1, maxAttemptsPerExecution: 1, overhead: allowance() });
const admitted = { type: "attempt" as const, executionId: modelIdentity.executionId, attemptId: modelIdentity.attemptId };
state.validate(admitted, now); state.apply(admitted);
const expiredAt = Date.parse(allowance().expiresAt);
expect(() => state.validate({ ...admitted, attemptId: "next" }, expiredAt)).toThrow("needs review");
expect(() => state.validate({ type: "reserve", requestId: "model", identity: modelIdentity, maxUsd: "1" }, expiredAt)).toThrow("needs review");
expect(() => state.validate({ type: "observe", observation: { observationId: "late-invoice", requestId: "overhead:ci_compute",
source: "invoice", provider: "aws", currency: "USD", route: "infrastructure", classification: "reconciled", costUsd: "0.5", final: true } }, expiredAt)).not.toThrow();
});
it("separates model readiness from unresolved overhead without releasing holds or masking model gaps", async () => {
const directory = await mkdtemp(path.join(tmpdir(), "eval-model-readiness-"));
const file = path.join(directory, "ledger.jsonl");
const overhead = { ...currentAllowance(), accountingReadiness: "model_requests" as const };
const ledger = await openEvalCostLedger(file, { campaignId: "model-readiness", maxUsd: "20",
deadlineAt: "2099-01-01T00:00:00Z", maxRequests: 10, maxConcurrent: 1, maxAttemptsPerExecution: 1, overhead });
try {
expect(evalReadinessStatus(await readEvalOperationsReport(file))).toBe("blocked");
await ledger.admitAttempt(modelIdentity.executionId, modelIdentity.attemptId);
await ledger.reserve("model", modelIdentity, "2");
expect(evalReadinessStatus(await readEvalOperationsReport(file))).toBe("blocked");
await ledger.finish("model", "cancelled");
expect(evalReadinessStatus(await readEvalOperationsReport(file))).toBe("blocked");
await ledger.observe({ observationId: "model-final", requestId: "model", source: "provider", provider: "anthropic",
currency: "USD", route: "direct", classification: "reported", costUsd: "0.5", final: true });
const report = await readEvalOperationsReport(file);
expect(evalAccountingStatus(report)).toBe("blocked");
expect(evalReadinessStatus(report)).toBe("receipts_complete");
expect(evalReadinessStatus({ ...report, accountingReadiness: undefined } as never)).toBe("blocked");
expect(report).toMatchObject({ accountingReadiness: "model_requests", heldUsd: "4.000000000",
committedUsd: "4.500000000", modelAccounting: { requests: 1, knownUsd: "0.500000000", unresolvedRequests: 0 } });
expect(renderEvalOperationsReport(report)).toContain("Operating costs remain separately unreconciled");
await ledger.observe({ observationId: "overrun", requestId: "overhead:ci_compute", source: "invoice", provider: "aws",
currency: "USD", route: "infrastructure", classification: "reconciled", costUsd: "21", final: true });
expect(evalReadinessStatus(await readEvalOperationsReport(file))).toBe("blocked");
} finally { await ledger.close(); await rm(directory, { recursive: true, force: true }); }
});
it("rejects unknown readiness policies instead of silently loosening accounting", () => {
expect(() => validateOperatingOverhead({ ...allowance(), accountingReadiness: "ignore_costs" } as never, "20"))
.toThrow("Invalid accounting readiness policy");
});
it("binds optional readiness policy to reviewed operating evidence without changing legacy hash recipes", () => {
for (const accountingReadiness of [undefined, "model_requests"] as const) {
const value = { ...allowance(), ...(accountingReadiness ? { accountingReadiness } : {}) };
const component = value.components[0]!;
const calculation = { reference: value.reference, runner: value.runner, verifiedAt: value.verifiedAt,
expiresAt: value.expiresAt, component: { ...component }, ...(accountingReadiness ? { accountingReadiness } : {}) };
component.provisionalBound = { version: 1, scope: "full_lifecycle", evidenceSha256: "a".repeat(64),
configurationSha256: costBoundConfigurationSha256(calculation) };
expect(operatingReservationBound(value, component)?.calculationSha256).toBe(component.provisionalBound.configurationSha256);
const changed = { ...value, accountingReadiness: accountingReadiness ? undefined : "model_requests" as const };
expect(() => operatingReservationBound(changed, component)).toThrow("Reviewed cost bound configuration changed");
}
});