mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - Native agents run inside remote Daytona sandboxes that require a
verified Runner provider pack
> - When a sandbox stages the provider pack into its workspace,
Paperclip copies, transfers, and verifies every
`provider-assets/<provider>` closure (~1.6 GB across pi, cursor,
copilot, kimi, and antigravity) even when the run only uses Claude,
Codex, OpenCode, or one provider
> - New image-backed Daytona sandbox environments also default to a 10
GiB disk, which leaves too little headroom for repository installs and
tests
> - This pull request stages and verifies only the
`provider-assets/<provider>` tree needed by the active run and raises
the Daytona plugin default disk size from 10 GiB to 20 GiB
> - The benefit is significantly more free workspace disk space, smaller
pack transfers, and safer default disk sizing without changing the
provider-pack archive format or breaking multi-provider workspace reuse
## Linked Issues or Issue Description
- Fixes: #19367
- Refs #19484
- Related: #19500 (ENOSPC fail-fast and full-sandbox recovery already
merged in #22068, #22239, #22383, #22466, and #22837), #22241
(deduplicated repeated bytes in staged packs)
## What Changed
- `server/src/services/native-runtime/provider-pack-compatibility.ts`:
add `requiredProviderAssetNames`, `isProviderAssetPathIncluded`, and
`providerAssetExcludeArgs` helpers that resolve the required
`provider-assets/<provider>` subset for a `PackProvider` (returning
unfiltered behavior when `provider` is omitted).
- `server/src/services/native-runtime/provider-pack-layers.ts`: filter
large layer entries by required provider assets before running the
remote reuse script and transferring missing layers, preserve
cross-provider image-twin reuse so core files can still reuse identical
bytes from excluded provider paths in the base image, and pass
`--exclude` flags to GNU `tar` for `overlay.tar.zst`.
- `server/src/services/native-runtime/provider-pack-archive.ts` and
`provider-pack-upload.ts`: forward `provider` and `manifest` into v1 and
v2 archive staging and exclude unused `provider-assets/*` during
extraction.
-
`server/src/services/native-runtime/remote-provider-pack-verification.ts`:
scope candidate asset tree digest checks to the active provider when
`provider` is passed and include `requiredAssets` in the verification
seal key so a pack verified for one provider cannot satisfy a seal check
for a different provider.
- `server/src/services/native-runtime/native-session-executor.ts` and
`server/src/services/kimi-connection-probe.ts`: pass the active
`PackProvider` to `prepareRemoteProviderPackOnTarget` and
`verifyRemoteProviderPackIdentity`.
- `packages/plugins/sandbox-providers/daytona/src/manifest.ts` and
`package.json`: raise the default `disk` allocation from `10` to `20`
GiB and bump the plugin version from `0.1.10` to `0.1.11` so
bundled-plugin boot reconciliation refreshes persisted manifests.
- Added unit and end-to-end tests in
`packages/plugins/sandbox-providers/daytona/src/plugin.test.ts`,
`server/src/services/native-runtime/provider-pack-archive.test.ts`,
`server/src/services/native-runtime/remote-provider-pack-verification.test.ts`,
and updated `server/src/__tests__/kimi-connection-probe.test.ts`.
## Verification
- **RED (before production edits):**
- `cd packages/plugins/sandbox-providers/daytona && npx vitest run
--config vitest.config.ts -t "bumps the plugin version|pre-fills
sizing|validates and passes the default 20 GiB"` — 3 failed (`0.1.10 !==
0.1.11`, `10 !== 20`).
- `cd server && npx vitest run
src/services/native-runtime/provider-pack-archive.test.ts -t "omits all
provider-assets|stages only the selected provider"` — 2 failed (unused
`provider-assets` staged on disk).
- `cd server && npx vitest run
src/services/native-runtime/remote-provider-pack-verification.test.ts -t
"verifies only the selected provider"` — 1 failed (`candidate_digest`
rejected Claude when `provider-assets/` was absent).
- **GREEN (after fix):**
- `cd server && npx tsc --noEmit -p tsconfig.json` — passed.
- `cd server && npx vitest run
src/services/native-runtime/provider-pack-archive.test.ts` — **56/56
passed**, including an end-to-end upload+verify test proving unfiltered
staging writes >= 6 MiB of provider assets, Claude staging omits all 6
MiB (< 256 KiB total) and verifies cleanly, and switching the same
workspace to Cursor rejects the Claude seal (`candidate_digest`) and
re-stages only Cursor (2 MiB, excluding Kimi and Pi).
- `cd server && npx vitest run
src/services/native-runtime/remote-provider-pack-verification.test.ts
src/services/native-runtime/remote-provider-pack.test.ts
src/services/native-runtime/retained-provider-pack-source.test.ts
src/__tests__/kimi-connection-probe.test.ts` — all passed
(`remote-provider-pack-verification.test.ts` 34/34,
`remote-provider-pack.test.ts` 60/60, `kimi-connection-probe.test.ts`
39/39, `retained-provider-pack-source.test.ts` all passed).
- `cd packages/plugins/sandbox-providers/daytona && pnpm typecheck &&
npx vitest run --config vitest.config.ts` — typecheck passed; all 15
offline test files passed (641 passed, 8 live tests skipped;
`archive-stream-window.test.ts` timed out once during parallel CPU
contention and passed in 6.17s when re-run).
- `node scripts/check-test-budget.mjs --files
server/src/services/native-runtime/provider-pack-archive.test.ts
server/src/services/native-runtime/remote-provider-pack-verification.test.ts
server/src/__tests__/kimi-connection-probe.test.ts` — passed (110
nightly suites validated, 3 test files checked).
- `pnpm verify --base 2d06567795
--explain` exited 2 because
`packages/plugins/sandbox-providers/daytona/package.json` is a global CI
input; focused suites and package typechecks ran locally and sharded PR
CI supplies broad coverage.
- **Not run locally:** Live Daytona sandbox provisioning (requires
`DAYTONA_API_KEY`). Managed Cloud snapshot disk sizing is updated
separately in the Cloud repository.
## Risks
- Low risk. Archive schema v1 and v2 remain unchanged, so existing
Docker images and retained OCI release packs work without rebuilding.
- If a reusable workspace previously staged a pack for one provider (for
example Claude) and a later run on the same workspace uses a provider
with native assets (for example Cursor), the provider-scoped
verification seal misses, `verifyStaged` fails with `candidate_digest`,
and `prepareRemoteProviderPackOnTarget` cleanly re-stages with the
needed provider assets.
- Raising the Daytona plugin default `disk` to 20 GiB only affects new
image-backed environments created with the form default; existing saved
environments and snapshot-backed environments keep their existing
configuration.
> 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
- Google Gemini (Antigravity agent) with shell, file editing, and local
test execution tools.
## 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
174 lines
8.9 KiB
TypeScript
174 lines
8.9 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
|
|
export function canonicalProviderPackJson(value: unknown): string {
|
|
if (Array.isArray(value)) return `[${value.map(canonicalProviderPackJson).join(",")}]`;
|
|
if (value && typeof value === "object") return `{${Object.entries(value).sort(([a], [b]) => a.localeCompare(b))
|
|
.map(([key, entry]) => `${JSON.stringify(key)}:${canonicalProviderPackJson(entry)}`).join(",")}}`;
|
|
return JSON.stringify(value) ?? "null";
|
|
}
|
|
|
|
export type ProviderPackIdentity = {
|
|
schema: string;
|
|
digest: string;
|
|
payload: {
|
|
compatibility?: { opencode: number; acpx: number };
|
|
contractDigest?: string;
|
|
acpxProfileDigests?: Record<string, string>;
|
|
providers?: Record<string, unknown>;
|
|
candidateProviders?: Record<string, unknown>;
|
|
pins: { opencode: string; [key: string]: string | null };
|
|
target: { platform: string; architecture: string };
|
|
runnerSourceRevision: string;
|
|
runnerInputsDigest?: string;
|
|
artifacts: { nodeCommand: { path: string; sha256: string }; opencodeCommand: { path: string; sha256: string }; [key: string]: { path: string; sha256: string } };
|
|
};
|
|
};
|
|
|
|
export function providerPackIncompatible(check: string, detail: string): Error & { failureCheck: string } {
|
|
return Object.assign(new Error(`runner_remote_provider_artifact_incompatible: ${detail}`), { failureCheck: check });
|
|
}
|
|
|
|
export type ProviderPackInstallation = { root: string; manifest: unknown; immutable: boolean };
|
|
export type PackProvider = { kind: "opencode" } | { kind: "acpx"; agent: string };
|
|
export type AdmittedProviderPackReceipt = {
|
|
providerPackDigest: string;
|
|
opencodeProxySha256: string;
|
|
sourceRevision: string;
|
|
};
|
|
|
|
const KNOWN_NATIVE_ASSET_PROVIDERS = ["cursor", "copilot", "pi", "kimi", "antigravity"] as const;
|
|
const BUILTIN_NON_ASSET_ACPX_PROVIDERS = ["claude", "codex", "grok"] as const;
|
|
const SAFE_PROVIDER_ASSET_NAME = /^[a-z0-9-]+$/;
|
|
|
|
/** Narrows a native execution provider to a PackProvider when applicable. */
|
|
export function toPackProvider(
|
|
provider: { kind: string; agent?: string } | undefined,
|
|
): PackProvider | undefined {
|
|
if (!provider) return undefined;
|
|
if (provider.kind === "opencode") return { kind: "opencode" };
|
|
if (provider.kind === "acpx" && typeof provider.agent === "string" && provider.agent.length > 0) {
|
|
return { kind: "acpx", agent: provider.agent };
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
/**
|
|
* Returns the provider-asset subdirectory names needed for `provider`, or `null`
|
|
* when no safe filter applies (stage/verify every declared asset tree).
|
|
*/
|
|
export function requiredProviderAssetNames(
|
|
provider?: PackProvider,
|
|
manifest?: Pick<ProviderPackIdentity, "payload">,
|
|
): string[] | null {
|
|
if (!provider) return null;
|
|
if (provider.kind === "opencode") return [];
|
|
const agent = provider.agent;
|
|
if (!SAFE_PROVIDER_ASSET_NAME.test(agent)) return null;
|
|
if (manifest) {
|
|
const declared = Object.hasOwn(manifest.payload.providers ?? {}, agent)
|
|
|| Object.hasOwn(manifest.payload.candidateProviders ?? {}, agent);
|
|
return declared ? [agent] : [];
|
|
}
|
|
if ((KNOWN_NATIVE_ASSET_PROVIDERS as readonly string[]).includes(agent)) return [agent];
|
|
if ((BUILTIN_NON_ASSET_ACPX_PROVIDERS as readonly string[]).includes(agent)) return [];
|
|
return null;
|
|
}
|
|
|
|
/** True when a pack-relative path belongs to the staged subset for `required`. */
|
|
export function isProviderAssetPathIncluded(
|
|
relativePath: string,
|
|
required: readonly string[] | null,
|
|
options?: { assetsOnly?: boolean },
|
|
): boolean {
|
|
const isAssetTree = relativePath === "provider-assets" || relativePath.startsWith("provider-assets/");
|
|
if (options?.assetsOnly && !isAssetTree) return false;
|
|
if (required === null) return true;
|
|
if (relativePath === "provider-assets") return required.length > 0;
|
|
if (!relativePath.startsWith("provider-assets/")) return true;
|
|
if (required.length === 0) return false;
|
|
const segment = relativePath.slice("provider-assets/".length).split("/")[0] ?? "";
|
|
return required.includes(segment);
|
|
}
|
|
|
|
/** GNU tar `--exclude` arguments that omit unused `provider-assets/*` trees. */
|
|
export function providerAssetExcludeArgs(input: {
|
|
provider?: PackProvider;
|
|
manifest?: Pick<ProviderPackIdentity, "payload">;
|
|
filePaths?: readonly string[];
|
|
}): string[] {
|
|
const required = requiredProviderAssetNames(input.provider, input.manifest);
|
|
if (required === null) return [];
|
|
if (required.length === 0) return ["--exclude=./provider-assets", "--exclude=provider-assets"];
|
|
const known = new Set<string>(KNOWN_NATIVE_ASSET_PROVIDERS);
|
|
for (const key of Object.keys(input.manifest?.payload.providers ?? {})) known.add(key);
|
|
for (const key of Object.keys(input.manifest?.payload.candidateProviders ?? {})) known.add(key);
|
|
for (const relativePath of input.filePaths ?? []) {
|
|
if (!relativePath.startsWith("provider-assets/")) continue;
|
|
const segment = relativePath.slice("provider-assets/".length).split("/")[0] ?? "";
|
|
if (segment) known.add(segment);
|
|
}
|
|
return [...known]
|
|
.filter(name => SAFE_PROVIDER_ASSET_NAME.test(name) && !required.includes(name))
|
|
.sort()
|
|
.flatMap(name => [`--exclude=./provider-assets/${name}`, `--exclude=provider-assets/${name}`]);
|
|
}
|
|
|
|
export function compatibleProviderPackInstallation<T extends ProviderPackIdentity>(
|
|
installation: ProviderPackInstallation, expected: T, packRoot: string,
|
|
provider: PackProvider, requireExactIdentity: boolean, requireCurrentOpenCodeProxy: boolean,
|
|
admittedReceipt?: AdmittedProviderPackReceipt,
|
|
): T {
|
|
const actual = installation.manifest as T | null;
|
|
const payload = actual?.payload;
|
|
const contract = expected.payload.compatibility?.[provider.kind];
|
|
const pinnedReceipt = requireExactIdentity ? admittedReceipt : undefined;
|
|
const matchesPinnedReceipt = pinnedReceipt !== undefined
|
|
&& actual?.digest === pinnedReceipt.providerPackDigest
|
|
&& payload?.artifacts?.opencodeProxy?.sha256 === pinnedReceipt.opencodeProxySha256
|
|
&& payload?.runnerSourceRevision === pinnedReceipt.sourceRevision;
|
|
const failed = !installation.immutable ? "installation_unprotected"
|
|
: installation.root !== packRoot ? "installation_root"
|
|
: !payload ? "manifest_missing"
|
|
: actual.schema !== expected.schema ? "schema"
|
|
: actual.digest !== `sha256:${createHash("sha256").update(canonicalProviderPackJson(payload)).digest("hex")}` ? "manifest_digest"
|
|
: canonicalProviderPackJson(payload.target) !== canonicalProviderPackJson(expected.payload.target) ? "target"
|
|
: pinnedReceipt ? (!matchesPinnedReceipt ? "exact_identity" : null)
|
|
: requireExactIdentity ? (actual.digest !== expected.digest ? "exact_identity" : null)
|
|
: !Number.isSafeInteger(contract) || contract! < 1 ? "expected_compatibility_missing"
|
|
: payload.compatibility?.[provider.kind] !== contract ? "compatibility_revision"
|
|
: !/^sha256:[a-f0-9]{64}$/.test(expected.payload.contractDigest ?? "") ? "expected_contract_digest_missing"
|
|
: payload.contractDigest === undefined ? "contract_digest_missing"
|
|
: payload.contractDigest !== expected.payload.contractDigest ? "contract_digest"
|
|
: null;
|
|
if (failed || !actual || !payload || typeof payload.pins?.opencode !== "string") {
|
|
throw providerPackIncompatible(failed ?? "opencode_pin_missing", "installed provider pack interface or installation is incompatible");
|
|
}
|
|
for (const [name, expectedArtifact] of Object.entries(expected.payload.artifacts)) {
|
|
const artifact = payload.artifacts?.[name];
|
|
if (artifact?.path !== expectedArtifact.path || !/^sha256:[a-f0-9]{64}$/.test(artifact.sha256)) {
|
|
throw providerPackIncompatible(`artifact:${name}`, "installed provider pack artifact identity is invalid");
|
|
}
|
|
}
|
|
if (provider.kind === "opencode" && requireCurrentOpenCodeProxy
|
|
&& payload.artifacts.opencodeProxy?.sha256 !== expected.payload.artifacts.opencodeProxy?.sha256) {
|
|
throw providerPackIncompatible("opencode_proxy", "installed proxy does not match the requested OpenCode diagnostics");
|
|
}
|
|
if (provider.kind === "acpx") {
|
|
const agent = provider.agent;
|
|
const currentProfile = expected.payload.acpxProfileDigests?.[agent];
|
|
const selected = expected.payload.providers?.[agent] ?? expected.payload.candidateProviders?.[agent];
|
|
const installed = payload.providers?.[agent] ?? payload.candidateProviders?.[agent];
|
|
if (pinnedReceipt) {
|
|
const installedProfile = payload.acpxProfileDigests?.[agent];
|
|
if (!/^sha256:[a-f0-9]{64}$/.test(installedProfile ?? "") && !installed) {
|
|
throw providerPackIncompatible("acpx_profile", "selected ACPX provider profile is incompatible");
|
|
}
|
|
} else if (currentProfile ? payload.acpxProfileDigests?.[agent] !== currentProfile
|
|
: !selected || !installed || ["version", "profileDigest", "closureDigest", "qualification", "path"].some(key =>
|
|
(installed as Record<string, unknown>)[key] !== (selected as Record<string, unknown>)[key])) {
|
|
throw providerPackIncompatible("acpx_profile", "selected ACPX provider profile is incompatible");
|
|
}
|
|
}
|
|
return structuredClone(actual);
|
|
}
|