Repository navigation
Closed
Labels
dev-leadFor dev-lead agent pickupFor dev-lead agent pickupinitiativeEpic / initiative tracking issueEpic / initiative tracking issue
Description
Story
As a maintainer running the initiative-planner,
I want apply-plan.sh to detect an already-materialized epic for the same discussion and skip creation instead of producing a duplicate,
so that a second dispatch or auto-trigger for the same idea never creates a duplicate epic + DAG.
Acceptance Criteria
- Before creating the epic, apply-plan.sh searches open
initiativeissues for the back-reference it already embeds in every epic body (Planned from idea discussion #<N>) for the current source discussion number. - If a matching epic is found, apply-plan.sh creates no issues, prints a clear
already planned (epic #X)message plus a step-summary note, and exits 0 (a benign re-run, not a failure). - If no match is found, behavior is unchanged: the epic + story sub-issues + DAG are created exactly as today.
- The search is performed via a DRY_RUN-aware helper in lib/mutations.sh that the offline bats suite can stub, so both paths are tested without touching the network.
- New bats cases in tests/test_initiative_planner.bats prove: with a simulated existing epic the run logs zero
create_issueops; with none it still logs the 4 creates.
Tasks / Subtasks
- Add a DRY_RUN-aware
find_existing_epichelper to lib/mutations.sh that, live, runsgh issue list --repo "$REPO" --label initiative --state open --search '<back-reference>'and returns a matching epic number (or empty); in DRY_RUN returns empty unless a test override env is set. (AC: test issue from agent #1, Optimize review: small-PR and incremental fast paths #4)- Reuse the exact back-reference string from apply-plan.sh (
Planned from idea discussion #${src}) as the idempotency key - Expose a stub hook (env override) so tests can simulate an existing epic offline
- Reuse the exact back-reference string from apply-plan.sh (
- Call the helper in apply-plan.sh immediately before the epic
create_issueand short-circuit (message + step summary + exit 0) when a match is found. (AC: test issue from agent #1, Go-live improvements for PR review agent #2) - Confirm the no-match path leaves the existing create/link/edge flow untouched. (AC: Add @claude delegation, auto-merge, and rebase handling #3)
- Add bats coverage for both the skip and the normal path. (AC: Optimize review: small-PR and incremental fast paths #4, feat: add Copilot engine support via REVIEW_ENGINE toggle #5)
Dev Notes
- The epic body already embeds the back-reference at apply-plan.sh:42-44 (
Planned from idea discussion #${src}). Reuse that EXACT string as the idempotency key — do not invent a new marker. - Put the search in scripts/initiative-planner/lib/mutations.sh alongside create_issue/link_sub_issue so it inherits the DRY_RUN switch and stays stubbable; the bats suite is fully offline (DRY_RUN=1, DRY_RUN_LOG).
- The concurrency group in .github/workflows/initiative-planner.yml:45-48 only blocks CONCURRENT runs, not sequential re-dispatches — confirmed in discussion 💡 Adversarial Plan-Critic + Structural Gates for the Initiative-Planner (Bob) #593; this guard closes that gap.
- Skip must exit 0, not error: a duplicate dispatch is benign. Emit to GITHUB_STEP_SUMMARY like the existing block at apply-plan.sh:129-137.
- Testing: mirror the existing DRY_RUN patterns in tests/test_initiative_planner.bats (grep -c '"op":"create_issue"' on the log).
Project Structure Notes
Pure addition to existing planner scripts; no new files beyond test cases. New shell must pass shellcheck --severity=warning -x (AGENTS.md / lint.yml shellcheck job).
References
- scripts/initiative-planner/apply-plan.sh#L37-L48
- scripts/initiative-planner/lib/mutations.sh#L41-L68
- .github/workflows/initiative-planner.yml#L45-L48
- tests/test_initiative_planner.bats#L75-L101
Likely target surface
scripts/initiative-planner/apply-plan.shscripts/initiative-planner/lib/mutations.shtests/test_initiative_planner.bats
Story prepared by the BMAD Scrum Master (Bob) for epic #597. Status: ready-for-dev.
Metadata
Metadata
Assignees
Labels
dev-leadFor dev-lead agent pickupFor dev-lead agent pickupinitiativeEpic / initiative tracking issueEpic / initiative tracking issue
Activity
don-petry commentedon Jun 12, 2026
Dev-Lead Implementation Plan
Issue: #598 — [Phase 1] Idempotency guard: never create a duplicate epic for the same idea
Scope
Add a DRY_RUN-aware
find_existing_epichelper tolib/mutations.shand call it inapply-plan.shbefore epic creation, short-circuiting (message + step-summary + exit 0) when an openinitiativeepic already embeds thePlanned from idea discussion #<N>back-reference for the current source discussion.Implementation Checklist
scripts/initiative-planner/lib/mutations.sh: addfind_existing_epic <repo> <back_reference>— live runsgh issue list --repo --label initiative --state open --search, filters by exact bodycontains, prints matching epic number or empty; DRY_RUN returns empty unlessDRY_RUN_EXISTING_EPICstub env is setscripts/initiative-planner/apply-plan.sh: extract the exactPlanned from idea discussion #${src}string into a reused idempotency-key var; call helper before the epiccreate_issue; on match, printalready planned (epic #X), write a step-summary note, andexit 0Tests to Write
tests/test_initiative_planner.bats: skip path —DRY_RUN_EXISTING_EPICset → 0create_issueops, exit 0,already planned (epic #X)in outputtests/test_initiative_planner.bats: no-match path — guard unset → still logs the 4create_issueopsTest Command
bats tests/test_initiative_planner.batsandbash .dev-lead/scripts/dev-lead-lint.shdon-petry commentedon Jun 12, 2026
Dev-Lead: Implementation Complete
Plan Execution
find_existing_epic <repo> <back_reference>tolib/mutations.sh(live:gh issue list --label initiative --state open --search, re-filtered with an exactcontainsbody match; DRY_RUN returns theDRY_RUN_EXISTING_EPICstub env, empty if unset)Planned from idea discussion #${src}string into a reusedidem_keyvar inapply-plan.shand called the guard immediately before the epiccreate_issuealready planned (epic #X), writes aGITHUB_STEP_SUMMARYnote, andexit 0(benign re-run)dev-lead-lint.sh(shellcheck warning -x + agent frontmatter) passesTest Results
Files Changed
scripts/initiative-planner/lib/mutations.sh: newfind_existing_epichelper (DRY_RUN-aware, stubbable viaDRY_RUN_EXISTING_EPIC)scripts/initiative-planner/apply-plan.sh: idempotency guard before epic creation — reuses the exact back-reference key, short-circuits with message + step summary + exit 0 on a matchtests/test_initiative_planner.bats: two new cases (skip path logs 0 creates; no-match path still logs 4 creates)Notes
ghresults with an exactcontains($ref)so a tokenized full-text hit on a different discussion cannot produce a false match.srcnon-empty); with no source, behavior is unchanged.feat: implement issue #598 — [Phase 1] Idempotency guard: never creat…
feat: implement issue #598 — initiative-planner idempotency guard (no…