fix(cloud): name a retained runtime skill run whose bundle left the disk and keep saving the runs after it (#22648)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - A hosted server copies the runtime skill bundles that retained runs
still need to shared storage before it moves to a volume-free shape
> - The online pass copies them a page at a time with
`migrateRuntimeSkillAssets`
> - The page fails at the first run whose bundle is no longer on the
disk, so the later runs on that page are never saved and the pass names
only the first failure
> - The offline migration continues past such a run, collects it as
unsaved, and refuses at the end
> - This pull request gives the online page the same behavior and names
each unsaved run
> - The benefit is that the pass saves every bundle it can and reports
each one it cannot

## Linked Issues or Issue Description

Refs #22190, #22294, #22641

**What happened?**
On staging, one stack reports `runtime_skill_assets_require_migration`.
Its passes showed
`runtime_skill_assets:runtime_skill_source_absent:missing` as a
whole-page failure: the runs after the first missing bundle were not
visited.

**Expected behavior**
The page saves every run whose bundle is on the disk and names each run
whose bundle is gone.

**Steps to reproduce**
1. Keep two retained native runs with unversioned skill bundles. Remove
the bundle of the first run from the disk.
2. Run `migrateRuntimeSkillAssets` with `apply`.
3. See that it throws `runtime_skill_source_absent:missing` and does not
save the second run.

**Additional context**
#22641 already makes every blocker in the pass result carry a code. This
pull request was reduced to the runtime skill page after #22641 merged.

## What Changed

- `migrateRuntimeSkillAssets` returns `{ status: "unsaved", code:
"runtime_skill_source_absent:<reason>" }` for a run whose bundle is not
on this disk, and continues. Other errors still stop the page, as in the
offline migration.
- The result type is a discriminated union, so `unsaved` always carries
a code.
- The online pass reports each unsaved run as
`runtime_skill_assets:<code>`.
- `migrate-skill-packages --phase=runtime-assets` prints the unsaved
rows and exits 1 when any run stays unsaved.

## Verification

- Red: `cd server && npx vitest run
src/services/online-durable-data-migration.test.ts
src/__tests__/runtime-skill-preservation.test.ts` failed 2 new tests:
the real page (embedded PostgreSQL, real bundle files) threw
`runtime_skill_source_absent:missing` before it saved the next run, and
the pass had no code for unsaved runs.
- Green: the same files and
`online-durable-data-migration-postgres.test.ts` pass (42 tests).
- `pnpm --filter @paperclipai/server typecheck` passes.
- Local `pnpm verify` selects most of the suite for this change (2,979
of 3,855 files). Required CI supplies that coverage.

## Risks

- No migration rule changes. A run whose bundle is gone still blocks the
move, online and offline.
- The maintenance command now exits 1 when a run stays unsaved, as it
did before when the page threw.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use and code
execution in Claude Code.

## 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
- [ ] All Paperclip CI gates are green
- [ ] 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>
This commit is contained in:
DottaandClaude Opus 5.5 authored and GitHub committed 2026-11-23 12:51:59 -06:00
1 parent 949bc3765c
commit fd6317de23
5 files changed
+59 -6

No files matched your search

+2
View File
@@ -38,4 +38,6 @@ try {
const result = await action({ apply, writersStopped: process.argv.includes("--writers-stopped"),
clearLegacy: process.argv.includes("--clear-legacy"), limit, after: value("--after"), companyId: value("--company") });
console.log(JSON.stringify({ phase, apply, ...result }));
if (phase === "runtime-assets" && (result as Awaited<ReturnType<typeof migrateRuntimeSkillAssets>>).results
.some(row => row.status === "unsaved")) process.exitCode = 1;
} finally { await db.$client.end({ timeout: 1 }); }
@@ -51,13 +51,13 @@ describe("admitted unversioned runtime skill preservation", () => {
await database?.cleanup();
if (home) await removeRuntimeAssetTree(home);
});
async function fixture() {
async function fixture(skill = "# original admitted skill\n") {
const companyId = randomUUID(), agentId = randomUUID(), runId = randomUUID(), issueId = randomUUID();
await db.insert(companies).values({ id: companyId, name: "Skill preservation", issuePrefix: `R${companyId.slice(0, 6)}` });
await db.insert(agents).values({ id: agentId, companyId, name: "Recovery source" });
await db.insert(issues).values({ id: issueId, companyId, title: "Preserve admitted skill" });
const bundle = await materializeAsset([
{ path: "SKILL.md", content: Buffer.from("# original admitted skill\n"), mode: 0o400 },
{ path: "SKILL.md", content: Buffer.from(skill), mode: 0o400 },
{ path: "scripts/run.sh", content: Buffer.from("#!/bin/sh\necho preserve\n"), mode: 0o500 },
{ path: "binary", content: Buffer.from([0, 255, 7]), mode: 0o444 },
]);
@@ -187,6 +187,20 @@ describe("admitted unversioned runtime skill preservation", () => {
await removeRuntimeAssetTree(f.bundle.rootPath);
expect(await preserveRuntimeSkillAssets(db, f, storage)).toEqual({ preserved: 1 });
});
it("names a retained run whose bundle left this disk and still saves the runs after it", async () => {
const lost = await fixture("# lost admitted skill\n"), kept = await fixture("# kept admitted skill\n");
await removeRuntimeAssetTree(lost.bundle.rootPath);
const page = await migrateRuntimeSkillAssets(db, { apply: true }, storage);
expect([...page.results].sort((a, b) => a.runId.localeCompare(b.runId))).toEqual([
{ runId: lost.runId, status: "unsaved", code: "runtime_skill_source_absent:missing" },
{ runId: kept.runId, status: "preserved", preserved: 1 },
].sort((a, b) => a.runId.localeCompare(b.runId)));
expect((await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, kept.runId)))[0]!.runnerProfileJson)
.toHaveProperty("nativeRuntimeSkillPreservation");
expect((await db.select().from(heartbeatRuns).where(eq(heartbeatRuns.id, lost.runId)))[0]!.runnerProfileJson)
.not.toHaveProperty("nativeRuntimeSkillPreservation");
expect(await hasLocalRuntimeSkillObligations(db)).toBe(true);
});
it("retains the original receipt through a contract revision but rejects a changed admitted asset or binding", async () => {
const f = await fixture();
await preserveRuntimeSkillAssets(db, f, storage);
@@ -268,13 +268,19 @@ export async function migrateRuntimeSkillAssets(db: Db, options: { companyId?: s
.where(and(retainedRuntimeSkillsSql(), options.companyId ? eq(heartbeatRuns.companyId, options.companyId) : undefined,
options.after ? gt(heartbeatRuns.id, options.after) : undefined)).orderBy(asc(heartbeatRuns.id))
.limit(Math.max(1, Math.min(50, options.limit ?? 10)));
const results: Array<{ runId: string; status: "candidate" | "preserved"; preserved?: number }> = [];
const results: Array<{ runId: string; status: "candidate" } | { runId: string; status: "preserved"; preserved: number }
| { runId: string; status: "unsaved"; code: `runtime_skill_source_absent:${RuntimeSkillSourceAbsent["reason"]}` }> = [];
await withSkillPackageReadScope(db, async () => {
for (const row of rows) {
options.signal?.throwIfAborted();
if (!options.apply) { results.push({ runId: row.id, status: "candidate" }); continue; }
const result = await preserveRuntimeSkillAssets(db, { companyId: row.companyId, runId: row.id, signal: options.signal }, storage);
results.push({ runId: row.id, status: "preserved", preserved: result.preserved });
try {
const result = await preserveRuntimeSkillAssets(db, { companyId: row.companyId, runId: row.id, signal: options.signal }, storage);
results.push({ runId: row.id, status: "preserved", preserved: result.preserved });
} catch (error) {
if (!(error instanceof RuntimeSkillSourceAbsent)) throw error;
results.push({ runId: row.id, status: "unsaved", code: `runtime_skill_source_absent:${error.reason}` });
}
}
});
return { inspected: rows.length, after: rows.at(-1)?.id ?? null, results };
@@ -194,6 +194,34 @@ describe("online durable-data migration pass", () => {
expect(result.deferred).toMatchObject({ "runtime_skill_assets:runtime_skill_source_absent:missing": 1 });
});
it("names each retained runtime skill run it could not save", async () => {
const fixture = owners({ runtimeSkillAssets: async () => ({ inspected: 3, after: null, results: [
{ runId: "r1", status: "preserved", preserved: 1 },
{ runId: "r2", status: "unsaved", code: "runtime_skill_source_absent:missing" },
{ runId: "r3", status: "unsaved", code: "runtime_skill_source_absent:missing" }] }) });
const result = await runOnlineDurableDataMigration(db, { budgetMs: 60_000 }, fixture.owners);
expect(result.counts.runtimeSkillRuns).toBe(1);
expect(result.deferred["runtime_skill_assets:runtime_skill_source_absent:missing"]).toBe(2);
});
it("keeps naming an unsaved runtime skill run after a later pass resumes past it", async () => {
let clock = 0;
const fixture = owners({
runtimeSkillAssets: async () => {
clock = 61_000;
return { inspected: 1, after: null, results: [{ runId: "r1", status: "unsaved", code: "runtime_skill_source_absent:missing" }] };
},
eligibility: vi.fn(async () => ({ eligible: false, blockers: ["runtime_skill_assets_require_migration"] })),
});
const first = await runOnlineDurableDataMigration(db, { budgetMs: 60_000, now: () => clock }, fixture.owners);
expect(first).toMatchObject({ state: "budget_exhausted", resumePhase: "run_logs" });
clock = 0;
const second = await runOnlineDurableDataMigration(db, { budgetMs: 60_000, now: () => clock }, fixture.owners);
expect(second.state).toBe("completed");
expect(second.deferred["runtime_skill_assets:runtime_skill_source_absent:missing"]).toBe(1);
expect(second.deferred["runtime_skill_assets:pending_inspection"]).toBeUndefined();
});
it("passes the page size to the skill object copy so a slow page can shrink", async () => {
const skillObjects = vi.fn(async () => ({ inspected: 0, migrated: 0, busy: 0, after: null }));
await runOnlineDurableDataMigration(db, { budgetMs: 60_000 }, owners({ skillObjects }).owners);
@@ -214,7 +214,10 @@ async function migrate(db: Db, input: { budgetMs: number; now?: () => number },
}
case "runtime_skill_assets": {
const result = await owners.runtimeSkillAssets(db, { apply: true, after, limit, signal }, storage);
add(counts, "runtimeSkillRuns", result.results.filter(row => row.status === "preserved").length);
for (const row of result.results) {
if (row.status === "preserved") add(counts, "runtimeSkillRuns");
else if (row.status === "unsaved") defer(`runtime_skill_assets:${row.code}`);
}
return result.inspected < limit || !result.after ? null : result.after;
}
case "run_logs":