mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 22:49:00 +01:00
## 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>
44 lines
3.2 KiB
TypeScript
44 lines
3.2 KiB
TypeScript
/** Run from the server package with its configured storage and DATABASE_URL. */
|
|
import { createDb } from "@paperclipai/db";
|
|
import { loadStorageConfig } from "../src/storage/config.js";
|
|
import { createStorageProviderFromConfig } from "../src/storage/provider-registry.js";
|
|
import { createStorageService } from "../src/storage/service.js";
|
|
import { skillPackageMaintenance } from "../src/services/skill-package-maintenance.js";
|
|
import { skillInstallationMaintenance } from "../src/services/skill-installation-maintenance.js";
|
|
import { migrateRuntimeSkillAssets } from "../src/services/native-runtime/runtime-skill-preservation.js";
|
|
import { isCloudManagedInstance } from "../src/services/cloud-instance.js";
|
|
import { cloudRuntimeConfigService } from "../src/services/cloud-runtime-config.js";
|
|
import { setCloudRuntimeConfigSnapshot } from "../src/services/cloud-runtime-config-snapshot.js";
|
|
|
|
const value = (flag: string) => process.argv.find(arg => arg.startsWith(`${flag}=`))?.slice(flag.length + 1);
|
|
const phase = value("--phase") ?? "snapshots";
|
|
const url = process.env.DATABASE_URL;
|
|
if (!url) throw new Error("DATABASE_URL must explicitly select the database to migrate");
|
|
const limit = Number(value("--limit") ?? 10);
|
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 50) throw new Error("--limit must be between 1 and 50");
|
|
const db = createDb(url, { maxConnections: 2 });
|
|
try {
|
|
if (isCloudManagedInstance()) {
|
|
const current = await cloudRuntimeConfigService(db).inspectStored();
|
|
if (!current) throw new Error("Initialize Cloud runtime configuration before running skill package maintenance");
|
|
setCloudRuntimeConfigSnapshot(current);
|
|
}
|
|
// Maintenance must inspect the old provider before Cloud cutover. Server
|
|
// startup prerequisites still apply to the normal global storage service.
|
|
const storage = createStorageService(createStorageProviderFromConfig(loadStorageConfig()));
|
|
const service = skillPackageMaintenance(db, storage);
|
|
const installations = skillInstallationMaintenance(db, storage);
|
|
const actions = { snapshots: service.migrateSnapshots, versions: service.migrateVersions,
|
|
orphans: service.collectOrphans, deletions: service.deleteObjects,
|
|
installations: installations.installations, eligibility: installations.eligibility, verification: installations.verifyVersions,
|
|
"runtime-assets": (options: Parameters<typeof migrateRuntimeSkillAssets>[1]) => migrateRuntimeSkillAssets(db, options, storage) };
|
|
const action = actions[phase as keyof typeof actions];
|
|
if (!action) throw new Error("--phase must be snapshots, versions, orphans, deletions, installations, eligibility, verification, or runtime-assets");
|
|
const apply = process.argv.includes("--apply");
|
|
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 }); }
|