From 0af13141b235a192f0b361884273b7b72eb81e4c Mon Sep 17 00:00:00 2001 From: Christian Gunderman Date: Thu, 30 Apr 2026 18:22:59 +0000 Subject: [PATCH] Fix posting invalid response to a comment (#26266) --- .github/workflows/gemini-cli-bot-brain.yml | 18 ++++++++++++++++-- tools/gemini-cli-bot/brain/common.md | 16 ++++++++-------- tools/gemini-cli-bot/brain/interactive.md | 14 +++++++++----- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/.github/workflows/gemini-cli-bot-brain.yml b/.github/workflows/gemini-cli-bot-brain.yml index ab5114796e..ef972f1bd1 100644 --- a/.github/workflows/gemini-cli-bot-brain.yml +++ b/.github/workflows/gemini-cli-bot-brain.yml @@ -86,8 +86,15 @@ jobs: if [ -n "$LAST_RUN_ID" ]; then echo "Found previous successful run: $LAST_RUN_ID" - # Download brain memory (all state in one artifact) - gh run download "$LAST_RUN_ID" -n brain-data -D . || echo "brain-data not found" + # Download brain memory to a temp dir so we can selectively restore only persistent state + mkdir -p .temp_brain_data + gh run download "$LAST_RUN_ID" -n brain-data -D .temp_brain_data || echo "brain-data not found" + + # Restore only persistent memory files + cp .temp_brain_data/tools/gemini-cli-bot/lessons-learned.md tools/gemini-cli-bot/lessons-learned.md 2>/dev/null || true + mkdir -p tools/gemini-cli-bot/history/ + cp .temp_brain_data/tools/gemini-cli-bot/history/*.csv tools/gemini-cli-bot/history/ 2>/dev/null || true + rm -rf .temp_brain_data else echo "No previous successful run found." fi @@ -133,6 +140,13 @@ jobs: node bundle/gemini.js --policy tools/gemini-cli-bot/ci-policy.toml -p "$(cat combined_prompt.md)" + if [ -n "$TRIGGER_ISSUE_NUMBER" ] && [ ! -s "issue-comment.md" ] && [ ! -s "pr-comment.md" ]; then + echo "Agent failed to respond. Generating fallback error message." + echo "⚠️ **Gemini CLI Bot failed to generate a response.**" > "issue-comment.md" + echo "" >> "issue-comment.md" + echo "I encountered an error or failed to generate a complete response to your request. You can check the [GitHub Actions Run Log](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details on what went wrong." >> "issue-comment.md" + fi + - name: 'Run Critique Phase' if: "${{ github.event.inputs.enable_prs == 'true' || github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment' || github.event.inputs.run_interactive == 'true' }}" env: diff --git a/tools/gemini-cli-bot/brain/common.md b/tools/gemini-cli-bot/brain/common.md index e0b7ad35dc..8ddf120887 100644 --- a/tools/gemini-cli-bot/brain/common.md +++ b/tools/gemini-cli-bot/brain/common.md @@ -93,15 +93,15 @@ advanced triage, or semantic labeling). If the `ENABLE_PRS` environment variable is `true` and you are proposing script or configuration changes: -1. **Generate `pr-description.md`**: Create this file in the root directory. - Include: +1. **Generate `pr-description.md`**: Use the `write_file` tool to create this + file in the root directory. Include: - What the change is. - Why it is recommended. - Expected impact on metrics or productivity. 2. **Surgical Changes**: Only propose a **single improvement or fix per PR**. Prioritize highest impact, lowest risk. -3. **Acknowledgment**: If invoked by a comment, write a brief acknowledgement - to `issue-comment.md`. +3. **Acknowledgment**: If invoked by a comment, use the `write_file` tool to + save a brief acknowledgement to `issue-comment.md`. 4. **Stage Files**: Use `git add ` to stage files for the PR. **DO NOT** stage internal bot files like `pr-description.md`, `lessons-learned.md`, branch-name.txt, pr-comment.md, pr-number.txt, issue-comment.md, or anything @@ -112,10 +112,10 @@ or configuration changes: If you are continuing work on an existing Task (e.g., status is `SUBMITTED`, `FAILED`, or `STUCK`): -1. **Update Existing PR**: Generate `branch-name.txt` with the branch name - (format: `bot/task-{ID}`). -2. **Respond to Maintainers**: Generate `pr-comment.md` (content) and - `pr-number.txt` (ID). +1. **Update Existing PR**: Use `write_file` to generate `branch-name.txt` with + the branch name (format: `bot/task-{ID}`). +2. **Respond to Maintainers**: Use `write_file` to generate `pr-comment.md` + (content) and `pr-number.txt` (ID). 3. **Handle CI Failures**: Diagnose failing checks using `gh run view` and priority must be generating a new patch to fix the failure. diff --git a/tools/gemini-cli-bot/brain/interactive.md b/tools/gemini-cli-bot/brain/interactive.md index 448c4c4045..d024bd0d51 100644 --- a/tools/gemini-cli-bot/brain/interactive.md +++ b/tools/gemini-cli-bot/brain/interactive.md @@ -30,7 +30,8 @@ Before beginning your analysis, you MUST perform the following research: Your ONLY goal is to address the user's specific comment. 3. **Verify Request Context**: Use the GitHub CLI to verify the current state of the issue/PR you were mentioned in. If the user's request is already - addressed or obsolete, inform them via `issue-comment.md`. + addressed or obsolete, inform them by using the `write_file` tool to save a + message to `issue-comment.md`. ### 1. Root-Cause Analysis & Hypothesis Testing @@ -54,9 +55,9 @@ If your investigation confirms that a code or configuration change is required: user's specific request. You are STRICTLY FORBIDDEN from including any unrelated updates (such as metrics updates, backlog triage changes, or background housekeeping) when operating in interactive mode. -- **Acknowledgment**: Write a brief acknowledgement to `issue-comment.md` (e.g., - "I've investigated the request and implemented a fix. A PR will be created - shortly."). +- **Acknowledgment**: Use the `write_file` tool to write a brief acknowledgement + to `issue-comment.md` (e.g., "I've investigated the request and implemented a + fix. A PR will be created shortly."). - **Follow Protocol**: Use the Memory Preservation and PR Preparation protocols provided in the common rules. @@ -66,4 +67,7 @@ If the user's request is purely informational: - **Evidence-Based Answers**: Use your research tools to verify facts before answering. -- **Output**: Write your response to `issue-comment.md`. +- **Output**: You MUST use the `write_file` tool to save your response to + `issue-comment.md`. DO NOT simply output your response to the console. The + workflow relies on `issue-comment.md` being created in the workspace to post + the comment.