mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
Honor plugin task driver concurrency defaults on hire (#23535)
## Thinking Path > - Paperclip schedules work for agents. > - Each agent has a limit on simultaneous runs. > - A task driver can provide an execution environment with its own capacity. > - Previously the creation form sent the same limit for every driver. > - A driver can now declare the value Core saves when a new agent has no explicit limit. ## Linked Issues or Issue Description **Subsystem affected** Agent hiring and plugin environment drivers. **Current behavior** The create form, API, and import flow supply the global concurrency default before the task driver can provide one. **Proposed behavior** Let each task driver declare an optional per-agent concurrency default. Apply it once during hire and honor explicit agent limits. ## What Changed - Refreshed the three SDK source pins for the changed files. - Added the optional driver field `defaultMaxConcurrentRuns` with integer bounds from 1 through 50. - Applied it during hire using the resolved task environment. Saved the resolved runtime configuration in hire approvals. - Removed early defaults from the creation form, routes and new-agent imports. Preserved saved limits on export, including explicit values equal to the global default. Kept the current limit when importing an update with an omitted limit. ## Verification - [Full PR CI](https://github.com/paperclipai/paperclip/actions/runs/47000023360) passed on `83cce42b9a`. Server shard 16 passed on retry after a PostgreSQL connection reset on the first attempt. - `pnpm -r typecheck` passed. The SDK source pin check passed. `pnpm verify` selected broad CI coverage because the SDK input registry changed. - On rebased commit `83cce42b9a`, all 441 tests in six focused Vitest suites passed, including the MCP rollback test corrected in #23560. The SDK source pin check passed. ## Risks This affects new hires on drivers that opt in. Existing agents retain their saved configuration. Single-run provider limits still apply. An older client that explicitly sends the global default will keep that value. ## Model Used OpenAI GPT-6 via Codex. Used local source inspection, code editing, TypeScript and test execution. ## 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 - [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>
This commit is contained in:
1 parent
53bebb59f9
commit
cc2e1d9d43
14 files changed
+46
-32
No files matched your search
@@ -10,6 +10,15 @@ Read [Sandbox file-sync lifecycle hooks](./SANDBOX_FILE_SYNC_HOOKS.md) for the
|
||||
native file-transfer hooks. Read the driver declaration shape in
|
||||
[the plugin specification](./PLUGIN_SPEC.md).
|
||||
|
||||
## Agent concurrency
|
||||
|
||||
A plugin Runner task driver can set `defaultMaxConcurrentRuns` to an integer
|
||||
from 1 to 50. When Core hires an agent on that driver, it saves the declared
|
||||
value in `runtimeConfig.heartbeat.maxConcurrentRuns` unless the caller supplied
|
||||
a limit. This also applies when the agent inherits the instance environment.
|
||||
Drivers that omit the field use the Core default. Changing the declaration
|
||||
affects future hires. Provider-specific single-run limits still apply.
|
||||
|
||||
## Fresh lease acquisition timeout
|
||||
|
||||
A driver can declare `defaultAcquireTimeoutMs` as a positive integer of at most
|
||||
|
||||
@@ -197,6 +197,7 @@ export interface PluginEnvironmentDriverDeclaration {
|
||||
requiresAgent?: boolean;
|
||||
/** Provides Runner execution, resource preparation, and PRP connections via environmentTask. */
|
||||
supportsTasks?: boolean;
|
||||
defaultMaxConcurrentRuns?: number;
|
||||
supportedAdapters?: string[];
|
||||
freshWorkspaceVersion?: 1;
|
||||
creationOperationVersion?: 1;
|
||||
|
||||
@@ -352,6 +352,16 @@ describe("plugin UI slot validators", () => {
|
||||
});
|
||||
|
||||
describe("sandbox provider capability declaration validators", () => {
|
||||
it("bounds an optional per-agent concurrency default", () => {
|
||||
for (const value of [1, 2, 50]) {
|
||||
const parsed = pluginManifestV1Schema.parse(buildSandboxProviderManifest({ defaultMaxConcurrentRuns: value }));
|
||||
expect(parsed.environmentDrivers?.[0]?.defaultMaxConcurrentRuns).toBe(value);
|
||||
}
|
||||
for (const value of [0, 51, 1.5, "2"]) {
|
||||
expect(pluginManifestV1Schema.safeParse(buildSandboxProviderManifest({ defaultMaxConcurrentRuns: value })).success).toBe(false);
|
||||
}
|
||||
});
|
||||
|
||||
it("preserves a declared acquisition budget and keeps it optional", () => {
|
||||
const parsed = pluginManifestV1Schema.parse(
|
||||
buildSandboxProviderManifest({ defaultAcquireTimeoutMs: 300_000 }),
|
||||
|
||||
@@ -169,6 +169,7 @@ export const pluginEnvironmentDriverDeclarationSchema = z.object({
|
||||
skillKeys: z.array(z.string().min(1).max(100)).max(100).optional(),
|
||||
requiresAgent: z.boolean().optional(),
|
||||
supportsTasks: z.boolean().optional(),
|
||||
defaultMaxConcurrentRuns: z.number().int().min(1).max(50).optional(),
|
||||
supportedAdapters: z.array(z.string().regex(/^[a-z0-9][a-z0-9_:-]{0,63}$/)).max(64).optional(),
|
||||
freshWorkspaceVersion: z.literal(1).optional(),
|
||||
creationOperationVersion: z.literal(1).optional(),
|
||||
|
||||
@@ -115,16 +115,17 @@ describe.skipIf(!support.supported)("Cursor Cloud API controller activation", ()
|
||||
await noComputerWork();
|
||||
});
|
||||
|
||||
it("keeps native Computer-backed setup preparation and warm-task defaults", async () => {
|
||||
it.each([undefined, 7, 20])("applies Computer hire defaults with explicit concurrency %s", async maxConcurrentRuns => {
|
||||
const pluginId = randomUUID();
|
||||
await db.insert(plugins).values({ id: pluginId, pluginKey: pluginId, packageName: "required-computer", version: "1.0.0", status: "ready",
|
||||
manifestJson: { capabilities: ["environment.drivers.register"], environmentDrivers: [{ driverKey: "tasks", requiresAgent: true, supportsTasks: true, warmTaskVersion: 1 }] } as never });
|
||||
manifestJson: { capabilities: ["environment.drivers.register"], environmentDrivers: [{ driverKey: "tasks", requiresAgent: true, supportsTasks: true, warmTaskVersion: 1, defaultMaxConcurrentRuns: 2 }] } as never });
|
||||
const [computer] = await db.insert(environments).values({ name: "Required Computer", driver: "plugin", status: "active",
|
||||
config: { pluginKey: pluginId, driverKey: "tasks", driverConfig: {} } }).returning();
|
||||
await instanceSettingsService(db).update({ defaultEnvironmentId: computer.id });
|
||||
const draft = await createAgentLifecycle(db).requestHire(companyId, { name: "Codex setup", adapterType: "paperclip_runner",
|
||||
const draft = await createAgentLifecycle(db).requestHire(companyId, { name: "Codex setup", adapterType: "paperclip_runner", runtimeConfig: { heartbeat: { maxConcurrentRuns } },
|
||||
adapterConfig: { provider: "codex", model: "gpt-5.6-luna", lifecycleMode: "per_turn" } }, { setupOnly: true, runnerResolved: true });
|
||||
expect(draft).toMatchObject({ status: "paused", lifecycleState: "preparing", lifecycleHolds: ["setup"], adapterConfig: { lifecycleMode: "warm" } });
|
||||
expect(draft.runtimeConfig.heartbeat).toMatchObject({ maxConcurrentRuns: maxConcurrentRuns ?? 2 });
|
||||
expect(fetch).not.toHaveBeenCalled();
|
||||
await noComputerWork();
|
||||
});
|
||||
|
||||
@@ -1497,7 +1497,6 @@ describe("agent permission routes", () => {
|
||||
heartbeat: {
|
||||
enabled: false,
|
||||
intervalSec: 3600,
|
||||
maxConcurrentRuns: 20,
|
||||
},
|
||||
},
|
||||
}),
|
||||
@@ -1612,7 +1611,6 @@ describe("agent permission routes", () => {
|
||||
heartbeat: {
|
||||
enabled: false,
|
||||
intervalSec: 3600,
|
||||
maxConcurrentRuns: 20,
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -3622,7 +3622,7 @@ describe("company portability", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("disables timer heartbeats and strips raw provider tracing on created imports", async () => {
|
||||
it("preserves the saved concurrency limit, disables timers, and strips raw tracing on imported agents", async () => {
|
||||
const portability = companyPortabilityService({} as any);
|
||||
|
||||
companySvc.create.mockResolvedValue({
|
||||
@@ -3641,6 +3641,7 @@ describe("company portability", () => {
|
||||
...agent,
|
||||
runtimeConfig: {
|
||||
...((agent.runtimeConfig ?? {}) as Record<string, unknown>),
|
||||
heartbeat: { enabled: true, maxConcurrentRuns: 20 },
|
||||
debug: { providerTrace: "raw", retainedDebugSetting: true },
|
||||
},
|
||||
})));
|
||||
@@ -3753,7 +3754,6 @@ describe("company portability", () => {
|
||||
runtimeConfig: {
|
||||
heartbeat: {
|
||||
enabled: false,
|
||||
maxConcurrentRuns: 20,
|
||||
},
|
||||
},
|
||||
}), { createdByUserId: "user-1" });
|
||||
|
||||
@@ -220,13 +220,13 @@ function parseFiniteNumberLike(value: unknown): number | null {
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
export function normalizeRuntimeConfigForNewAgent(runtimeConfig: unknown): Record<string, unknown> {
|
||||
export function normalizeRuntimeConfigForNewAgent(runtimeConfig: unknown, defaultMaxConcurrentRuns = AGENT_DEFAULT_MAX_CONCURRENT_RUNS): Record<string, unknown> {
|
||||
const normalizedRuntimeConfig = isPlainRecord(runtimeConfig) ? { ...runtimeConfig } : {};
|
||||
const heartbeat = isPlainRecord(normalizedRuntimeConfig.heartbeat)
|
||||
? { ...normalizedRuntimeConfig.heartbeat }
|
||||
: {};
|
||||
if (parseFiniteNumberLike(heartbeat.maxConcurrentRuns) == null) {
|
||||
heartbeat.maxConcurrentRuns = AGENT_DEFAULT_MAX_CONCURRENT_RUNS;
|
||||
heartbeat.maxConcurrentRuns = defaultMaxConcurrentRuns;
|
||||
}
|
||||
normalizedRuntimeConfig.heartbeat = heartbeat;
|
||||
return normalizedRuntimeConfig;
|
||||
|
||||
@@ -82,7 +82,6 @@ import {
|
||||
agentSkillSyncSchema,
|
||||
agentMineInboxQuerySchema,
|
||||
ADAPTER_AGNOSTIC_KEYS,
|
||||
AGENT_DEFAULT_MAX_CONCURRENT_RUNS,
|
||||
createAgentKeySchema,
|
||||
createAgentHireSchema,
|
||||
createAgentSchema,
|
||||
@@ -2243,9 +2242,6 @@ export function agentRoutes(
|
||||
if (parseBooleanLike(heartbeat.enabled) == null) {
|
||||
heartbeat.enabled = false;
|
||||
}
|
||||
if (parseNumberLike(heartbeat.maxConcurrentRuns) == null) {
|
||||
heartbeat.maxConcurrentRuns = AGENT_DEFAULT_MAX_CONCURRENT_RUNS;
|
||||
}
|
||||
|
||||
normalizedRuntimeConfig.heartbeat = heartbeat;
|
||||
|
||||
@@ -4848,7 +4844,7 @@ export function agentRoutes(
|
||||
) ?? {};
|
||||
const requestedRuntimeConfig =
|
||||
redactEventPayload(
|
||||
(normalizedHireInput.runtimeConfig ?? agent.runtimeConfig) as Record<string, unknown>,
|
||||
(agent.runtimeConfig ?? normalizedHireInput.runtimeConfig) as Record<string, unknown>,
|
||||
) ?? {};
|
||||
const requestedMetadata =
|
||||
redactEventPayload(
|
||||
|
||||
@@ -53,7 +53,6 @@ export async function prepareAgentHire(db: Db, companyId: string, input: CreateA
|
||||
const requestedPermissions = data.permissions && typeof data.permissions === "object" && !Array.isArray(data.permissions)
|
||||
? Object.fromEntries(Object.entries(data.permissions).filter(([key]) => key !== CEO_HIRING_DENIAL_KEY)) : data.permissions;
|
||||
const normalizedPermissions = normalizeAgentPermissions(requestedPermissions, { context: "create" });
|
||||
const runtimeConfig = normalizeRuntimeConfigForNewAgent(data.runtimeConfig);
|
||||
const adapterType = data.adapterType ?? "process";
|
||||
const rawAdapterConfig = isPlainRecord(data.adapterConfig)
|
||||
? await secretService(db).normalizeAdapterConfigForPersistence(companyId, data.adapterConfig, { adapterType })
|
||||
@@ -63,8 +62,10 @@ export async function prepareAgentHire(db: Db, companyId: string, input: CreateA
|
||||
const providerApiDraft = options?.setupOnly === true && isProviderApiSetupDraft(profile);
|
||||
const providerApi = providerApiDraft ? null : resolveProviderApiPlacement({ agent: profile });
|
||||
if (providerApi) assertProviderApiPlacementPolicy(await instanceSettingsService(db).getGeneral());
|
||||
if (!providerApiDraft && !providerApi && adapterType === "paperclip_runner" && !["openai_dot", "grok_bot", "muse"].includes(String(adapterConfig.provider)) &&
|
||||
(await resolveAgentRunnerTaskDriverForCompany(db, companyId, data.defaultEnvironmentId))?.warmTaskVersion === 1) {
|
||||
const taskDriver = !providerApiDraft && !providerApi && adapterType === "paperclip_runner" && !["openai_dot", "grok_bot", "muse"].includes(String(adapterConfig.provider))
|
||||
? await resolveAgentRunnerTaskDriverForCompany(db, companyId, data.defaultEnvironmentId) : undefined;
|
||||
const runtimeConfig = normalizeRuntimeConfigForNewAgent(data.runtimeConfig, taskDriver?.defaultMaxConcurrentRuns);
|
||||
if (taskDriver?.warmTaskVersion === 1) {
|
||||
adapterConfig.lifecycleMode = "warm";
|
||||
}
|
||||
await agentCredentialService(db).enforceClaudeOAuthBindingClaim(db, {
|
||||
|
||||
@@ -807,7 +807,6 @@ const RUNTIME_DEFAULT_RULES: Array<{ path: string[]; value: unknown }> = [
|
||||
{ path: ["heartbeat", "wakeOnAssignment"], value: true },
|
||||
{ path: ["heartbeat", "wakeOnAutomation"], value: true },
|
||||
{ path: ["heartbeat", "wakeOnDemand"], value: true },
|
||||
{ path: ["heartbeat", "maxConcurrentRuns"], value: AGENT_DEFAULT_MAX_CONCURRENT_RUNS },
|
||||
];
|
||||
|
||||
const ADAPTER_DEFAULT_RULES_BY_TYPE: Record<string, Array<{ path: string[]; value: unknown }>> = {
|
||||
@@ -1333,13 +1332,14 @@ function parseFiniteNumberLike(value: unknown): number | null {
|
||||
return Number.isFinite(parsed) ? parsed : null;
|
||||
}
|
||||
|
||||
function sanitizeImportedAgentRuntimeConfig(runtimeConfig: unknown) {
|
||||
function sanitizeImportedAgentRuntimeConfig(runtimeConfig: unknown, existingRuntimeConfig?: Record<string, unknown>) {
|
||||
const next = clonePortableRecord(runtimeConfig) ?? {};
|
||||
delete next.modelProfiles;
|
||||
const heartbeat = isPlainRecord(next.heartbeat) ? { ...next.heartbeat } : {};
|
||||
heartbeat.enabled = false;
|
||||
if (parseFiniteNumberLike(heartbeat.maxConcurrentRuns) == null) {
|
||||
heartbeat.maxConcurrentRuns = AGENT_DEFAULT_MAX_CONCURRENT_RUNS;
|
||||
if (existingRuntimeConfig && parseFiniteNumberLike(heartbeat.maxConcurrentRuns) == null) {
|
||||
const existingHeartbeat = isPlainRecord(existingRuntimeConfig.heartbeat) ? existingRuntimeConfig.heartbeat : {};
|
||||
heartbeat.maxConcurrentRuns = existingHeartbeat.maxConcurrentRuns ?? AGENT_DEFAULT_MAX_CONCURRENT_RUNS;
|
||||
}
|
||||
next.heartbeat = heartbeat;
|
||||
if (isPlainRecord(next.debug)) {
|
||||
@@ -5761,7 +5761,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) {
|
||||
reportsTo: null,
|
||||
adapterType: normalizedAdapter.adapterType,
|
||||
adapterConfig: normalizedAdapter.adapterConfig,
|
||||
runtimeConfig: sanitizeImportedAgentRuntimeConfig(manifestAgent.runtimeConfig),
|
||||
runtimeConfig: sanitizeImportedAgentRuntimeConfig(manifestAgent.runtimeConfig, existingImportAgent?.runtimeConfig),
|
||||
budgetMonthlyCents: manifestAgent.budgetMonthlyCents,
|
||||
permissions: manifestAgent.permissions,
|
||||
metadata: manifestAgent.metadata,
|
||||
|
||||
@@ -466,7 +466,7 @@
|
||||
"packages/shared/src/types/issue.ts": "1a01870cfda97510486c20425fabe7ac553460ac",
|
||||
"packages/shared/src/types/live.ts": "b90e55e4de8600c6fc17d7fa8d89079d4ae655ec",
|
||||
"packages/shared/src/types/native-finalization.ts": "c026a73003ae232fea4f7624d561493b383df358",
|
||||
"packages/shared/src/types/plugin.ts": "8745a3dd3043baa4a132df6dd223da18e68e7797",
|
||||
"packages/shared/src/types/plugin.ts": "9fa76312dc773a6fd461c7895323e7c7c3f99fef",
|
||||
"packages/shared/src/types/project.ts": "50b9d9c51cb38d5862e287c1a47726716603f21c",
|
||||
"packages/shared/src/types/quota.ts": "a0686a9afb3111a4de093f66200dc0c9152e883e",
|
||||
"packages/shared/src/types/resource-memberships.ts": "9eab6fad50facf3e489f8c40e5bedd92e1d1faf8",
|
||||
@@ -552,8 +552,8 @@
|
||||
"packages/shared/src/validators/native-finalization.ts": "d4e674de6ac7d36385e6f6c2172fa16ffc9b1830",
|
||||
"packages/shared/src/validators/onboarding-seed.ts": "de302a8400d4199053f379d9ed853522a3ac6d32",
|
||||
"packages/shared/src/validators/partial.ts": "fa60ec7481fc14175365e9e500c814b159f1ab53",
|
||||
"packages/shared/src/validators/plugin.test.ts": "4e281c0ceec0d3404b6b60f2c96ccb558600455a",
|
||||
"packages/shared/src/validators/plugin.ts": "10f4f8ecdee02eeb9f9c11556efeea79cd64bc60",
|
||||
"packages/shared/src/validators/plugin.test.ts": "3fbbf6803e7302056386d16c56545e429fb7c7c4",
|
||||
"packages/shared/src/validators/plugin.ts": "10d970446d52da15300db18102b2ebbaf684665a",
|
||||
"packages/shared/src/validators/project.ts": "6ea168f5faf3161e6004ea47274f60634c77b219",
|
||||
"packages/shared/src/validators/provider-trace.ts": "b38b6200a2e51513f5dca0f8b008f2fe68175e82",
|
||||
"packages/shared/src/validators/resource-memberships.ts": "b124ac8a8f24b4dbb03ae82bcc87541f6b4ecdfd",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// @vitest-environment node
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { AGENT_DEFAULT_MAX_CONCURRENT_RUNS } from "@paperclipai/shared";
|
||||
import { buildNewAgentRuntimeConfig, buildOnboardingAgentRuntimeConfig } from "./new-agent-runtime-config";
|
||||
|
||||
describe("buildNewAgentRuntimeConfig", () => {
|
||||
@@ -12,7 +11,6 @@ describe("buildNewAgentRuntimeConfig", () => {
|
||||
wakeOnDemand: true,
|
||||
skipTimerWhenNoActionableWork: true,
|
||||
cooldownSec: 10,
|
||||
maxConcurrentRuns: AGENT_DEFAULT_MAX_CONCURRENT_RUNS,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -30,7 +28,6 @@ describe("buildNewAgentRuntimeConfig", () => {
|
||||
wakeOnDemand: true,
|
||||
skipTimerWhenNoActionableWork: true,
|
||||
cooldownSec: 10,
|
||||
maxConcurrentRuns: AGENT_DEFAULT_MAX_CONCURRENT_RUNS,
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -38,7 +35,9 @@ describe("buildNewAgentRuntimeConfig", () => {
|
||||
|
||||
describe("buildOnboardingAgentRuntimeConfig", () => {
|
||||
it("hires without a timer while retaining on-demand wakes", () => {
|
||||
expect(buildOnboardingAgentRuntimeConfig()).toMatchObject({
|
||||
const config = buildOnboardingAgentRuntimeConfig();
|
||||
expect(config).not.toHaveProperty("heartbeat.maxConcurrentRuns");
|
||||
expect(config).toMatchObject({
|
||||
heartbeat: { enabled: false, wakeOnDemand: true },
|
||||
});
|
||||
});
|
||||
@@ -56,7 +55,7 @@ describe("buildOnboardingAgentRuntimeConfig", () => {
|
||||
});
|
||||
|
||||
it("preserves an existing agent's explicit policy when reconnecting", () => {
|
||||
const heartbeat = { enabled: true, intervalSec: 3600, wakeOnDemand: false };
|
||||
const heartbeat = { enabled: true, intervalSec: 3600, wakeOnDemand: false, maxConcurrentRuns: 7 };
|
||||
expect(buildOnboardingAgentRuntimeConfig({ heartbeat }, { preserveExisting: true })).toEqual({ heartbeat });
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,3 @@
|
||||
import { AGENT_DEFAULT_MAX_CONCURRENT_RUNS } from "@paperclipai/shared";
|
||||
import { defaultCreateValues } from "../components/agent-config-defaults";
|
||||
|
||||
export function buildNewAgentRuntimeConfig(input?: {
|
||||
@@ -12,7 +11,6 @@ export function buildNewAgentRuntimeConfig(input?: {
|
||||
wakeOnDemand: true,
|
||||
skipTimerWhenNoActionableWork: true,
|
||||
cooldownSec: 10,
|
||||
maxConcurrentRuns: AGENT_DEFAULT_MAX_CONCURRENT_RUNS,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user