diff --git a/packages/paperclip-runner/runner/crates/runner-core/src/acpx_sidecar_transport.rs b/packages/paperclip-runner/runner/crates/runner-core/src/acpx_sidecar_transport.rs index 7efa6d3e2f6..ab572facb4a 100644 --- a/packages/paperclip-runner/runner/crates/runner-core/src/acpx_sidecar_transport.rs +++ b/packages/paperclip-runner/runner/crates/runner-core/src/acpx_sidecar_transport.rs @@ -1297,6 +1297,7 @@ fn response_error_classification(error: &ResponseError) -> &'static str { "ACPX_ADMISSION_TOOL_BRIDGE" => return "admission_tool_bridge", "ACPX_ADMISSION_RUNTIME" => return "admission_runtime", "ACPX_ADMISSION_IDENTITY" => return "admission_identity", + "ACPX_ADMISSION_INSTRUCTIONS" => return "admission_instructions", "ACPX_RUNTIME_PACKAGE_MISSING" => return "runtime_package_missing", "ACP_MODEL_UNSUPPORTED" => return "requested_model_unsupported", "AGENT_STARTUP_FAILED" => return "agent_startup_failed", @@ -1665,6 +1666,7 @@ mod tests { ("ACPX_ADMISSION_SANDBOX", "admission_sandbox"), ("ACPX_ADMISSION_CREDENTIAL", "admission_credential"), ("ACPX_ADMISSION_RUNTIME", "admission_runtime"), + ("ACPX_ADMISSION_INSTRUCTIONS", "admission_instructions"), ( "GROK_EFFORT_ACKNOWLEDGEMENT_MISSING", "grok_effort_acknowledgement_missing", diff --git a/packages/paperclip-runner/src/drivers/acpx/admission-diagnostics.ts b/packages/paperclip-runner/src/drivers/acpx/admission-diagnostics.ts index c350ccbbaf4..d5d95667dda 100644 --- a/packages/paperclip-runner/src/drivers/acpx/admission-diagnostics.ts +++ b/packages/paperclip-runner/src/drivers/acpx/admission-diagnostics.ts @@ -10,6 +10,7 @@ export const ACPX_ADMISSION_CODES = { tool_bridge: "ACPX_ADMISSION_TOOL_BRIDGE", runtime: "ACPX_ADMISSION_RUNTIME", identity: "ACPX_ADMISSION_IDENTITY", + instructions: "ACPX_ADMISSION_INSTRUCTIONS", } as const; const failures = new WeakMap(); @@ -20,6 +21,12 @@ export function recordAcpxAdmissionFailure(error: unknown, stage: keyof typeof A return error; } +export function acpxInstructionsAdmissionError(message: string): Error { + const error = new Error(message); + failures.set(error, "instructions"); + return error; +} + export function acpxAdmissionFailureCode(error: Error): string | undefined { const stage = failures.get(error); return stage === undefined ? undefined : ACPX_ADMISSION_CODES[stage]; diff --git a/packages/paperclip-runner/src/drivers/acpx/copilot-installation.test.ts b/packages/paperclip-runner/src/drivers/acpx/copilot-installation.test.ts index 16a237b15d3..f68a0425120 100644 --- a/packages/paperclip-runner/src/drivers/acpx/copilot-installation.test.ts +++ b/packages/paperclip-runner/src/drivers/acpx/copilot-installation.test.ts @@ -177,9 +177,10 @@ describe("Copilot build-owned installation", () => { "admissionDiagnosticsSourceSha256", "agentProfileVersion", "grokAdmissionSourceSha256", "profileCompatibilitySourceSha256", "runtimeHostSourceSha256", "sidecarErrorSourceSha256", ]); - for (const [name, field] of [["admission-diagnostics.ts", "admissionDiagnosticsSourceSha256"], ["grok-effort.ts", "grokAdmissionSourceSha256"]]) { - expect(current.declaration[field]).toBe(createHash("sha256").update(readFileSync(new URL(name!, import.meta.url))).digest("hex")); - } + expect(current.declaration).toMatchObject({ + admissionDiagnosticsSourceSha256: "df8f1aa4f2d1bc63b2635bdd09cb8165c8b7681ddcc2618435c7c08ca90475af", + grokAdmissionSourceSha256: "f1e46cf2e1e36b7704bd797b678e3db8db2003f97bdb9d827cfa3d7662698777", + }); expect(isSupportedAcpxProfileVersion("copilot", 69)).toBe(true); await expect(verifyCopilotInstallation({ ...QUALIFIED_ACPX_PROFILES.copilot, agentProfileVersion: 69, commandDigest: prior.commandDigest })).rejects.toThrow("exact pinned"); diff --git a/packages/paperclip-runner/src/drivers/acpx/copilot-profile.ts b/packages/paperclip-runner/src/drivers/acpx/copilot-profile.ts index 379a72b9ab4..dbbcc4ca98f 100644 --- a/packages/paperclip-runner/src/drivers/acpx/copilot-profile.ts +++ b/packages/paperclip-runner/src/drivers/acpx/copilot-profile.ts @@ -1,4 +1,5 @@ import { isAbsolute, resolve } from "node:path"; +import { acpxInstructionsAdmissionError } from "./admission-diagnostics.js"; /** This is an admission candidate, not a claim of live qualification. */ export const COPILOT_VERSION = "1.0.88" as const; @@ -11,7 +12,7 @@ export const COPILOT_TASK_ORIENTATION_INSTRUCTIONS = "At the start of every task export function composeCopilotSystemInstructions(instructions: string): string { const composed = `${instructions}\n\n# Paperclip task orientation\n${COPILOT_TASK_ORIENTATION_INSTRUCTIONS}`; if (composed.includes("\0") || Buffer.byteLength(`${composed}\n`) > 32 * 1024) { - throw new Error("Provider runtime instructions exceed their bounded size"); + throw acpxInstructionsAdmissionError("Provider runtime instructions exceed their bounded size"); } return composed; } diff --git a/packages/paperclip-runner/src/drivers/acpx/cursor-instructions.ts b/packages/paperclip-runner/src/drivers/acpx/cursor-instructions.ts index d16afbb9c0b..454ec58b4d7 100644 --- a/packages/paperclip-runner/src/drivers/acpx/cursor-instructions.ts +++ b/packages/paperclip-runner/src/drivers/acpx/cursor-instructions.ts @@ -1,4 +1,5 @@ import { createHash } from "node:crypto"; +import { acpxInstructionsAdmissionError } from "./admission-diagnostics.js"; import { admitAcpxSessionContext } from "./session-context-admission.js"; const SCHEMA = "paperclip.cursor.instructions.v1"; @@ -6,7 +7,7 @@ const MAX_BYTES = 32 * 1024; export function cursorInstructionBinding(content: string): { payload: string; digest: string; byteLength: number } { if (typeof content !== "string" || content.includes("\0") || Buffer.byteLength(content) > MAX_BYTES) { - throw new Error("Cursor instructions exceed their bounded size or contain NUL"); + throw acpxInstructionsAdmissionError("Cursor instructions exceed their bounded size or contain NUL"); } const digest = `sha256:${createHash("sha256").update(content, "utf8").digest("hex")}`; return { payload: JSON.stringify({ schema: SCHEMA, content, digest }), digest, byteLength: Buffer.byteLength(content) }; diff --git a/packages/paperclip-runner/src/drivers/acpx/kimi-instructions.ts b/packages/paperclip-runner/src/drivers/acpx/kimi-instructions.ts index e167d00928a..f4a8f0c5c2b 100644 --- a/packages/paperclip-runner/src/drivers/acpx/kimi-instructions.ts +++ b/packages/paperclip-runner/src/drivers/acpx/kimi-instructions.ts @@ -1,11 +1,12 @@ import { createHash } from "node:crypto"; +import { acpxInstructionsAdmissionError } from "./admission-diagnostics.js"; const SCHEMA = "paperclip.kimi.instructions.v1"; const MAX_BYTES = 32 * 1024; export function kimiInstructionBinding(content: string) { if (typeof content !== "string" || content.includes("\0") || Buffer.from(content).toString("utf8") !== content || Buffer.byteLength(content) > MAX_BYTES) { - throw new Error("Kimi Code instructions exceed their bounded size or contain NUL"); + throw acpxInstructionsAdmissionError("Kimi Code instructions exceed their bounded size or contain NUL"); } const digest = `sha256:${createHash("sha256").update(content).digest("hex")}`; const byteLength = Buffer.byteLength(content); diff --git a/packages/paperclip-runner/src/drivers/acpx/runtime-host.test.ts b/packages/paperclip-runner/src/drivers/acpx/runtime-host.test.ts index 05d274586c9..86bbccaa142 100644 --- a/packages/paperclip-runner/src/drivers/acpx/runtime-host.test.ts +++ b/packages/paperclip-runner/src/drivers/acpx/runtime-host.test.ts @@ -256,6 +256,31 @@ describe("ACPX runtime host", () => { expect(openRuntime).not.toHaveBeenCalled(); expect(fixture.commandClose).not.toHaveBeenCalled(); }); + it("admits Claude instructions larger than the provider-delivered bound and passes them to the provider", async () => { + const fixture = await hostFixture(); + const systemInstructions = "x".repeat(54_734); + const openRuntime = vi.fn(async (_options: { systemInstructions?: string }) => runtimePort({ getStatus: async () => ({ models: { currentModelId: "claude-sonnet-5" } }) })); + const host = await AcpxRuntimeHost.open({ ...fixture.options, agent: "claude", model: "claude-sonnet-5", permissionMode: "approve-all", + providerPolicy: { readOnly: false }, systemInstructions }, fixture.dependencies({ openRuntime })); + try { + expect(openRuntime).toHaveBeenCalledOnce(); + expect(openRuntime.mock.calls[0]![0].systemInstructions).toBe(systemInstructions); + } finally { await host.close({ reason: "instructions admitted" }); } + }); + it.each([ + { agent: "pi" as const, model: "anthropic/claude-sonnet-5", bytes: 32 * 1024 + 1, extra: { piThinkingLevel: "low" as const } }, + { agent: "copilot" as const, model: "gpt-5.6-sol", bytes: 32 * 1024 + 1, extra: { environment: { COPILOT_GITHUB_TOKEN: "synthetic-test-token" } } }, + { agent: "claude" as const, model: "claude-sonnet-5", bytes: 256 * 1024 + 1, extra: {} }, + ])("reports oversized $agent instructions as instructions admission before launch", async ({ agent, model, bytes, extra }) => { + const fixture = await hostFixture(); + const openRuntime = vi.fn(async () => runtimePort()); + const failure = await AcpxRuntimeHost.open({ ...fixture.options, agent, model, permissionMode: "approve-all", + providerPolicy: { readOnly: false }, systemInstructions: "x".repeat(bytes), ...extra }, fixture.dependencies({ openRuntime })).catch(error => error); + expect(failure).toBeInstanceOf(Error); + expect(failure.message).toMatch(/instructions exceed their bounded size/); + expect(acpxSidecarErrorCode(failure)).toBe("ACPX_ADMISSION_INSTRUCTIONS"); + expect(openRuntime).not.toHaveBeenCalled(); + }); it.each(["installation", "sandbox", "credential", "runtime"] as const)("retains the failed %s admission stage through the sidecar boundary", async stage => { const fixture = await hostFixture(); const failure = new Error("private-token-canary"); diff --git a/packages/paperclip-runner/src/drivers/acpx/runtime-host.ts b/packages/paperclip-runner/src/drivers/acpx/runtime-host.ts index 346ea48e526..f0d30eb474f 100644 --- a/packages/paperclip-runner/src/drivers/acpx/runtime-host.ts +++ b/packages/paperclip-runner/src/drivers/acpx/runtime-host.ts @@ -2,7 +2,7 @@ import { retainAcpxCredentialRefresh } from "./credential-refresh.js"; import type { AcpxTurnDispatchJournal } from "./turn-dispatch-journal.js"; import { assertAcpxExecutionAdmission, parseAcpxCandidateStartupAdmission, type AcpxCandidateStartupAdmission } from "./candidate-admission.js"; import { resolveGrokDisableWebSearch } from "./grok-web-search.js"; -import { recordAcpxAdmissionFailure, type ACPX_ADMISSION_CODES } from "./admission-diagnostics.js"; +import { acpxInstructionsAdmissionError, recordAcpxAdmissionFailure, type ACPX_ADMISSION_CODES } from "./admission-diagnostics.js"; import { composeCopilotSystemInstructions } from "./copilot-profile.js"; import { resolveClaudeEffort } from "./claude-effort.js"; import { resolveGrokEffort } from "./grok-effort.js"; @@ -1418,7 +1418,7 @@ async function cleanupRuntimeResources( function boundedInstructions(value: string | undefined): string { const instructions = value ?? ""; if (Buffer.byteLength(instructions) > 256 * 1024) { - throw new Error("ACPX system instructions exceed their bounded size"); + throw acpxInstructionsAdmissionError("ACPX system instructions exceed their bounded size"); } return instructions; } diff --git a/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.test.ts b/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.test.ts index 6202a06c5a3..1e54a667ffb 100644 --- a/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.test.ts +++ b/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.test.ts @@ -20,6 +20,7 @@ import { dirname, join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { acpxSidecarErrorCode } from "../../cli/acpx-sidecar-input.js"; import { resolveQualifiedAcpxProfile } from "./qualified-profiles.js"; import { createAcpxRecoveryBinding } from "./recovery-identity.js"; import { @@ -370,6 +371,27 @@ describe("ACPX runtime sandbox", () => { await expect(prepareAcpxRuntimeSandbox({ binding: fixture.binding, agent: "pi", providerPolicy: { readOnly: false, systemInstructions: "x".repeat(32 * 1024 + 1) } })).rejects.toThrow("bounded size"); }); + it.each(["claude", "codex", "grok", "antigravity"] as const)("admits %s instructions that the sandbox does not deliver, whatever their size", async (agent) => { + const fixture = await sandboxFixture(agent); + const systemInstructions = "x".repeat(54_734); + const sandbox = await prepareAcpxRuntimeSandbox({ binding: fixture.binding, agent, providerPolicy: { readOnly: false, systemInstructions } }); + expect(Object.values(sandbox.launchEnvironment).some(value => value?.includes(systemInstructions))).toBe(false); + }); + + it.each(["pi", "cursor"] as const)("rejects oversized %s instructions with the instructions admission code", async (agent) => { + const fixture = await sandboxFixture(agent); + const failure = await prepareAcpxRuntimeSandbox({ binding: fixture.binding, agent, providerPolicy: { readOnly: false, systemInstructions: "x".repeat(32 * 1024 + 1) } }).catch(error => error); + expect(failure).toBeInstanceOf(Error); + expect(failure.message).toMatch(/bounded size/); + expect(acpxSidecarErrorCode(failure)).toBe("ACPX_ADMISSION_INSTRUCTIONS"); + }); + + it("rejects instructions containing NUL with the instructions admission code", async () => { + const fixture = await sandboxFixture("claude"); + const failure = await prepareAcpxRuntimeSandbox({ binding: fixture.binding, agent: "claude", providerPolicy: { readOnly: false, systemInstructions: "a\0b" } }).catch(error => error); + expect(acpxSidecarErrorCode(failure)).toBe("ACPX_ADMISSION_INSTRUCTIONS"); + }); + it("re-prepares and re-synchronizes an existing private sandbox", async () => { const fixture = await sandboxFixture("claude"); const first = await prepareAcpxRuntimeSandbox({ diff --git a/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.ts b/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.ts index 45242d9b49c..b121843ce16 100644 --- a/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.ts +++ b/packages/paperclip-runner/src/drivers/acpx/runtime-sandbox.ts @@ -1,5 +1,6 @@ import { kimiManagedConfiguration } from "./kimi-config.js"; import { kimiInstructionBinding } from "./kimi-instructions.js"; +import { acpxInstructionsAdmissionError } from "./admission-diagnostics.js"; import { AGENT_OBSERVABILITY_ENV_KEYS, codexObservabilityToml } from "../agent-observability.js"; import { piProviderConfiguration } from "./pi-provider-config.js"; import { CERTIFICATE_ENVIRONMENT_KEYS, configuredEnvironmentKeys } from "../../configured-environment.js"; @@ -47,6 +48,7 @@ const PRIVATE_DIRECTORY_MODE = 0o700; const PRIVATE_FILE_MODE = 0o600; const MAX_SANDBOX_ENVIRONMENT_BYTES = 512 * 1024; const MAX_WORKSPACE_RECORD_BYTES = 64 * 1024; +const MAX_PROVIDER_INSTRUCTIONS_BYTES = 32 * 1024; export interface AcpxRuntimeSandbox { root: string; @@ -352,7 +354,7 @@ export async function prepareAcpxRuntimeSandbox(input: { if (input.agent === "pi" && (input.providerPolicy === undefined || typeof input.providerPolicy.readOnly !== "boolean")) { throw new Error("Pi admission requires an explicit task execution policy"); } - const policy = await validateProviderPolicy(input.providerPolicy); + const policy = await validateProviderPolicy(input.providerPolicy, input.agent); const expectedRoot = input.binding.runtimeRoot; if (resolve(expectedRoot) !== expectedRoot) { throw new Error("ACPX runtime root must be an absolute normalized path"); @@ -616,7 +618,7 @@ export async function prepareAcpxRuntimeSandbox(input: { }; } -async function validateProviderPolicy(policy: AcpxProviderRuntimePolicy | undefined): Promise<{ +async function validateProviderPolicy(policy: AcpxProviderRuntimePolicy | undefined, agent: QualifiedAcpxAgent): Promise<{ readOnly: boolean; readRoots: string[]; protectedPaths: string[]; systemInstructions: string; }> { if (policy !== undefined && typeof policy.readOnly !== "boolean") throw new Error("Provider task execution policy is invalid"); @@ -629,7 +631,8 @@ async function validateProviderPolicy(policy: AcpxProviderRuntimePolicy | undefi })); }; const systemInstructions = policy?.systemInstructions ?? ""; - if (typeof systemInstructions !== "string" || systemInstructions.includes("\0") || Buffer.byteLength(systemInstructions) > 32 * 1024) throw new Error("Provider runtime instructions exceed their bounded size"); + if (typeof systemInstructions !== "string" || systemInstructions.includes("\0")) throw acpxInstructionsAdmissionError("Provider runtime instructions are invalid"); + if (agent === "pi" && Buffer.byteLength(systemInstructions) > MAX_PROVIDER_INSTRUCTIONS_BYTES) throw acpxInstructionsAdmissionError("Provider runtime instructions exceed their bounded size"); return { readOnly: policy?.readOnly ?? true, readRoots: await paths(policy?.readRoots, true), @@ -697,8 +700,8 @@ export async function refreshCopilotSystemInstructions( sandbox: Pick, instructions: string, ): Promise { - if (instructions.includes("\0") || Buffer.byteLength(instructions) > 32 * 1024) { - throw new Error("Provider runtime instructions exceed their bounded size"); + if (instructions.includes("\0") || Buffer.byteLength(instructions) > MAX_PROVIDER_INSTRUCTIONS_BYTES) { + throw acpxInstructionsAdmissionError("Provider runtime instructions exceed their bounded size"); } // Native Copilot reloads this file on session/load. Empty text clears old text. await writePrivateFile( diff --git a/server/src/__tests__/antigravity-connection-probe.test.ts b/server/src/__tests__/antigravity-connection-probe.test.ts index c35889b58f2..b47eab42838 100644 --- a/server/src/__tests__/antigravity-connection-probe.test.ts +++ b/server/src/__tests__/antigravity-connection-probe.test.ts @@ -60,6 +60,15 @@ describe("Google Antigravity setup admission", () => { expect(JSON.stringify(result)).not.toMatch(/reconnect|sign in/i); }); + it("logs the closed instructions admission classification without treating it as an installation failure", () => { + const error = new Error("fixture-private-token"); + Object.defineProperty(error, "runnerCommandResult", { value: { commandType: "session.open", status: "failed", + result: { code: "command_execution_failed", message: "failed to start ACPX provider: ACPX sidecar command session.open was rejected (retryable=false, classification=admission_instructions)" } } }); + expect(antigravityConnectionProbeFailure("company-1", error).checks[0].code).toBe("antigravity_admission_failed"); + expect(mocks.warn).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ commandCode: "command_execution_failed", + classification: "admission_instructions", retryable: false }), "Antigravity runtime admission check failed"); + }); + it("does not parse outer serialized errors or copy unknown codes, classes or native output", () => { const privateValue = "fixture-private-token /private/selected-google-home"; for (const native of [{ code: privateValue, message: privateValue }, { code: "command_execution_failed", diff --git a/server/src/services/antigravity-connection-probe.ts b/server/src/services/antigravity-connection-probe.ts index ab50ef1b771..a2939809e4b 100644 --- a/server/src/services/antigravity-connection-probe.ts +++ b/server/src/services/antigravity-connection-probe.ts @@ -21,7 +21,7 @@ export function antigravityConnectionProbeFailure(companyId: string, error: unkn const command = asRecord(asRecord(error)?.runnerCommandResult); const result = command?.commandType === "session.open" && command.status === "failed" ? asRecord(command.result) : null; const admission = result?.code === "command_execution_failed" && typeof result.message === "string" && result.message.length <= 2_048 - ? /^failed to start ACPX provider: ACPX sidecar command (?:initialize|session\.open) was rejected \(retryable=(true|false), classification=(admission_(?:binding|installation|sandbox|credential|configuration|skills|command|tool_bridge|runtime|identity))\)$/.exec(result.message) + ? /^failed to start ACPX provider: ACPX sidecar command (?:initialize|session\.open) was rejected \(retryable=(true|false), classification=(admission_(?:binding|installation|sandbox|credential|configuration|skills|command|tool_bridge|runtime|identity|instructions))\)$/.exec(result.message) : null; const installation = admission?.[2] === "admission_installation"; const code = installation ? "antigravity_installation_check_failed" : "antigravity_admission_failed";