mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-23 17:33:51 +02:00
## Thinking Path > - Paperclip manages AI agents and their operating budgets. > - Product E2E runs exercise real agents through a bounded gateway. > - The daily and weekly selections share one repository configuration variable. > - Their different request limits need different operating allowances. > - The existing parser accepts only one allowance, which cannot represent both reviewed limits. > - This change selects the allowance for the actual cadence and retains all existing validation. ## Linked Issues or Issue Description Refs #17009. **What happened?** The daily selection needs an $11 operating reservation; the weekly selection needs $21. A shared $21 allowance cannot fit the $20 daily cap. A shared $11 allowance does not cover the reviewed weekly resource bound. A configuration containing both allowances was rejected before paid admission. **Expected behavior** Each cadence uses its own reviewed allowance. Missing or malformed selected allowances stop admission before paid work. **Steps to reproduce** Set the operating allowance JSON to an object with daily and weekly allowances. Prepare either campaign through prepareScheduledCampaign. Before this change, both calls reject the outer object. **Paperclip version or commit**3bd709df8b. ## What Changed - Accept daily and weekly allowance entries in the existing configuration variable. - Select the actual cadence before validating its budget, runner and expiration. - Pass only the selected allowance through the existing workflow output. - Preserve single-allowance compatibility and document the configuration format. ## Verification - Reproduced both cadence failures before the fix: 2 failed, 12 passed. - Focused scheduled operations and operating overhead tests: 20 passed. - Eval TypeScript check passed. - Missing selected entries and unknown outer fields fail before creating a manifest. - Hosted CI passed at1c62cc8aeb, including full typecheck, tests, build and browser shards. - Greptile and Paperclip reviews both rated the exact commit 5/5 with no actionable findings. ## Risks - A map with a missing selected cadence now fails admission. It never substitutes the other cadence. - Operators must still provide reviewed rates and resource bounds. This parser does not prove actual charges. - This PR does not change limits, credentials, workflow permissions or enable gates. ## Model Used - OpenAI GPT-6 in Codex, with reasoning, repository inspection, code execution and test tools. The exact backend model identifier 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 - [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>
60 lines
3.4 KiB
TypeScript
60 lines
3.4 KiB
TypeScript
import { usdToUnits } from "../../packages/shared/src/money.js";
|
|
|
|
export const EVAL_OVERHEAD_COMPONENTS = ["ci_compute", "artifact_storage", "observability", "shared_subscription"] as const;
|
|
export interface EvalOperatingOverhead {
|
|
version: 1;
|
|
reference: string;
|
|
runner: "github-hosted" | "aws-fleet";
|
|
verifiedAt: string;
|
|
expiresAt: string;
|
|
components: Array<{ component: typeof EVAL_OVERHEAD_COMPONENTS[number]; maxUsd: string; reference: string }>;
|
|
}
|
|
|
|
const object = (value: unknown, allowed: string[]) => {
|
|
if (!value || typeof value !== "object" || Array.isArray(value)
|
|
|| Object.keys(value).some(key => !allowed.includes(key))) throw new Error("Invalid operating overhead fields");
|
|
};
|
|
const reference = (value: unknown) => typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9_.:/-]{0,511}$/.test(value);
|
|
|
|
export function validateOperatingOverhead(value: EvalOperatingOverhead, totalUsd: string): bigint {
|
|
object(value, ["version", "reference", "runner", "verifiedAt", "expiresAt", "components"]);
|
|
if (value.version !== 1 || !reference(value.reference) || !["github-hosted", "aws-fleet"].includes(value.runner)
|
|
|| typeof value.verifiedAt !== "string" || typeof value.expiresAt !== "string"
|
|
|| !Number.isFinite(Date.parse(value.verifiedAt)) || !Number.isFinite(Date.parse(value.expiresAt))
|
|
|| Date.parse(value.expiresAt) <= Date.parse(value.verifiedAt)
|
|
|| Date.parse(value.expiresAt) - Date.parse(value.verifiedAt) > 31 * 86_400_000
|
|
|| !Array.isArray(value.components) || value.components.length !== EVAL_OVERHEAD_COMPONENTS.length) {
|
|
throw new Error("Incomplete operating overhead allowance");
|
|
}
|
|
const seen = new Set<string>();
|
|
let reserved = 0n;
|
|
for (const component of value.components) {
|
|
object(component, ["component", "maxUsd", "reference"]);
|
|
if (!EVAL_OVERHEAD_COMPONENTS.includes(component.component) || seen.has(component.component)
|
|
|| !reference(component.reference) || typeof component.maxUsd !== "string"
|
|
|| !/^(?:0|[1-9][0-9]*)(?:\.[0-9]{1,9})?$/.test(component.maxUsd)) throw new Error("Invalid operating overhead component");
|
|
seen.add(component.component);
|
|
reserved += usdToUnits(component.maxUsd);
|
|
}
|
|
if (reserved >= usdToUnits(totalUsd)) throw new Error("Operating overhead leaves no model allowance");
|
|
return reserved;
|
|
}
|
|
|
|
export function scheduledOperatingOverhead(raw: string | undefined, runner: string | undefined, totalUsd: string, now: number, cadence?: "daily" | "weekly"): EvalOperatingOverhead {
|
|
if (!raw || raw.length > 16_384) throw new Error("Missing reviewed operating overhead allowance");
|
|
let parsed: unknown;
|
|
try { parsed = JSON.parse(raw); } catch { throw new Error("Invalid operating overhead JSON"); }
|
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed) && !("version" in parsed)) {
|
|
object(parsed, ["daily", "weekly"]);
|
|
if (!cadence) throw new Error("Missing operating overhead cadence");
|
|
parsed = (parsed as Record<string, unknown>)[cadence];
|
|
}
|
|
const value = parsed as EvalOperatingOverhead;
|
|
validateOperatingOverhead(value, totalUsd);
|
|
if (runner !== "ubuntu-latest" || value.runner !== "github-hosted") throw new Error("Bounded campaigns require the standard GitHub-hosted runner allowance");
|
|
if (!Number.isFinite(now) || now < Date.parse(value.verifiedAt) || now + 4 * 3_600_000 >= Date.parse(value.expiresAt)) {
|
|
throw new Error("Operating overhead allowance needs review before paid admission");
|
|
}
|
|
return value;
|
|
}
|