Skip to content

Commit e243b69

Browse files
authored
[One Workflow] Bugfix - concurrency limits / index refresh (#257829)
The shared helper used by both manual and alert-triggered paths was indexing with the default `refresh:false` meaning newly created execution documents could remain invisible to search long enough for concurrent requests to race through the concurrency gate. Fixes elastic/security-team#15651
1 parent dde5806 commit e243b69

File tree

1 file changed

+14
-4
lines changed
  • src/platform/plugins/shared/workflows_execution_engine/server

1 file changed

+14
-4
lines changed

src/platform/plugins/shared/workflows_execution_engine/server/plugin.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ export class WorkflowsExecutionEnginePlugin
521521
workflow: WorkflowExecutionEngineModel,
522522
context: Record<string, unknown>,
523523
defaultTriggeredBy: string,
524-
request: KibanaRequest
524+
request: KibanaRequest,
525+
options: { refresh: boolean | 'wait_for' } = { refresh: false }
525526
): Promise<{
526527
workflowExecution: Partial<EsWorkflowExecution>;
527528
repository: WorkflowExecutionRepository;
@@ -561,7 +562,14 @@ export class WorkflowsExecutionEnginePlugin
561562
workflowExecution.concurrencyGroupKey = concurrencyGroupKey;
562563
}
563564

564-
await workflowExecutionRepository.createWorkflowExecution(workflowExecution);
565+
// Only pay the refresh cost when the concurrency check will actually run.
566+
// Without a concurrencyGroupKey there is no check, so refresh:false is fine.
567+
// When a check will run, the caller dictates the strategy: manual/UI paths use
568+
// refresh:true (immediate, no latency for the user); async paths use refresh:'wait_for'
569+
// (piggybacks on the scheduled cycle, lower cluster cost).
570+
await workflowExecutionRepository.createWorkflowExecution(workflowExecution, {
571+
refresh: concurrencyGroupKey ? options.refresh : false,
572+
});
565573

566574
return { workflowExecution, repository: workflowExecutionRepository };
567575
};
@@ -610,7 +618,8 @@ export class WorkflowsExecutionEnginePlugin
610618
workflow,
611619
context,
612620
'manual',
613-
request
621+
request,
622+
{ refresh: true }
614623
);
615624

616625
// Check concurrency limits and apply collision strategy if needed
@@ -667,7 +676,8 @@ export class WorkflowsExecutionEnginePlugin
667676
workflow,
668677
context,
669678
'alert',
670-
request
679+
request,
680+
{ refresh: 'wait_for' }
671681
);
672682

673683
// Check concurrency limits and apply collision strategy if needed

0 commit comments

Comments
 (0)