mirror of https://github.com/buster-so/buster.git
Merge pull request #439 from buster-so/dal/retry-agent-logic
skip slack notification on no issues foudn + no major assumptions
This commit is contained in:
commit
0693e4ce25
|
@ -290,26 +290,10 @@ export const analystAgentTask: ReturnType<
|
||||||
throw new Error('BRAINTRUST_KEY is not set');
|
throw new Error('BRAINTRUST_KEY is not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start Braintrust initialization immediately but don't block the critical path
|
// Initialize Braintrust logger
|
||||||
const braintrustInitStart = Date.now();
|
const braintrustLogger = initLogger({
|
||||||
const braintrustInitPromise = Promise.resolve().then(async () => {
|
apiKey: process.env.BRAINTRUST_KEY,
|
||||||
try {
|
projectName: process.env.ENVIRONMENT || 'development',
|
||||||
initLogger({
|
|
||||||
apiKey: process.env.BRAINTRUST_KEY,
|
|
||||||
projectName: process.env.ENVIRONMENT || 'development',
|
|
||||||
});
|
|
||||||
logger.log('Braintrust initialization completed', {
|
|
||||||
messageId: payload.message_id,
|
|
||||||
braintrustInitTimeMs: Date.now() - braintrustInitStart,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
logger.error('Braintrust initialization failed', {
|
|
||||||
messageId: payload.message_id,
|
|
||||||
error: error instanceof Error ? error.message : 'Unknown error',
|
|
||||||
braintrustInitTimeMs: Date.now() - braintrustInitStart,
|
|
||||||
});
|
|
||||||
// Don't throw - allow workflow to continue without Braintrust
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -424,19 +408,6 @@ export const analystAgentTask: ReturnType<
|
||||||
// Log performance after workflow run creation
|
// Log performance after workflow run creation
|
||||||
logPerformanceMetrics('post-createrun', payload.message_id, taskStartTime, resourceTracker);
|
logPerformanceMetrics('post-createrun', payload.message_id, taskStartTime, resourceTracker);
|
||||||
|
|
||||||
// Wait for Braintrust initialization if it's not ready yet
|
|
||||||
const braintrustWaitStart = Date.now();
|
|
||||||
await braintrustInitPromise;
|
|
||||||
const braintrustWaitTime = Date.now() - braintrustWaitStart;
|
|
||||||
|
|
||||||
if (braintrustWaitTime > 10) {
|
|
||||||
// Only log if we actually had to wait
|
|
||||||
logger.log('Waited for Braintrust initialization', {
|
|
||||||
messageId: payload.message_id,
|
|
||||||
braintrustWaitTimeMs: braintrustWaitTime,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute workflow with tracing
|
// Execute workflow with tracing
|
||||||
const workflowStartMethodStart = Date.now();
|
const workflowStartMethodStart = Date.now();
|
||||||
const tracedWorkflow = wrapTraced(
|
const tracedWorkflow = wrapTraced(
|
||||||
|
@ -472,7 +443,6 @@ export const analystAgentTask: ReturnType<
|
||||||
workflowStartMethodTimeMs: workflowStartMethodTime,
|
workflowStartMethodTimeMs: workflowStartMethodTime,
|
||||||
totalWorkflowTimeMs: totalWorkflowTime,
|
totalWorkflowTimeMs: totalWorkflowTime,
|
||||||
createRunTimeMs: createRunTime,
|
createRunTimeMs: createRunTime,
|
||||||
braintrustWaitTimeMs: braintrustWaitTime,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Log final performance metrics
|
// Log final performance metrics
|
||||||
|
@ -491,7 +461,6 @@ export const analystAgentTask: ReturnType<
|
||||||
dataLoadTimeMs: dataLoadTime,
|
dataLoadTimeMs: dataLoadTime,
|
||||||
contextSetupTimeMs: contextSetupTime,
|
contextSetupTimeMs: contextSetupTime,
|
||||||
createRunTimeMs: createRunTime,
|
createRunTimeMs: createRunTime,
|
||||||
braintrustWaitTimeMs: braintrustWaitTime,
|
|
||||||
workflowStartMethodTimeMs: workflowStartMethodTime,
|
workflowStartMethodTimeMs: workflowStartMethodTime,
|
||||||
totalWorkflowTimeMs: totalWorkflowTime,
|
totalWorkflowTimeMs: totalWorkflowTime,
|
||||||
},
|
},
|
||||||
|
@ -549,6 +518,9 @@ export const analystAgentTask: ReturnType<
|
||||||
executionTimeMs: totalExecutionTime,
|
executionTimeMs: totalExecutionTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Need to flush the Braintrust logger to ensure all traces are sent
|
||||||
|
await braintrustLogger.flush();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
messageId: payload.message_id,
|
messageId: payload.message_id,
|
||||||
|
|
|
@ -135,8 +135,8 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
throw new Error('BRAINTRUST_KEY is not set');
|
throw new Error('BRAINTRUST_KEY is not set');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Braintrust logging for observability
|
// Initialize Braintrust logger
|
||||||
initLogger({
|
const braintrustLogger = initLogger({
|
||||||
apiKey: process.env.BRAINTRUST_KEY,
|
apiKey: process.env.BRAINTRUST_KEY,
|
||||||
projectName: process.env.ENVIRONMENT || 'development',
|
projectName: process.env.ENVIRONMENT || 'development',
|
||||||
});
|
});
|
||||||
|
@ -302,6 +302,12 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
// Step 6: Send Slack notification if conditions are met
|
// Step 6: Send Slack notification if conditions are met
|
||||||
let slackNotificationSent = false;
|
let slackNotificationSent = false;
|
||||||
|
|
||||||
|
// Skip Slack notification if tool_called is "noIssuesFound" and there are no major assumptions
|
||||||
|
const hasMajorAssumptions =
|
||||||
|
dbData.assumptions?.some((assumption) => assumption.label === 'major') ?? false;
|
||||||
|
const shouldSkipSlackNotification =
|
||||||
|
dbData.tool_called === 'noIssuesFound' && !hasMajorAssumptions;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logger.log('Checking Slack notification conditions', {
|
logger.log('Checking Slack notification conditions', {
|
||||||
messageId: payload.messageId,
|
messageId: payload.messageId,
|
||||||
|
@ -309,29 +315,38 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
summaryTitle: dbData.summary_title,
|
summaryTitle: dbData.summary_title,
|
||||||
summaryMessage: dbData.summary_message,
|
summaryMessage: dbData.summary_message,
|
||||||
toolCalled: dbData.tool_called,
|
toolCalled: dbData.tool_called,
|
||||||
|
hasMajorAssumptions,
|
||||||
|
shouldSkipSlackNotification,
|
||||||
});
|
});
|
||||||
|
|
||||||
const slackResult = await sendSlackNotification({
|
if (shouldSkipSlackNotification) {
|
||||||
organizationId: messageContext.organizationId,
|
logger.log('Skipping Slack notification: noIssuesFound with no major assumptions', {
|
||||||
userName: messageContext.userName,
|
|
||||||
chatId: messageContext.chatId,
|
|
||||||
summaryTitle: dbData.summary_title,
|
|
||||||
summaryMessage: dbData.summary_message,
|
|
||||||
toolCalled: dbData.tool_called,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (slackResult.sent) {
|
|
||||||
slackNotificationSent = true;
|
|
||||||
logger.log('Slack notification sent successfully', {
|
|
||||||
messageId: payload.messageId,
|
messageId: payload.messageId,
|
||||||
organizationId: messageContext.organizationId,
|
organizationId: messageContext.organizationId,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
logger.log('Slack notification not sent', {
|
const slackResult = await sendSlackNotification({
|
||||||
messageId: payload.messageId,
|
|
||||||
organizationId: messageContext.organizationId,
|
organizationId: messageContext.organizationId,
|
||||||
reason: slackResult.error,
|
userName: messageContext.userName,
|
||||||
|
chatId: messageContext.chatId,
|
||||||
|
summaryTitle: dbData.summary_title,
|
||||||
|
summaryMessage: dbData.summary_message,
|
||||||
|
toolCalled: dbData.tool_called,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (slackResult.sent) {
|
||||||
|
slackNotificationSent = true;
|
||||||
|
logger.log('Slack notification sent successfully', {
|
||||||
|
messageId: payload.messageId,
|
||||||
|
organizationId: messageContext.organizationId,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
logger.log('Slack notification not sent', {
|
||||||
|
messageId: payload.messageId,
|
||||||
|
organizationId: messageContext.organizationId,
|
||||||
|
reason: slackResult.error,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (slackError) {
|
} catch (slackError) {
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
|
@ -385,6 +400,9 @@ export const messagePostProcessingTask: ReturnType<
|
||||||
executionTimeMs: Date.now() - startTime,
|
executionTimeMs: Date.now() - startTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Need to flush the Braintrust logger to ensure all traces are sent
|
||||||
|
await braintrustLogger.flush();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
messageId: payload.messageId,
|
messageId: payload.messageId,
|
||||||
|
|
Loading…
Reference in New Issue