Skip to content

Commit 57adc85

Browse files
committed
chore(mothership): stop minting delegation tokens on request paths
The worker no longer consumes them (the CLI executes sim-side; the handler mints its own identity per invocation), so the chat POST, v2 chat, inbox, and execute senders were one DB roundtrip + a plaintext credential on the wire for nothing. mintDelegationToken stays — the sim_cli handler is its one consumer now. Claude-Session: https://claude.ai/code/session_01CgaxNAaeD3taGdghbXn17w
1 parent b9f9715 commit 57adc85

4 files changed

Lines changed: 12 additions & 31 deletions

File tree

apps/sim/app/api/mothership/execute/route.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
RESOLVED_SECRET_PROVENANCE_METADATA_V1,
1515
requestsPrivateToolMetadata,
1616
} from '@/lib/execution/private-tool-metadata'
17-
import { mintDelegationToken } from '@/lib/mothership/chat/delegation'
1817
import { buildIntegrationToolSchemas } from '@/lib/mothership/chat/payload'
1918
import { processContextsServer } from '@/lib/mothership/chat/process-contents'
2019
import {
@@ -272,7 +271,6 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
272271
? { ...m, content: `${contextBlocks.join('\n\n')}\n\n${m.content}` }
273272
: m
274273
)
275-
const delegationToken = await mintDelegationToken({ workspaceId, userId })
276274
const requestPayload: Record<string, unknown> = {
277275
messages: wireMessages,
278276
...(responseFormat !== undefined ? { responseFormat } : {}),
@@ -283,7 +281,6 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
283281
messageId,
284282
...(integrationTools.length > 0 ? { integrationTools } : {}),
285283
...(mothershipTools.length > 0 ? { mothershipTools } : {}),
286-
...(delegationToken ? { delegationToken } : {}),
287284
}
288285

289286
let allowExplicitAbort = true

apps/sim/app/api/v2/chat/route.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { resolveBillingAttribution } from '@/lib/billing/core/billing-attributio
1616
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
1717
import { getPersonalAndWorkspaceEnv } from '@/lib/environment/utils'
1818
import { chatOperations } from '@/lib/mothership/application/operations'
19-
import { mintDelegationToken } from '@/lib/mothership/chat/delegation'
2019
import { resolveOrCreateChat } from '@/lib/mothership/chat/lifecycle'
2120
import { persistCopilotChatTurn } from '@/lib/mothership/chat/messages-store'
2221
import { buildIntegrationToolSchemas } from '@/lib/mothership/chat/payload'
@@ -232,13 +231,12 @@ export const POST = withRouteHandler(
232231
})
233232
}
234233

235-
const [integrationTools, billingAttribution, delegationToken] = await Promise.all([
234+
const [integrationTools, billingAttribution] = await Promise.all([
236235
buildIntegrationToolSchemas(userId, messageId, undefined, workspaceId),
237236
// Hosted execution refuses to run without an attribution snapshot;
238237
// the executor path receives it as a header, this path resolves it
239238
// from the authenticated actor and asserted workspace.
240239
resolveBillingAttribution({ actorUserId: userId, workspaceId }),
241-
mintDelegationToken({ workspaceId, userId }),
242240
])
243241

244242
/**
@@ -255,7 +253,6 @@ export const POST = withRouteHandler(
255253
chatId,
256254
messageId,
257255
...(integrationTools.length > 0 ? { integrationTools } : {}),
258-
...(delegationToken ? { delegationToken } : {}),
259256
}
260257

261258
let allowExplicitAbort = true

apps/sim/lib/mothership/chat/post.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { getSession } from '@/lib/auth'
1212
import { resolveBillingAttribution } from '@/lib/billing/core/billing-attribution'
1313
import type { AtomicClaimResult } from '@/lib/core/idempotency'
1414
import { chatSendIdempotency } from '@/lib/core/idempotency'
15-
import { mintDelegationToken } from '@/lib/mothership/chat/delegation'
1615
import {
1716
DESKTOP_TERMINAL_HINT_ID_MAX_LENGTH,
1817
DESKTOP_TERMINAL_HINT_TEXT_MAX_LENGTH,
@@ -1248,9 +1247,6 @@ export async function handleUnifiedChatPost(req: NextRequest) {
12481247
* queries and ~900ms p95 per message). Its prep slot now mints the run-scoped
12491248
* delegation credential the worker presents on v2 calls (revamp D23).
12501249
*/
1251-
const delegationTokenPromise = workspaceId
1252-
? mintDelegationToken({ workspaceId, userId: authenticatedUserId })
1253-
: Promise.resolve(null)
12541250
const executionContextPromise = withCopilotSpan(
12551251
TraceSpan.CopilotChatBuildExecutionContext,
12561252
{ [TraceAttr.CopilotBranchKind]: branch.kind },
@@ -1294,14 +1290,12 @@ export async function handleUnifiedChatPost(req: NextRequest) {
12941290
notifyWorkspaceStatus: branch.notifyWorkspaceStatus,
12951291
parentOtelContext: activeOtelRoot.context,
12961292
})
1297-
const [agentContexts, userPermission, delegationToken, , executionContext] =
1298-
await Promise.all([
1299-
agentContextsPromise,
1300-
userPermissionPromise,
1301-
delegationTokenPromise,
1302-
persistUserMessagePromise,
1303-
executionContextPromise,
1304-
])
1293+
const [agentContexts, userPermission, , executionContext] = await Promise.all([
1294+
agentContextsPromise,
1295+
userPermissionPromise,
1296+
persistUserMessagePromise,
1297+
executionContextPromise,
1298+
])
13051299

13061300
executionContext.userPermission = userPermission ?? undefined
13071301

@@ -1375,7 +1369,6 @@ export async function handleUnifiedChatPost(req: NextRequest) {
13751369
requestPayload: {
13761370
...requestPayload,
13771371
protocolVersion: PROTOCOL_VERSION,
1378-
...(delegationToken ? { delegationToken } : {}),
13791372
},
13801373
userId: authenticatedUserId,
13811374
streamId: userMessageId,

apps/sim/lib/mothership/inbox/executor.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { generateId } from '@sim/utils/id'
55
import { and, eq, sql } from 'drizzle-orm'
66
import { getActivelyBannedUserIds, isEmailBlocked } from '@/lib/auth/ban'
77
import { resolveBillingAttribution } from '@/lib/billing/core/billing-attribution'
8-
import { mintDelegationToken } from '@/lib/mothership/chat/delegation'
98
import { resolveOrCreateChat } from '@/lib/mothership/chat/lifecycle'
109
import { appendCopilotChatMessages } from '@/lib/mothership/chat/messages-store'
1110
import { buildIntegrationToolSchemas } from '@/lib/mothership/chat/payload'
@@ -225,15 +224,11 @@ export async function executeInboxTask(taskId: string): Promise<void> {
225224
secretScope: ws.inboxSecretScope,
226225
mountedSecrets: ws.inboxMountedSecrets,
227226
})
228-
const [attachmentResult, integrationTools, billingAttribution, delegationToken] =
229-
await Promise.all([
230-
fetchAttachments(),
231-
buildIntegrationToolSchemas(userId, undefined, undefined, ws.id),
232-
resolveBillingAttribution({ actorUserId: userId, workspaceId: ws.id }),
233-
// Trigger-runtime caveat (see docs/revamp/06-cutover.md): a failed mint falls
234-
// back to null and the turn proceeds without CLI-backed capabilities.
235-
mintDelegationToken({ workspaceId: ws.id, userId }),
236-
])
227+
const [attachmentResult, integrationTools, billingAttribution] = await Promise.all([
228+
fetchAttachments(),
229+
buildIntegrationToolSchemas(userId, undefined, undefined, ws.id),
230+
resolveBillingAttribution({ actorUserId: userId, workspaceId: ws.id }),
231+
])
237232
const { attachments, fileAttachments, storedAttachments } = attachmentResult
238233

239234
const truncatedTask = {
@@ -254,7 +249,6 @@ export async function executeInboxTask(taskId: string): Promise<void> {
254249
chatId,
255250
messageId: userMessageId,
256251
...(integrationTools.length > 0 ? { integrationTools } : {}),
257-
...(delegationToken ? { delegationToken } : {}),
258252
}
259253

260254
const result = await runHeadlessCopilotLifecycle(requestPayload, {

0 commit comments

Comments
 (0)