Skip to content

Conversation

@yamoyamoto
Copy link
Contributor

@yamoyamoto yamoyamoto commented Oct 7, 2025

User description

Add error message to logging for model prediction failures in retry_with_fallback_models, capturing the exception message.

I’m currently encountering PR-Agent issue #2042 and need richer logs to investigate. No functional changes; logging-only.


PR Type

Enhancement


Description

  • Add exception details to model prediction failure logs

  • Improve error handling in retry_with_fallback_models function

  • Capture specific exception messages for debugging purposes


Diagram Walkthrough

flowchart LR
  A["Model Prediction"] -- "Exception occurs" --> B["Log Warning"]
  B -- "Enhanced with" --> C["Exception Message"]
Loading

File Walkthrough

Relevant files
Enhancement
pr_processing.py
Enhanced exception logging in retry function                         

pr_agent/algo/pr_processing.py

  • Enhanced exception handling to capture exception instance
  • Added exception message to warning log output
  • Improved debugging information for model prediction failures
+2/-2     

@qodo-merge-for-open-source
Copy link
Contributor

qodo-merge-for-open-source bot commented Oct 7, 2025

PR Compliance Guide 🔍

(Compliance updated until commit a194ca6)

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🟡
🎫 #2042
🟢 Add detailed error logging for model failures, including the exception message.
Improve visibility into which model failed during retries.
Preserve or improve final aggregated failure message when all fallback models fail.
🔴
Investigate large PR processing with different models (requires runtime validation).
Verify ARM64 host with AMD64 container compatibility (requires environment/runtime
validation).
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Consistent Naming Conventions

Objective: All new variables, functions, and classes must follow the project's established naming
standards

Status: Passed

No Dead or Commented-Out Code

Objective: Keep the codebase clean by ensuring all submitted code is active and necessary

Status: Passed

Robust Error Handling

Objective: Ensure potential errors and edge cases are anticipated and handled gracefully throughout
the code

Status: Passed

Single Responsibility for Functions

Objective: Each function should have a single, well-defined responsibility

Status: Passed

When relevant, utilize early return

Objective: In a code snippet containing multiple logic conditions (such as 'if-else'), prefer an
early return on edge cases than deep nesting

Status: Passed

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

Previous compliance checks

Compliance check up to commit be93651
Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🟡
🎫 #2042
🟢 Add detailed error logging when model prediction fails, including the exception message.
Improve visibility into which model/deployment failed during retries.
Enable investigation of large PR processing issues by enriching logs without changing
functionality.
🔴 Consider environment/compatibility factors in investigation (ARM64 host vs AMD64
container) – may require diagnostic logging.
None
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Consistent Naming Conventions

Objective: All new variables, functions, and classes must follow the project's established naming
standards

Status: Passed

No Dead or Commented-Out Code

Objective: Keep the codebase clean by ensuring all submitted code is active and necessary

Status: Passed

Robust Error Handling

Objective: Ensure potential errors and edge cases are anticipated and handled gracefully throughout
the code

Status: Passed

Single Responsibility for Functions

Objective: Each function should have a single, well-defined responsibility

Status: Passed

When relevant, utilize early return

Objective: In a code snippet containing multiple logic conditions (such as 'if-else'), prefer an
early return on edge cases than deep nesting

Status: Passed

@qodo-merge-for-open-source
Copy link
Contributor

qodo-merge-for-open-source bot commented Oct 7, 2025

PR Code Suggestions ✨

Latest suggestions up to a194ca6

CategorySuggestion                                                                                                                                    Impact
General
Log full, serializable error context

Enhance error logging by serializing the exception object, adding the stack
traceback, and including more context such as deployment ID and attempt number
in the log.

pr_agent/algo/pr_processing.py [332-338]

 except Exception as e:
     get_logger().warning(
-        f"Failed to generate prediction with {model}",
-        artifact={"error": e},
+        f"Failed to generate prediction with {model}{(' from deployment ' + deployment_id) if deployment_id else ''} on attempt {i + 1}/{len(all_models)}",
+        artifact={"error": str(e), "traceback": traceback.format_exc(), "deployment_id": deployment_id, "attempt": i + 1},
     )
     if i == len(all_models) - 1:  # If it's the last iteration
         raise Exception(f"Failed to generate prediction with any model of {all_models}") from e
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion significantly improves error logging by making the exception serializable, adding the stack trace, and including more context, which is crucial for debugging failures.

Medium
General
Log full exception traceback

Add the exception traceback to the log artifact to provide more context for
debugging, which is especially helpful in a retry mechanism.

pr_agent/algo/pr_processing.py [332-338]

 except Exception as e:
     get_logger().warning(
         f"Failed to generate prediction with {model}",
-        artifact={"error": e},
+        artifact={"error": str(e), "traceback": traceback.format_exc()},
     )
     if i == len(all_models) - 1:  # If it's the last iteration
         raise Exception(f"Failed to generate prediction with any model of {all_models}") from e
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: This is a valuable suggestion that significantly improves debuggability by logging the full traceback, which is crucial for diagnosing failures within a retry loop.

Medium
Possible issue
Make exception log serializable

Convert the raw exception object to a string before logging it in the artifact
to ensure it is serializable and prevent potential logging errors.

pr_agent/algo/pr_processing.py [332-338]

 except Exception as e:
     get_logger().warning(
         f"Failed to generate prediction with {model}",
-        artifact={"error": e},
+        artifact={"error": str(e)},
     )
     if i == len(all_models) - 1:  # If it's the last iteration
         raise Exception(f"Failed to generate prediction with any model of {all_models}") from e
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that logging a raw exception object can cause serialization issues and proposes converting it to a string, which is a robust practice for logging.

Low
  • More
  • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

Previous suggestions

✅ Suggestions up to commit be93651
CategorySuggestion                                                                                                                                    Impact
Possible issue
Preserve original exception context on failure
Suggestion Impact:The commit updated the final raise statement to include "from e", thereby preserving the original exception context as suggested.

code diff:

             if i == len(all_models) - 1:  # If it's the last iteration
-                raise Exception(f"Failed to generate prediction with any model of {all_models}")
+                raise Exception(f"Failed to generate prediction with any model of {all_models}") from e

Chain the last caught exception e when raising the final Exception to preserve
the original error context for better debugging.

pr_agent/algo/pr_processing.py [336-337]

 if i == len(all_models) - 1:  # If it's the last iteration
-    raise Exception(f"Failed to generate prediction with any model of {all_models}")
+    raise Exception(f"Failed to generate prediction with any model of {all_models}") from e

[Suggestion processed]

Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that chaining the original exception e will preserve the stack trace, which is crucial for debugging why all model predictions failed.

Medium

@ofir-frd ofir-frd self-requested a review October 10, 2025 07:13
Co-authored-by: qodo-merge-for-open-source[bot] <189517486+qodo-merge-for-open-source[bot]@users.noreply.github.com>
Copy link
Collaborator

@ofir-frd ofir-frd left a comment

Choose a reason for hiding this comment

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

Thanks @yamoyamoto , approved!

@ofir-frd ofir-frd merged commit 01a7c04 into qodo-ai:main Oct 11, 2025
2 checks passed
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