Skip to content

Fix: Clear old issues for KEEP/UPDATE when current newa_id found#354

Merged
kkaarreell merged 1 commit into
mainfrom
ks_fix_duplicate_old
Apr 23, 2026
Merged

Fix: Clear old issues for KEEP/UPDATE when current newa_id found#354
kkaarreell merged 1 commit into
mainfrom
ks_fix_duplicate_old

Conversation

@kkaarreell

@kkaarreell kkaarreell commented Apr 23, 2026

Copy link
Copy Markdown
Collaborator

When on_respin is set to KEEP or UPDATE and NEWA finds both:

  • An issue with the current newa_id (which gets re-used)
  • Old open/closed issues from previous respins with outdated newa_ids

The old issues were incorrectly being passed to _close_old_issues(), which expects to only receive issues when on_respin is CLOSE. This caused an "Invalid respin action" exception.

Changes:

  • Added logic to clear old_opened_issues and old_closed_issues when new_issues is found for KEEP/UPDATE actions
  • Added warning log for old open issues to alert users about potential orphaned issues that may need manual cleanup
  • Added debug log for old closed issues

🤖 Generated with Claude Code

Summary by Sourcery

Handle old JIRA issues correctly when reusing issues for a respin with KEEP or UPDATE actions.

Bug Fixes:

  • Prevent old respin issues with outdated newa_ids from being passed to logic that only supports CLOSE actions when KEEP or UPDATE is selected.

Enhancements:

  • Log warnings for ignored old open issues and debug messages for ignored old closed issues to aid in diagnosing potential orphaned JIRA issues.

When on_respin is set to KEEP or UPDATE and NEWA finds both:
- An issue with the current newa_id (which gets re-used)
- Old open/closed issues from previous respins with outdated newa_ids

The old issues were incorrectly being passed to _close_old_issues(),
which expects to only receive issues when on_respin is CLOSE.
This caused an "Invalid respin action" exception.

Changes:
- Added logic to clear old_opened_issues and old_closed_issues when
  new_issues is found for KEEP/UPDATE actions
- Added warning log for old open issues to alert users about potential
  orphaned issues that may need manual cleanup
- Added debug log for old closed issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@kkaarreell kkaarreell self-assigned this Apr 23, 2026
@sourcery-ai

sourcery-ai Bot commented Apr 23, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts Jira issue handling for KEEP/UPDATE respin actions so that only issues tied to the current newa_id are processed, clearing outdated issues and adding logging for potential manual cleanup.

Sequence diagram for KEEP/UPDATE respin issue handling with current newa_id

sequenceDiagram
    actor User
    participant NewaCli
    participant JiraHelpers
    participant JiraApi
    participant Logger

    User->>NewaCli: run_newa_with_on_respin_KEEP_or_UPDATE()
    NewaCli->>JiraHelpers: _find_or_create_issue(ctx, action, newa_id)

    JiraHelpers->>JiraApi: search_issues_by_newa_id(current_newa_id)
    JiraApi-->>JiraHelpers: new_issues_with_current_newa_id

    alt existing_issue_closed
        JiraHelpers->>JiraHelpers: reopen_issue(selected_issue)
        JiraHelpers->>JiraHelpers: mark_selected_issue_as_new()
    else existing_issue_open
        JiraHelpers->>JiraHelpers: mark_selected_issue_as_new()
    end

    JiraHelpers->>JiraHelpers: new_issues.append(selected_issue)
    JiraHelpers->>JiraHelpers: old_closed_issues = []

    alt action_on_respin_is_KEEP_or_UPDATE
        JiraHelpers->>JiraHelpers: detect_old_opened_issues_with_old_newa_id()
        alt old_opened_issues_not_empty
            JiraHelpers->>Logger: warning(Found old open issue ids, will be ignored)
            JiraHelpers->>JiraHelpers: old_opened_issues = []
        end

        JiraHelpers->>JiraHelpers: detect_old_closed_issues_with_old_newa_id()
        alt old_closed_issues_not_empty
            JiraHelpers->>Logger: debug(Ignoring old closed issue ids)
            JiraHelpers->>JiraHelpers: old_closed_issues = []
        end
    end

    JiraHelpers-->>NewaCli: return new_issues
    NewaCli-->>User: continue_processing_without_invalid_respin_error()
Loading

File-Level Changes

Change Details Files
Ensure old issues with outdated newa_ids are ignored when KEEP/UPDATE reuses current newa_id issues, with additional logging for visibility.
  • When new issues with the current newa_id are found, clear old_opened_issues and old_closed_issues for KEEP and UPDATE respin actions so they are not passed to old-issue handling logic
  • Log a warning listing IDs of old open issues that are being ignored, advising potential manual closure or use of CLOSE respin action
  • Log a debug message listing IDs of old closed issues that are being ignored to aid troubleshooting and traceability
newa/cli/jira_helpers.py

Possibly linked issues

  • #(not specified): PR fixes the reported invalid respin action KEEP error by clearing old issues for KEEP/UPDATE before closing.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've left some high level feedback:

  • The new else: block is attached to the preceding if (not shown here), but the comment inside assumes new_issues were found; consider making the condition explicit (e.g. if new_issues and action.on_respin in (...)) to avoid unintentionally changing control flow in other cases.
  • The warning/debug messages are quite long and repeat similar context; you might want to slightly shorten or factor shared phrasing to keep logs more readable while still conveying that old issues are being ignored for KEEP/UPDATE.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `else:` block is attached to the preceding `if` (not shown here), but the comment inside assumes `new_issues` were found; consider making the condition explicit (e.g. `if new_issues and action.on_respin in (...)`) to avoid unintentionally changing control flow in other cases.
- The warning/debug messages are quite long and repeat similar context; you might want to slightly shorten or factor shared phrasing to keep logs more readable while still conveying that old issues are being ignored for KEEP/UPDATE.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@kkaarreell kkaarreell merged commit 67aa0e7 into main Apr 23, 2026
18 checks passed
@kkaarreell kkaarreell deleted the ks_fix_duplicate_old branch April 23, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant