Files
DottaandPaperclip d855e550ad Finish Copilot native runtime on current master (#15701)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Paperclip Runner controls provider processes, permissions and task
completion.
> - Copilot needs its pinned distribution, native message identities and
accepted semantic completion receipts.
> - The release must preserve saved-token access and task lifecycle
guarantees.
> - This pull request will keep the current completion and recovery
fixes while adding the Copilot runtime.
> - The benefit is a reviewable part of the Copilot production release.

## Linked Issues or Issue Description

Refs #14434. Supersedes the runtime work in #15560. This is the first PR
in the stack; #15703, #15705 and #15706 follow. Related alternative
adapter work: #15881. This change uses the shared Runner path.

## What Changed

- Pin Copilot CLI 1.0.88 and bind the integrated implementation as
profile45.
- Keep native instruction, permission, receipt, process ownership and
cancellation boundaries.
- Preserve current master completion continuation and remote
verification behavior. Other provider release identities stay unchanged.

## Verification

Final reviewed source
[`4f3f1af807d2ed21adabb04c2f27f4df9c4bc8d5`](https://github.com/paperclipai/paperclip/commit/4f3f1af807d2ed21adabb04c2f27f4df9c4bc8d5)
includes master `cde944ed75648adfb569e86133adc8b118b55dd6`. The combined
four-part PR tree matches it except for the CI-owned lockfile. Every
prior public PR head remains an ancestor. Released master migrations
remain unchanged; Copilot adds migration361. No unrelated provider is
enabled.

Copilot CLI1.0.88 and profile47 retain digest
`sha256:55044aa235e88b3fe36ec8a556ee1e3382590870aab907e4462ef7d64af49cea`.
The pending qualification marker is removed. The [qualification
record](https://github.com/paperclipai/paperclip/blob/4f3f1af807d2ed21adabb04c2f27f4df9c4bc8d5/doc/plans/2026-10-20-copilot-qualification-v47.json)
reports **20/20 Product cells,154 assertions;7/7 protocol cases,46
assertions** against frozen installed application
`c2616370800f5f6df45246b0890ba35a7cd2faab`. Both environments use the
exact authenticated model `gpt-5.6-luna`. Every passing Product case
confirms cleanup. Automatic behavior retries are disabled. Original
failed attempts remain recorded.

The ordinary installed remote journey passed saved-token selection,
authenticated model discovery, normal UI save/reopen, metadata-only
Test, task completion, accepted receipt and an exact19-byte browser
download. An open model catalog caused no new discovery requests
during117seconds. Actual installed runtime smokes passed on macOS ARM64,
macOS x64 under Rosetta and native Linux x64 on Daytona. Raw token
browser entry was not exercised; the encrypted connection was created
through the normal API.

The original Daytona file attempt timed out during delayed semantic
dispatch. Its precise stalled layer remains unresolved. Independent
ordinary delivery and the other19 cells passed before one instrumented
recheck passed8/8 with unchanged source,prompt,assertions and deadlines.
No causal latency repair is claimed.

After current-master reconciliation,129 connection tests,59 runner
tests,72 shared eval tests and88 recovery/workspace tests pass.
Migration generation/safety, unchanged profile identity and UI token
gates pass. Prior required CI was green. Fresh exact-head required CI
and E2E are green for all four updated heads. Each has a fresh
Greptile5/5 review and zero unresolved review threads. The [final
normal-package cloud
build](https://github.com/paperclipai/paperclip/actions/runs/39414239704)
is running. Recursive typecheck,full CI test shards,build and all8
browser shards pass. These checks cover the final source; no additional
local full-suite pass is claimed.

The [frozen image
build](https://github.com/paperclipai/paperclip/actions/runs/39334401638)
and [original normal package
build](https://github.com/paperclipai/paperclip/actions/runs/39334407471)
passed. The exact image is published and independently retrieved
anonymously. No separate full-image scan is claimed. All18 original
normal archives were scanned with zero selected credentials. Docker
builds run in the cloud. Provider USD remains unknown and
GitHub-attributed.

**Qualification is complete on the recorded frozen build. Normal
protected merge, automatic master canary publication and final
shipped-package local/Daytona canaries remain. No production deployment
is claimed.**

## Risks

Shared Runner behavior can affect active tasks. Exact profile admission
rejects stale runtime identities. The final campaign and installed
canaries remain release gates.

## Model Used

OpenAI Codex, based on GPT-6. The exact serving model ID and context
window are not exposed in this task. Used for code changes, review and
tool-assisted verification.

## 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
- [ ] 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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-10-20 06:31:47 -05:00

175 lines
11 KiB
JavaScript

import assert from "node:assert/strict";
import { createHash } from "node:crypto";
import { spawnSync } from "node:child_process";
import { cpSync, existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import test from "node:test";
import profiles from "../acpx-profiles.json" with { type: "json" };
import distributions from "../cursor-distributions.json" with { type: "json" };
import { verifyReleaseProviderPack } from "./release-provider-pack.mjs";
import { existingReleaseProviderPack, releaseProviderPackManifest } from "./stage-release-runner-binaries.mjs";
const revision = "a".repeat(40);
const digest = "sha256:" + "b".repeat(64);
const canonical = value => Array.isArray(value) ? `[${value.map(canonical).join(",")}]`
: value && typeof value === "object" ? `{${Object.keys(value).sort().map(key => `${JSON.stringify(key)}:${canonical(value[key])}`).join(",")}}` : JSON.stringify(value);
function fixture() {
const payload = { target: { platform: "linux", architecture: "x64" }, runnerSourceRevision: revision,
pins: { acpx: profiles.acpxVersion },
acpxProfileDigests: Object.fromEntries(["grok", "claude", "codex"].map(agent => [agent, profiles.profiles[agent].commandDigest])),
providers: { cursor: { version: profiles.profiles.cursor.agentServerVersion, profileDigest: profiles.profiles.cursor.commandDigest,
closureDigest: `sha256:${distributions.platforms["linux-x64"].closureSha256}`, qualification: "qualified",
path: "provider-assets/cursor/linux-x64", sha256: digest } } };
payload.providers.copilot = { version: profiles.profiles.copilot.agentServerVersion,
profileDigest: profiles.profiles.copilot.commandDigest, closureDigest: "sha256:a3d8f4367cfa1694d79e3f8b7930b6fbfe42a229c272b375b11951d631db8d07",
qualification: "qualified", path: "provider-assets/copilot/linux-x64", sha256: digest };
return payload;
}
function seal(payload) { return { schema: "paperclip-runner/remote-provider-pack/v1", payload,
digest: `sha256:${createHash("sha256").update(canonical(payload)).digest("hex")}` }; }
test("accepts a pack whose source and profiles match the assembled release", () => {
const manifest = seal(fixture()); assert.equal(verifyReleaseProviderPack(manifest, revision), manifest);
});
for (const field of ["version", "profileDigest", "closureDigest", "qualification", "path"]) {
test(`rejects an independently rehashed stale Cursor ${field}`, () => {
const payload = fixture(); payload.providers.cursor[field] = field.endsWith("Digest") ? digest : "stale";
assert.throws(() => verifyReleaseProviderPack(seal(payload), revision), /Cursor identity/);
});
}
test("rejects omitted Cursor, conflicting legacy inventory, stale sources and forged payload digests", () => {
const missing = fixture(); delete missing.providers.cursor;
assert.throws(() => verifyReleaseProviderPack(seal(missing), revision), /Cursor identity/);
const mixed = fixture(); mixed.candidateProviders = { cursor: { ...mixed.providers.cursor, profileDigest: digest } };
assert.throws(() => verifyReleaseProviderPack(seal(mixed), revision), /Cursor identity/);
const old = fixture(); old.runnerSourceRevision = "c".repeat(40);
assert.throws(() => verifyReleaseProviderPack(seal(old), revision), /release source/);
const forged = seal(fixture()); forged.digest = digest;
assert.throws(() => verifyReleaseProviderPack(forged, revision), /payload digest/);
});
test("release assembly rejects rehashed stale or missing packs before staging any files", () => {
const root = realpathSync(mkdtempSync(join(tmpdir(), "release-provider-pack-")));
const source = dirname(dirname(fileURLToPath(import.meta.url)));
try {
// Run the actual assembler in an isolated layout so it cannot overwrite built artifacts.
for (const file of ["scripts/stage-release-runner-binaries.mjs", "scripts/release-provider-pack.mjs", "src/live/runner-binary.ts", "acpx-profiles.json", "cursor-distributions.json", "release-runner-targets.json"]) {
mkdirSync(dirname(join(root, file)), { recursive: true }); cpSync(join(source, file), join(root, file));
}
const platforms = {};
for (const target of ["darwin-arm64", "darwin-x64", "linux-x64", "linux-arm64"]) {
const bytes = Buffer.alloc(64);
if (target.startsWith("linux-")) {
bytes.set([0x7f, 0x45, 0x4c, 0x46, 2, 1]); bytes.writeUInt16LE(target === "linux-x64" ? 62 : 183, 18);
} else {
bytes.writeUInt32LE(0xfeedfacf, 0); bytes.writeUInt32LE(target === "darwin-arm64" ? 0x0100000c : 0x01000007, 4);
}
const path = join(root, target); writeFileSync(path, bytes);
platforms[target] = { path, sha256: `sha256:${createHash("sha256").update(bytes).digest("hex")}` };
}
const payload = fixture(); payload.providers.cursor.profileDigest = digest;
const bytes = JSON.stringify(seal(payload)), path = join(root, "provider-pack.json"); writeFileSync(path, bytes);
const manifest = { sourceRevision: revision, platforms, remoteProviderPack: { path, sha256: `sha256:${createHash("sha256").update(bytes).digest("hex")}` } };
for (const error of [/Cursor identity/, /requires the matching Linux remote provider pack/]) {
writeFileSync(join(root, "release.json"), JSON.stringify(manifest));
const result = spawnSync(process.execPath, [join(root, "scripts/stage-release-runner-binaries.mjs"), join(root, "release.json")], { encoding: "utf8" });
assert.equal(result.status, 1); assert.match(result.stderr, error);
assert.equal(existsSync(join(root, "dist")), false);
delete manifest.remoteProviderPack;
}
} finally { rmSync(root, { recursive: true, force: true }); }
});
test("daemon-only assembly retains an existing same-source Linux provider-pack identity", () => {
const root = realpathSync(mkdtempSync(join(tmpdir(), "release-provider-retained-")));
try {
assert.equal(existingReleaseProviderPack(root, revision), undefined);
const file = join(root, "dist/remote-provider-packs/linux-x64/provider-pack.json");
mkdirSync(dirname(file), { recursive: true });
const pack = seal(fixture()); writeFileSync(file, JSON.stringify(pack));
assert.deepEqual(existingReleaseProviderPack(root, revision), pack);
assert.throws(() => existingReleaseProviderPack(root, "c".repeat(40)), /release source/);
const wrongTarget = fixture(); wrongTarget.target = { platform: "darwin", architecture: "arm64" };
writeFileSync(file, JSON.stringify(seal(wrongTarget)));
assert.throws(() => existingReleaseProviderPack(root, revision), /Linux x64 target/);
} finally { rmSync(root, { recursive: true, force: true }); }
});
for (const field of ["version", "profileDigest", "closureDigest", "qualification", "path", "sha256"]) {
test(`rejects an independently rehashed stale Copilot ${field}`, () => {
const payload = fixture(); payload.providers.copilot[field] = "stale";
assert.throws(() => verifyReleaseProviderPack(seal(payload), revision), /Copilot identity/);
});
}
test("rejects omitted Copilot and a duplicate candidate inventory", () => {
const missing = fixture(); delete missing.providers.copilot;
assert.throws(() => verifyReleaseProviderPack(seal(missing), revision), /Copilot identity/);
const mixed = fixture(); mixed.candidateProviders = { copilot: mixed.providers.copilot };
assert.throws(() => verifyReleaseProviderPack(seal(mixed), revision), /Copilot identity/);
});
function armFixture() {
const payload = fixture();
payload.target.architecture = "arm64";
delete payload.providers;
return payload;
}
test("ARM pack binds its own target and preserves other providers qualification limits", () => {
const pack = seal(armFixture());
assert.equal(verifyReleaseProviderPack(pack, revision, "linux-arm64"), pack);
assert.throws(() => verifyReleaseProviderPack(pack, revision), /Linux x64 target/);
assert.throws(() => verifyReleaseProviderPack(seal(fixture()), revision, "linux-arm64"), /linux-arm64 target/);
for (const inventory of ["providers", "candidateProviders"]) {
const payload = armFixture(); payload[inventory] = { pi: {} };
assert.throws(() => verifyReleaseProviderPack(seal(payload), revision, "linux-arm64"), /must not expand/);
}
});
test("both remote pack identities bind one source and remain separated during assembly", () => {
const root = realpathSync(mkdtempSync(join(tmpdir(), "release-provider-targets-")));
try {
for (const [target, payload] of [["linux-x64", fixture()], ["linux-arm64", armFixture()]]) {
const file = join(root, target, "provider-pack.json"); mkdirSync(dirname(file), { recursive: true });
writeFileSync(file, JSON.stringify(seal(payload)));
}
const entries = releaseProviderPackManifest(root, revision);
assert.deepEqual(Object.keys(entries), ["linux-x64", "linux-arm64"]);
assert.notEqual(entries["linux-x64"].sha256, entries["linux-arm64"].sha256);
assert.throws(() => releaseProviderPackManifest(root, "c".repeat(40)), /release source/);
writeFileSync(join(root, "linux-arm64", "provider-pack.json"), JSON.stringify(seal(fixture())));
assert.throws(() => releaseProviderPackManifest(root, revision), /linux-arm64 target/);
rmSync(join(root, "linux-arm64"), { recursive: true });
assert.throws(() => releaseProviderPackManifest(root, revision), /exactly both/);
} finally { rmSync(root, { recursive: true, force: true }); }
});
test("frozen image validation uses release profiles rather than the newer workflow checkout", () => {
const frozenProfiles = structuredClone(profiles);
const frozenDistributions = structuredClone(distributions);
frozenProfiles.acpxVersion = "frozen-acpx";
for (const agent of ["claude", "codex", "grok", "cursor"]) frozenProfiles.profiles[agent].commandDigest = digest;
frozenProfiles.profiles.cursor.agentServerVersion = "frozen-cursor";
frozenDistributions.platforms["linux-x64"].closureSha256 = "c".repeat(64);
const payload = fixture();
payload.pins.acpx = frozenProfiles.acpxVersion;
for (const agent of ["claude", "codex", "grok"]) payload.acpxProfileDigests[agent] = digest;
Object.assign(payload.providers.cursor, { version: "frozen-cursor", profileDigest: digest, closureDigest: "sha256:" + "c".repeat(64) });
const pack = seal(payload);
const expected = { profiles: frozenProfiles, distributions: frozenDistributions };
assert.throws(() => verifyReleaseProviderPack(pack, revision), /profiles/);
assert.equal(verifyReleaseProviderPack(pack, revision, "linux-x64", expected), pack);
payload.acpxProfileDigests.claude = "sha256:" + "d".repeat(64);
assert.throws(() => verifyReleaseProviderPack(seal(payload), revision, "linux-x64", expected), /profiles/);
});
test("uses the frozen release's Copilot profile when the workflow checkout has advanced", () => {
const releaseProfiles = structuredClone(profiles);
releaseProfiles.profiles.copilot.commandDigest = "sha256:" + "e".repeat(64);
const payload = fixture(); payload.providers.copilot.profileDigest = releaseProfiles.profiles.copilot.commandDigest;
const manifest = seal(payload);
assert.equal(verifyReleaseProviderPack(manifest, revision, "linux-x64", { profiles: releaseProfiles, distributions }), manifest);
assert.throws(() => verifyReleaseProviderPack(manifest, revision), /Copilot identity/);
});