-
Notifications
You must be signed in to change notification settings - Fork 7
Add daily detector agentic workflow for "Resource not accessible by integration" across long-term branches #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d3dd145
Initial plan
Copilot c0bbd02
Add daily fixer workflow for 'Resource not accessible by integration'…
Copilot 21b725b
Adjust resource-not-accessible workflow to pre-scan and file one issue
github-actions[bot] bdfd89f
Convert to detection workflow: pre-scan step, single issue output, lo…
Copilot 922bc15
Merge branch 'main' into copilot/add-daily-fixer-workflow
strawgate 76f1842
Merge main and address review feedback
strawgate 74f8366
fix: remove stray merge marker from workflow README
github-actions[bot] 68c36f2
Merge branch 'main' into copilot/add-daily-fixer-workflow
strawgate 72e18e3
Merge branch 'main' into copilot/add-daily-fixer-workflow
strawgate 0100f4a
Updates from review
strawgate 4937ddf
Merge branch 'main' into copilot/add-daily-fixer-workflow
strawgate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1,639 changes: 1,639 additions & 0 deletions
1,639
.github/workflows/gh-aw-resource-not-accessible-by-integration-fixer.lock.yml
Large diffs are not rendered by default.
Oops, something went wrong.
224 changes: 224 additions & 0 deletions
224
.github/workflows/gh-aw-resource-not-accessible-by-integration-fixer.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| --- | ||
| inlined-imports: true | ||
| description: "Daily fixer for 'Resource not accessible by integration' across long-term branches" | ||
| imports: | ||
| - gh-aw-fragments/elastic-tools.md | ||
| - gh-aw-fragments/runtime-setup.md | ||
| - gh-aw-fragments/formatting.md | ||
| - gh-aw-fragments/rigor.md | ||
| - gh-aw-fragments/mcp-pagination.md | ||
| - gh-aw-fragments/messages-footer.md | ||
| - gh-aw-fragments/safe-output-create-pr.md | ||
| - gh-aw-fragments/workflow-edit-guardrails.md | ||
| - gh-aw-fragments/network-ecosystems.md | ||
| engine: | ||
| id: copilot | ||
| model: ${{ inputs.model }} | ||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| model: | ||
| description: "AI model to use" | ||
| type: string | ||
| required: false | ||
| default: "gpt-5.3-codex" | ||
| additional-instructions: | ||
| description: "Repo-specific instructions appended to the agent prompt" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| setup-commands: | ||
| description: "Shell commands to run before the agent starts (dependency install, build, etc.)" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| allowed-bot-users: | ||
| description: "Allowlisted bot actor usernames (comma-separated)" | ||
| type: string | ||
| required: false | ||
| default: "github-actions[bot]" | ||
| messages-footer: | ||
| description: "Footer appended to all agent comments and reviews" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| long-term-branches: | ||
| description: "Space-separated list of long-term branch names to scan in addition to the default branch (e.g. 'main 8.x 7.17')" | ||
| type: string | ||
| required: false | ||
| default: "" | ||
| draft-prs: | ||
| description: "Whether to create pull requests as drafts" | ||
| type: boolean | ||
| required: false | ||
| default: false | ||
| secrets: | ||
| COPILOT_GITHUB_TOKEN: | ||
| required: true | ||
| roles: [admin, maintainer, write] | ||
| bots: | ||
| - "${{ inputs.allowed-bot-users }}" | ||
| concurrency: | ||
| group: resource-not-accessible-by-integration-fixer | ||
| cancel-in-progress: true | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| issues: read | ||
| pull-requests: read | ||
| tools: | ||
| github: | ||
| toolsets: [repos, issues, pull_requests, search, actions] | ||
| bash: true | ||
| web-fetch: | ||
| strict: false | ||
| safe-outputs: | ||
| activation-comments: false | ||
| noop: | ||
| timeout-minutes: 90 | ||
| steps: | ||
| - name: Repo-specific setup | ||
| if: ${{ inputs.setup-commands != '' }} | ||
| env: | ||
| SETUP_COMMANDS: ${{ inputs.setup-commands }} | ||
| run: eval "$SETUP_COMMANDS" | ||
| --- | ||
|
|
||
| # Resource Not Accessible By Integration Fixer | ||
|
|
||
| Scan workflow runs from the last 24 hours across all long-term branches in ${{ github.repository }}, find failures caused by `Resource not accessible by integration`, and open one remediation PR per affected workflow. | ||
|
|
||
| ## Context | ||
|
|
||
| - **Repository**: ${{ github.repository }} | ||
| - **Default Branch**: ${{ github.event.repository.default_branch }} | ||
| - **Additional long-term branches**: ${{ inputs.long-term-branches }} (space-separated; empty means default branch only) | ||
| - **Error pattern**: `Resource not accessible by integration` | ||
| - **Remediation instructions URL**: `https://raw.githubusercontent.com/elastic/observability-cicd/main/github-actions/actionable/alerts/app/prompts/accessible-by-integration.txt` | ||
|
|
||
| ## Constraints | ||
|
|
||
| - **CAN**: Read files, search code, modify files locally, run commands, create pull requests. | ||
| - **CANNOT**: Push directly to the repository — use `create_pull_request`. Merge or close PRs. | ||
| - **One PR per failing workflow** (never combine fixes for different workflows into a single PR). | ||
| - Scope: default branch plus all branches listed in `long-term-branches`. | ||
| - If no runs match the error pattern, call `noop` with message "No 'Resource not accessible by integration' failures found in the last 24 hours — nothing to fix". | ||
| - **Do not auto-merge.** Leave every PR open for review by the `elastic/observablt-ci` team. | ||
|
|
||
| ## Step 1: Gather context | ||
|
|
||
| 1. Call `generate_agents_md` to get repository conventions (if it fails, continue). | ||
| 2. Load the remediation instructions at runtime via `web_fetch`: | ||
| ``` | ||
| https://raw.githubusercontent.com/elastic/observability-cicd/main/github-actions/actionable/alerts/app/prompts/accessible-by-integration.txt | ||
| ``` | ||
| Store the content for use in Step 3. If the fetch fails, fall back to the general principle: add the minimum required `permissions` block to the failing workflow jobs or use a `GITHUB_TOKEN` with sufficient scopes. | ||
| 3. Determine the scan window — the ISO 8601 timestamp for 24 hours ago: | ||
| ````bash | ||
| SINCE=$(date -u -d '24 hours ago' '+%Y-%m-%dT%H:%M:%SZ' 2>/dev/null \ | ||
| || date -u -v-24H '+%Y-%m-%dT%H:%M:%SZ') | ||
| echo "Scan since: $SINCE" | ||
| ```` | ||
| 4. Build the branch list: always start with the repository default branch, then append the space-separated values from `${{ inputs.long-term-branches }}` (skip duplicates and blanks). | ||
|
|
||
| ## Step 2: Scan for failures | ||
|
|
||
| For each branch in scope: | ||
|
|
||
| 1. List failed workflow runs created since `$SINCE`: | ||
| ````bash | ||
| gh api "repos/${{ github.repository }}/actions/runs" \ | ||
| --method GET \ | ||
| -f branch=BRANCH_NAME \ | ||
| -f status=failure \ | ||
| -f created=">=${SINCE}" \ | ||
| --paginate \ | ||
| --jq '.workflow_runs[] | {id: .id, name: .name, html_url: .html_url, path: .path, head_branch: .head_branch, created_at: .created_at}' | ||
| ```` | ||
|
|
||
| 2. For each failed run, download and search logs for the exact string `Resource not accessible by integration`: | ||
| ````bash | ||
| mkdir -p /tmp/gh-aw/agent | ||
| gh api "repos/${{ github.repository }}/actions/runs/{run_id}/logs" \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| > /tmp/gh-aw/agent/workflow-logs-{run_id}.zip | ||
| unzip -o /tmp/gh-aw/agent/workflow-logs-{run_id}.zip \ | ||
| -d /tmp/gh-aw/agent/workflow-logs-{run_id}/ | ||
| grep -rl "Resource not accessible by integration" \ | ||
| /tmp/gh-aw/agent/workflow-logs-{run_id}/ || true | ||
| ```` | ||
|
|
||
| 3. Collect all runs where the log search returned matches. Group matching runs by the **workflow path** (the `.github/workflows/` file that defines the workflow) — this ensures exactly one PR per workflow, even when multiple runs or branches are affected. | ||
|
|
||
| If no runs match after scanning all branches, call `noop` with message "No 'Resource not accessible by integration' failures found in the last 24 hours — nothing to fix". | ||
|
|
||
| ## Step 3: Analyze and fix each affected workflow | ||
|
|
||
| For each distinct workflow path that produced at least one matching run: | ||
|
|
||
| 1. Read the workflow file from the repository: | ||
| ````bash | ||
| cat .github/workflows/<workflow-file> | ||
| ```` | ||
|
|
||
| 2. Extract the exact log lines containing `Resource not accessible by integration` from a representative failing run as evidence (copy verbatim). | ||
|
|
||
| 3. Apply the remediation instructions loaded in Step 1 as the primary fix policy. Follow those instructions exactly when patching the workflow file's permissions or token configuration. | ||
|
|
||
| 4. Because workflow files live under `.github/workflows/`, follow the workflow-edit guardrails: place the patched copy in `github/workflows/` (without the leading dot). The PR body must note that a maintainer must rename the directory back to `.github/workflows/` before merging. | ||
|
|
||
| ## Step 4: Quality gate | ||
|
|
||
| Before creating any PR: | ||
|
|
||
| - Confirm the patch resolves the permission issue described in the evidence. | ||
| - Confirm each change is minimal — only add or adjust the permissions or token configuration required to fix the error. | ||
| - Call `ready_to_make_pr`. | ||
|
|
||
| ## Step 5: Create one PR per affected workflow | ||
|
|
||
| For each patched workflow, call `create_pull_request` with: | ||
|
|
||
| - **Title**: `fix(ci): resolve "Resource not accessible by integration" in <workflow-name> [<branch>]` | ||
| - Include the branch only when the failure is branch-specific; omit it for failures across all branches. | ||
| - **Body** (all sections required): | ||
|
|
||
| ``` | ||
| ## Affected Workflow | ||
|
|
||
| - **File**: `.github/workflows/<workflow-file>` | ||
| - **Workflow name**: <workflow-name> | ||
|
|
||
| ## Failing Runs | ||
|
|
||
| | Branch | Run | Created | | ||
| | --- | --- | --- | | ||
| | <branch> | [<run-id>](<html_url>) | <created_at> | | ||
|
|
||
| ## Failure Evidence | ||
|
|
||
| ``` | ||
| <verbatim log excerpt containing "Resource not accessible by integration"> | ||
| ``` | ||
|
|
||
|
strawgate marked this conversation as resolved.
Outdated
|
||
| ## Root Cause | ||
|
|
||
| <Concise explanation of why the permission was missing> | ||
|
|
||
| ## Remediation Applied | ||
|
|
||
| <Description of the change made, with reference to the external instructions URL> | ||
|
|
||
| Source: https://raw.githubusercontent.com/elastic/observability-cicd/main/github-actions/actionable/alerts/app/prompts/accessible-by-integration.txt | ||
|
|
||
| ## Reviewer Note | ||
|
|
||
| This PR was created by an automated fixer. Please review and approve. | ||
| The patched file is in `github/workflows/` — a maintainer must move it to `.github/workflows/` before merging. | ||
| ``` | ||
|
|
||
| - **Reviewers**: request review from team `elastic/observablt-ci`. | ||
|
|
||
| > **Important**: Do NOT merge the PR. Leave it open for review by `elastic/observablt-ci`. | ||
|
|
||
|
strawgate marked this conversation as resolved.
Outdated
|
||
| ${{ inputs.additional-instructions }} | ||
21 changes: 21 additions & 0 deletions
21
.github/workflows/trigger-resource-not-accessible-by-integration-fixer.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # This file is auto-generated by scripts/dogfood.sh. Do not edit directly. | ||
| # Edit gh-agent-workflows/resource-not-accessible-by-integration-fixer/example.yml and run 'make compile' to regenerate. | ||
| name: Trigger Resource Not Accessible By Integration Fixer | ||
| on: | ||
| schedule: | ||
| - cron: "0 6 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| run: | ||
| uses: ./.github/workflows/gh-aw-resource-not-accessible-by-integration-fixer.lock.yml | ||
| with: | ||
| long-term-branches: "" | ||
| secrets: | ||
| COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
gh-agent-workflows/resource-not-accessible-by-integration-fixer/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Resource Not Accessible By Integration Fixer | ||
|
|
||
| Daily fixer that scans for `Resource not accessible by integration` errors across long-term branches and opens remediation PRs. | ||
|
|
||
| ## How it works | ||
|
|
||
| Runs once every 24 hours. Queries all failed workflow runs from the last 24 hours on the default branch and any configured long-term (release) branches. For each run, it downloads the logs and searches for the exact error text `Resource not accessible by integration`. Matching runs are grouped by workflow file, and the agent opens **one PR per affected workflow** that patches the missing permissions using the centralized remediation instructions from the observability-cicd repository. If no matching failures are found the run ends with `noop` and no PR is opened. | ||
|
|
||
| Each generated PR: | ||
| - includes links to all matching failed runs, a verbatim log excerpt, root cause, and the remediation applied; | ||
| - requests review from the `elastic/observablt-ci` team; | ||
| - is left open (never auto-merged) until approved. | ||
|
|
||
| ## Quick Install | ||
|
|
||
| ```bash | ||
| mkdir -p .github/workflows && curl -sL \ | ||
| https://raw.githubusercontent.com/elastic/ai-github-actions/v0/gh-agent-workflows/resource-not-accessible-by-integration-fixer/example.yml \ | ||
| -o .github/workflows/resource-not-accessible-by-integration-fixer.yml | ||
| ``` | ||
|
|
||
| See [example.yml](example.yml) for the full workflow file. | ||
|
|
||
| ## Trigger | ||
|
|
||
| | Event | Schedule | | ||
| | --- | --- | | ||
| | `schedule` | Daily (06:00 UTC) | | ||
| | `workflow_dispatch` | Manual | | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Input | Description | Required | Default | | ||
| | --- | --- | --- | --- | | ||
| | `long-term-branches` | Space-separated list of long-term branch names to scan in addition to the default branch (e.g. `'8.x 7.17'`) | No | `""` | | ||
| | `additional-instructions` | Repo-specific instructions appended to the agent prompt | No | `""` | | ||
| | `setup-commands` | Shell commands run before the agent starts | No | `""` | | ||
| | `allowed-bot-users` | Allowlisted bot actor usernames (comma-separated) | No | `github-actions[bot]` | | ||
| | `draft-prs` | Whether to create pull requests as drafts | No | `false` | | ||
|
|
||
| ## Safe Outputs | ||
|
|
||
| - `create-pull-request` — open one remediation PR per affected workflow (max 1 per workflow per run) | ||
| - `noop` — emitted when no matching failures are found | ||
|
|
||
| ## Behavior details | ||
|
|
||
| | Scenario | Outcome | | ||
| | --- | --- | | ||
| | No `Resource not accessible by integration` failures in last 24 h | `noop` — no PR opened | | ||
| | One workflow fails on one branch | One PR opened targeting that branch | | ||
| | Same workflow fails on multiple branches | One PR per branch to keep diffs reviewable | | ||
| | Multiple distinct workflows fail | One PR per workflow | | ||
|
|
||
| ## External remediation instructions | ||
|
|
||
| The agent fetches remediation instructions at runtime from: | ||
|
|
||
| ``` | ||
| https://raw.githubusercontent.com/elastic/observability-cicd/main/github-actions/actionable/alerts/app/prompts/accessible-by-integration.txt | ||
| ``` | ||
|
|
||
| If the fetch fails the agent falls back to the general principle of adding the minimum required `permissions` block to the failing workflow jobs. | ||
|
|
||
| ## Required permissions | ||
|
|
||
| The caller workflow must grant: | ||
|
|
||
| ```yaml | ||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| pull-requests: write | ||
| ``` |
19 changes: 19 additions & 0 deletions
19
gh-agent-workflows/resource-not-accessible-by-integration-fixer/example.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: Resource Not Accessible By Integration Fixer | ||
| on: | ||
| schedule: | ||
| - cron: "0 6 * * *" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| run: | ||
| uses: elastic/ai-github-actions/.github/workflows/gh-aw-resource-not-accessible-by-integration-fixer.lock.yml@v0 | ||
| with: | ||
| long-term-branches: "" | ||
| secrets: | ||
| COPILOT_GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.