From ba85c8ad6c9791569bb19b3d7a41920881cb302b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pr=C5=AF=C5=A1a?= <87543374+Patai5@users.noreply.github.com> Date: Tue, 10 Nov 2026 22:26:05 +0100 Subject: [PATCH 1/3] ci: optimize claude failing platform tests investigation workflow --- ...form-tests-claude-investigate-and-fix.yaml | 301 ------------- ...lic_platform-tests-claude-investigate.yaml | 405 ++++++++++++++++++ CONTRIBUTING.md | 2 +- docs/workflows.md | 46 +- 4 files changed, 431 insertions(+), 323 deletions(-) delete mode 100644 .github/workflows/public_platform-tests-claude-investigate-and-fix.yaml create mode 100644 .github/workflows/public_platform-tests-claude-investigate.yaml diff --git a/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml b/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml deleted file mode 100644 index d83dbc3a..00000000 --- a/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml +++ /dev/null @@ -1,301 +0,0 @@ -name: 'Platform tests: Claude failure investigation and fix' - -# Notion page docs: https://app.notion.com/p/apify/374f39950a2280d99c89f27fc9fb49c5 - -# Reusable workflow that uses Claude Code to investigate a failing E2E platform test and -# attempt an automated fix. -# -# Two-phase execution: -# 1. investigate: Claude reviews test logs, recent workflow history, and existing issues, -# then opens a GitHub issue with its findings. Skips silently if a duplicate exists. -# On success, adds a "claude" label to the issue for visibility. -# 2. fix: Runs only when investigate created a new issue. Claude reads the issue, -# implements a fix, and opens a PR. On success, adds a "claude:done" label to the issue. -# -# Note: this workflow is intended to be called from a scheduled workflow. Scheduled runs use -# GITHUB_TOKEN with reduced permissions that cannot trigger other workflow runs. For this reason -# the PR phase is chained as a direct job dependency rather than relying on a label-based trigger. -# -# Example usage: -# -# jobs: -# platformTestsCore: -# uses: apify/apify-test-tools/.github/workflows/public_platform-tests.yaml@workflows-v0 -# with: -# test-files-glob: 'test/platform/hourly/**' -# report-slack-channel: '#notif-my-repo' -# secrets: -# TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} -# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} -# -# handle-failure: -# needs: platformTestsCore -# if: ${{ failure() }} -# uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml@workflows-v0 -# secrets: -# ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} -# TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} - -on: - workflow_call: - inputs: - model: - required: false - type: string - default: sonnet - description: Claude model to use for investigation and fix - effort: - required: false - type: string - default: '' - description: Claude effort level (low, medium, high, xhigh, max) to use for investigation and fix. Uses the Claude Code default when empty. - max_flakiness_runs: - required: false - type: number - default: 200 - description: The most times Claude may re-run the failing Actor run to measure how often the failure happens, when that isn't obvious. Claude decides how many of them it needs. - investigate_prompt: - required: false - type: string - default: | - Investigate the failing E2E platform test and open a GitHub issue documenting your findings. Start by reviewing the test logs, error messages, and recent workflow run history to determine the root cause. - - Use available tools to check previous workflow runs, git history, and existing GitHub issues to gather context and avoid creating duplicate issues. For deeper context, - use tools to investigate the run on Apify platform, review its logs, datasets, key-value stores. - - Look specifically for debug traces, not just the top-level error: - - Debug snapshots: often stored as a field on dataset items (e.g. `_debugSnapshots`) or as records in a key-value store, keyed so they can be matched to the log line for the failing request. - - Any other debug artifacts the Actor produced (extra logs, error/state fields on output items) that narrow down the failing request. - - Before you create a new issue, check whether the `platform-tests-investigate-and-fix:measure-flakiness` skill applies, and follow it if it does. - - At the end of your investigation, before you create a new issue, follow the `platform-tests-investigate-and-fix:assess-impact` skill. - - When you create the issue, write it like an incident postmortem: a short summary and impact up top for anyone skimming, full technical detail below for whoever fixes it. Don't water down the engineering detail to make the top readable. - - Title: short and clean, describing the actual problem in plain terms — no dates, run numbers, or other noise. Prefix it with a conventional-commit-style type, e.g. "fix: blocking issue on detail endpoint". - - Body, section 1 ("## Summary"): one line stating what's broken plus its impact, in plain language a PM can understand at a glance — no jargon, internal field names, or stack traces (e.g. "Scraping product detail pages fails when a listing has no reviews"). - - If you measured flakiness, a "## Flakiness" section right after the Summary, as the `measure-flakiness` skill describes. - - An "## Impact" section under the Flakiness section (or under the Summary if there's none), as the `assess-impact` skill describes. - - A `---` divider, then section 2 ("## Details"): the engineering bug report — root cause, relevant log lines, links to the failing run, and any other internals an engineer needs. If a single item/request failed among otherwise-good ones, show or link that specific one (e.g. the dataset item index/id, or its matching debug snapshot) rather than just describing the run as failed. - - If you create a new issue, you MUST write its issue number (just the number, nothing else) to $GITHUB_WORKSPACE/issue-number.txt as the very last thing you do. If you skip creating one because a duplicate already exists, do not create the file. - description: Prompt given to Claude for the investigation phase. Override to customize how issues are investigated, titled, and described. - priority_prompt: - required: false - type: string - # The prio prompt here is purposefully vague; you can adjust it to - # use custom thresholds based on measured impact metrics. - default: | - After you create a new issue and before you write its issue number to $GITHUB_WORKSPACE/issue-number.txt, set its Priority field from the failure's impact and flakiness: - - To do so, exercise your best judgement. Issues marked with higher priority will be reacted to first. - Here are guidelines: - - Determine priority based on combined severity and revenue actually at risk: a less severe bug can outrank a more severe one if much more revenue is actually at risk, and vice versa. - - If the Impact section considers the bug from several points of view, each in its own sub-section, base the priority on the most impactful one. - - If it helps you, you can base your assessment off priorities of already existing bugs in the repo. - - Invisible to the user or Test severity always receives lowest priority. - - Priority is an organization-level issue field. If the revenue actually at risk can't be determined, e.g. the Impact section says "Cannot be determined", leave Priority unset, unless the relative severity is Invisible to the user or Test. - description: Prompt given to Claude for setting a new issue's Priority field from its impact and flakiness. Override to customize how priority is judged, e.g. to set revenue thresholds. - secrets: - ANTHROPIC_API_KEY: - required: true - description: Claude API key - TESTER_APIFY_TOKEN: - required: true - description: Apify token for investigating the failing run — reading it, its log and its storages — and re-running it to measure how often the failure happens. - NPM_TOKEN: - required: false - description: Read-only token for installing private npm packages before Claude runs. - REDASH_API_KEY: - required: false - description: Redash API key for measuring the failure's impact — affected runs, high-touch customers and revenue — from Snowflake. - AGENT_SKILLS_INTERNAL_GITHUB_TOKEN: - required: false - description: GitHub token with read access to apify/agent-skills-internal, for installing its redash-analyst plugin. - -jobs: - investigate: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: read - issues: write - actions: read - outputs: - issue_number: ${{ steps.issue.outputs.number }} - steps: - - name: Checkout repository - uses: actions/checkout@v5 - - - name: Check which optional secrets are set - id: optional-secrets - run: | - echo "agent-skills-token=${{ secrets.AGENT_SKILLS_INTERNAL_GITHUB_TOKEN != '' }}" >> "$GITHUB_OUTPUT" - echo "redash-api-key=${{ secrets.REDASH_API_KEY != '' }}" >> "$GITHUB_OUTPUT" - - - name: Checkout internal agent skills - id: agent-skills-internal - if: steps.optional-secrets.outputs.agent-skills-token == 'true' - continue-on-error: true - uses: actions/checkout@v5 - with: - repository: apify/agent-skills-internal - token: ${{ secrets.AGENT_SKILLS_INTERNAL_GITHUB_TOKEN }} - path: .agent-skills-internal - sparse-checkout: | - .claude-plugin - skills/redash-analyst - persist-credentials: false - - - uses: actions/setup-node@v6 - if: steps.optional-secrets.outputs.redash-api-key == 'true' - with: - node-version: 24 - - - name: Install Redash MCP server - if: steps.optional-secrets.outputs.redash-api-key == 'true' - continue-on-error: true - working-directory: ${{ runner.temp }} - run: npm install --prefix redash-mcp --ignore-scripts --no-audit --no-fund @suthio/redash-mcp@0.1.0 - - - name: Run Claude Code - id: claude - uses: anthropics/claude-code-action@8251c103ac8c1d761882c86aba1412c7f583c844 # v1.0.213 - env: - TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} - REDASH_API_KEY: ${{ secrets.REDASH_API_KEY }} - MAX_FLAKINESS_RUNS: ${{ inputs.max_flakiness_runs }} - with: - prompt: | - The failing E2E platform test ran in workflow run ${{ github.run_id }} of this repo. - - ${{ inputs.investigate_prompt }} - - ${{ inputs.priority_prompt }} - github_token: ${{ secrets.GITHUB_TOKEN }} - anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - plugin_marketplaces: | - https://github.com/apify/apify-test-tools.git - ${{ steps.agent-skills-internal.outcome == 'success' && format('{0}/.agent-skills-internal', github.workspace) || '' }} - plugins: | - platform-tests-investigate-and-fix@apify-test-tools - ${{ steps.agent-skills-internal.outcome == 'success' && 'redash-analyst@apify-agent-skills-internal' || '' }} - # The `tools` query parameter below selects which tools the Apify MCP server - # exposes: reading an Actor run — its status, exit code, storage ids and log — and - # reading that run's dataset items and its key-value store keys and records, e.g. - # INPUT, OUTPUT and error snapshots. WARN: the server adds `abort-actor-run` on top - # even when not listed here, see https://github.com/apify/apify-mcp-server - # `--disallowedTools` removes the Redash MCP server's tools that change Redash: creating, - # editing, sharing or deleting queries, visualizations, dashboards, widgets, alerts and snippets. - claude_args: | - --mcp-config '{"mcpServers":{"apify":{"type":"http","url":"https://mcp.apify.com/?tools=get-actor-run,get-actor-run-log,get-dataset-list,get-dataset,get-dataset-items,get-key-value-store-list,get-key-value-store,get-key-value-store-keys,get-key-value-store-record","headers":{"Authorization":"Bearer ${TESTER_APIFY_TOKEN}"}},"redash":{"type":"stdio","command":"${{ runner.temp }}/redash-mcp/node_modules/.bin/redash-mcp","env":{"REDASH_URL":"https://charts.apify.com/","REDASH_API_KEY":"${REDASH_API_KEY}"}}}}' - --disallowedTools mcp__redash__create_query,mcp__redash__update_query,mcp__redash__update_query_parameters,mcp__redash__archive_query,mcp__redash__fork_query,mcp__redash__add_query_favorite,mcp__redash__remove_query_favorite,mcp__redash__create_visualization,mcp__redash__update_visualization,mcp__redash__update_chart_visualization,mcp__redash__delete_visualization,mcp__redash__create_dashboard,mcp__redash__update_dashboard,mcp__redash__update_dashboard_parameters,mcp__redash__archive_dashboard,mcp__redash__fork_dashboard,mcp__redash__share_dashboard,mcp__redash__unshare_dashboard,mcp__redash__add_dashboard_favorite,mcp__redash__remove_dashboard_favorite,mcp__redash__create_alert,mcp__redash__update_alert,mcp__redash__delete_alert,mcp__redash__mute_alert,mcp__redash__add_alert_subscription,mcp__redash__remove_alert_subscription,mcp__redash__create_widget,mcp__redash__update_widget,mcp__redash__update_widget_layout,mcp__redash__update_dashboard_layout,mcp__redash__update_widget_parameter_mappings,mcp__redash__delete_widget,mcp__redash__create_query_snippet,mcp__redash__update_query_snippet,mcp__redash__delete_query_snippet - --model ${{ inputs.model }} - ${{ inputs.effort && format('--effort {0}', inputs.effort) || '' }} - --dangerously-skip-permissions - - - name: Upload Claude output (for debugging) - if: always() - uses: actions/upload-artifact@v6 - with: - name: claude-output-investigate - path: /home/runner/work/_temp/claude-execution-output.json - - - name: Read created issue - id: issue - # Claude writes the issue number to a file because there is no direct way to pass - # structured output from a Claude Code action step to subsequent steps. - run: | - if [ -f "$GITHUB_WORKSPACE/issue-number.txt" ]; then - ISSUE_NUMBER=$(cat "$GITHUB_WORKSPACE/issue-number.txt") - echo "number=$ISSUE_NUMBER" >> "$GITHUB_OUTPUT" - echo "Issue created: #$ISSUE_NUMBER" - else - echo "number=" >> "$GITHUB_OUTPUT" - echo "No issue created (duplicate skipped)" - fi - - # Adds the "claude" label for visibility. Normally this would trigger the claude.yaml - # workflow, but scheduled runs lack the permissions to trigger other workflows, so the - # PR phase is driven by the fix job dependency instead. - - name: Add Claude label to issue - if: steps.issue.outputs.number != '' - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - try { - await github.rest.issues.createLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: "claude", - color: "d93f0b", - }); - } catch (e) { - // Label already exists - } - - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: parseInt('${{ steps.issue.outputs.number }}'), - labels: ["claude"], - }); - - fix: - needs: investigate - if: needs.investigate.outputs.issue_number != '' - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - issues: write - id-token: write - actions: read - steps: - - name: Setup repository and dependencies - # `$/` loads the action from this repo at the commit this workflow was called at, so a caller - # pinned to a SHA or a branch gets that commit's action and CLI, not whatever the major tag is on. - uses: $/.github/actions/checkout-restore-dependencies - with: - npm-token: ${{ secrets.NPM_TOKEN }} - - - name: Run Claude Code - id: claude - uses: anthropics/claude-code-action@8251c103ac8c1d761882c86aba1412c7f583c844 # v1.0.213 - with: - anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} - use_commit_signing: true - prompt: 'Open a pull request to address GitHub issue #${{ needs.investigate.outputs.issue_number }}. Use `gh issue view ${{ needs.investigate.outputs.issue_number }}` to read the issue details first, then implement the fix and create a PR.' - claude_args: | - --model ${{ inputs.model }} - ${{ inputs.effort && format('--effort {0}', inputs.effort) || '' }} - --dangerously-skip-permissions - - - name: Upload Claude output (for debugging) - if: always() - uses: actions/upload-artifact@v6 - with: - name: claude-output-fix - path: /home/runner/work/_temp/claude-execution-output.json - - # Adds "claude:done" to the issue to signal that a fix PR was opened. Pure status - # tracking — does not trigger any further automation. - - name: Mark issue as processed by Claude - if: steps.claude.conclusion == 'success' - uses: actions/github-script@v7 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - try { - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: parseInt('${{ needs.investigate.outputs.issue_number }}'), - labels: ['claude:done'] - }); - console.log('Label claude:done added to issue.'); - } catch (e) { - console.log('Label claude:done does not exist. Skipping.'); - } diff --git a/.github/workflows/public_platform-tests-claude-investigate.yaml b/.github/workflows/public_platform-tests-claude-investigate.yaml new file mode 100644 index 00000000..d11139f5 --- /dev/null +++ b/.github/workflows/public_platform-tests-claude-investigate.yaml @@ -0,0 +1,405 @@ +name: 'Platform tests: Claude failure investigation' + +# Notion page docs: https://app.notion.com/p/apify/374f39950a2280d99c89f27fc9fb49c5 + +# Reusable workflow that uses Claude Code to investigate a failing E2E platform test. +# +# 1. A cheap model works out what broke and whether open issues already cover it, and updates the recurrence +# comment on each covering issue. If they cover everything, the job stops there. +# 2. Otherwise the main model investigates what isn't covered and opens an issue with its findings. +# +# Example usage: +# +# jobs: +# platformTestsCore: +# uses: apify/apify-test-tools/.github/workflows/public_platform-tests.yaml@workflows-v0 +# with: +# test-files-glob: 'test/platform/hourly/**' +# report-slack-channel: '#notif-my-repo' +# secrets: +# TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} +# SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} +# +# handle-failure: +# needs: platformTestsCore +# if: ${{ failure() }} +# uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate.yaml@workflows-v0 +# secrets: +# ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} +# TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} + +on: + workflow_call: + inputs: + model: + required: false + type: string + default: sonnet + description: Claude model to use for the investigation + effort: + required: false + type: string + default: '' + description: Claude effort level (low, medium, high, xhigh, max) to use for the investigation. Uses the Claude Code default when empty. + dedupe_model: + required: false + type: string + default: haiku + description: Claude model that checks whether open issues already cover the failing tests, before the investigation + max_flakiness_runs: + required: false + type: number + default: 200 + description: The most times Claude may re-run the failing Actor run to measure how often the failure happens, when that isn't obvious. Claude decides how many of them it needs. + investigate_prompt: + required: false + type: string + default: | + Investigate the failing E2E platform test and open a GitHub issue documenting your findings. + + Start by reviewing the test logs, error messages, and recent workflow run history to determine the root cause. Use available tools to check previous workflow runs, git history, and existing GitHub issues to gather context and avoid creating duplicate issues. For deeper context, + use tools to investigate the run on Apify platform, review its logs, datasets, key-value stores. + + Look specifically for debug traces, not just the top-level error: + - Debug snapshots: often stored as a field on dataset items (e.g. `_debugSnapshots`) or as records in a key-value store, keyed so they can be matched to the log line for the failing request. + - Any other debug artifacts the Actor produced (extra logs, error/state fields on output items) that narrow down the failing request. + + Before you create a new issue, check whether the `platform-tests-investigate-and-fix:measure-flakiness` skill applies, and follow it if it does. + + At the end of your investigation, before you create a new issue, follow the `platform-tests-investigate-and-fix:assess-impact` skill. + + When you create the issue, write it like an incident postmortem: a short summary and impact up top for anyone skimming, full technical detail below for whoever fixes it. Don't water down the engineering detail to make the top readable. + - Title: short and clean, describing the actual problem in plain terms — no dates, run numbers, or other noise. Prefix it with a conventional-commit-style type, e.g. "fix: blocking issue on detail endpoint". + - Body, section 1 ("## Summary"): one line stating what's broken plus its impact, in plain language a PM can understand at a glance — no jargon, internal field names, or stack traces (e.g. "Scraping product detail pages fails when a listing has no reviews"). + - If you measured flakiness, a "## Flakiness" section right after the Summary, as the `measure-flakiness` skill describes. + - An "## Impact" section under the Flakiness section (or under the Summary if there's none), as the `assess-impact` skill describes. + - A `---` divider, then section 2 ("## Details"): the engineering bug report — root cause, relevant log lines, links to the failing run, and any other internals an engineer needs. State the root cause and the error messages it produces, so later runs can recognize the same failure. If a single item/request failed among otherwise-good ones, show or link that specific one (e.g. the dataset item index/id, or its matching debug snapshot) rather than just describing the run as failed. + + If you create a new issue, you MUST write its issue number (just the number, nothing else) to $GITHUB_WORKSPACE/issue-number.txt as the very last thing you do. If you skip creating one because a duplicate already exists, do not create the file, and add the duplicate's number on its own line to $GITHUB_WORKSPACE/duplicate-of.txt. + description: Prompt given to Claude for the investigation phase. Override to customize how issues are investigated, titled, and described. + priority_prompt: + required: false + type: string + # The prio prompt here is purposefully vague; you can adjust it to + # use custom thresholds based on measured impact metrics. + default: | + After you create a new issue and before you write its issue number to $GITHUB_WORKSPACE/issue-number.txt, set its Priority field from the failure's impact and flakiness: + + To do so, exercise your best judgement. Issues marked with higher priority will be reacted to first. + Here are guidelines: + - Determine priority based on combined severity and revenue actually at risk: a less severe bug can outrank a more severe one if much more revenue is actually at risk, and vice versa. + - If the Impact section considers the bug from several points of view, each in its own sub-section, base the priority on the most impactful one. + - If it helps you, you can base your assessment off priorities of already existing bugs in the repo. + - Invisible to the user or Test severity always receives lowest priority. + + Priority is an organization-level issue field. If the revenue actually at risk can't be determined, e.g. the Impact section says "Cannot be determined", leave Priority unset, unless the relative severity is Invisible to the user or Test. + description: Prompt given to Claude for setting a new issue's Priority field from its impact and flakiness. Override to customize how priority is judged, e.g. to set revenue thresholds. + secrets: + ANTHROPIC_API_KEY: + required: true + description: Claude API key + TESTER_APIFY_TOKEN: + required: true + description: Apify token for investigating the failing run — reading it, its log and its storages — and re-running it to measure how often the failure happens. + REDASH_API_KEY: + required: false + description: Redash API key for measuring the failure's impact — affected runs, high-touch customers and revenue — from Snowflake. + AGENT_SKILLS_INTERNAL_GITHUB_TOKEN: + required: false + description: GitHub token with read access to apify/agent-skills-internal, for installing its redash-analyst plugin. + +jobs: + investigate: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: read + issues: write + actions: read + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Check which optional secrets are set + id: optional-secrets + run: | + echo "agent-skills-token=${{ secrets.AGENT_SKILLS_INTERNAL_GITHUB_TOKEN != '' }}" >> "$GITHUB_OUTPUT" + echo "redash-api-key=${{ secrets.REDASH_API_KEY != '' }}" >> "$GITHUB_OUTPUT" + + - uses: actions/setup-node@v6 + if: steps.optional-secrets.outputs.redash-api-key == 'true' + with: + node-version: 24 + + - name: Install Redash MCP server + if: steps.optional-secrets.outputs.redash-api-key == 'true' + continue-on-error: true + working-directory: ${{ runner.temp }} + run: npm install --prefix redash-mcp --ignore-scripts --no-audit --no-fund @suthio/redash-mcp@0.1.0 + + # The `tools` query parameter below selects which tools the Apify MCP server + # exposes: reading an Actor run — its status, exit code, storage ids and log — and + # reading that run's dataset items and its key-value store keys and records, e.g. + # INPUT, OUTPUT and error snapshots. WARN: the server adds `abort-actor-run` on top + # even when not listed here, see https://github.com/apify/apify-mcp-server + # `--disallowedTools` removes the Redash MCP server's tools that change Redash: creating, + # editing, sharing or deleting queries, visualizations, dashboards, widgets, alerts and snippets. + - name: Configure the MCP servers + id: mcp + run: | + echo 'config={"mcpServers":{"apify":{"type":"http","url":"https://mcp.apify.com/?tools=get-actor-run,get-actor-run-log,get-dataset-list,get-dataset,get-dataset-items,get-key-value-store-list,get-key-value-store,get-key-value-store-keys,get-key-value-store-record","headers":{"Authorization":"Bearer ${TESTER_APIFY_TOKEN}"}},"redash":{"type":"stdio","command":"${{ runner.temp }}/redash-mcp/node_modules/.bin/redash-mcp","env":{"REDASH_URL":"https://charts.apify.com/","REDASH_API_KEY":"${REDASH_API_KEY}"}}}}' >> "$GITHUB_OUTPUT" + echo 'disallowed-tools=mcp__redash__create_query,mcp__redash__update_query,mcp__redash__update_query_parameters,mcp__redash__archive_query,mcp__redash__fork_query,mcp__redash__add_query_favorite,mcp__redash__remove_query_favorite,mcp__redash__create_visualization,mcp__redash__update_visualization,mcp__redash__update_chart_visualization,mcp__redash__delete_visualization,mcp__redash__create_dashboard,mcp__redash__update_dashboard,mcp__redash__update_dashboard_parameters,mcp__redash__archive_dashboard,mcp__redash__fork_dashboard,mcp__redash__share_dashboard,mcp__redash__unshare_dashboard,mcp__redash__add_dashboard_favorite,mcp__redash__remove_dashboard_favorite,mcp__redash__create_alert,mcp__redash__update_alert,mcp__redash__delete_alert,mcp__redash__mute_alert,mcp__redash__add_alert_subscription,mcp__redash__remove_alert_subscription,mcp__redash__create_widget,mcp__redash__update_widget,mcp__redash__update_widget_layout,mcp__redash__update_dashboard_layout,mcp__redash__update_widget_parameter_mappings,mcp__redash__delete_widget,mcp__redash__create_query_snippet,mcp__redash__update_query_snippet,mcp__redash__delete_query_snippet' >> "$GITHUB_OUTPUT" + + - name: Check for existing issues + id: dedupe + continue-on-error: true + uses: anthropics/claude-code-action@8251c103ac8c1d761882c86aba1412c7f583c844 # v1.0.213 + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} + REDASH_API_KEY: ${{ secrets.REDASH_API_KEY }} + with: + prompt: | + E2E platform tests failed in workflow run ${{ github.run_id }} of this repo. Get the failures from its test report with `gh run download ${{ github.run_id }} --name vitest-results --dir $RUNNER_TEMP/vitest-results`: test-report.json lists each test with its status and failure messages, plus any errors outside the tests. + + The tests overlap a lot, so one bug usually fails several of them. Work out what actually broke, the distinct root causes behind these failures, and whether an open issue in this repo already covers each one. List the open issues with `gh issue list --state open --limit 200 --json number,title,body,labels`, focusing on those labeled `claude`, and read any you need in full with `gh issue view`. An issue covers a failure when it describes the same root cause, no matter which tests it mentions. If the failure messages aren't enough to tell, look at the failing Actor runs with the Apify tools. When unsure, treat the failure as not covered: a missed duplicate costs one investigation, a wrong match hides a bug. + + Don't investigate further and don't change anything on GitHub. Write your answer to $GITHUB_WORKSPACE/dedupe.json as `{"issues": [], "uncovered": ""}`. + github_token: ${{ secrets.GITHUB_TOKEN }} + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + claude_args: | + --model ${{ inputs.dedupe_model }} + --mcp-config '${{ steps.mcp.outputs.config }}' + --disallowedTools ${{ steps.mcp.outputs.disallowed-tools }} + --allowedTools "Bash(gh run download:*),Bash(gh run view:*),Bash(gh issue list:*),Bash(gh issue view:*),Read,Write,mcp__apify,mcp__redash" + + - name: Upload dedupe Claude output (for debugging) + if: always() && steps.dedupe.outcome != 'skipped' + uses: actions/upload-artifact@v6 + with: + name: claude-output-dedupe + path: /home/runner/work/_temp/claude-execution-output.json + + # Reads the cheap model's answer: + # + # 1. Everything covered: skip the investigation. + # 2. Part covered: tell the main model which part, so it investigates only the rest. + # 3. No usable answer: investigate everything. + - name: Decide whether to investigate + id: duplicates + if: ${{ !cancelled() }} + run: | + answer="$GITHUB_WORKSPACE/dedupe.json" + issues='[]' + uncovered='no answer from the check' + if jq -e '(.issues | type == "array") and (.uncovered | type == "string")' "$answer" > /dev/null 2>&1; then + issues=$(jq -c '[.issues[] | select(type == "number" and . > 0 and floor == .)] | unique' "$answer") || issues='[]' + uncovered=$(jq -r '.uncovered' "$answer") + fi + refs=$(jq -r 'map("#\(.)") | join(", ")' <<< "$issues") + + if [ "$(jq length <<< "$issues")" -gt 0 ]; then + jq -r '.[]' <<< "$issues" > "$GITHUB_WORKSPACE/duplicate-of.txt" + fi + if [ "$(jq length <<< "$issues")" -gt 0 ] && [ -z "$(tr -d '[:space:]' <<< "$uncovered")" ]; then + echo "all-duplicates=true" >> "$GITHUB_OUTPUT" + echo "Open issues $refs already cover the failure, skipping the investigation" + exit 0 + fi + + echo "all-duplicates=false" >> "$GITHUB_OUTPUT" + echo "Covered by: ${refs:-none}. Not covered: $uncovered" + if [ "$(jq length <<< "$issues")" -gt 0 ]; then + delimiter="EOF_$(openssl rand -hex 8)" + { + echo "note<<$delimiter" + echo "A first check found that open issues $refs already cover part of this failure, so don't investigate that part again. What they don't cover: $uncovered" + echo "$delimiter" + } >> "$GITHUB_OUTPUT" + fi + + - name: Checkout internal agent skills + id: agent-skills-internal + if: steps.duplicates.outputs.all-duplicates != 'true' && steps.optional-secrets.outputs.agent-skills-token == 'true' + continue-on-error: true + uses: actions/checkout@v5 + with: + repository: apify/agent-skills-internal + token: ${{ secrets.AGENT_SKILLS_INTERNAL_GITHUB_TOKEN }} + path: .agent-skills-internal + sparse-checkout: | + .claude-plugin + skills/redash-analyst + persist-credentials: false + + - name: Run Claude Code + id: claude + if: steps.duplicates.outputs.all-duplicates != 'true' + uses: anthropics/claude-code-action@8251c103ac8c1d761882c86aba1412c7f583c844 # v1.0.213 + env: + TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} + REDASH_API_KEY: ${{ secrets.REDASH_API_KEY }} + MAX_FLAKINESS_RUNS: ${{ inputs.max_flakiness_runs }} + with: + prompt: | + The failing E2E platform test ran in workflow run ${{ github.run_id }} of this repo. + + ${{ steps.duplicates.outputs.note }} + + ${{ inputs.investigate_prompt }} + + ${{ inputs.priority_prompt }} + github_token: ${{ secrets.GITHUB_TOKEN }} + anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} + plugin_marketplaces: | + https://github.com/apify/apify-test-tools.git + ${{ steps.agent-skills-internal.outcome == 'success' && format('{0}/.agent-skills-internal', github.workspace) || '' }} + plugins: | + platform-tests-investigate-and-fix@apify-test-tools + ${{ steps.agent-skills-internal.outcome == 'success' && 'redash-analyst@apify-agent-skills-internal' || '' }} + claude_args: | + --mcp-config '${{ steps.mcp.outputs.config }}' + --disallowedTools ${{ steps.mcp.outputs.disallowed-tools }} + --model ${{ inputs.model }} + ${{ inputs.effort && format('--effort {0}', inputs.effort) || '' }} + --dangerously-skip-permissions + + - name: Upload Claude output (for debugging) + if: always() && steps.claude.outcome != 'skipped' + uses: actions/upload-artifact@v6 + with: + name: claude-output-investigate + path: /home/runner/work/_temp/claude-execution-output.json + + - name: Read created issue + id: issue + # Claude writes the issue number to a file because there is no direct way to pass + # structured output from a Claude Code action step to subsequent steps. + run: | + if [ -f "$GITHUB_WORKSPACE/issue-number.txt" ]; then + ISSUE_NUMBER=$(cat "$GITHUB_WORKSPACE/issue-number.txt") + echo "number=$ISSUE_NUMBER" >> "$GITHUB_OUTPUT" + echo "Issue created: #$ISSUE_NUMBER" + else + echo "number=" >> "$GITHUB_OUTPUT" + echo "No issue created (duplicate skipped)" + fi + + # Adds the "claude" label for visibility. Scheduled runs lack the permissions to trigger other + # workflows, so this doesn't start the Claude workflow on the issue. + - name: Add Claude label to issue + if: steps.issue.outputs.number != '' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + try { + await github.rest.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: "claude", + color: "d93f0b", + }); + } catch (e) { + // Label already exists + } + + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: parseInt('${{ steps.issue.outputs.number }}'), + labels: ["claude"], + }); + + # Records this run on each existing issue Claude found covering the failure, in one comment per issue + # that later runs update in place. The comment looks like this on GitHub: + # + # ### Failed again in later runs + # + # Platform tests failed on this issue **5** more times after it was opened. Last seen 2026-11-10 14:03 UTC. + # + # Most recent 5 runs: + # - 2026-11-10 14:03 UTC: [Platform tests (hourly)]() + # - 2026-11-10 13:03 UTC: [Platform tests (hourly)]() + # - ... + # + # Editing a comment doesn't notify the issue's subscribers, so a test failing every hour doesn't flood them. + # Note: two runs updating the same comment at once can lose one of the counts. + - name: Record the failure on existing issues + if: always() + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + # Source: claude + script: | + const fs = require('fs'); + const MARKER = ''))); + } catch { + core.warning(`Could not parse the recurrence comment on #${issueNumber}, starting over`); + } + } + state.count += 1; + state.runs = [run, ...state.runs].slice(0, MAX_RUNS); + + const body = [ + `${MARKER} ${JSON.stringify(state)} -->`, + '### Failed again in later runs', + '', + `Platform tests failed on this issue **${state.count}** more ${state.count === 1 ? 'time' : 'times'} after it was opened. Last seen ${formatDate(run.at)}.`, + '', + `Most recent ${state.runs.length === 1 ? 'run' : `${state.runs.length} runs`}:`, + ...state.runs.map((r) => `- ${formatDate(r.at)}: [${r.workflow}](${r.url})`), + ].join('\n'); + + if (existing) { + await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body }); + } else { + await github.rest.issues.createComment({ owner, repo, issue_number: issueNumber, body }); + } + console.log(`Recorded the failure on #${issueNumber} (${state.count} so far)`); + } catch (error) { + core.warning(`Could not record the failure on #${issueNumber}: ${error.message}`); + } + } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ea9a231b..d7cbc1b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,7 +74,7 @@ You need to run `npm run build` inside `apify-test-tools` repo everytime you wan The `public_`-prefixed workflows are the ones consumer repos call: `public_pr-build-test`, `public_platform-tests`, `public_push-build-latest`, `public_claude`, `public_review`, `public_stale-issues` and -`public_platform-tests-claude-investigate-and-fix`. They live here because they call this package's +`public_platform-tests-claude-investigate`. They live here because they call this package's CLI, so a change to both is one PR. GitHub only reads workflow files at the top level of `.github/workflows`, so they sit next to this repo's own CI, and the prefix is what separates the two: `public_` is the API other repos depend on, `_` is internal plumbing, and `on_`/`manual_` are diff --git a/docs/workflows.md b/docs/workflows.md index 42a94c82..fe0f0aaf 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -19,15 +19,15 @@ Always reference them at the `@workflows-v0` major tag, never at `@master` — s They only run on GitHub Actions. On another CI platform, build the same steps with the [CLI](cli.md); each workflow The build, release and test workflows below list the CLI commands they run. -| Workflow | Typical trigger | What it does | -| ---------------------------------------------------------------------------------------------------------------- | ----------------------------------- | -------------------------------------------------------------------------------- | -| [`public_pr-build-test.yaml`](#public_pr-build-testyaml) | `pull_request` | Builds the Actors a PR changes into `0.99` and tests them, plus static checks | -| [`public_push-build-latest.yaml`](#public_push-build-latestyaml) | `push` to `master` | Builds the changed Actors into their default version and announces the release | -| [`public_platform-tests.yaml`](#public_platform-testsyaml) | `schedule` | Runs platform tests against the released builds and reports results to Slack | -| [`public_review.yaml`](#public_reviewyaml) | `pull_request` (labeled) | Claude reviews the PR against the shared guidelines | -| [`public_claude.yaml`](#public_claudeyaml) | issue and PR comments, issue labels | Claude acts on `@claude` mentions | -| [`public_stale-issues.yaml`](#public_stale-issuesyaml) | `schedule` | Warns owners of inactive issues, then closes them a month later | -| [`public_platform-tests-claude-investigate-and-fix.yaml`](#public_platform-tests-claude-investigate-and-fixyaml) | after a failed platform test job | Claude investigates a failing platform test, opens an issue, and tries to fix it | +| Workflow | Typical trigger | What it does | +| ------------------------------------------------------------------------------------------------ | ----------------------------------- | ------------------------------------------------------------------------------ | +| [`public_pr-build-test.yaml`](#public_pr-build-testyaml) | `pull_request` | Builds the Actors a PR changes into `0.99` and tests them, plus static checks | +| [`public_push-build-latest.yaml`](#public_push-build-latestyaml) | `push` to `master` | Builds the changed Actors into their default version and announces the release | +| [`public_platform-tests.yaml`](#public_platform-testsyaml) | `schedule` | Runs platform tests against the released builds and reports results to Slack | +| [`public_review.yaml`](#public_reviewyaml) | `pull_request` (labeled) | Claude reviews the PR against the shared guidelines | +| [`public_claude.yaml`](#public_claudeyaml) | issue and PR comments, issue labels | Claude acts on `@claude` mentions | +| [`public_stale-issues.yaml`](#public_stale-issuesyaml) | `schedule` | Warns owners of inactive issues, then closes them a month later | +| [`public_platform-tests-claude-investigate.yaml`](#public_platform-tests-claude-investigateyaml) | after a failed platform test job | Claude investigates a failing platform test and opens an issue | All of them run on `ubuntu-latest` with Node.js 24. The ones that need the repo's dependencies install them with `npm ci`, or with pnpm when the repo has a `pnpm-lock.yaml` and no `package-lock.json`. @@ -295,28 +295,32 @@ jobs: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} ``` -## `public_platform-tests-claude-investigate-and-fix.yaml` +## `public_platform-tests-claude-investigate.yaml` -Optional. Call it after a failed platform test job. It runs in two phases: +Optional. Call it after a failed platform test job. It runs in two stages: -1. **investigate** — Claude reviews the test logs, recent workflow runs and existing issues, and investigates the - failing run on the Apify platform (its log, dataset and key-value store). It opens a GitHub issue with its - findings and labels it `claude`, or does nothing if a matching issue already exists. -2. **fix** — runs only when the first phase opened an issue. Claude implements a fix, opens a PR, and labels the - issue `claude:done`. +1. **Deduplication** — a cheap model, Haiku by default, reads the failing tests from the run's test report, works + out what actually broke, and checks whether open issues already cover it. The tests overlap a lot, so it judges by + root cause, not by test. It has the same Apify and Redash access as the investigation, but on GitHub it can only + read issues. Each covering issue gets the run recorded in one comment that keeps a count and links to the latest + runs, updated in place so subscribers aren't notified every time. If open issues cover everything, the job stops + here, so a known bug isn't investigated in full on every scheduled run. +2. **Investigation** — otherwise the main model investigates what isn't covered: the test logs, recent workflow runs, + and the failing run on the Apify platform (its log, dataset and key-value store). It opens a GitHub issue with its + findings and labels it `claude`. -Scheduled runs use a `GITHUB_TOKEN` that cannot trigger other workflows, so the fix phase is a direct job -dependency rather than a label-triggered run of `public_claude.yaml`. +If the deduplication can't give an answer, e.g. the run has no test report or the model fails, the investigation runs. | Input | Type | Default | Description | | -------------------- | ------ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `model` | string | `sonnet` | Claude model for both phases | +| `model` | string | `sonnet` | Claude model for the investigation | | `effort` | string | `''` | Claude effort level (`low`, `medium`, `high`, `xhigh`, `max`). Empty uses the Claude Code default | +| `dedupe_model` | string | `haiku` | Claude model that checks whether open issues already cover the failing tests, before the investigation | | `max_flakiness_runs` | number | `200` | The most times Claude may re-run the failing Actor run to measure how often the failure happens | | `investigate_prompt` | string | (built in) | Prompt for the investigation phase. Override to change how issues are investigated, titled and described | | `priority_prompt` | string | (built in) | Prompt for setting a new issue's Priority field from its impact and flakiness. Override to change how priority is judged, e.g. to set revenue thresholds | -Secrets: `ANTHROPIC_API_KEY`, `TESTER_APIFY_TOKEN`, and optionally `NPM_TOKEN`, `REDASH_API_KEY` and `AGENT_SKILLS_INTERNAL_GITHUB_TOKEN`. +Secrets: `ANTHROPIC_API_KEY`, `TESTER_APIFY_TOKEN`, and optionally `REDASH_API_KEY` and `AGENT_SKILLS_INTERNAL_GITHUB_TOKEN`. ```yaml jobs: @@ -332,7 +336,7 @@ jobs: handle-failure: needs: platformTestsHourly if: ${{ failure() }} - uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml@workflows-v0 + uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate.yaml@workflows-v0 secrets: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} From 144691ac444bfd2ce8919d32e11ef29ef4a75185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pr=C5=AF=C5=A1a?= <87543374+Patai5@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:06:26 +0100 Subject: [PATCH 2/3] ci: fix actionlint shellcheck error --- .../workflows/public_platform-tests-claude-investigate.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/public_platform-tests-claude-investigate.yaml b/.github/workflows/public_platform-tests-claude-investigate.yaml index d11139f5..afc740b2 100644 --- a/.github/workflows/public_platform-tests-claude-investigate.yaml +++ b/.github/workflows/public_platform-tests-claude-investigate.yaml @@ -146,8 +146,10 @@ jobs: # editing, sharing or deleting queries, visualizations, dashboards, widgets, alerts and snippets. - name: Configure the MCP servers id: mcp + env: + MCP_CONFIG: '{"mcpServers":{"apify":{"type":"http","url":"https://mcp.apify.com/?tools=get-actor-run,get-actor-run-log,get-dataset-list,get-dataset,get-dataset-items,get-key-value-store-list,get-key-value-store,get-key-value-store-keys,get-key-value-store-record","headers":{"Authorization":"Bearer ${TESTER_APIFY_TOKEN}"}},"redash":{"type":"stdio","command":"${{ runner.temp }}/redash-mcp/node_modules/.bin/redash-mcp","env":{"REDASH_URL":"https://charts.apify.com/","REDASH_API_KEY":"${REDASH_API_KEY}"}}}}' run: | - echo 'config={"mcpServers":{"apify":{"type":"http","url":"https://mcp.apify.com/?tools=get-actor-run,get-actor-run-log,get-dataset-list,get-dataset,get-dataset-items,get-key-value-store-list,get-key-value-store,get-key-value-store-keys,get-key-value-store-record","headers":{"Authorization":"Bearer ${TESTER_APIFY_TOKEN}"}},"redash":{"type":"stdio","command":"${{ runner.temp }}/redash-mcp/node_modules/.bin/redash-mcp","env":{"REDASH_URL":"https://charts.apify.com/","REDASH_API_KEY":"${REDASH_API_KEY}"}}}}' >> "$GITHUB_OUTPUT" + echo "config=$MCP_CONFIG" >> "$GITHUB_OUTPUT" echo 'disallowed-tools=mcp__redash__create_query,mcp__redash__update_query,mcp__redash__update_query_parameters,mcp__redash__archive_query,mcp__redash__fork_query,mcp__redash__add_query_favorite,mcp__redash__remove_query_favorite,mcp__redash__create_visualization,mcp__redash__update_visualization,mcp__redash__update_chart_visualization,mcp__redash__delete_visualization,mcp__redash__create_dashboard,mcp__redash__update_dashboard,mcp__redash__update_dashboard_parameters,mcp__redash__archive_dashboard,mcp__redash__fork_dashboard,mcp__redash__share_dashboard,mcp__redash__unshare_dashboard,mcp__redash__add_dashboard_favorite,mcp__redash__remove_dashboard_favorite,mcp__redash__create_alert,mcp__redash__update_alert,mcp__redash__delete_alert,mcp__redash__mute_alert,mcp__redash__add_alert_subscription,mcp__redash__remove_alert_subscription,mcp__redash__create_widget,mcp__redash__update_widget,mcp__redash__update_widget_layout,mcp__redash__update_dashboard_layout,mcp__redash__update_widget_parameter_mappings,mcp__redash__delete_widget,mcp__redash__create_query_snippet,mcp__redash__update_query_snippet,mcp__redash__delete_query_snippet' >> "$GITHUB_OUTPUT" - name: Check for existing issues From 1461591565c3de257ac8258986e3125f481687bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pr=C5=AF=C5=A1a?= <87543374+Patai5@users.noreply.github.com> Date: Fri, 27 Nov 2026 21:51:20 -0800 Subject: [PATCH 3/3] ci: keep the workflow filename and address review --- ...orm-tests-claude-investigate-and-fix.yaml} | 76 ++++++++++++------- CONTRIBUTING.md | 2 +- docs/workflows.md | 37 ++++----- 3 files changed, 70 insertions(+), 45 deletions(-) rename .github/workflows/{public_platform-tests-claude-investigate.yaml => public_platform-tests-claude-investigate-and-fix.yaml} (86%) diff --git a/.github/workflows/public_platform-tests-claude-investigate.yaml b/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml similarity index 86% rename from .github/workflows/public_platform-tests-claude-investigate.yaml rename to .github/workflows/public_platform-tests-claude-investigate-and-fix.yaml index 89d72aea..0e88aa70 100644 --- a/.github/workflows/public_platform-tests-claude-investigate.yaml +++ b/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml @@ -4,7 +4,7 @@ name: 'Platform tests: Claude failure investigation' # Reusable workflow that uses Claude Code to investigate a failing E2E platform test. # -# 1. A cheap model works out what broke and whether open issues already cover it, and updates the recurrence +# 1. A first check works out what broke and whether open issues already cover it, and updates the recurrence # comment on each covering issue. If they cover everything, the job stops there. # 2. Otherwise the main model investigates what isn't covered and opens an issue with its findings. # @@ -28,7 +28,7 @@ name: 'Platform tests: Claude failure investigation' # handle-failure: # needs: platformTestsCore # if: ${{ failure() }} -# uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate.yaml@workflows-v0 +# uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml@workflows-v0 # secrets: # ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} # # The token the tests ran the Actors with, so Claude can read the failing run @@ -40,7 +40,7 @@ on: model: required: false type: string - default: sonnet + default: opus description: Claude model to use for the investigation effort: required: false @@ -50,7 +50,7 @@ on: dedupe_model: required: false type: string - default: haiku + default: sonnet description: Claude model that checks whether open issues already cover the failing tests, before the investigation max_flakiness_runs: required: false @@ -127,7 +127,7 @@ jobs: investigate: runs-on: ubuntu-latest permissions: - contents: write + contents: read pull-requests: read issues: write actions: read @@ -143,16 +143,12 @@ jobs: echo "agent-skills-token=${{ secrets.AGENT_SKILLS_INTERNAL_GITHUB_TOKEN != '' }}" >> "$GITHUB_OUTPUT" echo "redash-api-key=${{ secrets.REDASH_API_KEY != '' }}" >> "$GITHUB_OUTPUT" - - uses: actions/setup-node@v6 - if: steps.optional-secrets.outputs.redash-api-key == 'true' - with: - node-version: 24 - - - name: Install Redash MCP server - if: steps.optional-secrets.outputs.redash-api-key == 'true' + - name: Download the test report continue-on-error: true - working-directory: ${{ runner.temp }} - run: npm install --prefix redash-mcp --ignore-scripts --no-audit --no-fund @suthio/redash-mcp@0.1.0 + uses: actions/download-artifact@v5 + with: + name: vitest-results + path: vitest-results # The `tools` query parameter below selects which tools the Apify MCP server # exposes: reading an Actor run — its status, exit code, storage ids and log — and @@ -166,20 +162,23 @@ jobs: env: MCP_CONFIG: '{"mcpServers":{"apify":{"type":"http","url":"https://mcp.apify.com/?tools=get-actor-run,get-actor-run-log,get-dataset-list,get-dataset,get-dataset-items,get-key-value-store-list,get-key-value-store,get-key-value-store-keys,get-key-value-store-record","headers":{"Authorization":"Bearer ${TESTER_APIFY_TOKEN}"}},"redash":{"type":"stdio","command":"${{ runner.temp }}/redash-mcp/node_modules/.bin/redash-mcp","env":{"REDASH_URL":"https://charts.apify.com/","REDASH_API_KEY":"${REDASH_API_KEY}"}}}}' run: | - echo "config=$MCP_CONFIG" >> "$GITHUB_OUTPUT" - echo 'disallowed-tools=mcp__redash__create_query,mcp__redash__update_query,mcp__redash__update_query_parameters,mcp__redash__archive_query,mcp__redash__fork_query,mcp__redash__add_query_favorite,mcp__redash__remove_query_favorite,mcp__redash__create_visualization,mcp__redash__update_visualization,mcp__redash__update_chart_visualization,mcp__redash__delete_visualization,mcp__redash__create_dashboard,mcp__redash__update_dashboard,mcp__redash__update_dashboard_parameters,mcp__redash__archive_dashboard,mcp__redash__fork_dashboard,mcp__redash__share_dashboard,mcp__redash__unshare_dashboard,mcp__redash__add_dashboard_favorite,mcp__redash__remove_dashboard_favorite,mcp__redash__create_alert,mcp__redash__update_alert,mcp__redash__delete_alert,mcp__redash__mute_alert,mcp__redash__add_alert_subscription,mcp__redash__remove_alert_subscription,mcp__redash__create_widget,mcp__redash__update_widget,mcp__redash__update_widget_layout,mcp__redash__update_dashboard_layout,mcp__redash__update_widget_parameter_mappings,mcp__redash__delete_widget,mcp__redash__create_query_snippet,mcp__redash__update_query_snippet,mcp__redash__delete_query_snippet' >> "$GITHUB_OUTPUT" + { + echo "config=$MCP_CONFIG" + echo "dedupe-config=$(jq -c 'del(.mcpServers.redash)' <<< "$MCP_CONFIG")" + echo 'disallowed-tools=mcp__redash__create_query,mcp__redash__update_query,mcp__redash__update_query_parameters,mcp__redash__archive_query,mcp__redash__fork_query,mcp__redash__add_query_favorite,mcp__redash__remove_query_favorite,mcp__redash__create_visualization,mcp__redash__update_visualization,mcp__redash__update_chart_visualization,mcp__redash__delete_visualization,mcp__redash__create_dashboard,mcp__redash__update_dashboard,mcp__redash__update_dashboard_parameters,mcp__redash__archive_dashboard,mcp__redash__fork_dashboard,mcp__redash__share_dashboard,mcp__redash__unshare_dashboard,mcp__redash__add_dashboard_favorite,mcp__redash__remove_dashboard_favorite,mcp__redash__create_alert,mcp__redash__update_alert,mcp__redash__delete_alert,mcp__redash__mute_alert,mcp__redash__add_alert_subscription,mcp__redash__remove_alert_subscription,mcp__redash__create_widget,mcp__redash__update_widget,mcp__redash__update_widget_layout,mcp__redash__update_dashboard_layout,mcp__redash__update_widget_parameter_mappings,mcp__redash__delete_widget,mcp__redash__create_query_snippet,mcp__redash__update_query_snippet,mcp__redash__delete_query_snippet' + } >> "$GITHUB_OUTPUT" - name: Check for existing issues id: dedupe + if: hashFiles('vitest-results/test-report.json') != '' continue-on-error: true uses: anthropics/claude-code-action@8251c103ac8c1d761882c86aba1412c7f583c844 # v1.0.213 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} TESTER_APIFY_TOKEN: ${{ secrets.TESTER_APIFY_TOKEN }} - REDASH_API_KEY: ${{ secrets.REDASH_API_KEY }} with: prompt: | - E2E platform tests failed in workflow run ${{ github.run_id }} of this repo. Get the failures from its test report with `gh run download ${{ github.run_id }} --name vitest-results --dir $RUNNER_TEMP/vitest-results`: test-report.json lists each test with its status and failure messages, plus any errors outside the tests. + E2E platform tests failed in workflow run ${{ github.run_id }} of this repo. Its test report is at $GITHUB_WORKSPACE/vitest-results/test-report.json: it lists each test with its status and failure messages, plus any errors outside the tests. The tests overlap a lot, so one bug usually fails several of them. Work out what actually broke, the distinct root causes behind these failures, and whether an open issue in this repo already covers each one. List the open issues with `gh issue list --state open --limit 200 --json number,title,body,labels`, focusing on those labeled `claude`, and read any you need in full with `gh issue view`. An issue covers a failure when it describes the same root cause, no matter which tests it mentions. If the failure messages aren't enough to tell, look at the failing Actor runs with the Apify tools. When unsure, treat the failure as not covered: a missed duplicate costs one investigation, a wrong match hides a bug. @@ -188,9 +187,8 @@ jobs: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} claude_args: | --model ${{ inputs.dedupe_model }} - --mcp-config '${{ steps.mcp.outputs.config }}' - --disallowedTools ${{ steps.mcp.outputs.disallowed-tools }} - --allowedTools "Bash(gh run download:*),Bash(gh run view:*),Bash(gh issue list:*),Bash(gh issue view:*),Read,Write,mcp__apify,mcp__redash" + --mcp-config '${{ steps.mcp.outputs.dedupe-config }}' + --allowedTools "Bash(gh run view:*),Bash(gh issue list:*),Bash(gh issue view:*),Read,Write,mcp__apify" - name: Upload dedupe Claude output (for debugging) if: always() && steps.dedupe.outcome != 'skipped' @@ -199,7 +197,7 @@ jobs: name: claude-output-dedupe path: /home/runner/work/_temp/claude-execution-output.json - # Reads the cheap model's answer: + # Reads the check's answer: # # 1. Everything covered: skip the investigation. # 2. Part covered: tell the main model which part, so it investigates only the rest. @@ -207,6 +205,8 @@ jobs: - name: Decide whether to investigate id: duplicates if: ${{ !cancelled() }} + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | answer="$GITHUB_WORKSPACE/dedupe.json" issues='[]' @@ -215,6 +215,19 @@ jobs: issues=$(jq -c '[.issues[] | select(type == "number" and . > 0 and floor == .)] | unique' "$answer") || issues='[]' uncovered=$(jq -r '.uncovered' "$answer") fi + + # Filter out invalid issue numbers. The agent could have made a mistake. + open=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --limit 1000 --json number --jq 'map(.number)') || { + echo "::warning::Could not list the open issues" + open='[]' + } + dropped=$(jq -c --argjson open "$open" 'map(select(IN($open[]) | not))' <<< "$issues") + issues=$(jq -c --argjson open "$open" 'map(select(IN($open[])))' <<< "$issues") + if [ "$(jq length <<< "$dropped")" -gt 0 ]; then + dropped_refs=$(jq -r 'map("#\(.)") | join(", ")' <<< "$dropped") + echo "::warning::The check matched the failure to $dropped_refs, which aren't open issues" + uncovered="${uncovered:+$uncovered }Also what the check matched to $dropped_refs, which aren't open issues." + fi refs=$(jq -r 'map("#\(.)") | join(", ")' <<< "$issues") if [ "$(jq length <<< "$issues")" -gt 0 ]; then @@ -232,11 +245,22 @@ jobs: delimiter="EOF_$(openssl rand -hex 8)" { echo "note<<$delimiter" - echo "A first check found that open issues $refs already cover part of this failure, so don't investigate that part again. What they don't cover: $uncovered" + echo "A first check found that open issues $refs already cover part of this failure. Read them and investigate only what they don't explain." echo "$delimiter" } >> "$GITHUB_OUTPUT" fi + - uses: actions/setup-node@v6 + if: steps.duplicates.outputs.all-duplicates != 'true' && steps.optional-secrets.outputs.redash-api-key == 'true' + with: + node-version: 24 + + - name: Install Redash MCP server + if: steps.duplicates.outputs.all-duplicates != 'true' && steps.optional-secrets.outputs.redash-api-key == 'true' + continue-on-error: true + working-directory: ${{ runner.temp }} + run: npm install --prefix redash-mcp --ignore-scripts --no-audit --no-fund @suthio/redash-mcp@0.1.0 + - name: Checkout internal agent skills id: agent-skills-internal if: steps.duplicates.outputs.all-duplicates != 'true' && steps.optional-secrets.outputs.agent-skills-token == 'true' @@ -335,7 +359,7 @@ jobs: # # ### Failed again in later runs # - # Platform tests failed on this issue **5** more times after it was opened. Last seen 2026-11-10 14:03 UTC. + # Platform tests failed on this issue **5** times since this comment was added. Last seen 2026-11-10 14:03 UTC. # # Most recent 5 runs: # - 2026-11-10 14:03 UTC: [Platform tests (hourly)]() @@ -345,7 +369,7 @@ jobs: # Editing a comment doesn't notify the issue's subscribers, so a test failing every hour doesn't flood them. # Note: two runs updating the same comment at once can lose one of the counts. - name: Record the failure on existing issues - if: always() + if: ${{ !cancelled() }} uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -406,7 +430,7 @@ jobs: `${MARKER} ${JSON.stringify(state)} -->`, '### Failed again in later runs', '', - `Platform tests failed on this issue **${state.count}** more ${state.count === 1 ? 'time' : 'times'} after it was opened. Last seen ${formatDate(run.at)}.`, + `Platform tests failed on this issue **${state.count}** ${state.count === 1 ? 'time' : 'times'} since this comment was added. Last seen ${formatDate(run.at)}.`, '', `Most recent ${state.runs.length === 1 ? 'run' : `${state.runs.length} runs`}:`, ...state.runs.map((r) => `- ${formatDate(r.at)}: [${r.workflow}](${r.url})`), diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fcb0077..1779c1e6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,7 +74,7 @@ You need to run `npm run build` inside `apify-test-tools` repo everytime you wan The `public_`-prefixed workflows are the ones consumer repos call: `public_pr-build-test`, `public_platform-tests`, `public_push-build-latest`, `public_claude`, `public_review`, `public_stale-issues` and -`public_platform-tests-claude-investigate`. They live here because they call this package's +`public_platform-tests-claude-investigate-and-fix`. They live here because they call this package's CLI, so a change to both is one PR. GitHub only reads workflow files at the top level of `.github/workflows`, so they sit next to this repo's own CI, and the prefix is what separates the two: `public_` is the API other repos depend on, `_` is internal plumbing, and `on_`/`manual_` are diff --git a/docs/workflows.md b/docs/workflows.md index 630c00f6..d92cfed5 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -19,15 +19,15 @@ Always reference them at the `@workflows-v0` major tag, never at `@master` — s They only run on GitHub Actions. On another CI platform, build the same steps with the [CLI](cli.md); each workflow The build, release and test workflows below list the CLI commands they run. -| Workflow | Typical trigger | What it does | -| ------------------------------------------------------------------------------------------------ | ----------------------------------- | ------------------------------------------------------------------------------ | -| [`public_pr-build-test.yaml`](#public_pr-build-testyaml) | `pull_request` | Builds the Actors a PR changes into `0.99` and tests them, plus static checks | -| [`public_push-build-latest.yaml`](#public_push-build-latestyaml) | `push` to `master` | Builds the changed Actors into their default version and announces the release | -| [`public_platform-tests.yaml`](#public_platform-testsyaml) | `schedule` | Runs platform tests against the released builds and reports results to Slack | -| [`public_review.yaml`](#public_reviewyaml) | `pull_request` (labeled) | Claude reviews the PR against the shared guidelines | -| [`public_claude.yaml`](#public_claudeyaml) | issue and PR comments, issue labels | Claude acts on `@claude` mentions | -| [`public_stale-issues.yaml`](#public_stale-issuesyaml) | `schedule` | Warns owners of inactive issues, then closes them a month later | -| [`public_platform-tests-claude-investigate.yaml`](#public_platform-tests-claude-investigateyaml) | after a failed platform test job | Claude investigates a failing platform test and opens an issue | +| Workflow | Typical trigger | What it does | +| ---------------------------------------------------------------------------------------------------------------- | ----------------------------------- | ------------------------------------------------------------------------------ | +| [`public_pr-build-test.yaml`](#public_pr-build-testyaml) | `pull_request` | Builds the Actors a PR changes into `0.99` and tests them, plus static checks | +| [`public_push-build-latest.yaml`](#public_push-build-latestyaml) | `push` to `master` | Builds the changed Actors into their default version and announces the release | +| [`public_platform-tests.yaml`](#public_platform-testsyaml) | `schedule` | Runs platform tests against the released builds and reports results to Slack | +| [`public_review.yaml`](#public_reviewyaml) | `pull_request` (labeled) | Claude reviews the PR against the shared guidelines | +| [`public_claude.yaml`](#public_claudeyaml) | issue and PR comments, issue labels | Claude acts on `@claude` mentions | +| [`public_stale-issues.yaml`](#public_stale-issuesyaml) | `schedule` | Warns owners of inactive issues, then closes them a month later | +| [`public_platform-tests-claude-investigate-and-fix.yaml`](#public_platform-tests-claude-investigate-and-fixyaml) | after a failed platform test job | Claude investigates a failing platform test and opens an issue | All of them run on `ubuntu-latest` with Node.js 24. The ones that need the repo's dependencies install them with `npm ci`, or with pnpm when the repo has a `pnpm-lock.yaml` and no `package-lock.json`. @@ -309,16 +309,17 @@ jobs: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} ``` -## `public_platform-tests-claude-investigate.yaml` +## `public_platform-tests-claude-investigate-and-fix.yaml` Optional. Call it after a failed platform test job. It runs in two stages: -1. **Deduplication** — a cheap model, Haiku by default, reads the failing tests from the run's test report, works +1. **Deduplication** — a first check, on Sonnet by default, reads the failing tests from the run's test report, works out what actually broke, and checks whether open issues already cover it. The tests overlap a lot, so it judges by - root cause, not by test. It has the same Apify and Redash access as the investigation, but on GitHub it can only - read issues. Each covering issue gets the run recorded in one comment that keeps a count and links to the latest - runs, updated in place so subscribers aren't notified every time. If open issues cover everything, the job stops - here, so a known bug isn't investigated in full on every scheduled run. + root cause, not by test. It can read the failing runs on the Apify platform, but has no Redash access, and on + GitHub it can only read issues. A match counts only if it is an open issue. Each covering issue gets the run + recorded in one comment that keeps a count and links to the latest runs, updated in place so subscribers aren't + notified every time. If open issues cover everything, the job stops here, so a known bug isn't investigated in full + on every scheduled run. 2. **Investigation** — otherwise the main model investigates what isn't covered: the test logs, recent workflow runs, and the failing run on the Apify platform (its log, dataset and key-value store). It opens a GitHub issue with its findings and labels it `claude`. @@ -327,9 +328,9 @@ If the deduplication can't give an answer, e.g. the run has no test report or th | Input | Type | Default | Description | | -------------------- | ------ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `model` | string | `sonnet` | Claude model for the investigation | +| `model` | string | `opus` | Claude model for the investigation | | `effort` | string | `''` | Claude effort level (`low`, `medium`, `high`, `xhigh`, `max`). Empty uses the Claude Code default | -| `dedupe_model` | string | `haiku` | Claude model that checks whether open issues already cover the failing tests, before the investigation | +| `dedupe_model` | string | `sonnet` | Claude model that checks whether open issues already cover the failing tests, before the investigation | | `max_flakiness_runs` | number | `200` | The most times Claude may re-run the failing Actor run to measure how often the failure happens | | `investigate_prompt` | string | (built in) | Prompt for the investigation phase. Override to change how issues are investigated, titled and described | | `priority_prompt` | string | (built in) | Prompt for setting a new issue's Priority field from its impact and flakiness. Override to change how priority is judged, e.g. to set revenue thresholds | @@ -370,7 +371,7 @@ jobs: handle-failure: needs: platformTestsHourly if: ${{ failure() }} - uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate.yaml@workflows-v0 + uses: apify/apify-test-tools/.github/workflows/public_platform-tests-claude-investigate-and-fix.yaml@workflows-v0 secrets: ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} # The token the tests ran the Actors with, so Claude can read the failing run