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');
|
||||
}
|
||||
|
||||
// Start Braintrust initialization immediately but don't block the critical path
|
||||
const braintrustInitStart = Date.now();
|
||||
const braintrustInitPromise = Promise.resolve().then(async () => {
|
||||
try {
|
||||
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
|
||||
}
|
||||
// Initialize Braintrust logger
|
||||
const braintrustLogger = initLogger({
|
||||
apiKey: process.env.BRAINTRUST_KEY,
|
||||
projectName: process.env.ENVIRONMENT || 'development',
|
||||
});
|
||||
|
||||
try {
|
||||
|
@ -424,19 +408,6 @@ export const analystAgentTask: ReturnType<
|
|||
// Log performance after workflow run creation
|
||||
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
|
||||
const workflowStartMethodStart = Date.now();
|
||||
const tracedWorkflow = wrapTraced(
|
||||
|
@ -472,7 +443,6 @@ export const analystAgentTask: ReturnType<
|
|||
workflowStartMethodTimeMs: workflowStartMethodTime,
|
||||
totalWorkflowTimeMs: totalWorkflowTime,
|
||||
createRunTimeMs: createRunTime,
|
||||
braintrustWaitTimeMs: braintrustWaitTime,
|
||||
});
|
||||
|
||||
// Log final performance metrics
|
||||
|
@ -491,7 +461,6 @@ export const analystAgentTask: ReturnType<
|
|||
dataLoadTimeMs: dataLoadTime,
|
||||
contextSetupTimeMs: contextSetupTime,
|
||||
createRunTimeMs: createRunTime,
|
||||
braintrustWaitTimeMs: braintrustWaitTime,
|
||||
workflowStartMethodTimeMs: workflowStartMethodTime,
|
||||
totalWorkflowTimeMs: totalWorkflowTime,
|
||||
},
|
||||
|
@ -549,6 +518,9 @@ export const analystAgentTask: ReturnType<
|
|||
executionTimeMs: totalExecutionTime,
|
||||
});
|
||||
|
||||
// Need to flush the Braintrust logger to ensure all traces are sent
|
||||
await braintrustLogger.flush();
|
||||
|
||||
return {
|
||||
success: false,
|
||||
messageId: payload.message_id,
|
||||
|
|
|
@ -135,8 +135,8 @@ export const messagePostProcessingTask: ReturnType<
|
|||
throw new Error('BRAINTRUST_KEY is not set');
|
||||
}
|
||||
|
||||
// Initialize Braintrust logging for observability
|
||||
initLogger({
|
||||
// Initialize Braintrust logger
|
||||
const braintrustLogger = initLogger({
|
||||
apiKey: process.env.BRAINTRUST_KEY,
|
||||
projectName: process.env.ENVIRONMENT || 'development',
|
||||
});
|
||||
|
@ -302,6 +302,12 @@ export const messagePostProcessingTask: ReturnType<
|
|||
// Step 6: Send Slack notification if conditions are met
|
||||
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 {
|
||||
logger.log('Checking Slack notification conditions', {
|
||||
messageId: payload.messageId,
|
||||
|
@ -309,29 +315,38 @@ export const messagePostProcessingTask: ReturnType<
|
|||
summaryTitle: dbData.summary_title,
|
||||
summaryMessage: dbData.summary_message,
|
||||
toolCalled: dbData.tool_called,
|
||||
hasMajorAssumptions,
|
||||
shouldSkipSlackNotification,
|
||||
});
|
||||
|
||||
const slackResult = await sendSlackNotification({
|
||||
organizationId: messageContext.organizationId,
|
||||
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', {
|
||||
if (shouldSkipSlackNotification) {
|
||||
logger.log('Skipping Slack notification: noIssuesFound with no major assumptions', {
|
||||
messageId: payload.messageId,
|
||||
organizationId: messageContext.organizationId,
|
||||
});
|
||||
} else {
|
||||
logger.log('Slack notification not sent', {
|
||||
messageId: payload.messageId,
|
||||
const slackResult = await sendSlackNotification({
|
||||
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) {
|
||||
const errorMessage =
|
||||
|
@ -385,6 +400,9 @@ export const messagePostProcessingTask: ReturnType<
|
|||
executionTimeMs: Date.now() - startTime,
|
||||
});
|
||||
|
||||
// Need to flush the Braintrust logger to ensure all traces are sent
|
||||
await braintrustLogger.flush();
|
||||
|
||||
return {
|
||||
success: false,
|
||||
messageId: payload.messageId,
|
||||
|
|
Loading…
Reference in New Issue