Skip to content

Commit 51df824

Browse files
fix(copilot): align principal lifetime with orchestration (#6649)
* fix(copilot): align principal lifetime with orchestration * fix(copilot): align workflow lifetime expectation
1 parent f890c89 commit 51df824

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

apps/sim/lib/copilot/application/execute-workflow-use-case.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
executeCopilotWorkflowUseCase,
1515
messageForCopilotWorkflowError,
1616
} from '@/lib/copilot/application/execute-workflow-use-case'
17+
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
1718
import { OrchestrationError } from '@/lib/core/orchestration/types'
1819
import { workflowOperations } from '@/lib/workflows/application/operations'
1920

@@ -57,7 +58,7 @@ describe('Copilot Workflow application adapter', () => {
5758
delegationId: 'copilot-tool:tool-call-1',
5859
audience: 'sim:workflows',
5960
issuedAt: new Date('2026-01-01T00:00:00Z'),
60-
expiresAt: new Date('2026-01-01T00:05:00Z'),
61+
expiresAt: new Date(Date.now() + ORCHESTRATION_TIMEOUT_MS),
6162
resourceScope: { chatId: 'chat-1', executionId: 'execution-1' },
6263
},
6364
input: { workflowId: 'workflow-1', assertedWorkspaceId: 'workspace-1' },

apps/sim/lib/copilot/auth/application-delegation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { DelegatedPrincipal } from '@sim/auth/principal'
2+
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
23

3-
export const COPILOT_APPLICATION_DELEGATION_TTL_MS = 5 * 60 * 1000
4+
/** Keeps delegated authority valid for the full bounded Copilot orchestration lifetime. */
5+
export const COPILOT_APPLICATION_DELEGATION_TTL_MS = ORCHESTRATION_TIMEOUT_MS
46

57
export interface CopilotExecutionContext {
68
userId?: string

apps/sim/lib/copilot/auth/file-delegation.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
messageForCopilotFileError,
99
resolveCopilotFilePrincipal,
1010
} from '@/lib/copilot/auth/file-delegation'
11+
import { ORCHESTRATION_TIMEOUT_MS } from '@/lib/copilot/constants'
1112
import { OrchestrationError } from '@/lib/core/orchestration/types'
1213

1314
const trustedContext = {
@@ -20,7 +21,7 @@ const trustedContext = {
2021
}
2122

2223
describe('Copilot file delegation', () => {
23-
it('creates a short-lived principal scoped to the trusted workspace and file', () => {
24+
it('creates an orchestration-bounded principal scoped to the trusted workspace and file', () => {
2425
const principal = resolveCopilotFilePrincipal(trustedContext, 'file-1')
2526

2627
expect(principal).toMatchObject({
@@ -36,7 +37,9 @@ describe('Copilot file delegation', () => {
3637
executionId: 'execution-1',
3738
},
3839
})
39-
expect(principal.expiresAt.getTime()).toBeGreaterThan(principal.issuedAt.getTime())
40+
expect(principal.expiresAt.getTime() - principal.issuedAt.getTime()).toBe(
41+
ORCHESTRATION_TIMEOUT_MS
42+
)
4043
})
4144

4245
it('creates a workspace-scoped principal for file creation', () => {

0 commit comments

Comments
 (0)