Skip to content

Commit 90a4333

Browse files
committed
fix(mothership): own sandbox profile at the code tool boundary
1 parent 7df11b0 commit 90a4333

9 files changed

Lines changed: 22 additions & 62 deletions

File tree

‎apps/sim/lib/mothership/agent-cli/saved-run-read.postgres.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,6 @@ describe.skipIf(!process.env.MSHIP_TEST_DATABASE_URL)(
23072307
toolCallId: generateId(),
23082308
copilotToolExecution: true,
23092309
copilotInteractionMode: 'interactive',
2310-
sandboxProfile: 'mothership',
23112310
userPermission: 'write',
23122311
resolvedSecretTraceRegistry: new ResolvedSecretTraceRegistry([], {
23132312
userId: 'run-reader',
@@ -2682,7 +2681,6 @@ describe.skipIf(!process.env.MSHIP_TEST_DATABASE_URL)(
26822681
chatId,
26832682
toolCallId: generateId(),
26842683
copilotToolExecution: true,
2685-
sandboxProfile: 'mothership',
26862684
}
26872685
const mediaReference = await resolveCopilotWorkspaceFileReference(
26882686
context,

‎apps/sim/lib/mothership/request/lifecycle/run.test.ts‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -574,46 +574,6 @@ describe('runCopilotLifecycle', () => {
574574
expect(sentBody).not.toHaveProperty('systemPromptOverride')
575575
})
576576

577-
it.each([
578-
{ goRoute: undefined, expected: 'mothership' },
579-
{ goRoute: '/api/copilot', expected: 'mothership' },
580-
{ goRoute: '/api/mothership-unknown', expected: undefined },
581-
{ goRoute: '/api/mothership', expected: 'mothership' },
582-
{ goRoute: '/api/mothership/execute', expected: 'mothership' },
583-
])(
584-
'derives the sandbox profile from the trusted Go route ($goRoute)',
585-
async ({ goRoute, expected }) => {
586-
let sandboxProfile: ExecutionContext['sandboxProfile']
587-
mockRunStreamLoop.mockImplementationOnce(
588-
async (
589-
_url: string,
590-
_request: RequestInit,
591-
_streamingContext: StreamingContext,
592-
context: ExecutionContext
593-
) => {
594-
sandboxProfile = context.sandboxProfile
595-
}
596-
)
597-
598-
await runCopilotLifecycle(
599-
{ message: 'hello', messageId: `sandbox-profile-${goRoute ?? 'default'}` },
600-
{
601-
userId: 'user-1',
602-
workspaceId: 'ws-1',
603-
...(goRoute ? { goRoute } : {}),
604-
executionContext: {
605-
userId: 'user-1',
606-
workflowId: '',
607-
workspaceId: 'ws-1',
608-
sandboxProfile: 'mothership',
609-
},
610-
}
611-
)
612-
613-
expect(sandboxProfile).toBe(expected)
614-
}
615-
)
616-
617577
it('does not infer model provenance from a dormant environment catalog', async () => {
618578
const registry = new ResolvedSecretTraceRegistry([
619579
{

‎apps/sim/lib/mothership/request/lifecycle/run.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secr
8282

8383
const logger = createLogger('CopilotLifecycle')
8484

85-
const MOTHERSHIP_CODE_TOOL_ROUTES = new Set([
86-
'/api/copilot',
87-
'/api/mothership',
88-
'/api/mothership/execute',
89-
])
90-
9185
const COPILOT_MODEL_CONTENT_PROJECTION_ERROR = 'Copilot model input could not be safely projected'
9286

9387
class CopilotModelContentProjectionError extends Error {
@@ -370,11 +364,6 @@ export async function runCopilotLifecycle(
370364
}
371365
execContext.copilotInteractionMode =
372366
lifecycleOptions.interactive === true ? 'interactive' : 'headless'
373-
if (goRoute && MOTHERSHIP_CODE_TOOL_ROUTES.has(goRoute)) {
374-
execContext.sandboxProfile = 'mothership'
375-
} else {
376-
execContext.sandboxProfile = undefined
377-
}
378367
if (
379368
isHosted &&
380369
(!(execContext.workspaceId || execContext.organizationId) || !execContext.billingAttribution)

‎apps/sim/lib/mothership/request/tools/executor.test.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,6 @@ describe('buildToolExecutionContext', () => {
290290
userId: 'user-1',
291291
workflowId: 'workflow-1',
292292
runId: 'run-1',
293-
sandboxProfile: 'mothership',
294293
}
295294

296295
expect(
@@ -303,7 +302,6 @@ describe('buildToolExecutionContext', () => {
303302
)
304303
).toMatchObject({
305304
runId: 'run-1',
306-
sandboxProfile: 'mothership',
307305
toolCallId: 'call-1',
308306
parentToolCallId: 'parent-1',
309307
})

‎apps/sim/lib/mothership/tool-executor/types.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { BillingAttributionSnapshot } from '@/lib/billing/core/billing-attribution'
2-
import type { MothershipResource, MothershipResourceUpdate } from '@/lib/mothership/resources/types'
2+
import type { MothershipResourceUpdate } from '@/lib/mothership/resources/types'
33
import type { SecretMountPolicy } from '@/lib/mothership/secret-mount-policy'
44
import type { WorkspaceSearchFilters } from '@/lib/knowledge/search/filters'
55
import type { ExecutorDelegationOrigin } from '@/executor/types'
@@ -32,8 +32,6 @@ export interface ToolExecutionContext {
3232
copilotToolExecution?: boolean
3333
/** Trusted lifecycle classification stamped by the server, never from model parameters. */
3434
copilotInteractionMode?: 'interactive' | 'headless'
35-
/** Server-owned base image selected from the fixed Go route for this turn. */
36-
sandboxProfile?: 'mothership'
3735
requestMode?: string
3836
assistantSearch?: WorkspaceSearchFilters
3937
currentAgentId?: string

‎apps/sim/lib/mothership/tools/handlers/function-execute-file-mounts.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const context: ToolExecutionContext = {
6969
chatId: 'chat',
7070
toolCallId: 'mount',
7171
copilotToolExecution: true,
72-
sandboxProfile: 'mothership',
7372
}
7473

7574
function queueProvenance(status: 'exact' | 'unknown', currentRevision = revision, secret = false) {

‎apps/sim/lib/mothership/tools/handlers/function-execute-session.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ const BASE_CONTEXT: ToolExecutionContext = {
4949
userId: 'user-1',
5050
workflowId: '',
5151
workspaceId: 'ws-1',
52-
sandboxProfile: 'mothership',
5352
}
5453

5554
describe('executeFunctionExecute session plumbing', () => {
@@ -159,6 +158,26 @@ describe.each([
159158
})
160159
afterEach(clearHandlers)
161160

161+
it('owns the Mothership profile for direct callback and checkpoint dispatch', async () => {
162+
const params = {
163+
code: "return { template: '{{API_KEY}}' }",
164+
language: 'javascript',
165+
sandboxProfile: 'model-supplied',
166+
internalSandboxProfile: 'model-supplied',
167+
}
168+
const result = await executeTool(toolId, params, {
169+
...BASE_CONTEXT,
170+
copilotToolExecution: true,
171+
userPermission: 'write',
172+
})
173+
expect(result.success).toBe(true)
174+
const [, input, options] = mockExecuteTool.mock.calls[0]
175+
expect(input.code).toBe(params.code)
176+
expect(input).not.toHaveProperty('sandboxProfile')
177+
expect(input).not.toHaveProperty('internalSandboxProfile')
178+
expect(options.internalSandboxProfile).toBe('mothership')
179+
})
180+
162181
it.each([
163182
{ timeout: undefined, expected: 60_000 },
164183
{ timeout: 0.5, expected: 500 },

‎apps/sim/lib/mothership/tools/handlers/function-execute-table-mounts.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ const context: ToolExecutionContext = {
7171
chatId: 'chat',
7272
toolCallId: 'mount-call',
7373
copilotToolExecution: true,
74-
sandboxProfile: 'mothership',
7574
}
7675
const table: TableDefinition = {
7776
id: 'table-orders',

‎apps/sim/lib/mothership/tools/handlers/function-execute.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ export async function executeFunctionExecute(
572572
resolvedSecretTraceRegistry: mountedRegistry,
573573
},
574574
...(context.abortSignal ? { signal: context.abortSignal } : {}),
575-
...(context.sandboxProfile ? { internalSandboxProfile: context.sandboxProfile } : {}),
575+
internalSandboxProfile: 'mothership',
576576
})
577577
crossingValue = result
578578
return result

0 commit comments

Comments
 (0)