Skip to content

feat: implement issue #598 — [Phase 1] Idempotency guard: never create a duplicate epic for the same idea - #620

Merged
don-petry merged 12 commits into
mainfrom
dev-lead/issue-598-20260612-0137
Jun 14, 2026
Merged

don-petry merged 12 commits into
mainfrom
dev-lead/issue-598-20260612-0137

Conversation

@don-petry

@don-petry don-petry commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #598

Implemented by dev-lead agent. Please review.

Summary by CodeRabbit

  • New Features

    • Initiative planner now prevents duplicate epic creation by detecting existing epics for the same discussion source, improving idempotency.
  • Tests

    • Added test coverage verifying deduplication behavior and normal creation workflow.

@don-petry
don-petry requested a review from a team as a code owner June 12, 2026 01:40
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@don-petry, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 9 minutes and 40 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: cce5df2e-b745-4825-967d-1a806ee6e514

📥 Commits

Reviewing files that changed from the base of the PR and between 8671ac2 and ed58b53.

📒 Files selected for processing (3)
  • scripts/initiative-planner/apply-plan.sh
  • scripts/initiative-planner/lib/mutations.sh
  • tests/test_initiative_planner.bats
📝 Walkthrough

Walkthrough

The PR implements an idempotency guard for the initiative-planner that prevents duplicate epic creation. When apply-plan.sh runs, it now checks for an existing epic linked to the same source discussion before creating a new one. If found, it skips creation and exits cleanly; otherwise it proceeds with normal epic and DAG creation.

Changes

Initiative Planner Idempotency Guard

Layer / File(s) Summary
find_existing_epic helper function
scripts/initiative-planner/lib/mutations.sh
New helper searches for open initiative issues containing a back-reference marker. Supports DRY_RUN mode via DRY_RUN_EXISTING_EPIC stub for offline testing, and live mode queries gh issue list with exact body substring matching via jq to return matching issue number or nothing.
apply-plan.sh idempotency guard
scripts/initiative-planner/apply-plan.sh
Derives idem_key from source discussion number and embeds it in epic body. Calls find_existing_epic before epic creation; when an existing epic is found, logs to GITHUB_STEP_SUMMARY (DRY_RUN-aware) and exits 0. Otherwise builds epic body and continues with normal issue creation flow unchanged.
Idempotency test coverage
tests/test_initiative_planner.bats
Two test cases verify both control paths: one simulates existing epic via DRY_RUN_EXISTING_EPIC stub and asserts zero create operations; the other runs without stub and asserts all four expected create operations are logged (epic plus three stories).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

enhancement, initiative

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly aligns with the primary change: implementing an idempotency guard to prevent duplicate epic creation, which is the core objective of issue #598.
Linked Issues check ✅ Passed All coding requirements from issue #598 are met: find_existing_epic helper added [#598 AC#1,#4], called in apply-plan.sh with skip logic [#598 AC#1,#2], no-match path preserved [#598 AC#3], and bats coverage added for both paths [#598 AC#4,#5].
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the idempotency guard feature: modifications to apply-plan.sh, new helper in lib/mutations.sh, and test coverage—no unrelated changes detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev-lead/issue-598-20260612-0137

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 12, 2026 01:40

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request adds an idempotency guard to the initiative planner to prevent duplicate epic and DAG creation for the same idea discussion, along with corresponding unit tests. The feedback suggests wrapping the search query in literal double quotes in find_existing_epic to perform an exact phrase search, preventing unrelated issues from filling up the default 30-issue limit of gh issue list.

Comment thread scripts/initiative-planner/lib/mutations.sh
@don-petry
don-petry disabled auto-merge June 12, 2026 01:41
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 12, 2026
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-reviews (applied)

Changes committed and pushed.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 12, 2026 01:43
@don-petry
don-petry disabled auto-merge June 12, 2026 01:46
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 12, 2026 01:48
@don-petry
don-petry disabled auto-merge June 12, 2026 01:59
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 12, 2026 02:03
@don-petry
don-petry disabled auto-merge June 12, 2026 02:13
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry disabled auto-merge June 14, 2026 16:04
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 14, 2026 16:04
@don-petry
don-petry disabled auto-merge June 14, 2026 16:20
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 14, 2026 16:20
@don-petry
don-petry disabled auto-merge June 14, 2026 19:56
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 14, 2026 19:59
@don-petry
don-petry disabled auto-merge June 14, 2026 20:03
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-bot-comment (no-changes)

Agent reasoning
Issues addressed: 0
Files changed: none
Skipped: 0
Status: No changes required — all quality gates passed ✅
```

@don-petry
don-petry enabled auto-merge (squash) June 14, 2026 20:04
@sonarqubecloud

Copy link
Copy Markdown

@don-petry
don-petry disabled auto-merge June 14, 2026 20:46
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) June 14, 2026 20:48
@donpetry-bot donpetry-bot added the needs-human-review Flagged by automated PR review agent label Jun 14, 2026
@don-petry
don-petry merged commit e4890e7 into main Jun 14, 2026
27 checks passed
@don-petry
don-petry deleted the dev-lead/issue-598-20260612-0137 branch June 14, 2026 21:11
don-petry pushed a commit that referenced this pull request Jun 14, 2026
main shipped the prevent-duplicates idempotency guard (#620: find_existing_epic
+ the in-epic skip). The merge left two parallel guards. Collapse to one:

- Drop the duplicate find_existing_initiative_epic and the separate top-of-file
  gate; keep main's find_existing_epic as the single detector.
- Graft the net-new behavior onto main's guard: FORCE_REPLAN=1 records the
  existing epic for supersede and continues; the default skip now also posts an
  "already planned" discussion comment with a force_replan hint.
- list_sub_issue_numbers uses main's DRY_RUN stub convention
  (DRY_RUN_EXISTING_SUBISSUES) instead of a bespoke override.
- Tests repointed to DRY_RUN_EXISTING_EPIC / DRY_RUN_EXISTING_SUBISSUES; the
  first reframed to assert the skip-path discussion comment (main's test already
  covers no-creation).

shellcheck clean; 28/28 bats pass.

https://claude.ai/code/session_014djuNDBa3GASVDLQPXXg9L
don-petry added a commit that referenced this pull request Jun 15, 2026
* initiative-planner: idempotent re-plans with opt-in supersede

Re-approving / re-dispatching / re-toggling the label on an already-planned
discussion previously relied on the BMAD agent choosing not to re-create the
epic — a fragile guard the agent even mis-described as built-in when it was
not. The result was silent no-ops (discussion #653) with no audit trail and a
latent risk of duplicate epics.

Make apply-plan.sh own this decision deterministically via the back-reference
it already stamps on every epic ("Planned from idea discussion #<src>"):

- Default: if an OPEN `initiative` epic already exists for the discussion,
  create nothing and point the discussion back at it.
- FORCE_REPLAN=1 (new `force_replan` workflow input): supersede instead —
  build the fresh epic/DAG, then CLOSE (never delete) the old epic and its
  sub-issues with a "superseded by #NEW" note so history and inbound
  references stay resolvable.

The planner prompt now always runs apply-plan.sh and defers the
create/skip/supersede decision to the script. Read-path helpers honor
DRY_RUN/test overrides so the offline suite stays network-free.

Adds bats coverage for the guard no-op, the supersede path, and force_replan
with nothing to supersede.

https://claude.ai/code/session_014djuNDBa3GASVDLQPXXg9L

* initiative-planner: address review — bound issue list, harden supersede loop

- find_existing_initiative_epic: add `--limit 1000` to `gh issue list`. The
  default cap of 30 would miss an existing epic once the repo has >30 open
  `initiative` issues (it already has 80+), silently defeating the guard and
  risking duplicate epics.
- supersede loop: capture sub-issue numbers via command substitution instead of
  process substitution so a failed lookup trips `set -e` and aborts, rather than
  silently skipping the sub-issue closes.

https://claude.ai/code/session_014djuNDBa3GASVDLQPXXg9L

* initiative-planner: reconcile with main's #620 guard — supersede only

main shipped the prevent-duplicates idempotency guard (#620: find_existing_epic
+ the in-epic skip). The merge left two parallel guards. Collapse to one:

- Drop the duplicate find_existing_initiative_epic and the separate top-of-file
  gate; keep main's find_existing_epic as the single detector.
- Graft the net-new behavior onto main's guard: FORCE_REPLAN=1 records the
  existing epic for supersede and continues; the default skip now also posts an
  "already planned" discussion comment with a force_replan hint.
- list_sub_issue_numbers uses main's DRY_RUN stub convention
  (DRY_RUN_EXISTING_SUBISSUES) instead of a bespoke override.
- Tests repointed to DRY_RUN_EXISTING_EPIC / DRY_RUN_EXISTING_SUBISSUES; the
  first reframed to assert the skip-path discussion comment (main's test already
  covers no-creation).

shellcheck clean; 28/28 bats pass.

https://claude.ai/code/session_014djuNDBa3GASVDLQPXXg9L

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-human-review Flagged by automated PR review agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Phase 1] Idempotency guard: never create a duplicate epic for the same idea

2 participants