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:
Nicky LeachandPaperclip authored and GitHub committed 2026-12-02 16:23:42 -08:00
1 parent 53bebb59f9
commit cc2e1d9d43
14 files changed
+46 -32

No files matched your search

@@ -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" });
+2 -2
View File
@@ -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;
+1 -5
View File
@@ -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(
+4 -3
View File
@@ -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, {
+5 -5
View File
@@ -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,