refactor(automation): use JSON-stringified execution keys
P1-19: Previous string-join with ':' separator could collide when field values contain colons (e.g. runId='a:b' vs runId='a' + previousStatus='b'). Use JSON.stringify for unambiguous serialization.
This commit is contained in:
1 parent
2050c0e8fd
commit
62050c9c05
1 file changed
+18
-18
@@ -111,16 +111,16 @@ export function createAutomationService({
|
|||||||
const rules = db.listActiveAutomationRules(ctx.companyId, trigger);
|
const rules = db.listActiveAutomationRules(ctx.companyId, trigger);
|
||||||
for (const rule of rules) {
|
for (const rule of rules) {
|
||||||
if (!matchesConditions(db, rule, ctx)) continue;
|
if (!matchesConditions(db, rule, ctx)) continue;
|
||||||
const executionKey = [
|
const executionKey = JSON.stringify({
|
||||||
rule.id,
|
ruleId: rule.id,
|
||||||
trigger,
|
trigger,
|
||||||
ctx.companyId,
|
companyId: ctx.companyId,
|
||||||
ctx.taskId ?? "-",
|
taskId: ctx.taskId ?? null,
|
||||||
ctx.agentId ?? "-",
|
agentId: ctx.agentId ?? null,
|
||||||
ctx.runId ?? "-",
|
runId: ctx.runId ?? null,
|
||||||
ctx.previousStatus ?? "-",
|
previousStatus: ctx.previousStatus ?? null,
|
||||||
ctx.newStatus ?? "-",
|
newStatus: ctx.newStatus ?? null,
|
||||||
].join(":");
|
});
|
||||||
if (activeAutomationExecutions.has(executionKey)) {
|
if (activeAutomationExecutions.has(executionKey)) {
|
||||||
logger.warn(`[automation] Skipping re-entrant execution for rule "${rule.name}" (${executionKey})`);
|
logger.warn(`[automation] Skipping re-entrant execution for rule "${rule.name}" (${executionKey})`);
|
||||||
continue;
|
continue;
|
||||||
@@ -168,16 +168,16 @@ export function createAutomationService({
|
|||||||
const workflows = db.listTriggerableWorkflows(ctx.companyId, trigger);
|
const workflows = db.listTriggerableWorkflows(ctx.companyId, trigger);
|
||||||
for (const workflow of workflows) {
|
for (const workflow of workflows) {
|
||||||
if (!matchesEventConfig(db, workflow.triggerConfigJson, null, ctx)) continue;
|
if (!matchesEventConfig(db, workflow.triggerConfigJson, null, ctx)) continue;
|
||||||
const executionKey = [
|
const executionKey = JSON.stringify({
|
||||||
workflow.id,
|
workflowId: workflow.id,
|
||||||
trigger,
|
trigger,
|
||||||
ctx.companyId,
|
companyId: ctx.companyId,
|
||||||
ctx.taskId ?? "-",
|
taskId: ctx.taskId ?? null,
|
||||||
ctx.agentId ?? "-",
|
agentId: ctx.agentId ?? null,
|
||||||
ctx.runId ?? "-",
|
runId: ctx.runId ?? null,
|
||||||
ctx.previousStatus ?? "-",
|
previousStatus: ctx.previousStatus ?? null,
|
||||||
ctx.newStatus ?? "-",
|
newStatus: ctx.newStatus ?? null,
|
||||||
].join(":");
|
});
|
||||||
if (activeWorkflowTriggerExecutions.has(executionKey)) {
|
if (activeWorkflowTriggerExecutions.has(executionKey)) {
|
||||||
logger.warn(`[workflow] Skipping re-entrant trigger for workflow "${workflow.name}" (${executionKey})`);
|
logger.warn(`[workflow] Skipping re-entrant trigger for workflow "${workflow.name}" (${executionKey})`);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in new issue
Block a user