From ae36f73017568f8c5b2408d21ea44b61232c2a5f Mon Sep 17 00:00:00 2001 From: Zbigniew Sobiecki Date: Fri, 13 Feb 2026 18:56:54 +0100 Subject: [PATCH] fix(triggers): update initial PR comment when GitHub-bound agents fail (#194) Previously, GitHub-bound agents (review, respond-to-ci, respond-to-review) posted an initial "working on it" comment but never updated it on failure, leaving a stale optimistic message with no indication of what happened. Co-authored-by: Claude Opus 4.6 --- src/triggers/github/webhook-handler.ts | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/triggers/github/webhook-handler.ts b/src/triggers/github/webhook-handler.ts index 68fcf880..e9c39178 100644 --- a/src/triggers/github/webhook-handler.ts +++ b/src/triggers/github/webhook-handler.ts @@ -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'; @@ -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, @@ -62,6 +68,28 @@ async function executeGitHubAgent( }); } +async function updateInitialCommentWithError( + result: TriggerResult, + agentResult: { success: boolean; error?: string }, +): Promise { + 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\nManual intervention may be required.`; + + await safeOperation(() => githubClient.updatePRComment(owner, repo, initialCommentId, body), { + action: 'update PR comment with error', + prNumber: result.prNumber, + }); +} + async function postAcknowledgmentComment(result: TriggerResult): Promise { if (result.agentType !== 'respond-to-review' || !result.prNumber) { return; @@ -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);