Skip to content

fix: generate issue summaries after save - #5568

Open
Tanishq-mellu wants to merge 2 commits into
OWASP:mainfrom
Tanishq-mellu:fix/5506-ai-summary-fallback
Open

Tanishq-mellu wants to merge 2 commits into
OWASP:mainfrom
Tanishq-mellu:fix/5506-ai-summary-fallback

Conversation

@Tanishq-mellu

Copy link
Copy Markdown
Contributor

Summary

Fixes #5506
Fixes AI-generated issue summaries for newly created GitHub issues.

Root Cause

Issue.save() previously attempted to generate the AI summary before the issue was persisted.

For a newly created issue, self.id was still None. Since generate_summary() checks is_indexable, and is_indexable requires the issue to have an ID, summary generation returned early.

As a result, newly created issues could be saved without an AI-generated summary.

Changes

  • Save the issue before generating its AI summary.
  • Generate the summary after the issue has been persisted.
  • Persist the generated summary with a second save.
  • Fall back to the issue body when the AI completion returns an empty result.
  • Add a regression test verifying that summary generation occurs after the issue receives its database ID.
  • Add coverage for the empty AI response fallback.

Testing

Targeted unit tests

poetry run pytest tests/unit/apps/github/models/issue_test.py -q
--cov=apps.github.models.issue
--cov-report=term-missing
--cov-fail-under=0

20 passed
apps/github/models/issue.py: 100% coverage

Additional validation

git diff --check

@coderabbitai

coderabbitai Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 1bb6171f-38dc-4552-b6a1-fe0cf3041ff6

📥 Commits

Reviewing files that changed from the base of the PR and between 6465cd2 and 90f1ed5.

📒 Files selected for processing (1)
  • backend/src/apps/github/models/issue.py

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 2dda6544-48e6-4796-9753-0ee7a549f988

📥 Commits

Reviewing files that changed from the base of the PR and between 12e607f and 7212928.

📒 Files selected for processing (2)
  • backend/src/apps/github/models/issue.py
  • backend/tests/unit/apps/github/models/issue_test.py

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


Summary by CodeRabbit

  • Bug Fixes

    • Issue summaries now fall back to the issue body when no AI-generated content is available.
    • Summaries are generated after an issue is saved, ensuring they can use the assigned issue identifier.
  • Tests

    • Added coverage for summary fallback behavior and post-save summary generation.

Walkthrough

The issue model now uses the issue body when AI summary generation returns no content. It saves open issues before generating summaries, then persists the summary with a second save. Tests cover both behaviors.

Changes

Issue summary persistence

Layer / File(s) Summary
Summary fallback behavior
backend/src/apps/github/models/issue.py, backend/tests/unit/apps/github/models/issue_test.py
Empty AI responses now fall back to the issue body. The unit test expects "Test Body".
Post-save summary generation
backend/src/apps/github/models/issue.py, backend/tests/unit/apps/github/models/issue_test.py
Issue.save generates the hint before the initial save and the summary after the issue receives an id. A second save persists the summary. The test verifies both saves and the summary-generation order.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 6465c

New issue summaries are generated after the issue is saved, but the follow-up summary save may not use the same database as the initial save. In deployments using non-default database aliases, cards could still lack persisted summaries; routing should be corrected before merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: generating issue summaries after the issue is saved.
Description check ✅ Passed The description directly explains the summary-generation bug, the fallback behavior, the implementation changes, and the regression tests.
Linked Issues check ✅ Passed The changes address issue #5506 by generating summaries after persistence, falling back to the issue body when the AI response is empty, and adding regression coverage for both behaviors.
Out of Scope Changes check ✅ Passed The changes are limited to issue summary generation, fallback behavior, persistence, and related unit tests. No unrelated changes are present.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_signature: One or more commits are not signed.

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Sep 10, 2026
@Tanishq-mellu
Tanishq-mellu force-pushed the fix/5506-ai-summary-fallback branch from 7212928 to afd78b7 Compare September 10, 2026 14:29
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_signature: One or more commits are not signed.

Signed-off-by: Tanishq-mellu <tnshqmeshram@gmail.com>
@Tanishq-mellu
Tanishq-mellu force-pushed the fix/5506-ai-summary-fallback branch from afd78b7 to 6465cd2 Compare September 10, 2026 14:36

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found and verified against the latest diff

Confidence score: 4/5

  • backend/src/apps/github/models/issue.py still generates and saves a summary when callers intentionally use Django’s valid save(update_fields=[]) no-op, causing unexpected work and persistence changes; return early for an empty update_fields before hint generation or the first save.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/src/apps/github/models/issue.py">

<violation number="1" location="backend/src/apps/github/models/issue.py:192">
P2: When callers use Django’s valid `save(update_fields=[])` no-op, this branch still generates and saves a summary. Return immediately for an empty `update_fields` before running hint generation or the first save.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/src/apps/github/models/issue.py
Comment thread backend/src/apps/github/models/issue.py Outdated

if not self.summary:
self.generate_summary()
if self.is_open and not self.hint:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: When callers use Django’s valid save(update_fields=[]) no-op, this branch still generates and saves a summary. Return immediately for an empty update_fields before running hint generation or the first save.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/src/apps/github/models/issue.py, line 192:

<comment>When callers use Django’s valid `save(update_fields=[])` no-op, this branch still generates and saves a summary. Return immediately for an empty `update_fields` before running hint generation or the first save.</comment>

<file context>
@@ -185,19 +185,19 @@ def generate_summary(self, open_ai: OpenAi | None = None, max_tokens: int = 500)
-
-            if not self.summary:
-                self.generate_summary()
+        if self.is_open and not self.hint:
+            self.generate_hint()
 
</file context>
Suggested change
if self.is_open and not self.hint:
if "update_fields" in kwargs and not kwargs["update_fields"]:
return
if self.is_open and not self.hint:

Comment thread backend/tests/unit/apps/github/models/issue_test.py
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

1 similar comment
@github-actions

Copy link
Copy Markdown

Contribution validation failed:

  • commit_sign_off: One or more commits are missing or have an invalid Signed-off-by trailer.

@sonarqubecloud

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread backend/src/apps/github/models/issue.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix AI-generated issue summaries and add fallback

1 participant