Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/triggers/github/webhook-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { runAgent } from '../../agents/registry.js';
import { findProjectByRepo } from '../../config/projects.js';
import { getSessionState } from '../../gadgets/sessionState.js';
import { githubClient } from '../../github/client.js';
import { trelloClient } from '../../trello/client.js';
import type { CascadeConfig, ProjectConfig, TriggerContext } from '../../types/index.js';
Expand Down Expand Up @@ -54,6 +55,11 @@ async function executeGitHubAgent(
}
}

// Update initial PR comment on failure for GitHub-bound agents
if (!agentResult.success && result.prNumber) {
await updateInitialCommentWithError(result, agentResult);
}

logger.info('GitHub agent completed', {
agentType: result.agentType,
prNumber: result.prNumber,
Expand All @@ -62,6 +68,28 @@ async function executeGitHubAgent(
});
}

async function updateInitialCommentWithError(
result: TriggerResult,
agentResult: { success: boolean; error?: string },
): Promise<void> {
const input = result.agentInput as { repoFullName?: string };
if (!input.repoFullName || !result.prNumber) return;

const [owner, repo] = input.repoFullName.split('/');
if (!owner || !repo) return;

const { initialCommentId } = getSessionState();
if (!initialCommentId) return;

const errorMessage = agentResult.error || 'Agent completed without making changes';
const body = `⚠️ **${result.agentType} agent failed**\n\n${errorMessage}\n\n<sub>Manual intervention may be required.</sub>`;

await safeOperation(() => githubClient.updatePRComment(owner, repo, initialCommentId, body), {
action: 'update PR comment with error',
prNumber: result.prNumber,
});
}

async function postAcknowledgmentComment(result: TriggerResult): Promise<void> {
if (result.agentType !== 'respond-to-review' || !result.prNumber) {
return;
Expand Down Expand Up @@ -165,6 +193,7 @@ export async function processGitHubWebhook(
await executeGitHubAgent(result, project, config);
} catch (err) {
logger.error('Failed to process GitHub webhook', { error: String(err) });
await updateInitialCommentWithError(result, { success: false, error: String(err) });
} finally {
setProcessing(false);
processNextQueuedGitHubWebhook(config, registry);
Expand Down