elastic / elastic/ai-github-actions
[refactor-opportunist] Extract shared request-mode routing for Mention in PR workflows
- Dominant language
- Python
- Stars
- 11
- Forks
- 16
- Avg merge
- 22h 9m
- Merged PRs (30d)
- 31
Description
## 🏗️ Refactor Proposal
**Summary:** Move the shared request-routing rules out of `gh-aw-mention-in-pr.md` into a reusable fragment so sandbox and no-sandbox PR assistants can converge on one source of truth.
## Problem
`mention-in-pr` and `mention-in-pr-no-sandbox` are tightly coupled workflow variants with high co-change, but shared instructions still live inline instead of in fragments.
Concrete evidence:
- `.github/workflows/gh-aw-mention-in-pr.md:152-156` contains request-mode routing rules inline (review vs fix vs merge-conflict vs question).
- `.github/workflows/gh-aw-mention-in-pr-no-sandbox.md:152-156` currently carries this responsibility in the sibling workflow body rather than a shared fragment path.
- 60-day churn signal:
- `.github/workflows/gh-aw-mention-in-pr.md`: **36** touches
- `.github/workflows/gh-aw-mention-in-pr-no-sandbox.md`: **23** touches
- commits touching both files: **22**
This is structural (not cosmetic): operational behavior guidance is duplicated across variant workflows, increasing drift risk whenever request-routing semantics evolve.
## Proposed Approach
Create a dedicated fragment for request routing order and import it from Mention-in-PR workflows.
- Shared logic moves to `.github/workflows/gh-aw-fragments/mention-pr-request-modes.md`.
- Workflow wrappers keep variant-specific behavior (sandbox config, safe-output differences, inputs).
## Proof of Concept
I partially implemented this refactor on one representative slice to verify viability.
**Files changed:**
- `.github/workflows/gh-aw-fragments/mention-pr-request-modes.md` (new)
- `.github/workflows/gh-aw-mention-in-pr.md`
- `.github/workflows/gh-aw-mention-in-pr.lock.yml` (compiled output)
- `gh-agent-workflows/DEVELOPING.md`
**Before → After:**
Before (`.github/workflows/gh-aw-mention-in-pr.md:152-156`):
```md
Based on what's asked, do the appropriate thing.
1. Determine the primary request mode: review, code fix/review feedback, merge conflict resolution, or code question.
2. **Requests can combine multiple actions** (e.g., "fix merge conflicts and address the review feedback"). When they do, handle them in this order: merge conflicts first, then code changes/review feedback, then push once at the end.
3. Do not push between steps — batch all changes into a single push.
```
After:
- Imported fragment in `.github/workflows/gh-aw-mention-in-pr.md:14`:
- `gh-aw-fragments/mention-pr-request-modes.md`
- Removed the inline 3-item routing block from `.github/workflows/gh-aw-mention-in-pr.md`
- Added shared fragment content:
- `.github/workflows/gh-aw-fragments/mention-pr-request-modes.md:1-5`
- Verified compiled workflow contains fragment text:
- `.github/workflows/gh-aw-mention-in-pr.lock.yml:389-391`
**Verification:**
- `make compile` ✅ (`0 error(s), 3 warning(s)`)
- `make lint` ✅
- `make test` initially failed due missing `uv` in this runner; executed equivalent test suite in a venv with `pytest tests/ -v` after installing test/docs dependencies ✅ (`53 passed`)
## Incremental Rollout Plan
This refactor can be completed incrementally:
1. **Completed:** extracted request-mode routing for `gh-aw-mention-in-pr.md` into a fragment.
2. Migrate `gh-aw-mention-in-pr-no-sandbox.md` to consume the same fragment.
3. Consolidate additional shared PR-assistant sections (context/constraints/review flow) into focused fragments while preserving wrapper-specific policy knobs.
## Risks and Mitigations
- **Risk:** wrapper/fragment split may accidentally drop variant-specific instructions.
**Mitigation:** keep fragment scope narrow (request-mode routing only) and retain variant-only directives in wrapper files.
- **Risk:** import-order confusion in long prompts.
**Mitigation:** document fragment purpose in `gh-agent-workflows/DEVELOPING.md` and keep one-fragment-per-concern granularity.
## Evidence
- `.github/workflows/gh-aw-mention-in-pr.md:14,152-156`
- `.github/workflows/gh-aw-fragments/mention-pr-request-modes.md:1-5`
- `.github/workflows/gh-aw-mention-in-pr.lock.yml:389-391`
- `.github/workflows/gh-aw-mention-in-pr-no-sandbox.md:152-156`
- Prior findings reviewed (`/tmp/previous-findings.json`): no existing issue for this specific mention-in-pr request-routing consolidation (distinct from #835 and #884).
> [!WARNING]
>
> ⚠️ Firewall blocked 1 domain
>
> The following domain was blocked by the firewall during workflow execution:
>
> - `astral.sh`
>
> To allow these domains, add them to the `network.allowed` list in your workflow frontmatter:
>
> ```yaml
> network:
> allowed:
> - defaults
> - "astral.sh"
> ```
>
> See [Network Configuration](https://github.github.com/gh-aw/reference/network/) for more information.
>
>
---
[What is this?](https://ela.st/github-ai-tools) | [From workflow: Trigger Refactor Opportunist](https://github.com/elastic/ai-github-actions/actions/runs/24672654166)
Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.
Contributor guide
Assessment
This issue has not been assessed yet.