From b6cd49d4b6926fae61a2c68a31ce7c659b69eaa6 Mon Sep 17 00:00:00 2001 From: Dotta Date: Tue, 27 Oct 2026 05:36:04 -0500 Subject: [PATCH] fix: keep provisioning run attribution in supported activity audit Co-Authored-By: Paperclip --- server/src/__tests__/built-in-agent-routes.test.ts | 2 ++ server/src/routes/built-in-agents.ts | 1 - server/src/services/built-in-agents.ts | 11 +++++------ 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/__tests__/built-in-agent-routes.test.ts b/server/src/__tests__/built-in-agent-routes.test.ts index c07fc56985d..ef10e506286 100644 --- a/server/src/__tests__/built-in-agent-routes.test.ts +++ b/server/src/__tests__/built-in-agent-routes.test.ts @@ -380,6 +380,7 @@ describe("built-in agent routes", () => { const app = await createApp({ type: "agent", agentId: "manager-agent", + runId: "native-request-run", companyId, source: "agent_key", }); @@ -403,6 +404,7 @@ describe("built-in agent routes", () => { actorType: "agent", actorId: "manager-agent", action: "approval.created", + runId: "native-request-run", entityId: "approval-1", })); }); diff --git a/server/src/routes/built-in-agents.ts b/server/src/routes/built-in-agents.ts index 087bda77c85..f9ea7e1e110 100644 --- a/server/src/routes/built-in-agents.ts +++ b/server/src/routes/built-in-agents.ts @@ -189,7 +189,6 @@ export function builtInAgentRoutes(db: Db) { if (req.body.budgetMonthlyCents !== undefined) assertBoard(req); const result = await svc.provision(companyId, key, req.body, { requestedByAgentId: actor.actorType === "agent" ? actor.actorId : null, - ...(actor.runId ? { sourceRunId: actor.runId } : {}), requestedByUserId: actor.actorType === "user" ? actor.actorId : null, }); const { state, approval } = result; diff --git a/server/src/services/built-in-agents.ts b/server/src/services/built-in-agents.ts index 3e015da3d54..83181a1504c 100644 --- a/server/src/services/built-in-agents.ts +++ b/server/src/services/built-in-agents.ts @@ -75,7 +75,6 @@ export interface BuiltInAgentProvisionInput { } export interface BuiltInAgentProvisionActor { - sourceRunId?: string | null; requestedByAgentId?: string | null; requestedByUserId?: string | null; } @@ -1730,7 +1729,7 @@ export function builtInAgentService(db: Db) { companyId: string, key: string, input: BuiltInAgentProvisionInput = {}, - options: { isRaceRetry?: boolean; createdByUserId?: string | null; createdByAgentId?: string | null; sourceRunId?: string | null } = {}, + options: { isRaceRetry?: boolean; createdByUserId?: string | null; createdByAgentId?: string | null } = {}, ) { const definition = requireBuiltInAgentDefinition(key); await ensureCompany(companyId); @@ -1798,7 +1797,7 @@ export function builtInAgentService(db: Db) { } const updated = await agentSvc.update(existing.id, patch, { allowBuiltInAgentMetadata: true, - recordRevision: { source: "built-in-agent:ensure", createdByUserId: options.createdByUserId, createdByAgentId: options.createdByAgentId, sourceRunId: options.sourceRunId }, + recordRevision: { source: "built-in-agent:ensure", createdByUserId: options.createdByUserId, createdByAgentId: options.createdByAgentId }, }); if (!updated) throw notFound("Built-in agent not found"); if (existingPendingApproval) { @@ -1840,7 +1839,7 @@ export function builtInAgentService(db: Db) { // and the partial unique index rejected ours. Re-run once; the winning // row now exists, so we take the update path instead of inserting again. if (!options.isRaceRetry && isBuiltInAgentMarkerConflict(error)) { - return ensure(companyId, key, input, { isRaceRetry: true, createdByUserId: options.createdByUserId, createdByAgentId: options.createdByAgentId, sourceRunId: options.sourceRunId }); + return ensure(companyId, key, input, { isRaceRetry: true, createdByUserId: options.createdByUserId, createdByAgentId: options.createdByAgentId }); } throw error; } @@ -1873,7 +1872,7 @@ export function builtInAgentService(db: Db) { const definition = requireBuiltInAgentDefinition(key); const company = await ensureCompany(companyId); if (!company.requireBoardApprovalForNewAgents) { - return { state: await ensure(companyId, key, input, { createdByUserId: actor.requestedByUserId ?? null, createdByAgentId: actor.requestedByAgentId ?? null, sourceRunId: actor.sourceRunId }), approval: null }; + return { state: await ensure(companyId, key, input, { createdByUserId: actor.requestedByUserId ?? null, createdByAgentId: actor.requestedByAgentId ?? null }), approval: null }; } await assertKnownBuiltInAgentModel(definition, input); @@ -1905,7 +1904,7 @@ export function builtInAgentService(db: Db) { // it does when board approval is not required, instead of dead-ending on a // fresh board-approval requirement the operator can never satisfy. if (providesAdapterSetup && (existing.metadata?.paperclipBuiltInSetupRequired === true || !hasCompleteAdapterConfig(existing.adapterType, existing.adapterConfig))) { - return { state: await ensure(companyId, key, input, { createdByUserId: actor.requestedByUserId ?? null, createdByAgentId: actor.requestedByAgentId ?? null, sourceRunId: actor.sourceRunId }), approval: null }; + return { state: await ensure(companyId, key, input, { createdByUserId: actor.requestedByUserId ?? null, createdByAgentId: actor.requestedByAgentId ?? null }), approval: null }; } // Changing the adapter of an already-configured (`ready`/`paused`)