Skip to content

Commit 03b8fc6

Browse files
authored
fix(organization-search): refuse runs resumed by someone else, single-source operations, surface-neutral shared tools (#10562)
* fix(organization-search): refuse runs resumed by someone else; document log visibility; single-source operations; surface-neutral shared tools; hide the block without Search * chore(organization-search): regenerate docs and tool metadata after staging * test(organization-search): type the refused principals and the read input in full * test(organization-search): an unknown live reference reads as not found * test(resume): expect the resumer recorded for each principal, none for a workspace key * fix(resume): keep a member's resume across branches that completed without pausing again * test(resume): build the starter with the session principal factory * chore(organization-search): regenerate tool metadata after staging
1 parent edbc90b commit 03b8fc6

42 files changed

Lines changed: 584 additions & 108 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/docs/content/docs/integrations/meta.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
"onepassword",
205205
"oracle_fusion_financials",
206206
"oracledb",
207+
"organization",
207208
"otter",
208209
"outlook",
209210
"pagerduty",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: Organization Search
3+
description: Search your organization’s sources, people directory, and your own chat history and activity
4+
integration:
5+
type: "organization"
6+
color: "#2563EB"
7+
---
8+
9+
10+
## Use the block [#usage-instructions]
11+
12+
Search the organization’s connected sources through their live APIs, read the documents they return, look people up in the People directory, list your own questions to Sim over a date window, and list what you did across your connected sources. Every operation runs as the person who started the run, within their own access, so a scheduled or webhook run without a person fails instead of borrowing anyone’s access. Results are returned to the workflow and appear in its run logs, which other workspace members can read.
13+
14+

‎apps/sim/app/api/resume/[workflowId]/[executionId]/[contextId]/route.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ describe('POST /api/resume/[workflowId]/[executionId]/[contextId]', () => {
309309
contextId: CONTEXT_ID,
310310
resumeInput: { approved: true },
311311
userId: WORKSPACE_BILLING_OWNER_ID,
312+
resumedBy: { subjectUserId: null },
312313
allowedPauseKinds: ['human'],
313314
})
314315
})
@@ -460,6 +461,7 @@ describe('POST /api/resume/[workflowId]/[executionId]/[contextId]', () => {
460461
contextId: CONTEXT_ID,
461462
workspaceId: WORKSPACE_ID,
462463
userId: 'current-api-key-user',
464+
resumedBy: { subjectUserId: 'current-api-key-user' },
463465
resumeInput: { approved: true },
464466
isApiCaller: true,
465467
pollingSurface: 'v2',

‎apps/sim/blocks/blocks/organization.ts‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { OrganizationSearchIcon } from '@/components/icons'
2+
import {
3+
ORGANIZATION_SEARCH_OPERATIONS,
4+
ORGANIZATION_SEARCH_TOOL_IDS,
5+
organizationSearchToolId,
6+
} from '@/lib/internal/organization-search/tool-ids'
27
import type { BlockConfig } from '@/blocks/types'
38
import {
49
blockFieldOrToolArg,
@@ -7,16 +12,7 @@ import {
712
parseOptionalNumberInput,
813
} from '@/blocks/utils'
914

10-
/** Operations, keyed by the Search MCP tool they run; each runs the tool `organization_<id>`. */
11-
const OPERATIONS = [
12-
{ label: 'Search', id: 'search' },
13-
{ label: 'Read Document', id: 'read_document' },
14-
{ label: 'Search People', id: 'search_people' },
15-
{ label: 'List My Chat History', id: 'list_my_chat_history' },
16-
{ label: 'List My Activity', id: 'list_my_activity' },
17-
] as const
18-
19-
const OPERATION_IDS = new Set<string>(OPERATIONS.map((operation) => operation.id))
15+
const OPERATION_IDS = new Set<string>(ORGANIZATION_SEARCH_OPERATIONS.map(({ id }) => id))
2016

2117
/** Organization Search: the Search MCP tools as one workflow block, run as the run's person. */
2218
export const OrganizationBlock: BlockConfig = {
@@ -25,12 +21,13 @@ export const OrganizationBlock: BlockConfig = {
2521
description:
2622
'Search your organization’s sources, people directory, and your own chat history and activity',
2723
longDescription:
28-
'Search the organization’s connected sources through their live APIs, read the documents they return, look people up in the People directory, list your own questions to Sim over a date window, and list what you did across your connected sources. Every operation runs as the person who started the run, within their own access, so a scheduled or webhook run without a person fails instead of borrowing anyone’s access.',
24+
'Search the organization’s connected sources through their live APIs, read the documents they return, look people up in the People directory, list your own questions to Sim over a date window, and list what you did across your connected sources. Every operation runs as the person who started the run, within their own access, so a scheduled or webhook run without a person fails instead of borrowing anyone’s access. Results are returned to the workflow and appear in its run logs, which other workspace members can read.',
2925
bestPractices: `
3026
- Use Search to find candidates, then Read Document with a returned documentId when the passage is not enough.
3127
- Search People covers only this organization's people; use Search for customers, vendors, and other outside contacts.
3228
- List My Activity covers only the run's person's own activity; use Search to find what anyone else did.
33-
- Runs started by a schedule, a webhook, or a workspace API key have no person to search as, and fail.
29+
- Runs started by a schedule, a webhook, or a workspace API key have no person to search as, and fail; so does a run resumed by someone other than the person who started it.
30+
- Results are returned to the workflow and appear in its run logs, which other workspace members can read. Pass on only what the workflow needs.
3431
`,
3532
bgColor: '#2563EB',
3633
icon: OrganizationSearchIcon,
@@ -60,7 +57,7 @@ export const OrganizationBlock: BlockConfig = {
6057
id: 'operation',
6158
title: 'Operation',
6259
type: 'dropdown',
63-
options: [...OPERATIONS],
60+
options: [...ORGANIZATION_SEARCH_OPERATIONS],
6461
value: () => 'search',
6562
},
6663
{
@@ -297,9 +294,9 @@ export const OrganizationBlock: BlockConfig = {
297294
},
298295
],
299296
tools: {
300-
access: OPERATIONS.map((operation) => `organization_${operation.id}`),
297+
access: [...ORGANIZATION_SEARCH_TOOL_IDS],
301298
config: {
302-
tool: (params) => `organization_${params.operation || 'search'}`,
299+
tool: (params) => organizationSearchToolId(params.operation || 'search'),
303300
params: (params, context) => {
304301
const operation = mapperOperation(params, context) || 'search'
305302
if (!OPERATION_IDS.has(operation))

‎apps/sim/executor/execution/snapshot-serializer.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ function buildExecutionSnapshot(
308308
/** Preserve the run-level agent-events opt-in across HITL pause/resume. */
309309
agentEvents: metadataFromContext?.agentEvents === true ? true : undefined,
310310
stopAfterBlockId: metadataFromContext?.stopAfterBlockId,
311+
/** A resume by someone other than the run's person stays on the run for every later segment. */
312+
resumedBy: metadataFromContext?.resumedBy,
311313
}
312314

313315
const snapshot = new ExecutionSnapshot(

‎apps/sim/executor/execution/types.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { NodeMetadata } from '@/executor/dag/types'
77
import type {
88
BlockLog,
99
BlockState,
10+
ExecutionResumer,
1011
ExecutorDelegationOrigin,
1112
NormalizedBlockOutput,
1213
StartBlockRunMetadata,
@@ -62,6 +63,8 @@ export interface ExecutionMetadata {
6263
resumeTerminalNoop?: boolean
6364
/** Other durable pauses remain after the current context resumes. */
6465
resumeHasPendingPauses?: boolean
66+
/** Who resumed this attempt, for operations that act as the run's person. */
67+
resumedBy?: ExecutionResumer
6568
/** Original workflow block ID, before loop/parallel sentinel resolution. */
6669
stopAfterBlockId?: string
6770
/** A resumed pause completed the stop target before the engine starts. */

‎apps/sim/executor/types.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ export interface PausePoint {
9191
response: any
9292
registeredAt: string
9393
resumeStatus: ResumeStatus
94+
/** The caller who resumed this point, recorded when the resume is admitted. */
95+
resumedBy?: ExecutionResumer
9496
automaticResumeWaitingReason?: string
9597
snapshotReady: boolean
9698
parallelScope?: ParallelPauseScope
@@ -451,6 +453,17 @@ export interface ExecutorDelegationOrigin {
451453
executionId?: string
452454
principal?: WorkflowExecutionPrincipal
453455
currentWorkflow?: WorkflowExecutionAuthority
456+
/** Who resumed this run from a pause; absent for a run never resumed, or resumed on a timer. */
457+
resumedBy?: ExecutionResumer
458+
}
459+
460+
/**
461+
* The caller who resumed a paused run: their Sim user, or `null` for a caller acting for no
462+
* person (a workspace API key). Operations that act as the run's person refuse a run resumed by
463+
* anyone else, so a resume cannot steer them as the person who started it.
464+
*/
465+
export interface ExecutionResumer {
466+
subjectUserId: string | null
454467
}
455468

456469
export interface ExecutionContext {

‎apps/sim/hooks/use-integration-access.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export function useIntegrationAccessPolicy(
6060
): IntegrationAccessPolicyState {
6161
const enabled = options?.enabled ?? true
6262
const blockOverlayVersion = useCustomBlockOverlayVersion()
63-
const credentialGroupsEnabled = useOptionalWorkspaceHostContext()?.features?.credentialGroups
63+
const hostFeatures = useOptionalWorkspaceHostContext()?.features
64+
const credentialGroupsEnabled = hostFeatures?.credentialGroups
65+
const organizationSearchEnabled = hostFeatures?.organizationSearch
6466
const {
6567
data: permissionData,
6668
isSuccess: isPermissionReady,
@@ -85,8 +87,15 @@ export function useIntegrationAccessPolicy(
8587
availability: availabilityData?.integrationAvailability ?? [],
8688
visibility: overlayVisibility(),
8789
credentialGroupsEnabled: credentialGroupsEnabled === true,
90+
organizationSearchEnabled: organizationSearchEnabled === true,
8891
}),
89-
[permissionData?.config, availabilityData, credentialGroupsEnabled, blockOverlayVersion]
92+
[
93+
permissionData?.config,
94+
availabilityData,
95+
credentialGroupsEnabled,
96+
organizationSearchEnabled,
97+
blockOverlayVersion,
98+
]
9099
)
91100

92101
const oauthServiceAvailability = useMemo(

‎apps/sim/lib/integrations/access.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function accessOf(
1717
deploymentAllowlist?: string[] | null
1818
availability?: IntegrationAvailabilityResponse[]
1919
credentialGroupsEnabled?: boolean
20+
organizationSearchEnabled?: boolean
2021
groupConfig?: PermissionGroupConfig
2122
}
2223
): IntegrationAccess {
@@ -28,6 +29,7 @@ function accessOf(
2829
availability: policy.availability ?? [],
2930
visibility: null,
3031
credentialGroupsEnabled: policy.credentialGroupsEnabled ?? true,
32+
organizationSearchEnabled: policy.organizationSearchEnabled ?? true,
3133
groupConfig: policy.groupConfig,
3234
})
3335
)
@@ -73,4 +75,9 @@ describe('resolveIntegrationAccess', () => {
7375
it('denies credential groups where the feature is off, even when unrestricted', () => {
7476
expect(accessOf('credential_group', { credentialGroupsEnabled: false })).toBe('denied')
7577
})
78+
79+
it('denies Organization Search outside an organization with Search, even when unrestricted', () => {
80+
expect(accessOf('organization', { organizationSearchEnabled: false })).toBe('denied')
81+
expect(accessOf('organization', { organizationSearchEnabled: true })).toBe('available')
82+
})
7683
})

‎apps/sim/lib/integrations/access.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ export interface IntegrationAccessPolicy {
5252
/** Deployment availability by lowercased block type, projected through the viewer's visibility. */
5353
availability: ReadonlyMap<string, IntegrationAvailabilityResponse>
5454
credentialGroupsEnabled: boolean
55+
/**
56+
* Organization Search is on for the workspace's organization and open to the viewer. This only
57+
* hides the block; its use cases still refuse an organization without Search on the server.
58+
*/
59+
organizationSearchEnabled: boolean
5560
groupConfig?: PermissionGroupConfig | null
5661
}
5762

@@ -61,6 +66,7 @@ interface IntegrationAccessPolicyInput {
6166
availability: readonly IntegrationAvailabilityResponse[]
6267
visibility: BlockVisibilityState | null
6368
credentialGroupsEnabled: boolean
69+
organizationSearchEnabled: boolean
6470
groupConfig?: PermissionGroupConfig | null
6571
}
6672

@@ -70,6 +76,7 @@ export function createIntegrationAccessPolicy({
7076
availability,
7177
visibility,
7278
credentialGroupsEnabled,
79+
organizationSearchEnabled,
7380
groupConfig,
7481
}: IntegrationAccessPolicyInput): IntegrationAccessPolicy {
7582
return {
@@ -82,6 +89,7 @@ export function createIntegrationAccessPolicy({
8289
])
8390
),
8491
credentialGroupsEnabled,
92+
organizationSearchEnabled,
8593
groupConfig,
8694
}
8795
}
@@ -106,6 +114,10 @@ export function resolveIntegrationAccess(
106114
if (normalizedBlockType === 'credential_group' && !policy.credentialGroupsEnabled) {
107115
return 'denied'
108116
}
117+
// Organization Search runs only in an organization that has Search, for one of its members.
118+
if (normalizedBlockType === 'organization' && !policy.organizationSearchEnabled) {
119+
return 'denied'
120+
}
109121
const state = policy.availability.get(normalizedBlockType)?.state
110122
const unconfigured =
111123
isDeploymentGatedIntegrationType(normalizedBlockType) &&

0 commit comments

Comments
 (0)