Skip to content

Consolidate Retry Utilities and Centralize API Responses#7

Merged
arn0ld87 merged 1 commit intomainfrom
refactor/retry-utils-api-migration-1182158918778102176
Apr 23, 2026
Merged

Consolidate Retry Utilities and Centralize API Responses#7
arn0ld87 merged 1 commit intomainfrom
refactor/retry-utils-api-migration-1182158918778102176

Conversation

@arn0ld87
Copy link
Copy Markdown
Owner

This PR consolidates the fragmented retry implementations in backend/app/utils/retry.py into a single, robust mechanism with consistent semantics and logging. It also completes the rollout of centralized API response and error handling to the remaining core API modules (graph.py, report.py, simulation_prepare.py, simulation_profiles.py, and status.py), significantly reducing boilerplate and improving maintainability.

Key changes:

  • Centralized backoff, jitter, and logging logic in a private _RetryState class.
  • Unified max_retries behavior: max_retries=3 now consistently means 4 total attempts.
  • Fixed a bug where retry_with_backoff_async could raise None on certain failure paths.
  • Replaced manual try-except blocks in API handlers with the @handle_api_errors decorator.
  • Added 9 new unit tests covering various retry scenarios.
  • Expanded the scoped Ruff linting to include the refactored modules.

Fixes #6


PR created automatically by Jules for task 1182158918778102176 started by @arn0ld87

- Consolidated retry logic in `backend/app/utils/retry.py` using a shared `_RetryState` helper.
- Standardized `max_retries` semantics to mean "additional attempts after the initial try" across all retry helpers.
- Migrated `graph.py`, `report.py`, `simulation_prepare.py`, `simulation_profiles.py`, and `status.py` to use centralized response handling (`@handle_api_errors`, `json_success`, `json_error`).
- Added comprehensive unit tests for retry logic in `tests/test_retry.py`.
- Updated existing tests and CI/linting configuration to include newly cleaned modules.

Co-authored-by: arn0ld87 <212052432+arn0ld87@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown

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

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 standardizes API responses and error handling across several modules using decorators and utility functions. It also consolidates the retry logic for synchronous and asynchronous calls into a unified internal state tracker. Review feedback suggests moving a local import in graph.py to the top level for PEP 8 compliance and restoring detailed docstring documentation in report.py.

Comment thread backend/app/api/graph.py

except Exception as e:
# Update project status to failed
import traceback
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better code style and adherence to PEP 8, it's recommended to have all imports at the top of the file. Please remove this local import and add import traceback to the top-level imports of this file.

Comment thread backend/app/api/report.py
Comment on lines 180 to 182
"""
Query report-generation progress.

Accepts any of: task_id, simulation_id, report_id (at least one required).
When report_id is given, the response is SPECIFIC to that run — no older
reports of the same simulation are returned as "completed" by accident.
"""
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The removed part of the docstring contained useful information about the accepted parameters (task_id, simulation_id, report_id) and the behavior when report_id is provided. It would be beneficial for maintainability to restore this part of the documentation.

Suggested change
"""
Query report-generation progress.
Accepts any of: task_id, simulation_id, report_id (at least one required).
When report_id is given, the response is SPECIFIC to that runno older
reports of the same simulation are returned as "completed" by accident.
"""
"""
Query report-generation progress.
Accepts any of: task_id, simulation_id, report_id (at least one required).
When report_id is given, the response is SPECIFIC to that runno older
reports of the same simulation are returned as "completed" by accident.
"""

@arn0ld87 arn0ld87 merged commit 027424a into main Apr 23, 2026
5 checks passed
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.

Konsolidiere Retry-Utilities in app/utils/retry.py und schließe verbleibende API-Antwort-Duplikate

1 participant