mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
Preserve SSH conversations and select authentication before pools
Keep only account-scoped Codex conversation and native index state between in-place SSH turns. Refresh current credentials and managed files for each turn, copy authentication back before cleanup, and start a named fresh session when saved state is unavailable or the account changes. Resolve SSH authentication before pool selection and native home selection. Preserve admitted native recovery inputs. Update transport test fixtures for the stdin command envelope and refresh the committed SDK source pins. Validated 164 execution/routing/probe tests, 91 CI regression tests, 58 SDK support tests, and Codex, Grok and server typechecks. Physical shell tests cover two turns, refresh, account changes, old saved parameters, and failure cleanup. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
8490bf9df2
commit
03e654e870
14 files changed
+293
-18
No files matched your search
@@ -58,7 +58,7 @@ import { readRecoverableRunLog } from "./native-runtime/native-run-log-recovery.
|
||||
import { observabilitySecretValues } from "@paperclipai/adapter-utils/agent-observability";
|
||||
import { prepareHeartbeatSession, resolveHeartbeatAdapterSession } from "./heartbeat/session-preparation.js";
|
||||
import { prepareHeartbeatTaskContext } from "./heartbeat/task-context.js";
|
||||
import { selectHeartbeatEnvironment } from "./heartbeat/environment-selection.js";
|
||||
import { selectHeartbeatEnvironment, resolveSshAuthenticationBeforeRouting } from "./heartbeat/environment-selection.js";
|
||||
import { reconcileMuseNativeTerminalRun } from "./native-runtime/muse-terminal-reconciliation.js";
|
||||
import { prepareHeartbeatWorkspace } from "./heartbeat/workspace-preparation.js";
|
||||
import { nativeRecoveryClaimRelinquished, ownNativeExecutionLeaseLapsed, releaseLapsedNativeRestartClaim } from "./native-runtime/native-execution-lease.js";
|
||||
@@ -2666,8 +2666,17 @@ export function heartbeatService(
|
||||
if ("homeMode" in homeConfig) config = { ...config, homeMode: homeConfig.homeMode };
|
||||
}
|
||||
const persistedRouterPoolId = routerHasPersistedInput ? readNonEmptyString(parseObject(context.aiRouterSelection).poolId) : null;
|
||||
const sshAuthentication = routerHasPersistedInput ? null : await resolveSshAuthenticationBeforeRouting({
|
||||
agentDefaultEnvironmentId: agent.defaultEnvironmentId,
|
||||
lowTrustIssueEnvironmentId: trustPreset.kind === "low_trust_review"
|
||||
? parseIssueExecutionWorkspaceSettings(issueContext?.executionWorkspaceSettings, { includeEnvironmentId: true })?.environmentId ?? null : null,
|
||||
environmentsSvc, instanceSettings,
|
||||
});
|
||||
if (agent.adapterType === "paperclip_runner" && sshAuthentication) {
|
||||
config = { ...config, homeMode: sshAuthentication === "host" ? "preconfigured" : "isolated" };
|
||||
}
|
||||
const preconfiguredHome = agent.adapterType === "paperclip_runner" && config.homeMode === "preconfigured";
|
||||
const requestedAiBinding = preconfiguredHome ? undefined : persistedRouterPoolId ? { mode: "router" as const, connectionId: persistedRouterPoolId } : agent.runtimeConfig?.aiConnection ? aiRuntimeConnectionBindingSchema.parse(agent.runtimeConfig.aiConnection) : undefined;
|
||||
const requestedAiBinding = preconfiguredHome || sshAuthentication === "host" ? undefined : persistedRouterPoolId ? { mode: "router" as const, connectionId: persistedRouterPoolId } : agent.runtimeConfig?.aiConnection ? aiRuntimeConnectionBindingSchema.parse(agent.runtimeConfig.aiConnection) : undefined;
|
||||
let aiBinding = requestedAiBinding?.mode === "router" ? undefined : requestedAiBinding;
|
||||
const originalAiIssueOverrides = issueAssigneeOverrides;
|
||||
if (requestedAiBinding?.mode === "router") {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { heartbeatExternalProvider, nativeExecutionUsesTaskWorkspace } from "./e
|
||||
import { heartbeatRuns, issues, type Db, type agents } from "@paperclipai/db";
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { readGitCacheExpiration } from "../git-workspace-restoration.js";
|
||||
import type { ExecutionWorkspace, IssueExecutionWorkspaceSettings, ProjectExecutionWorkspacePolicy } from "@paperclipai/shared";
|
||||
import type { ExecutionWorkspace, InstanceSettings, IssueExecutionWorkspaceSettings, ProjectExecutionWorkspacePolicy } from "@paperclipai/shared";
|
||||
import { parseObject } from "../../adapters/utils.js";
|
||||
import { logger } from "../../middleware/logger.js";
|
||||
import { parseNativeExecutionInput } from "../../vendor/paperclip-runner/index.js";
|
||||
@@ -39,6 +39,23 @@ import { resolveNativeRecoveryExecutionWorkspaceBinding, resolveExecutionWorkspa
|
||||
|
||||
type Issue = typeof issues.$inferSelect;
|
||||
|
||||
export async function resolveSshAuthenticationBeforeRouting(input: {
|
||||
agentDefaultEnvironmentId: string | null;
|
||||
lowTrustIssueEnvironmentId: string | null;
|
||||
environmentsSvc: Pick<ReturnType<typeof environmentService>, "getById">;
|
||||
instanceSettings: { get(): Promise<{
|
||||
defaultEnvironmentId: InstanceSettings["defaultEnvironmentId"];
|
||||
general: Pick<InstanceSettings["general"], "executionMode">;
|
||||
}> };
|
||||
}): Promise<"host" | "managed" | null> {
|
||||
const settings = await input.instanceSettings.get();
|
||||
if (isExecutionForcedToKubernetes({ executionMode: settings.general.executionMode })) return null;
|
||||
const id = input.lowTrustIssueEnvironmentId ?? input.agentDefaultEnvironmentId ?? settings.defaultEnvironmentId;
|
||||
if (!id) return null;
|
||||
const environment = await input.environmentsSvc.getById(id);
|
||||
return environment?.driver === "ssh" ? environment.config.useHostAuth === false ? "managed" : "host" : null;
|
||||
}
|
||||
|
||||
/** Selects policy and reuse inputs; lease acquisition and cleanup belong to the executor. */
|
||||
export interface HeartbeatEnvironmentSelectionInput {
|
||||
run: Pick<typeof heartbeatRuns.$inferSelect,
|
||||
|
||||
@@ -102,7 +102,7 @@ export async function prepareHeartbeatExecutionConfiguration(db: Db, input: Hear
|
||||
const useSshHostAuth = selectedEnvironmentForConfig?.driver === "ssh" && selectedEnvironmentForConfig.config.useHostAuth !== false && !persistedNativeExecutionInput;
|
||||
const sourceWorkspaceConfig = agent.adapterType === "paperclip_runner"
|
||||
? { ...input.config.sourceWorkspaceConfig,
|
||||
homeMode: bindHeartbeatRunnerHomeMode({ ...parseObject(agent.adapterConfig), ...(useSshHostAuth ? { homeMode: "preconfigured" } : {}) }, persistedNativeExecutionInput).homeMode }
|
||||
homeMode: bindHeartbeatRunnerHomeMode({ ...parseObject(agent.adapterConfig), ...(selectedEnvironmentForConfig?.driver === "ssh" && !persistedNativeExecutionInput ? { homeMode: useSshHostAuth ? "preconfigured" : "isolated" } : {}) }, persistedNativeExecutionInput).homeMode }
|
||||
: input.config.sourceWorkspaceConfig;
|
||||
const preconfiguredHome = agent.adapterType === "paperclip_runner" && sourceWorkspaceConfig.homeMode === "preconfigured";
|
||||
if (preconfiguredHome && pinnedSkillTest) {
|
||||
|
||||
@@ -58,7 +58,7 @@ describe("native SSH deliverable output budget", () => {
|
||||
});
|
||||
|
||||
it("still delivers every byte when SSH consumes the upload", async () => {
|
||||
await writeFile(join(root, "ssh"), `#!${process.execPath}\nconst hash = require('node:crypto').createHash('sha256');\nprocess.stdin.on('data', chunk => hash.update(chunk));\nprocess.stdin.on('end', () => process.stdout.write(hash.digest('hex')));\n`);
|
||||
await writeFile(join(root, "ssh"), `#!${process.execPath}\nconst chunks = [];\nprocess.stdin.on('data', chunk => chunks.push(chunk));\nprocess.stdin.on('end', () => { const wire = Buffer.concat(chunks); const end = wire.indexOf(10); if (end < 0) process.exit(1); process.stdout.write(require('node:crypto').createHash('sha256').update(wire.subarray(end + 1)).digest('hex')); });\n`);
|
||||
const stdin = "synthetic upload bytes\0".repeat(32_768);
|
||||
const result = await createRunner().execute({ command: "node", args: ["unused"], stdin, timeoutMs: 5000 });
|
||||
expect(result.exitCode).toBe(0);
|
||||
|
||||
Reference in new issue
Block a user