From a3c96305c10e006965f45c253b7dce11cb7c649c Mon Sep 17 00:00:00 2001 From: Ashwin Bhat Date: Mon, 4 Aug 2025 16:50:24 -0700 Subject: [PATCH] fix: move critical outputs to immediately after prepare step Previously, outputs like GITHUB_TOKEN and branch_name were set after Claude execution completed. This caused issues if Claude failed, as downstream cleanup steps wouldn't have access to these outputs. Now outputs are set immediately after prepare() completes, ensuring they're available even if Claude execution fails. --- src/entrypoints/run.ts | 62 +++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/src/entrypoints/run.ts b/src/entrypoints/run.ts index 99d98f5..6028eef 100644 --- a/src/entrypoints/run.ts +++ b/src/entrypoints/run.ts @@ -80,6 +80,19 @@ async function run() { githubToken, }); + // Set critical outputs immediately after prepare completes + // This ensures they're available for cleanup even if Claude fails + core.setOutput("GITHUB_TOKEN", githubToken); + core.setOutput("mcp_config", prepareResult.mcpConfig); + if (prepareResult.branchInfo.claudeBranch) { + core.setOutput("branch_name", prepareResult.branchInfo.claudeBranch); + core.setOutput("CLAUDE_BRANCH", prepareResult.branchInfo.claudeBranch); + } + core.setOutput("BASE_BRANCH", prepareResult.branchInfo.baseBranch); + if (prepareResult.commentId) { + core.setOutput("claude_comment_id", prepareResult.commentId.toString()); + } + // Step 7: The mode.prepare() call already created the prompt and set up tools // We need to get the allowed/disallowed tools from environment variables // TODO: Update Mode interface to return tools from prepare() instead of relying on env vars @@ -102,40 +115,21 @@ async function run() { CLAUDE_CODE_ACTION: "1", }; - // Run Claude using the shared core function - try { - await runClaudeCore({ - promptFile, - settings: process.env.SETTINGS, - allowedTools, - disallowedTools, - maxTurns: process.env.MAX_TURNS, - mcpConfig: prepareResult.mcpConfig, - systemPrompt: "", - appendSystemPrompt: "", - claudeEnv: process.env.CLAUDE_ENV, - fallbackModel: process.env.FALLBACK_MODEL, - model: process.env.ANTHROPIC_MODEL || process.env.MODEL, - timeoutMinutes: process.env.TIMEOUT_MINUTES || "30", - env: claudeEnvObject, - }); - } catch (claudeError) { - // The outputs should already be set by runClaudeCore - // Just re-throw to handle in outer catch - throw claudeError; - } - - // Set outputs that were previously set by prepare step - core.setOutput("GITHUB_TOKEN", githubToken); - core.setOutput("mcp_config", prepareResult.mcpConfig); - if (prepareResult.branchInfo.claudeBranch) { - core.setOutput("branch_name", prepareResult.branchInfo.claudeBranch); - core.setOutput("CLAUDE_BRANCH", prepareResult.branchInfo.claudeBranch); - } - core.setOutput("BASE_BRANCH", prepareResult.branchInfo.baseBranch); - if (prepareResult.commentId) { - core.setOutput("claude_comment_id", prepareResult.commentId.toString()); - } + await runClaudeCore({ + promptFile, + settings: process.env.SETTINGS, + allowedTools, + disallowedTools, + maxTurns: process.env.MAX_TURNS, + mcpConfig: prepareResult.mcpConfig, + systemPrompt: "", + appendSystemPrompt: "", + claudeEnv: process.env.CLAUDE_ENV, + fallbackModel: process.env.FALLBACK_MODEL, + model: process.env.ANTHROPIC_MODEL || process.env.MODEL, + timeoutMinutes: process.env.TIMEOUT_MINUTES || "30", + env: claudeEnvObject, + }); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); core.setFailed(`Action failed with error: ${errorMessage}`);