mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 05:47:10 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - Its image workflow builds immutable images and requires proof for the exact source. > - GitHub API quota failures can stop metadata generation and verification reads. > - Short retries before the quota reset consume requests without restoring progress. > - This pull request removes metadata API reads and makes quota retries respect server timing and job budgets. > - The benefit is fewer API requests and clear quota errors without weakening release proof. ## Linked Issues or Issue Description Refs #22677, which adds conditional requests for unchanged Actions polls. This change retains that cache and extends quota recovery. **What happened?** [Docker run 45215585951](https://github.com/paperclipai/paperclip/actions/runs/45215585951) failed in both Docker metadata steps with an installation API rate-limit error. [Run 45210434846](https://github.com/paperclipai/paperclip/actions/runs/45210434846) built both architectures but failed during source verification reads. The reader retried quota-proven HTTP 403 responses after seconds and then failed with a generic HTTP error. It ignored the primary reset time and could shorten Retry-After below the server requirement. **Expected behavior** Metadata generation should need no GitHub API request. Quota recovery should wait until GitHub permits another request, within the caller deadline. Exhausted budgets should identify the quota failure and safe response-header details. Permission failures must remain immediate. Missing source, migrator, or attestation proof must still block publication. **Steps to reproduce** 1. Return HTTP 403 with zero remaining requests and a reset two minutes away to the Actions reader. 2. Observe the old reader retry after seconds and exhaust its attempts before the reset. 3. Return an hour-long Retry-After value. Observe the old reader retry after its one-minute cap. **Version** Master after #22677. **Deployment mode** GitHub Actions image publication and release verification. ## What Changed - Honor primary reset times and Retry-After seconds or dates. Use a minute-long exponential fallback for secondary throttling without timing headers. - Bound the entire wait by a per-read budget and the caller deadline. Keep permission-denied 403s immediate and preserve ETag caching and transport retries. - Emit a typed quota error with allowlisted token-source, resource, limit, remaining, and reset diagnostics. Do not log tokens, response bodies, or request URLs. - Share the Docker observer's 40-minute deadline with its reader. Bound final proof rechecks to five minutes. Add an explicit `github.token` source hint beside workflow-issued token bindings. - Generate Docker tags and OCI labels from checkout and workflow inputs. Keep release-lane and immutable SHA tags. Feed metadata JSON explicitly to manifest publication. Stop fetching the GitHub repository description; keep local license and migration labels. - Add regression tests and run them in the trusted PR and source-verification workflows. Document retry budgets and metadata inputs. ## Verification - Final acceptance: [CI attempt 3](https://github.com/paperclipai/paperclip/actions/runs/45263398107/attempts/3) succeeded on `302da8c`. All 68 reported checks are complete, with no pending or failing checks. Greptile reviewed that exact commit at 5/5 and both review threads are resolved. The voice timeout recovered without code changes; its earlier cause remains unconfirmed. Prior failures and local reproduction limits remain below. - [CI attempt 2](https://github.com/paperclipai/paperclip/actions/runs/45263398107/attempts/2) recovered the interrupted checks. Its only remaining test failure is server shard 2/12: `voice-session-store.integration.test.ts`, “retains both spoken sides once on the public call task and preserves quarantine,” exceeded 15 seconds on both Vitest attempts. The `ci / verify` failure is its aggregate. The voice test file is byte-identical to master and absent from this PR diff; its cause is not established as an infrastructure fault. A focused local attempt could not start PostgreSQL because the macOS binary lacks `libzstd.1.dylib`; no voice test passed locally. Requesting one bounded retry of the affected shard without code changes; all earlier failures remain recorded here. - The automatic runner-loss retry helper for the current run failed on a GitHub job-log download with HTTP 503 ([helper run 45265762243](https://github.com/paperclipai/paperclip/actions/runs/45265762243)). Once the PR workflow completed, a manual failed-job retry was requested successfully for unchanged head `302da8c`. Retry results remain pending; no interrupted check is treated as passed. - [CI run 45263398107](https://github.com/paperclipai/paperclip/actions/runs/45263398107) on `302da8c` lost 25 jobs during verification. Inspected the logs for these 25 jobs: all 25 contain an explicit runner shutdown signal followed by cancellation, with no additional error records. This includes Rust, browser, general-server, and serialized-server lanes. These are interrupted checks and remain unverified until retried. Greptile reviewed this exact commit at 5/5 with no new findings. - Combined focused release/metadata and PR policy suite: **1,008 tests passed**, zero failures. Command: `node --test scripts/github-actions-rate-limit.test.mjs scripts/docker-image-metadata.test.mjs scripts/cloud-source-verification.test.mjs scripts/cloud-readiness-runner-loss.test.mjs scripts/standard-image-contract.test.mjs scripts/reuse-canary-image.test.mjs scripts/merge-group-image.test.mjs scripts/__tests__/release-verify-workflow.test.mjs .github/scripts/tests/*.test.mjs`. - `pnpm exec vitest run server/src/services/online-durable-data-migration.test.ts --project @paperclipai/server`: **32 tests passed** after incorporating upstream #22686. The final PR diff includes no migration test or runtime change. - In `packages/paperclip-runner`, `pnpm exec vitest run src/drivers/acpx/cursor-mode.test.ts src/drivers/acpx/grok-native-session-options.test.ts --maxWorkers 1`: **26 tests passed**. This local pass does not explain the earlier CI timeouts. - New tests first reproduced ignored primary reset timing, early Retry-After retries, missing service-error waits, and older-checkout failures. CLI tests confirm quota exhaustion produces a safe annotation, no verified output, and no cancellation request. Workflow tests cover neither, either, and both new test files being present. - Initial policy CI failed two assertions that expected the old metadata action and single-file proof test command. Updated them to check both local metadata steps, the full-SHA tag, and all proof tests. Initial Greptile findings about service Retry-After and older checkouts are fixed and resolved. - [CI attempt 1](https://github.com/paperclipai/paperclip/actions/runs/45259240827/attempts/1) lost the Build runner and server shards 1, 7, and 12 within four seconds. Logs explicitly record shutdown signals followed by cancellation; Build reported no compiler error. Runner lane 2/3 hit five-second Cursor and Grok test timeouts. E2E shard 2/8 failed document visibility after outage/reload and the cached-task 404 assertion. Those test failures are not assumed to be infrastructure faults. Their aggregate checks also failed. They remain merge blockers until fresh CI passes. - Server shard 9 also found a deterministic, pre-existing blocker-enumeration test failure. Reproduced it on unchanged base `427d13c38c63`: the source scanner omitted helper-declared blockers. Upstream #22686 fixes that test. Incorporated its version when updating from master and removed the duplicate fix from the final diff. A failed-job retry was accepted after attempt 1 finished; the updated branch now needs fresh CI. - Local setup: filtered frozen-lockfile installation changed no lockfile. Initial server-test startup lacked built plugin SDK output; `pnpm --filter @paperclipai/plugin-sdk ensure-build-deps` supplied it before the passing run. Local tests used macOS and Node 25.6.1; CI checks Linux and its configured Node version. - `pnpm verify` initially could not start because the fresh worktree lacked `cli/node_modules/tsx`. The underlying `node scripts/local-verify.mjs` returned exit 2: workflow changes require broad CI. No full local Vitest or Docker build was run. Required CI supplies broad coverage. - No credentials were changed and no live publication or deployment was requested. CI retries do not authorize image publication or bypass proof. ## Risks - A reset outside the allowed wait still fails closed. Shared repository quota pressure from other workflows can still delay publication. - Attestation and source/migrator proof remain required. This change does not add a privileged token or bypass a check. - OCI labels now use checkout inputs. The remote repository description is omitted; source, revision, version, creation time, license, and schema labels remain available. - Revert this PR to restore the previous reader and metadata action. No database or runtime application changes are required. ## Model Used OpenAI gpt-6.1-sol with xhigh reasoning, through Codex in T3 Code. Used code editing, GitHub log and upstream action-source inspection, and local test execution. ## 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] This is a CI reliability fix; it does not change planned product scope - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have described the issue in-PR following the bug template - [x] I have not referenced internal or instance-local issues or links - [x] My branch name describes the change - [x] I have run focused tests locally and they pass; the broad verification limitation is recorded - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation - [x] I have considered and documented risks - [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>
125 lines
6.4 KiB
JavaScript
125 lines
6.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { spawnSync } from "node:child_process";
|
|
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { createActionsReader } from "./github-actions-reader.mjs";
|
|
|
|
function fixture(responses, options = {}) {
|
|
let clock = Date.UTC(2000, 0, 1);
|
|
const calls = [], waits = [], logs = [];
|
|
const api = createActionsReader({
|
|
token: "fixture-secret", tokenSource: "github.token", now: () => clock,
|
|
sleep: async ms => { waits.push(ms); clock += ms; },
|
|
log: message => logs.push(message),
|
|
fetchImpl: async () => {
|
|
calls.push(clock);
|
|
const next = responses.shift();
|
|
assert.ok(next, "Unexpected extra API request");
|
|
return new Response(JSON.stringify({ message: "fixture-private-body", ok: true }), next);
|
|
}, ...options,
|
|
});
|
|
return { api, calls, waits, logs };
|
|
}
|
|
|
|
const reset = String(Date.UTC(2000, 0, 1) / 1000 + 120);
|
|
|
|
test("primary throttling waits for the real reset and emits only safe quota diagnostics", async () => {
|
|
const f = fixture([{ status: 403, headers: { "x-ratelimit-remaining": "0", "x-ratelimit-limit": "1000", "x-ratelimit-reset": reset,
|
|
"x-ratelimit-resource": "core" } }, { status: 200 }]);
|
|
await f.api("/repos/example/repo/actions/runs");
|
|
assert.deepEqual(f.waits, [121_000]);
|
|
assert.equal(f.calls[1] - f.calls[0], 121_000);
|
|
assert.match(f.logs[0], /credential: github.token.*resource: core.*limit: 1000.*remaining: 0.*reset: 2000-01-01T00:02:00.000Z/);
|
|
assert.doesNotMatch(f.logs.join(""), /fixture-secret|fixture-private-body|example\/repo/);
|
|
});
|
|
|
|
test("a reset or Retry-After outside the budget stops without an early retry", async () => {
|
|
for (const headers of [{ "x-ratelimit-remaining": "0", "x-ratelimit-reset": reset }, { "retry-after": "3600" }]) {
|
|
const f = fixture([{ status: 403, headers }], { maxRetryAfterMs: 60_000 });
|
|
await assert.rejects(f.api("/repos/x"), /GitHub API rate limited/);
|
|
assert.equal(f.calls.length, 1);
|
|
assert.deepEqual(f.waits, []);
|
|
}
|
|
});
|
|
|
|
test("the caller deadline accounts for the entire server wait", async () => {
|
|
const f = fixture([{ status: 429, headers: { "retry-after": "120" } }], { deadlineAt: () => Date.UTC(2000, 0, 1) + 60_000 });
|
|
await assert.rejects(f.api("/repos/x"), /GitHub API rate limited/);
|
|
assert.deepEqual(f.waits, []);
|
|
assert.equal(f.calls.length, 1);
|
|
});
|
|
|
|
test("secondary throttling without a reset backs off for at least a minute", async () => {
|
|
const f = fixture([{ status: 429 }, { status: 429 }, { status: 200 }]);
|
|
await f.api("/repos/x");
|
|
assert.deepEqual(f.waits, [60_000, 120_000]);
|
|
});
|
|
|
|
test("Retry-After dates and a later primary reset are both respected", async () => {
|
|
const f = fixture([{ status: 429, headers: { "retry-after": "Sat, 01 Jan 2000 00:03:00 GMT", "x-ratelimit-remaining": "0", "x-ratelimit-reset": reset } }, { status: 200 }]);
|
|
await f.api("/repos/x");
|
|
assert.deepEqual(f.waits, [180_000]);
|
|
});
|
|
|
|
test("quota errors stay explicit when attempts are exhausted and do not guess a token source", async () => {
|
|
const f = fixture([{ status: 429, headers: { "x-ratelimit-resource": "fixture-private-body", "x-ratelimit-limit": "unsafe-value" } }],
|
|
{ attempts: 1, tokenSource: "fixture-secret" });
|
|
await assert.rejects(f.api("/repos/x"), error => {
|
|
assert.equal(error.name, "GitHubActionsRateLimitError");
|
|
assert.match(error.message, /HTTP 429; credential: configured credential/);
|
|
assert.doesNotMatch(error.message, /fixture-secret|fixture-private-body|unsafe-value|github.token/);
|
|
return true;
|
|
});
|
|
});
|
|
|
|
test("an ordinary forbidden response is still an immediate permission failure", async () => {
|
|
const f = fixture([{ status: 403, headers: { "x-ratelimit-remaining": "999" } }]);
|
|
await assert.rejects(f.api("/repos/x"), /GitHub Actions read failed \(HTTP 403\)/);
|
|
assert.deepEqual(f.waits, []);
|
|
});
|
|
|
|
test("transient service failures honor Retry-After seconds and dates", async () => {
|
|
for (const retryAfter of ["30", "Sat, 01 Jan 2000 00:00:30 GMT"]) {
|
|
const f = fixture([{ status: 503, headers: { "retry-after": retryAfter } }, { status: 200 }]);
|
|
await f.api("/repos/x");
|
|
assert.deepEqual(f.waits, [30_000]);
|
|
assert.equal(f.calls[1] - f.calls[0], 30_000);
|
|
}
|
|
});
|
|
|
|
test("transient Retry-After waits outside either budget fail without an early retry", async () => {
|
|
for (const options of [{ maxRetryAfterMs: 20_000 }, { deadlineAt: () => Date.UTC(2000, 0, 1) + 20_000 }]) {
|
|
const f = fixture([{ status: 503, headers: { "retry-after": "30" } }], options);
|
|
await assert.rejects(f.api("/repos/x"), /GitHub Actions read failed \(HTTP 503\)/);
|
|
assert.deepEqual(f.waits, []);
|
|
assert.equal(f.calls.length, 1);
|
|
}
|
|
});
|
|
|
|
|
|
test("the release CLI reports safe quota evidence and cannot publish proof or cancel work", () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "github-quota-cli-"));
|
|
try {
|
|
const mock = join(dir, "fetch.mjs"), output = join(dir, "outputs");
|
|
writeFileSync(mock, `globalThis.fetch = async (_url, init) => {
|
|
if (init?.method && init.method !== "GET") throw new Error("Unexpected mutation");
|
|
return new Response(JSON.stringify({ message: "fixture-private-body" }), { status: 403,
|
|
headers: { "x-ratelimit-remaining": "0", "x-ratelimit-limit": "1000", "x-ratelimit-reset": String(Math.floor(Date.now() / 1000) + 7200) } });
|
|
};`);
|
|
for (const args of [[], ["--require-proof"], ["--check-proof"]]) {
|
|
writeFileSync(output, "");
|
|
const result = spawnSync(process.execPath, ["--import", mock, new URL("./watch-release-source.mjs", import.meta.url).pathname, ...args], {
|
|
encoding: "utf8", timeout: 5000, env: { ...process.env, GITHUB_TOKEN: "fixture-secret", GITHUB_TOKEN_SOURCE: "github.token",
|
|
GITHUB_REPOSITORY: "paperclipai/paperclip", GITHUB_REF: "refs/heads/master", GITHUB_SHA: "a".repeat(40),
|
|
GITHUB_RUN_ID: "1", GITHUB_RUN_ATTEMPT: "1", GITHUB_OUTPUT: output },
|
|
});
|
|
assert.equal(result.status, 1, result.stderr);
|
|
assert.match(result.stderr, /::error title=GitHub API rate limited::GitHub API rate limited.*credential: github.token.*limit: 1000.*remaining: 0.*reset:/);
|
|
assert.doesNotMatch(result.stderr + result.stdout, /fixture-secret|fixture-private-body|Unexpected mutation/);
|
|
assert.equal(readFileSync(output, "utf8"), "");
|
|
}
|
|
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
});
|