Skip to content

[WIP] Fix mergeAt error by removing field filtering#2760

Merged
pelikhan merged 3 commits intomainfrom
copilot/fix-mergeat-error
Oct 30, 2025
Merged

[WIP] Fix mergeAt error by removing field filtering#2760
pelikhan merged 3 commits intomainfrom
copilot/fix-mergeat-error

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

✅ Fix mergedAt error in copilot-pr-prompt-analysis workflow

Problem

The workflow .github/workflows/copilot-pr-prompt-analysis.md was using gh search prs with the --json flag requesting the mergedAt field, but this field is not supported by the gh search prs command, causing the workflow to fail.

Root Cause

According to gh search prs --help, the supported JSON fields are:

assignees, author, authorAssociation, body, closedAt, commentsCount, createdAt,
id, isDraft, isLocked, isPullRequest, labels, number, repository, state, title,
updatedAt, url

The mergedAt field is NOT in this list. When the workflow tried to fetch PR data with mergedAt included in the --json parameter, the command would fail.

Solution

Removed mergedAt from field filtering in gh search prs command

Changes Made

  1. Removed mergedAt from the --json field list in the gh search prs command in .github/workflows/copilot-pr-prompt-analysis.md
  2. Updated workflow documentation (Phase 2) to note that gh pr view <number> --json mergedAt must be used to get merge status for individual PRs
  3. Updated workflow documentation (Phase 2, step 3) to note that gh pr view <number> --json mergedAt,closedAt can be used to get merge/close dates
  4. Recompiled the workflow to generate updated .github/workflows/copilot-pr-prompt-analysis.lock.yml

Validation

  • ✅ Workflow compiles successfully: 0 error(s), 0 warning(s)
  • ✅ Strict mode compilation passes
  • ✅ All unit tests pass
  • ✅ Build succeeds

Files Modified

  • .github/workflows/copilot-pr-prompt-analysis.md - Removed mergedAt from --json field list and updated documentation
  • .github/workflows/copilot-pr-prompt-analysis.lock.yml - Recompiled workflow with updated command

Impact

This fix allows the workflow to successfully fetch Copilot PR data without errors. The workflow can still determine merge status by using gh pr view commands for individual PRs as documented in the updated instructions.

Original prompt

Fix the mergeAt error by removing the field filtering. Update the agentic workflow:

https://github.com/githubnext/gh-aw/actions/runs/18925434756/job/54031296901


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Oct 30, 2025
Copilot AI and others added 2 commits October 30, 2025 00:07
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan pelikhan marked this pull request as ready for review October 30, 2025 00:11
Copilot AI review requested due to automatic review settings October 30, 2025 00:11
@pelikhan pelikhan merged commit d4bd619 into main Oct 30, 2025
6 checks passed
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan pelikhan deleted the copilot/fix-mergeat-error branch October 30, 2025 00:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a workflow failure caused by requesting an unsupported field (mergedAt) from the gh search prs command. The fix removes the unsupported field from the JSON field list and updates documentation to explain how to obtain merge status through individual PR queries instead.

Key changes:

  • Removed mergedAt from the --json field list in the gh search prs command
  • Updated workflow documentation to clarify that gh pr view must be used to determine merge status for individual PRs
  • Recompiled the workflow to generate the updated lock file

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
.github/workflows/copilot-pr-prompt-analysis.md Removed unsupported mergedAt field from search command and added documentation notes about obtaining merge status via gh pr view
.github/workflows/copilot-pr-prompt-analysis.lock.yml Recompiled workflow with the corrected command and updated documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- **Merged**: `mergedAt` is not null
- **Closed (not merged)**: `state` is "CLOSED" and `mergedAt` is null
- **Note**: The `gh search prs` command doesn't return `mergedAt` in its JSON output
- To determine merge status, you'll need to use `gh pr view <number> --json mergedAt` for each PR
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The documentation instructs to check merge status for 'each PR', but this could be inefficient for large datasets (up to 1000 PRs). Consider adding a note about potential performance implications or suggesting batch processing strategies to avoid rate limiting.

Suggested change
- To determine merge status, you'll need to use `gh pr view <number> --json mergedAt` for each PR
- To determine merge status, you'll need to use `gh pr view <number> --json mergedAt` for each PR
- ⚠️ **Performance Note**: For large datasets (hundreds or thousands of PRs), checking merge status for each PR individually can be inefficient and may lead to GitHub API rate limiting. Consider batching requests, using the GitHub REST API to fetch multiple PRs at once, or limiting the number of PRs processed in a single run.

Copilot uses AI. Check for mistakes.
2. **Categorize the PR outcome**:
- **Merged**: `mergedAt` is not null
- **Closed (not merged)**: `state` is "CLOSED" and `mergedAt` is null
- **Note**: The `gh search prs` command doesn't return `mergedAt` in its JSON output
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected backtick usage: should use backticks around the command name for consistency with other code references in the document.

Copilot uses AI. Check for mistakes.
Copilot AI requested a review from pelikhan October 30, 2025 00:12
@github-actions
Copy link
Contributor

🔍 Smoke Test Investigation - Run #50

Summary

Smoke OpenCode workflow failed due to an Anthropic API error during agent execution. The OpenCode agent successfully initialized (installed plugins, configured MCP servers) but failed when attempting to make the initial API call to Anthropic, preventing any safe-outputs from being created.

Failure Details

  • Run: 18926079635
  • Commit: d4bd619
  • Trigger: schedule
  • Duration: 1.0 minute
  • Date: 2025-10-30 00:33:20 UTC

Root Cause Analysis

Primary Issue

The agent job failed with an AI_APICallError when calling the Anthropic API:

Timeline of Events:

  1. ✅ OpenCode agent started successfully (v0.15.13)
  2. ✅ Installed required plugins (opencode-copilot-auth, opencode-anthropic-auth)
  3. ✅ Configured MCP servers (github, safeoutputs)
  4. ✅ Created session and prepared to process prompt
  5. Failed during Anthropic API call to `(redacted)

Model Requested: anthropic/claude-3-5-sonnet-20241022

The error occurred after session creation but before any actual work could be done, resulting in 0 turns and 0 token usage.

Cascading Failure

Because the agent job failed before creating any outputs, the downstream create_issue job also failed:

Error reading agent output file: ENOENT: no such file or directory, 
open '/tmp/gh-aw/safeoutputs/agent_output.json'

This is a consequence, not a root cause - the create_issue job expects the agent to produce outputs.

Failed Jobs and Errors

Failed: agent (36s)

  • Error Type: AI_APICallError - Anthropic API call failure
  • API Endpoint: `(redacted)
  • Model: claude-3-5-sonnet-20241022
  • Context: Failed during initial API request after session setup
  • Is Transient: Yes ✅

Failed: create_issue (4s)

  • Error Type: ENOENT - Missing output file
  • Is Consequence: Yes (agent failed to produce outputs)

Succeeded Jobs

  • ✅ pre_activation (5s)
  • ✅ activation (3s)

Investigation Findings

Pattern Analysis

Pattern ID: OPENCODE_ANTHROPIC_API_ERROR (Recurring Pattern)

  • Occurrence Count: 10th occurrence since 2025-10-22
  • Severity: High (prevents workflow completion)
  • Category: AI Engine - API Failure
  • Flaky: Yes - depends on Anthropic API availability
  • Is Transient: Yes - typically resolves on retry

Related Historical Failures:

  • Run 18917831537 (2025-10-29): Same pattern - OpenCode Anthropic API error
  • Run 18893290104 (2025-10-29): OpenCode with AI_APICallError
  • Run 18722224746 (2025-10-22): First documented occurrence

This is a well-established recurring pattern affecting OpenCode workflows.

Possible Root Causes

Based on the error signature and pattern history:

  1. Anthropic API temporarily unavailable (most likely)
  2. API rate limiting during scheduled workflow execution
  3. Network connectivity issue between GitHub Actions and Anthropic
  4. Authentication token issue (less likely, would show different error)
  5. Model unavailability for claude-3-5-sonnet-20241022

Recommended Actions

🔴 High Priority

  • Add retry logic to OpenCode agent step: Implement exponential backoff retry for API failures

    • Initial delay: 30 seconds
    • Max retries: 3 attempts
    • Exponential backoff multiplier: 2x
    • Prevents: Transient API failures causing workflow failure
    • Implementation: Add retry wrapper around OpenCode run command
  • Make create_issue job conditional: Only run when agent succeeds

    • Add condition: if: success() && hashFiles('/tmp/gh-aw/safeoutputs/agent_output.json') != ''
    • Prevents: Cascading failures and false error signals from downstream jobs

🟡 Medium Priority

  • Add API health check: Pre-flight check for Anthropic API availability

    • Query Anthropic API status endpoint before running agent
    • Skip or delay workflow if API is known to be down
    • Prevents: Wasted time on known outages
  • Implement fallback model: Configure fallback to haiku or alternative model

    • Prevents: Complete workflow failure when specific model unavailable

🟢 Low Priority

  • Monitor API failure rates: Track OpenCode Anthropic failures over time
    • Identify patterns (time of day, frequency)
    • Alert if failure rate exceeds threshold
    • Prevents: Recurring failures going unnoticed

Prevention Strategies

Immediate Actions

  1. Pattern documented: Updated /tmp/gh-aw/cache-memory/patterns/opencode_anthropic_api_error.json
  2. Investigation saved: Created /tmp/gh-aw/cache-memory/investigations/2025-10-30-18926079635.json
  3. Next: Implement retry logic (highest impact fix)

Long-term Improvements

  • Consider workflow scheduling adjustments to avoid peak API load times
  • Implement circuit breaker pattern for repeated API failures within time window
  • Add OpenCode error handling improvements (graceful degradation)
  • Monitor Anthropic API status page for planned maintenance

Historical Context

Frequency Analysis

  • Total occurrences: 10 times since Oct 22, 2025
  • Frequency: ~1-2 times per day (smoke tests run every 6 hours)
  • Success rate: ~75% (estimate based on investigation history)
  • Pattern: More common during scheduled runs (possible concurrent load)

Similar Past Investigations

This is part of an established pattern of OpenCode + Anthropic API failures. Previous investigations recommended:

  • Adding retry logic (still not implemented) ⚠️
  • Making create_issue conditional (still not implemented) ⚠️
  • Investigating OpenCode failure logs (completed) ✅

These recommendations remain valid and should be prioritized.

Related PR Context

PR #2760: "Fix mergeAt error by removing field filtering"

  • Merged: 22 minutes before workflow run
  • Content: Fixed workflow compilation issue with gh search prs command
  • Relevance: ❌ Not related to failure
  • Assessment: This PR fixed a completely different issue (gh CLI field filtering). The OpenCode failure is a transient Anthropic API issue, not caused by code changes.

The timing is coincidental - smoke tests run on schedule regardless of recent merges.


Investigation Metadata

  • Pattern: OPENCODE_ANTHROPIC_API_ERROR (10th occurrence)
  • Investigator: smoke-detector
  • Investigation Run: 18926099021
  • Investigation Files:
    • /tmp/gh-aw/cache-memory/investigations/2025-10-30-18926079635.json
    • /tmp/gh-aw/cache-memory/patterns/opencode_anthropic_api_error.json

AI generated by Smoke Detector - Smoke Test Failure Investigator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants