feat(cloud): read-only durable-data eligibility for online enrollment (#22051)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Hosted Paperclip servers can move from a server with a persistent
volume to a volume-free server, which allows deploys without downtime
> - The online move is allowed only when no durable data still lives on
the local disk; Core checks this in `readEphemeralServerDataEligibility`
> - Cloud can only learn the result by calling the preparation endpoint,
and that call starts a real move when the server is eligible
> - So Cloud cannot safely survey many servers, or watch a background
migration make progress
> - This pull request adds a signed, read-only GET that runs the same
check and returns the blocker names
> - The benefit is that operators can see which data blocks each server,
and move only the servers that are ready

## Linked Issues or Issue Description

**What existing behavior does this improve?**
Cloud can see a server's durable-data eligibility only through `POST
/api/instance/ephemeral-enrollment/prepare`. A refused call returns the
blockers. An accepted call starts the online move.

**Subsystem affected**
Server: Cloud control endpoints and ephemeral enrollment
(`server/src/routes/ephemeral-enrollment.ts`,
`server/src/services/ephemeral-enrollment.ts`,
`server/src/middleware/cloud-control.ts`).

**Current behavior**
There is no way to read eligibility without the side effect of
preparation.

**Proposed behavior**
`GET /api/instance/ephemeral-enrollment/eligibility` accepts only a
Cloud control assertion for the new action
`ephemeral-enrollment:eligibility`. It returns `{ eligible, blockers,
ephemeralServer }` and writes nothing.

**Reason and benefit**
A rollout to many servers needs to know which servers are ready, and
which data owners block the others, before it starts any move.

**Breaking changes**
None. This adds one endpoint and one action. Existing actions are
unchanged.

## What Changed

- `routes/ephemeral-enrollment.ts`: new `GET
/instance/ephemeral-enrollment/eligibility`. It requires a verified
Cloud control claim for `ephemeral-enrollment:eligibility` and sets
`Cache-Control: no-store`.
- `services/ephemeral-enrollment.ts`: new
`readOnlineEphemeralEnrollmentEligibility`. It uses the same check as
preparation (`purpose: "startup"`) and returns only the eligibility
flag, the canonical blocker names, and whether this server is already
volume-free.
- `middleware/cloud-control.ts` and
`services/cloud-runtime-identity.ts`: register the endpoint and the
action. Each assertion stays bound to one action, so a prepare token
cannot read eligibility, and the reverse.
- `__tests__/openapi-routes.test.ts`: list the route with the other
Cloud-control endpoints that are not in the board OpenAPI document.

## Verification

- `npx vitest run src/routes/ephemeral-enrollment.test.ts
src/__tests__/openapi-routes.test.ts
src/services/ephemeral-enrollment.test.ts
src/services/cloud-runtime-identity.test.ts`: 83/83 pass.
- New route tests:
  - a signed read returns the result and does not call preparation;
  - an unsigned caller and a tenant instance admin get 403;
  - a prepare assertion on this path gets 401.
- The three new tests fail without the route (red) and pass with it
(green).
- `tsc --noEmit` reports no errors in the touched files. A full local
typecheck needs the Runner build, so CI covers it.

## Risks

- Low risk. The endpoint is read-only and reachable only with a Cloud
control assertion bound to this stack and this action.
- The check runs a few indexed reads and pages skill installations.
Cloud calls it on request, not on a timer.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use
(shell, file edits).

## 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-17 13:02:37 -06:00
1 parent b43a08201c
commit 98ff5e002a
6 files changed
+40 -2

No files matched your search

@@ -128,6 +128,7 @@ const explicitOpenApiOperationCoverageExclusions = new Set([
// Exact Cloud-control signed action; ordinary board/agent credentials cannot invoke it.
"POST /api/instance/connector-events/wake",
"POST /api/instance/ephemeral-enrollment/prepare",
"GET /api/instance/ephemeral-enrollment/eligibility",
// Muse uses its closed, versioned receiver protocol and dedicated credentials,
// documented in doc/muse-personal-agent.md and the shared protocol contract.
// Board connection/qualification management remains in this OpenAPI document.
+1
View File
@@ -22,6 +22,7 @@ export function verifiedIdleCapabilities(req: Request): VerifiedIdleCapabilities
/** Endpoint → method → the one action a control assertion must name to take it. */
const ACTIONS_BY_ENDPOINT: Record<string, Record<string, CloudControlAction>> = {
"/api/instance/ephemeral-enrollment/prepare": { POST: "ephemeral-enrollment:prepare" },
"/api/instance/ephemeral-enrollment/eligibility": { GET: "ephemeral-enrollment:eligibility" },
"/api/instance/connector-events/wake": { POST: "connector-events:wake" },
"/api/instance/task-drain/status": { POST: "task-drain:read-body" },
"/api/instance/task-drain": {
+25 -1
View File
@@ -10,7 +10,9 @@ import { CLOUD_CONTROL_AUDIENCE, CLOUD_CONTROL_HEADER, CLOUD_CONTROL_JWS_TYPE,
CLOUD_RUNTIME_IDENTITY_ISSUER, resetCloudControlReplayFenceForTests } from "../services/cloud-runtime-identity.js";
const prepare = vi.hoisted(() => vi.fn());
vi.mock("../services/ephemeral-enrollment.js", () => ({ prepareOnlineEphemeralEnrollment: prepare }));
const eligibility = vi.hoisted(() => vi.fn());
vi.mock("../services/ephemeral-enrollment.js", () => ({ prepareOnlineEphemeralEnrollment: prepare,
readOnlineEphemeralEnrollmentEligibility: eligibility }));
const pair = generateKeyPairSync("ed25519");
const jwk = { ...pair.publicKey.export({ format: "jwk" }), kid: "enrollment-fixture", alg: "EdDSA", use: "sig" };
const path = "/api/instance/ephemeral-enrollment/prepare";
@@ -42,6 +44,7 @@ beforeEach(() => {
vi.stubEnv("PAPERCLIP_CLOUD_STACK_ID", "stack-fixture");
vi.stubEnv("PAPERCLIP_CLOUD_RUNTIME_IDENTITY_JWKS", JSON.stringify({ keys: [jwk] }));
prepare.mockResolvedValue({ attemptId, enrollmentReady: false, decisionSigningSecret: "fixture-original-key" });
eligibility.mockResolvedValue({ eligible: false, blockers: ["workspaces_require_migration"], ephemeralServer: false });
});
afterEach(() => vi.unstubAllEnvs());
@@ -79,3 +82,24 @@ it("keeps enrollment HTTP diagnostics secret-sensitive, including rejected metho
expect(isSecretSensitiveHttpRequest(method, `https://fixture.test${path}`)).toBe(true);
}
});
const eligibilityPath = "/api/instance/ephemeral-enrollment/eligibility";
it("reports durable-data eligibility to a signed read and changes nothing", async () => {
const result = await request(app()).get(eligibilityPath).set(CLOUD_CONTROL_HEADER, assertion("ephemeral-enrollment:eligibility"));
expect(result.status).toBe(200);
expect(result.headers["cache-control"]).toBe("no-store");
expect(result.body).toEqual({ eligible: false, blockers: ["workspaces_require_migration"], ephemeralServer: false });
expect(prepare).not.toHaveBeenCalled();
});
it.each([false, true])("refuses an unsigned eligibility read, including a tenant instance admin (%s)", async tenant => {
expect((await request(app(tenant)).get(eligibilityPath)).status).toBe(403);
expect(eligibility).not.toHaveBeenCalled();
});
it("refuses a prepare assertion on the eligibility read", async () => {
const result = await request(app()).get(eligibilityPath).set(CLOUD_CONTROL_HEADER, assertion("ephemeral-enrollment:prepare"));
expect(result.status).toBe(401);
expect(eligibility).not.toHaveBeenCalled();
});
+7 -1
View File
@@ -3,7 +3,7 @@ import { z } from "zod";
import type { Db } from "@paperclipai/db";
import { validate } from "../middleware/validate.js";
import { verifiedCloudControlClaims } from "../middleware/cloud-control.js";
import { prepareOnlineEphemeralEnrollment } from "../services/ephemeral-enrollment.js";
import { prepareOnlineEphemeralEnrollment, readOnlineEphemeralEnrollmentEligibility } from "../services/ephemeral-enrollment.js";
export function ephemeralEnrollmentRoutes(db: Db) {
const router = Router();
@@ -16,5 +16,11 @@ export function ephemeralEnrollmentRoutes(db: Db) {
if (claims?.action !== "ephemeral-enrollment:prepare") { res.status(403).json({ error: "cloud_control_required" }); return; }
res.json(await prepareOnlineEphemeralEnrollment(db, req.body.attemptId, claims));
});
router.get("/instance/ephemeral-enrollment/eligibility", async (req, res) => {
res.set("Cache-Control", "no-store");
const claims = req.actor.source === "cloud_control" ? verifiedCloudControlClaims(req) : undefined;
if (claims?.action !== "ephemeral-enrollment:eligibility") { res.status(403).json({ error: "cloud_control_required" }); return; }
res.json(await readOnlineEphemeralEnrollmentEligibility(db));
});
return router;
}
@@ -449,6 +449,7 @@ export const CLOUD_CONTROL_AUDIENCE = "paperclip-cloud-control/v1";
export const CLOUD_CONTROL_JWS_TYPE = "paperclip-cloud-control+jwt";
export const CLOUD_CONTROL_ACTIONS = [
"ephemeral-enrollment:prepare",
"ephemeral-enrollment:eligibility",
"task-drain:read",
"task-drain:read-body",
"task-drain:start",
@@ -9,6 +9,11 @@ import { cloudTenantPrimaryCompanyId, getCloudStackContext } from "./cloud-insta
import { resolveDecisionSigningSecret } from "./decision-signing.js";
import { assertEphemeralServerConfig, ephemeralServerEnabled, readEphemeralServerDataEligibility } from "./ephemeral-server-contract.js";
export async function readOnlineEphemeralEnrollmentEligibility(db: Db) {
const { eligible, blockers } = await readEphemeralServerDataEligibility(db, { purpose: "startup" });
return { eligible, blockers, ephemeralServer: ephemeralServerEnabled() };
}
export async function prepareOnlineEphemeralEnrollment(db: Db, attemptId: string, control: Pick<CloudControlClaims, "requestId" | "exp">) {
const stackId = getCloudStackContext()?.stackId;
const commit = readBuildCommit();