Skip to content

fix(gitea): report success/failure and submit reviews, not drafts - #2878

Merged
IsmaelMartinez merged 2 commits into
The-PR-Agent:mainfrom
space-josh:fix/gitea-inline-comment-status
Sep 1, 2026
Merged

IsmaelMartinez merged 2 commits into
The-PR-Agent:mainfrom
space-josh:fix/gitea-inline-comment-status

Conversation

@space-josh

Copy link
Copy Markdown

Problem

With pr_code_suggestions.commitable_code_suggestions = true, /improve on a Gitea/Forgejo provider produces two bugs:

  1. Every suggestion gets duplicated. GiteaProvider.publish_inline_comments/publish_code_suggestions never returned a value (implicit None). PRCodeSuggestions.push_inline_code_suggestions checks the return of publish_code_suggestions and, on falsy, republishes every suggestion individually as a fallback - so a fully successful publish is always treated as a failure and every suggestion is posted twice.
  2. The review is invisible. RepoApi.create_inline_comment POSTs to /pulls/{id}/reviews without an event field. Per the Gitea/Forgejo API, an event-less review defaults to a draft (PENDING), visible only to its author until someone manually submits it - and nothing in this flow ever does.

Fix

  • publish_inline_comments and publish_code_suggestions now return bool, reflecting whether the underlying API call actually succeeded.
  • create_inline_comment submits "event": "COMMENT" so the review lands as a normal, visible comment instead of a stuck draft.

Verification

  • Added TestGiteaProviderInlineCommentStatus (5 tests) covering both failure modes. Confirmed each fails against the pre-fix code and passes against the fix.
  • pytest tests/unittest/test_gitea_provider.py: 44 passed.
  • Also verified against a live Forgejo instance (not just mocks): before the fix, one /improve call left a PENDING review with a duplicated inline comment; after the fix, exactly one COMMENT-state review with exactly one comment.

Both bugs are gated behind commitable_code_suggestions = true (default false), which explains why they haven't surfaced before - the default /improve path uses a different, single-comment publish method untouched by this change.

`publish_inline_comments`/`publish_code_suggestions` never returned a
value, so `PRCodeSuggestions.push_inline_code_suggestions` always
treated a successful publish as failed and republished every
suggestion a second time, duplicating each one on the PR.

`create_inline_comment` also posted to `/pulls/{id}/reviews` without
an `event`. Gitea/Forgejo defaults an event-less review to a draft
(state `PENDING`), invisible to everyone but its author - there is no
later step anywhere in this flow that submits it, so with
`commitable_code_suggestions = true` every `/improve` review was
silently invisible to the PR author and any other reviewer.

Both bugs only surface with `commitable_code_suggestions = true`
(default `false`), which is presumably why they haven't been caught:
the default `/improve` path uses a different, single-comment publish
method untouched by this fix.

Verified against a live Forgejo instance (not just mocks): before the
fix, one `/improve` call left a `PENDING` review with a duplicated
suggestion; after, exactly one `COMMENT`-state review with one
comment. Added regression tests for both failure modes; confirmed
each new test fails against the pre-fix code and passes against the
fix.
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Fix Gitea inline suggestion status and review submission

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Return publication outcomes so successful Gitea suggestions are not duplicated.
• Submit inline reviews as visible comments instead of pending drafts.
• Add regression coverage for success, failure, deduplication, and review state.
Diagram

graph TD
  A["Improve Command"] --> B["Suggestion Flow"] --> C["Gitea Provider"] --> D["Repo API"]
  D -- "event: COMMENT" --> E["Reviews Endpoint"] --> F["Visible Review"]
  E -- "API result" --> D -- "boolean status" --> C -- "fallback decision" --> B
Loading
High-Level Assessment

The current approach is optimal: it honors the provider's existing boolean publication contract and atomically creates a submitted COMMENT review. Creating a draft and invoking a separate submit endpoint would add another failure point without providing value for this flow.

Files changed (2) +92 / -5

Bug fix (1) +15 / -5
gitea_provider.pyPropagate publication status and submit visible reviews +15/-5

Propagate publication status and submit visible reviews

• Returns explicit success or failure from inline comment publication and aggregates results across code suggestions, allowing callers to invoke fallback only on genuine failures. Adds the COMMENT event to Gitea/Forgejo review creation so inline reviews are immediately submitted and visible.

pr_agent/git_providers/gitea_provider.py

Tests (1) +77 / -0
test_gitea_provider.pyCover inline publication outcomes and submitted review state +77/-0

Cover inline publication outcomes and submitted review state

• Adds five regression tests for successful and failed inline publication, aggregate code suggestion status without duplicate API calls, and inclusion of the COMMENT review event.

tests/unittest/test_gitea_provider.py

@qodo-code-review

qodo-code-review Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (3) 📜 Skill insights (0)

Grey Divider


Action required

1. API errors bypass fallback 🐞 Bug ☼ Reliability
Description
publish_inline_comments returns False only for a falsy normal response, but it does not catch
ApiException or other errors from create_inline_comment. Consequently, ordinary request failures
propagate out of publish_code_suggestions instead of returning False, so the caller's
individual-suggestion fallback never runs.
Code

pr_agent/git_providers/gitea_provider.py[R409-411]

        if not response:
            self.logger.error("Failed to publish inline comment")
-            return
+            return False
Relevance

●●● Strong

Recent reliability precedents accept boolean failure propagation so callers can execute fallback
paths.

PR-#2492
PR-#2404

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
create_inline_comment directly returns ApiClient.call_api, but the changed publisher has no
exception handling around it. Elsewhere this same provider catches ApiException around repository
API operations and specifically around a direct call_api, proving that failures use the exception
path; the fallback caller only reacts to a returned falsy value.

pr_agent/git_providers/gitea_provider.py[399-414]
pr_agent/git_providers/gitea_provider.py[883-902]
pr_agent/git_providers/gitea_provider.py[941-968]
pr_agent/tools/pr_code_suggestions.py[825-834]
PR-#2492

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new boolean contract does not cover exceptions raised by the Gitea API client. A failed review request can escape from `publish_inline_comments`, abort the loop, and prevent `PRCodeSuggestions.push_inline_code_suggestions` from executing its fallback.

## Issue Context
Other Gitea provider operations explicitly catch `ApiException`, and direct `call_api` usage in this module documents that API failures are raised. Catch expected publication exceptions, log them, and return `False` while preserving an appropriate policy for unexpected programming errors.

## Fix Focus Areas
- pr_agent/git_providers/gitea_provider.py[399-414]
- pr_agent/git_providers/gitea_provider.py[883-902]
- pr_agent/tools/pr_code_suggestions.py[825-834]
- tests/unittest/test_gitea_provider.py[830-858]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Partial failures duplicate suggestions ✓ Resolved 🐞 Bug ≡ Correctness
Description
publish_code_suggestions publishes suggestions one at a time but collapses their results into one
False; the caller then republishes the entire list, including suggestions already posted
successfully. Any mixed-success run therefore still creates duplicate review comments for the
successful subset.
Code

pr_agent/git_providers/gitea_provider.py[R432-434]

+                all_successful &= self.publish_inline_comments([payload],title_body)
            else:
-                self.publish_inline_comments([payload])
+                all_successful &= self.publish_inline_comments([payload])
Relevance

●●● Strong

PR #2404 explicitly accepted guarding fallback paths against duplicate publication after partial or
failed updates.

PR-#2404

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Gitea invokes publish_inline_comments separately for every suggestion and aggregates those
independent outcomes, while the only consumer interprets a false aggregate as permission to replay
every original suggestion. The accepted PR #2404 identifies the same duplicate-thread pattern when a
fallback is allowed to run after partial success.

pr_agent/git_providers/gitea_provider.py[416-435]
pr_agent/tools/pr_code_suggestions.py[825-834]
pr_agent/git_providers/gitea_provider.py[883-902]
PR-#2404

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`GiteaProvider.publish_code_suggestions` posts each suggestion independently, then returns one aggregate boolean. If some requests succeed and a later request fails, `PRCodeSuggestions.push_inline_code_suggestions` retries the full list and duplicates every suggestion that already succeeded.

## Issue Context
The generic caller only receives a boolean, so it cannot identify which Gitea suggestions need retrying. Preserve all-at-once success/failure semantics by batching the comments into a single review when possible, or handle per-item failures inside the provider without causing the caller to replay already successful items.

## Fix Focus Areas
- pr_agent/git_providers/gitea_provider.py[416-435]
- pr_agent/tools/pr_code_suggestions.py[825-834]
- tests/unittest/test_gitea_provider.py[840-858]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Regression docstring lacks imperative 📘 Rule violation ⚙ Maintainability
Description
The new class docstring begins with the noun phrase Regression tests for... rather than an
imperative verb. It does not follow the required imperative docstring convention.
Code

tests/unittest/test_gitea_provider.py[R802-805]

+    """Regression tests for the ``/improve`` inline-comment path:
+
+    1. ``publish_inline_comments``/``publish_code_suggestions`` never reported
+       success or failure, so ``PRCodeSuggestions.push_inline_code_suggestions``
Relevance

●●● Strong

Recent reviews accepted imperative rewrites for newly added test class and regression docstrings.

PR-#2807
PR-#2703

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 2694688 requires added docstrings to begin with imperative phrasing, while this docstring
begins Regression tests for and continues with narrative descriptions of past behavior.

Rule 2694688: Docstrings and comments must use imperative phrasing
tests/unittest/test_gitea_provider.py[802-811]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Rewrite the new regression-test docstring so its opening description uses imperative phrasing.

## Issue Context
Compliance rule 2694688 applies to newly added docstrings and requires imperative wording such as `Verify` or `Test`.

## Fix Focus Areas
- tests/unittest/test_gitea_provider.py[802-811]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Review comment uses narrative phrasing 📘 Rule violation ⚙ Maintainability
Description
The new block comment starts with the descriptive statement Gitea/Forgejo defaults... rather than
an imperative instruction. This violates the required comment phrasing convention.
Code

pr_agent/git_providers/gitea_provider.py[R888-891]

+            # Gitea/Forgejo defaults an event-less review to a draft (state
+            # PENDING), invisible to everyone but the review's author until
+            # someone manually submits it from the web UI. There is no such
+            # "submit" step in this flow, so the review must be submitted as
Relevance

●●● Strong

Recent repository reviews accepted rewriting narrative behavior comments into imperative phrasing
under this convention.

PR-#2797
PR-#2817

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 2694688 requires behavior comments to use imperative phrasing; the cited added comment narrates
Gitea/Forgejo behavior with defaults, submits, and must be submitted instead.

Rule 2694688: Docstrings and comments must use imperative phrasing
pr_agent/git_providers/gitea_provider.py[888-892]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Rewrite the review-event explanation as an imperative code comment rather than narrative prose.

## Issue Context
Compliance rule 2694688 requires newly added comments that describe behavior to use command-style phrasing.

## Fix Focus Areas
- pr_agent/git_providers/gitea_provider.py[888-892]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

5. Test comment uses narrative phrasing 📘 Rule violation ⚙ Maintainability
Description
The new test comment narrates historical behavior with Before the fix... instead of giving an
imperative instruction. This violates the prescribed style for behavior comments.
Code

tests/unittest/test_gitea_provider.py[R841-843]

+        # Before the fix, a truthy result here was still treated as failure by
+        # PRCodeSuggestions.push_inline_code_suggestions, which republished
+        # every suggestion a second time.
Relevance

● Weak

A closely matching recent review rejected rewriting a narrative behavior comment into imperative
phrasing.

PR-#2774

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Rule 2694688 requires behavior comments to be phrased as commands; the cited comment instead
narrates what happened before the fix and what the caller did.

Rule 2694688: Docstrings and comments must use imperative phrasing
tests/unittest/test_gitea_provider.py[841-843]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Rewrite the test comment as an imperative explanation of what the assertion should verify.

## Issue Context
Compliance rule 2694688 requires behavior comments to use command-style rather than narrative phrasing.

## Fix Focus Areas
- tests/unittest/test_gitea_provider.py[841-843]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


  • Author self-review: I have reviewed the code review findings, and addressed the relevant ones.

Grey Divider

Context sources
✅ Compliance rules (platform): 34 rules
Review mode: ⚖️ Balanced: This is a localized behavioral fix in a provider/API integration, with meaningful correctness impact and multiple related paths, but not a dense enough change to warrant redundant extended review.

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines 409 to +411
if not response:
self.logger.error("Failed to publish inline comment")
return
return False

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.

Action required

5. Api errors bypass fallback 🐞 Bug ☼ Reliability

publish_inline_comments returns False only for a falsy normal response, but it does not catch
ApiException or other errors from create_inline_comment. Consequently, ordinary request failures
propagate out of publish_code_suggestions instead of returning False, so the caller's
individual-suggestion fallback never runs.
Agent Prompt
## Issue description
The new boolean contract does not cover exceptions raised by the Gitea API client. A failed review request can escape from `publish_inline_comments`, abort the loop, and prevent `PRCodeSuggestions.push_inline_code_suggestions` from executing its fallback.

## Issue Context
Other Gitea provider operations explicitly catch `ApiException`, and direct `call_api` usage in this module documents that API failures are raised. Catch expected publication exceptions, log them, and return `False` while preserving an appropriate policy for unexpected programming errors.

## Fix Focus Areas
- pr_agent/git_providers/gitea_provider.py[399-414]
- pr_agent/git_providers/gitea_provider.py[883-902]
- pr_agent/tools/pr_code_suggestions.py[825-834]
- tests/unittest/test_gitea_provider.py[830-858]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, and both diagnoses hold: the event-less review really does stay PENDING, and the falsy return really does republish every suggestion.

Disclosure: I have an older PR of my own, #2716, covering the return-value half only. Yours is the fuller fix, so I will close mine in its favour once this lands.

One change first, on the duplication Qodo flagged. Patch inline. You can disregard its three phrasing findings, which are a platform rule rather than ours.

else:
self.publish_inline_comments([payload])
all_successful &= self.publish_inline_comments([payload])
return all_successful

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Qodo is right here. This aggregates all-succeeded, so with three suggestions where the second fails you return False, the caller replays the whole list, and the two that already succeeded post a second time. Measured on a merged tree: 6 API calls against 3 for any-succeeded.

Not a one-click suggestion, because the initialiser on line 418 sits in a different hunk from this one and applying half of it would break the function. The whole change:

-        all_successful = True
+        publishable_count = 0
+        published_count = 0
         for suggestion in suggestions:
             ...
             payload = dict(body=body, path=path, old_position=old_position,new_position = new_position)
+            publishable_count += 1
             if title_body:
                 title_body = f"**Suggestion:** {title_body}"
-                all_successful &= self.publish_inline_comments([payload],title_body)
+                published = self.publish_inline_comments([payload],title_body)
             else:
-                all_successful &= self.publish_inline_comments([payload])
-        return all_successful
+                published = self.publish_inline_comments([payload])
+            if published:
+                published_count += 1
+
+        # A partial failure must not report failure: the caller republishes the whole
+        # list, which would post the already-accepted suggestions a second time.
+        return published_count > 0 or publishable_count == 0

Worth a sixth test for the partial-failure case, since none of the five cover it.

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.

Agreed. all_successful is unsafe here because the caller retries the entire batch after any False, duplicating suggestions that already succeeded. The published_count > 0 or publishable_count == 0 result preserves the caller’s retry contract while preventing retries after partial success. I also agree a partial-failure regression test is needed, asserting three suggestions make only three API calls and return True when one fails.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Applied exactly as diffed - publishable_count/published_count, false only when nothing published. Added the partial-failure test too: 3 suggestions, second fails, asserts call_count == 3 and result is True. Confirmed it fails against the pre-fix all_successful &= logic before reapplying the patch.

Separately: Qodo also flagged that publish_inline_comments does not catch ApiException from create_inline_comment, so a real API error propagates instead of returning False, which would skip the caller's fallback too. You didn't call that one out - want it folded into this PR, or should it be a separate issue/PR?

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.

Keep it as a separate issue/PR. This change already fixes two focused behaviors: review visibility and duplicate retries after partial success. Catching ApiException changes error-handling and retry semantics, especially when earlier suggestions in the batch were already accepted.

If pursued separately, add tests for:

  • an exception on the first suggestion returning False;
  • an exception after a successful suggestion not causing the caller to replay the whole batch;
  • logging the exception details without hiding the failure.

The current partial-failure test covers False responses, but not raised API exceptions.

publish_code_suggestions aggregated per-suggestion results with
`all_successful &=`, so any single failure in a batch made the whole
call report failure. The caller (push_inline_code_suggestions) then
replays the entire suggestion list on any falsy result, reposting the
ones that already succeeded - three suggestions with one failure
becomes six API calls instead of three.

Track publishable/published counts instead and report failure only
when nothing published, matching the caller's retry contract: republish
only on a genuinely empty result.

Per review on The-PR-Agent#2878.
@qodo-code-review

qodo-code-review Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

Grey Divider

Sorry, something went wrong

We weren't able to complete the code review on our side. Please try again manually by commenting /agentic_review on this PR.

Grey Divider

Qodo Logo

@IsmaelMartinez IsmaelMartinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving. You applied the aggregation change exactly as diffed and the partial-failure test does what it claims: against main all six new tests go red, and the 45 gitea tests pass on the merged tree.

Agreed on deferring Qodo's ApiException finding, and I traced it rather than taking the agreement at face value. push_inline_code_suggestions runs inside a try/except in pr_code_suggestions.py, so an exception is logged rather than crashing /improve. It costs the fallback republish, which is a degradation and not a break, so a separate PR is the right call.

As promised, I will close my own #2716 in favour of this once it lands. Same gate as the other first-time contributions: only the release drafter has run, so the queued workflows need releasing before it can merge.

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.

2 participants