mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-08 21:35:36 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Its release pipeline publishes Core images and exact-source database
migrators.
> - A migrator run can pass admission but skip all build and publication
work.
> - The image observer could stop checking after provisional build
admission.
> - The final image gate checked source proof without checking migrator
publication.
> - This pull request requires the exact migrator publisher to finish
before image publication.
> - Consumers can then use the published image with its matching
migration artifact.
## Linked Issues or Issue Description
**What happened?**
The [migrator run for
e968131](https://github.com/paperclipai/paperclip/actions/runs/41868122685)
passed its admission job but skipped build and publish. Its [Docker
run](https://github.com/paperclipai/paperclip/actions/runs/41868122627)
still published an image. The exact-source migrator artifact was absent.
**Expected behavior**
An image consumer restarts a strictly deferred producer. It waits for
the exact migrator publication before it publishes the image. A
successful admission job alone does not prove publication.
**Steps to reproduce**
1. Let a migrator run defer work while the image consumer starts.
2. Make the producer appear admitted before its build later becomes
skipped.
3. Complete the source verification job.
4. Observe that the old image gate can accept source proof without a
successful migrator publisher.
The regression fixtures model this state. The real producer records
establish the missing publication; the exact transient API response seen
by the original observer is not retained.
**Paperclip version or commit**
The observed source was `e968131efa7e63d321f3bcca8d47a62513c2efb4`. This
patch is based on current master.
No duplicate fix was found in open migrator PRs. PR #18406 concerns npm
canary scheduling and does not provide this image publication gate.
## What Changed
- Require the successful canonical migrator `publish` job for the exact
source and latest attempt. Check complete job pages and re-read the run
after the jobs.
- Continue observing deferred producers until publication, even after a
build appeared admitted. Only a physical runner proves build admission.
- Check migrator publication again in the final read-only
`--check-proof` image gate. Failed producers still require inspection
and are not retried automatically.
- Add regression coverage for deferred recovery, skipped and stale
publication, attempt races, and the final CLI gate. Update release
documentation.
## Verification
- All 57 current-head check contexts are successful or expected skips on
`daed1c756a9fc02b8c15128b96af4da86d447e3f`; both required checks (`ci /
verify`, `ci / e2e`) passed. Greptile is 5/5 with no review threads, and
the branch has no merge conflicts. GitHub master rules require CODEOWNER
review before merging.
- The first CI attempt failed serialized server shard 2/9:
`heartbeat-process-recovery.test.ts` timed out after three seconds
waiting for an adapter execution to start (1 failed, 411 passed).
[Failed
job](https://github.com/paperclipai/paperclip/actions/runs/41894941958/job/126802368555).
This PR changes no server or package files. The exact timeout cause is
not established; this failure is retained and is not described as
infrastructure noise.
- The same first attempt also failed general server shard 6/12:
`heartbeat-stale-queue-invalidation.test.ts` waited five seconds for an
adapter execution after native-owner completion; the run remained
running with no error (1 failed, 2,627 passed, 3 skipped). [Failed
job](https://github.com/paperclipai/paperclip/actions/runs/41894941958/job/126802369329).
Its cause is also not established. The first-attempt failures remain
part of this record.
- The single controlled failed-jobs rerun completed successfully on
attempt 2 at the identical commit. Both previously failed heartbeat
shards and the aggregate verifier passed. This demonstrates recovery on
rerun; the underlying first-attempt failure causes are not established.
[Successful
rerun](https://github.com/paperclipai/paperclip/actions/runs/41894941958/attempts/2).
- Node 24: `node --test scripts/cloud-source-verification.test.mjs
scripts/standard-image-contract.test.mjs` passed: 62 tests, 0 failures,
after rebasing on current master.
- An explicitly gated read-only live probe rejected the real skipped
producer for `e968131` and accepted the published producer for
`afbc5a885b52e96df10c1c6e643bea31b51caac8`.
- `git diff --check` and Gitleaks passed before push.
- A broader run that also included
`scripts/__tests__/release-verify-workflow.test.mjs` failed when local
fixture creation and package installation hit `ENOSPC`. Those failures
remain unverified locally; the focused source and image tests passed
separately, and CI Typecheck + Release Registry subsequently passed.
- Full workspace typecheck, Vitest and app builds were not run locally.
Disk capacity does not permit installing the full workspace in this
separate checkout. No application TypeScript or package manifest
changed. The complete CI run subsequently passed, including typecheck,
build, general and serialized tests, release checks and e2e.
- No live Slack posts, workflow dispatches, producer reruns, deployments
or provider mutations.
## Risks
- Image publication now waits for the exact migrator publisher. A failed
publisher blocks the image and reports a publication failure. Existing
source failure cancellation still applies.
- This adds bounded Actions reads to the existing source observer. The
observer keeps its existing deadline. The final publication runner only
reads evidence and cannot restart producers.
- The publisher job name is part of this gate. A workflow rename must
update the gate.
- No database schema, migration content, image contents, credentials or
application behavior change. Revert this PR to restore the prior
publication gate.
## Model Used
- OpenAI `gpt-6.1-sol`, xhigh reasoning effort, through Codex in T3
Code. Source inspection, tool use and code execution. Context window
size is not exposed by the harness.
## 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 pass;
broader local ENOSPC 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>
109 lines
6.9 KiB
JavaScript
109 lines
6.9 KiB
JavaScript
import { appendFile } from "node:fs/promises";
|
|
import { pathToFileURL } from "node:url";
|
|
import { createActionsReader, readSourceVerification, SourceVerificationFailed, SourceVerificationDeferred } from "./cloud-source-verification.mjs";
|
|
import { requestDeferredProducer, readMigratorPublication, sourceAdmissionJob, migratorAdmissionJob, createReleaseRerunner } from "./cloud-release-admission.mjs";
|
|
|
|
const repository = "paperclipai/paperclip";
|
|
|
|
export function runnerWaits(jobs, now = Date.now()) {
|
|
return jobs.filter(job => ["queued", "in_progress", "completed"].includes(job.status) &&
|
|
job.conclusion !== "skipped" && job.labels?.length > 0).map(job => ({
|
|
job: job.name, id: job.id,
|
|
seconds: Math.max(0, Math.floor(((job.runner_id > 0 && job.started_at ? Date.parse(job.started_at) : now) - Date.parse(job.created_at)) / 1000)),
|
|
})).filter(job => Number.isFinite(job.seconds));
|
|
}
|
|
|
|
// The write is limited to this canonical master Docker run. Never cancel
|
|
// another workflow, a tag release, or a run selected from untrusted input.
|
|
export async function cancelImageRun({ api, cancel, runId, attempt, sha }) {
|
|
const run = await api(`/repos/${repository}/actions/runs/${runId}`);
|
|
if (run.id !== runId || run.run_attempt !== attempt || run.head_sha !== sha || run.head_branch !== "master" ||
|
|
run.repository?.id !== 1170821064 || run.head_repository?.id !== 1170821064 ||
|
|
run.path !== ".github/workflows/docker.yml" || !["push", "workflow_dispatch"].includes(run.event)) {
|
|
throw new Error("Refusing to cancel a different image workflow identity.");
|
|
}
|
|
if (run.status !== "completed") await cancel(`/repos/${repository}/actions/runs/${runId}/cancel`);
|
|
}
|
|
|
|
async function cancelFailedVerification({ api, cancel, sha }, failure) {
|
|
const run = await api(`/repos/${repository}/actions/runs/${failure.runId}`);
|
|
// A concurrent retry owns the new attempt; a late observer leaves it alone.
|
|
if (run.run_attempt !== failure.attempt) return;
|
|
if (run.id !== failure.runId || run.head_sha !== sha || run.head_branch !== "master" || run.event !== "push" ||
|
|
run.repository?.full_name !== repository || run.head_repository?.full_name !== repository ||
|
|
run.path !== ".github/workflows/cloud-readiness.yml") throw new Error("Failed verification identity changed.");
|
|
if (run.status !== "completed") await cancel(`/repos/${repository}/actions/runs/${failure.runId}/cancel`);
|
|
}
|
|
|
|
export async function watchReleaseSource({ sha, runId, attempt, api, cancel, rerun, now = Date.now,
|
|
sleep = ms => new Promise(resolve => setTimeout(resolve, ms)), log = console.log,
|
|
timeoutMs = 40 * 60_000, intervalMs = 30_000, requireProof = false, summary = async () => {} }) {
|
|
if (!/^[a-f0-9]{40}$/.test(sha ?? "") || !Number.isSafeInteger(runId) || runId < 1 ||
|
|
!Number.isSafeInteger(attempt) || attempt < 1) throw new Error("Invalid release identity.");
|
|
const deadline = now() + timeoutMs;
|
|
const warned = new Set();
|
|
const requested = new Set();
|
|
const reportWaits = async jobs => {
|
|
for (const wait of runnerWaits(jobs, now())) {
|
|
if (wait.seconds > 60 && !warned.has(wait.id)) {
|
|
warned.add(wait.id);
|
|
log(`::warning title=Release runner waited over 60 seconds::Job ${wait.id} waited ${wait.seconds}s for a runner.`);
|
|
await summary(`Release runner wait: ${wait.job} — ${wait.seconds}s (job ${wait.id}).\n`);
|
|
}
|
|
}
|
|
};
|
|
while (now() < deadline) {
|
|
// Keep observing until publication, even after a build appeared admitted.
|
|
// GitHub may transiently label a job in progress before skipping it.
|
|
if (rerun) await requestDeferredProducer({ file: "cloud-migrator-artifacts.yml", sha, admissionJob: migratorAdmissionJob, api, rerun, requested });
|
|
const batch = await api(`/repos/${repository}/actions/runs/${runId}/attempts/${attempt}/jobs?per_page=100`);
|
|
if (!Array.isArray(batch.jobs) || batch.total_count > 100) throw new Error("Incomplete image job listing.");
|
|
await reportWaits(batch.jobs);
|
|
try {
|
|
const proof = await readSourceVerification(sha, api, { failFast: true, onJobs: reportWaits });
|
|
if (proof && (!rerun || await readMigratorPublication(sha, api))) {
|
|
await summary(`Exact source verified: ${sha}; readiness run ${proof.runId}, attempt ${proof.attempt}.\n`);
|
|
return proof;
|
|
}
|
|
} catch (error) {
|
|
if (error instanceof SourceVerificationDeferred && rerun) {
|
|
await requestDeferredProducer({ file: "cloud-readiness.yml", sha, admissionJob: sourceAdmissionJob, api, rerun, requested });
|
|
} else {
|
|
if (error instanceof SourceVerificationFailed) {
|
|
await cancelFailedVerification({ api, cancel, sha }, error);
|
|
await cancelImageRun({ api, cancel, runId, attempt, sha });
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
await sleep(Math.min(intervalMs, Math.max(0, deadline - now())));
|
|
}
|
|
// This early failure observer is not the publication deadline. Healthy
|
|
// checks can outlive a Spot worker; a separate exact-source gate still
|
|
// waits for proof before publishing any image.
|
|
if (requireProof) throw new Error("Exact-source verification and migrator publication did not become ready before the publication deadline.");
|
|
await summary("Source monitoring window ended; final publication still requires exact-source verification and migrator publication.\n");
|
|
return undefined;
|
|
}
|
|
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
const token = process.env.GITHUB_TOKEN;
|
|
if (!token || process.env.GITHUB_REPOSITORY !== repository || process.env.GITHUB_REF !== "refs/heads/master") throw new Error("Canonical master token required.");
|
|
const requireProof = process.argv.includes("--require-proof");
|
|
const checkProof = process.argv.includes("--check-proof");
|
|
const api = createActionsReader({ token });
|
|
const proof = checkProof ? await readSourceVerification(process.env.GITHUB_SHA, api, { failFast: true }) : await watchReleaseSource({ requireProof, sha: process.env.GITHUB_SHA, runId: Number(process.env.GITHUB_RUN_ID), attempt: Number(process.env.GITHUB_RUN_ATTEMPT),
|
|
api,
|
|
rerun: createReleaseRerunner(token),
|
|
cancel: async path => {
|
|
const response = await fetch(`https://api.github.com${path}`, { method: "POST", redirect: "error",
|
|
headers: { Authorization: `Bearer ${token}`, Accept: "application/vnd.github+json" }, signal: AbortSignal.timeout(30_000) });
|
|
if (!response.ok) throw new Error(`Could not cancel failed-source image work: HTTP ${response.status}.`);
|
|
},
|
|
summary: text => process.env.GITHUB_STEP_SUMMARY ? appendFile(process.env.GITHUB_STEP_SUMMARY, text) : Promise.resolve(),
|
|
});
|
|
if (checkProof && !proof) throw new Error("Exact-source proof changed before publication.");
|
|
if (checkProof && !await readMigratorPublication(process.env.GITHUB_SHA, api)) throw new Error("Exact-source migrator has not published.");
|
|
if (process.env.GITHUB_OUTPUT) await appendFile(process.env.GITHUB_OUTPUT, `verified=${Boolean(proof)}\n`);
|
|
}
|