mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-30 09:05:15 +01:00
Give managed agents persistent cryptographic identities (#15352)
Give agents persistent Ed25519 identities encrypted with the existing instance master key. Create keys transactionally for new agents and lazily before supported managed runs, expose public identities in the API and agent UI, and protect private material during runtime delivery and output persistence. Preserve identities in recovery backups while giving imported and development-cloned agents fresh keys. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
d9f600043f
commit
a590ab769d
73 files changed
+2014
-63
No files matched your search
@@ -3,6 +3,7 @@ import { readLocalAiCredentialFile } from "../local-ai-credential-file.js";
|
||||
import { prepareGrokRunnerCredentials } from "./grok-runner-credentials.js";
|
||||
import { copyBackGrokAuth } from "@paperclipai/adapter-grok-local/server";
|
||||
|
||||
import { createAgentIdentityRedactor } from "../agent-identity-redaction.js";
|
||||
import {
|
||||
isSupportedRemoteCodexVersion,
|
||||
parseCodexCliVersion,
|
||||
@@ -5256,6 +5257,7 @@ function nativeSessionConfigDigest(
|
||||
.update(
|
||||
JSON.stringify({
|
||||
companyId: execution.binding.companyId,
|
||||
...(execution.binding.agentKeyId ? { agentKeyId: execution.binding.agentKeyId } : {}),
|
||||
normalizedSessionId: nativeSessionKey(execution),
|
||||
executionLocation,
|
||||
provider: execution.provider,
|
||||
@@ -5308,6 +5310,7 @@ function nativeHarnessEnvironmentFingerprint(
|
||||
.update(
|
||||
canonicalJson({
|
||||
companyId: execution.binding.companyId,
|
||||
...(execution.binding.agentKeyId ? { agentKeyId: execution.binding.agentKeyId } : {}),
|
||||
agentId: execution.binding.agentId,
|
||||
issueId: execution.binding.issueId,
|
||||
normalizedSessionId: nativeSessionKey(execution),
|
||||
@@ -7294,6 +7297,14 @@ export async function executePaperclipNativeSession(input: {
|
||||
},
|
||||
) => Promise<unknown>;
|
||||
}): Promise<AdapterExecutionResult> {
|
||||
const agentKeyId = input.runnerEnvironment?.PAPERCLIP_AGENT_KEY_ID;
|
||||
if (agentKeyId) {
|
||||
// Recovered pre-upgrade inputs also need the current public identity marker
|
||||
// before deciding whether an already-running provider can be reused.
|
||||
input = { ...input, execution: { ...input.execution,
|
||||
binding: { ...input.execution.binding, agentKeyId },
|
||||
} };
|
||||
}
|
||||
const runId = input.execution.binding.runId;
|
||||
if (nativeSessionStartups.has(runId)) {
|
||||
throw new Error("native_session_supervisor_busy");
|
||||
@@ -7435,6 +7446,10 @@ export async function executePaperclipNativeSession(input: {
|
||||
async function executePaperclipNativeSessionWithinScope(
|
||||
input: Parameters<typeof executePaperclipNativeSession>[0],
|
||||
): Promise<AdapterExecutionResult> {
|
||||
const identityRedactor = createAgentIdentityRedactor(input.runnerEnvironment?.PAPERCLIP_AGENT_PRIVATE_KEY);
|
||||
const redactIdentityText = (text: string) => redactSensitiveText(
|
||||
identityRedactor.chunk("diagnostic", text) + identityRedactor.finish("diagnostic"),
|
||||
);
|
||||
if (
|
||||
input.execution.provider.kind !== "codex" &&
|
||||
input.execution.provider.kind !== "opencode" &&
|
||||
@@ -7853,6 +7868,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
controlPlaneSourceInstanceId: controlPlaneInstanceId,
|
||||
},
|
||||
{
|
||||
privateKeyPem: input.runnerEnvironment?.PAPERCLIP_AGENT_PRIVATE_KEY,
|
||||
onCommittedEvent: async (event) => {
|
||||
await toolTrace.observe(event);
|
||||
if (event.eventType === "item.completed" &&
|
||||
@@ -8412,6 +8428,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
requireSessionCloseBeforeReturn: runnerdBackend !== null || input.instructionWorkingCopy !== undefined,
|
||||
onSessionClosed: input.instructionWorkingCopy?.collectStopped,
|
||||
onCheckpoint: async (snapshot) => {
|
||||
snapshot = identityRedactor.redact(snapshot);
|
||||
if (warmSessionId !== null && warmConfigDigest !== null) {
|
||||
await persistWarmNativeCheckpoint(
|
||||
input.execution,
|
||||
@@ -8428,7 +8445,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
}
|
||||
},
|
||||
onPostCompletionEnrichmentFailure: async ({ stage, error }) => {
|
||||
const detail = redactSensitiveText(
|
||||
const detail = redactIdentityText(
|
||||
error instanceof Error ? error.message : String(error),
|
||||
).slice(-4_096);
|
||||
await input.onLog?.(
|
||||
@@ -8439,7 +8456,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
onSessionQuarantined: async (reason) => {
|
||||
await input.onLog?.(
|
||||
"stderr",
|
||||
`[paperclip-runner] warm native session quarantined: ${redactSensitiveText(reason).slice(-1_000)}\n`,
|
||||
`[paperclip-runner] warm native session quarantined: ${redactIdentityText(reason).slice(-1_000)}\n`,
|
||||
);
|
||||
},
|
||||
onContinuityBreak: async (continuity) => {
|
||||
@@ -8636,6 +8653,16 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
clearSteeringDeliveries(input.execution.binding.runId);
|
||||
clearNativeRuntimeRequestResolutions(input.execution.binding.runId);
|
||||
} catch (error) {
|
||||
// Preserve typed failure semantics while removing credentials before any
|
||||
// persistence, reporting, logging, or rethrow at this boundary.
|
||||
if (error instanceof Error) {
|
||||
const originalMessage = error.message;
|
||||
error.message = redactIdentityText(originalMessage);
|
||||
if (error.stack) error.stack = redactIdentityText(originalMessage
|
||||
? error.stack.split(originalMessage).join(error.message) : error.stack);
|
||||
} else {
|
||||
error = identityRedactor.redact(error);
|
||||
}
|
||||
if (nativeRunsDetachingForRestart.has(input.execution.binding.runId)) {
|
||||
await leaseRenewal.stop().catch(() => undefined);
|
||||
liveQuestions.close();
|
||||
@@ -8674,7 +8701,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
);
|
||||
|
||||
const failedAtMs = Date.now();
|
||||
const executionFailureMessage = redactSensitiveText(
|
||||
const executionFailureMessage = redactIdentityText(
|
||||
error instanceof Error ? error.message : String(error),
|
||||
).slice(-4_096);
|
||||
if (!taskSettleScope) {
|
||||
@@ -8785,11 +8812,10 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
const { exhausted } = recoveryProjection;
|
||||
const integrityFailure =
|
||||
sourceFailureCode === "native_event_replay_conflict";
|
||||
const message =
|
||||
error instanceof Error
|
||||
? error.message.slice(0, 2_000)
|
||||
: String(error).slice(0, 2_000);
|
||||
const sanitizedStderrTail = redactSensitiveText(message).slice(-4_096);
|
||||
const message = redactIdentityText(
|
||||
error instanceof Error ? error.message : String(error),
|
||||
).slice(0, 2_000);
|
||||
const sanitizedStderrTail = redactIdentityText(message).slice(-4_096);
|
||||
// Set inside the transaction only when the write below genuinely
|
||||
// transitions the run into "failed". Read after the transaction
|
||||
// commits, so a rolled-back write never reports a false failure.
|
||||
@@ -8820,7 +8846,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
recoveryState:
|
||||
phase === "retryable_failure" ? "resuming_session" : "blocked",
|
||||
failureCode,
|
||||
failureDetail: {
|
||||
failureDetail: identityRedactor.redact({
|
||||
message,
|
||||
originalFailureCode:
|
||||
error instanceof NativeProviderTerminalFailure
|
||||
@@ -8857,7 +8883,7 @@ async function executePaperclipNativeSessionWithinScope(
|
||||
"bootstrap_retry"
|
||||
? "Retry provider bootstrap on this same run; durable evidence proves no provider session or provider event was created."
|
||||
: "Resume this same run from its exact persisted native provider checkpoint after the retry delay.",
|
||||
},
|
||||
}),
|
||||
nextAttemptAt,
|
||||
recoveryHistory: sql`(
|
||||
select coalesce(jsonb_agg(item order by ordinal), '[]'::jsonb)
|
||||
|
||||
Reference in new issue
Block a user