Skip to content

Commit c76655f

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 a22b029 commit c76655f

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'
@@ -325,13 +324,12 @@ export const POST = withRouteHandler(
325324
})
326325
}
327326

328-
const [integrationTools, billingAttribution, delegationToken] = await Promise.all([
327+
const [integrationTools, billingAttribution] = await Promise.all([
329328
buildIntegrationToolSchemas(userId, messageId, undefined, workspaceId),
330329
// Hosted execution refuses to run without an attribution snapshot;
331330
// the executor path receives it as a header, this path resolves it
332331
// from the authenticated actor and asserted workspace.
333332
resolveBillingAttribution({ actorUserId: userId, workspaceId }),
334-
mintDelegationToken({ workspaceId, userId }),
335333
])
336334

337335
/**
@@ -348,7 +346,6 @@ export const POST = withRouteHandler(
348346
chatId,
349347
messageId,
350348
...(integrationTools.length > 0 ? { integrationTools } : {}),
351-
...(delegationToken ? { delegationToken } : {}),
352349
}
353350

354351
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 { chatOperations } from '@/lib/mothership/application/operations'
1414
import { withAskModeContext } from '@/lib/mothership/chat/ask-mode'
15-
import { mintDelegationToken } from '@/lib/mothership/chat/delegation'
1615
import {
1716
DESKTOP_TERMINAL_HINT_ID_MAX_LENGTH,
1817
DESKTOP_TERMINAL_HINT_TEXT_MAX_LENGTH,
@@ -1295,9 +1294,6 @@ export async function handleUnifiedChatPost(req: NextRequest) {
12951294
* queries and ~900ms p95 per message). Its prep slot now mints the run-scoped
12961295
* delegation credential the worker presents on v2 calls (revamp D23).
12971296
*/
1298-
const delegationTokenPromise = workspaceId
1299-
? mintDelegationToken({ workspaceId, userId: authenticatedUserId })
1300-
: Promise.resolve(null)
13011297
const executionContextPromise = withCopilotSpan(
13021298
TraceSpan.CopilotChatBuildExecutionContext,
13031299
{ [TraceAttr.CopilotBranchKind]: branch.kind },
@@ -1341,14 +1337,12 @@ export async function handleUnifiedChatPost(req: NextRequest) {
13411337
notifyWorkspaceStatus: branch.notifyWorkspaceStatus,
13421338
parentOtelContext: activeOtelRoot.context,
13431339
})
1344-
const [agentContexts, userPermission, delegationToken, , executionContext] =
1345-
await Promise.all([
1346-
agentContextsPromise,
1347-
userPermissionPromise,
1348-
delegationTokenPromise,
1349-
persistUserMessagePromise,
1350-
executionContextPromise,
1351-
])
1340+
const [agentContexts, userPermission, , executionContext] = await Promise.all([
1341+
agentContextsPromise,
1342+
userPermissionPromise,
1343+
persistUserMessagePromise,
1344+
executionContextPromise,
1345+
])
13521346
const turnContexts = withAskModeContext(agentContexts, body.mode)
13531347

13541348
executionContext.userPermission = userPermission ?? undefined
@@ -1423,7 +1417,6 @@ export async function handleUnifiedChatPost(req: NextRequest) {
14231417
requestPayload: {
14241418
...requestPayload,
14251419
protocolVersion: PROTOCOL_VERSION,
1426-
...(delegationToken ? { delegationToken } : {}),
14271420
},
14281421
userId: authenticatedUserId,
14291422
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, isNull, 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'
@@ -235,15 +234,11 @@ export async function executeInboxTask(taskId: string): Promise<void> {
235234
secretScope: ws.inboxSecretScope,
236235
mountedSecrets: ws.inboxMountedSecrets,
237236
})
238-
const [attachmentResult, integrationTools, billingAttribution, delegationToken] =
239-
await Promise.all([
240-
fetchAttachments(),
241-
buildIntegrationToolSchemas(userId, undefined, undefined, ws.id),
242-
resolveBillingAttribution({ actorUserId: userId, workspaceId: ws.id }),
243-
// Trigger-runtime caveat (see docs/revamp/06-cutover.md): a failed mint falls
244-
// back to null and the turn proceeds without CLI-backed capabilities.
245-
mintDelegationToken({ workspaceId: ws.id, userId }),
246-
])
237+
const [attachmentResult, integrationTools, billingAttribution] = await Promise.all([
238+
fetchAttachments(),
239+
buildIntegrationToolSchemas(userId, undefined, undefined, ws.id),
240+
resolveBillingAttribution({ actorUserId: userId, workspaceId: ws.id }),
241+
])
247242
const { attachments, fileAttachments, storedAttachments } = attachmentResult
248243

249244
const truncatedTask = {
@@ -264,7 +259,6 @@ export async function executeInboxTask(taskId: string): Promise<void> {
264259
chatId,
265260
messageId: userMessageId,
266261
...(integrationTools.length > 0 ? { integrationTools } : {}),
267-
...(delegationToken ? { delegationToken } : {}),
268262
}
269263

270264
const result = await runHeadlessCopilotLifecycle(requestPayload, {

0 commit comments

Comments
 (0)