Skip to content

Conversation

@Jdubrick
Copy link
Contributor

@Jdubrick Jdubrick commented Aug 11, 2025

Description

Updates the responses to match what was originally in Road Core: https://github.com/road-core/service/blob/9d65d15a4d1dec47e5aac15ee86fef39db975006/ols/app/endpoints/feedback.py#L93-L110

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue # N/A
  • Closes # N/A

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • New Features

    • Introduced a standardized ErrorResponse for API errors with detailed key-value information.
    • Added a 500 Internal Server Error response to /v1/feedback for storage failures.
  • Documentation

    • Updated /v1/feedback OpenAPI: 200 now documents a FeedbackResponse with a clearer description; removed 400 in favor of 401 Unauthorized; refined 403 description; added ErrorResponse schema with examples and referenced it in the new 500 response.

Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Walkthrough

Updates align the feedback endpoint’s OpenAPI docs with implementation: refined 200/401/403 responses, removed 400, and added a 500 error. Introduces a reusable ErrorResponse schema/model and wires it into the endpoint’s documented responses. Runtime behavior stays the same; changes are documentation and schema additions.

Changes

Cohort / File(s) Summary of Changes
OpenAPI spec updates
docs/openapi.json
Updated /v1/feedback responses: 200 description refined; 400 removed; 401 retained; 403 description updated; added 500 referencing new ErrorResponse. Added components.schemas.ErrorResponse with examples.
Endpoint response annotations
src/app/endpoints/feedback.py
Adjusted response models/descriptions to match spec: 200 now uses FeedbackResponse with description; removed 400; updated 403 text; added 500 using ErrorResponse. Added import for ErrorResponse.
Models: new error schema
src/models/responses.py
Added ErrorResponse Pydantic model with detail: dict[str,str] and example payloads for JSON schema.

Sequence Diagram(s)

sequenceDiagram
  actor Client
  participant API as Feedback API (/v1/feedback)
  participant Store as Storage

  Client->>API: POST feedback
  API->>Store: Save feedback
  alt Success
    Store-->>API: OK
    API-->>Client: 200 FeedbackResponse
  else Unauthorized
    API-->>Client: 401 UnauthorizedResponse
  else Forbidden
    API-->>Client: 403 Forbidden
  else Storage error
    Store-->>API: Failure
    API-->>Client: 500 ErrorResponse
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Poem

I thump my paw—specs aligned, neat!
New errors hop in, tidy and complete.
Four-oh-oh gone, five-hundred’s here,
With details clear as springtime air.
I stash your feedback, burrow-deep—
If storage trips, ErrorResponse will speak. 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (2)
src/app/endpoints/feedback.py (1)

96-105: Avoid leaking internal exception details in client-facing 500s; include stack trace in logs.

Returning str(e) in the HTTP response can leak filesystem paths or provider errors. Log the exception with stack trace, but send a generic cause to clients.

-    except Exception as e:
-        logger.error("Error storing user feedback: %s", e)
+    except Exception as e:
+        logger.exception("Error storing user feedback")
         raise HTTPException(
             status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
             detail={
                 "response": "Error storing user feedback",
-                "cause": str(e),
+                "cause": "Internal server error",
             },
         ) from e
docs/openapi.json (1)

285-356: Standardize “Missing or invalid credentials” responses to use 401
There are two operations in docs/openapi.json that currently return 400 for unauthorized requests while others use 401 with the same description. For consistency, update these to 401:

• docs/openapi.json:137–140 (change "400": { … } to "401": { … })
• docs/openapi.json:641–644 (change "400": { … } to "401": { … })

🧹 Nitpick comments (6)
src/models/responses.py (2)

475-497: Docstring scope + example polish (grammar, UUID, vendor URL).

  • Docstring says “for query endpoint” but this model is used across endpoints (feedback 500). Make it generic.
  • Grammar: “Error while validation question” → “Error while validating question”.
  • Example UUID “1237-…” isn’t a valid UUID shape; use the existing example UUID used elsewhere in this file.
  • Prefer avoiding vendor-specific URLs in public examples; replace with a generic upstream hostname.

Apply:

-class ErrorResponse(BaseModel):
-    """Model representing error response for query endpoint."""
+class ErrorResponse(BaseModel):
+    """Generic error response payload used across endpoints."""
@@
-            "examples": [
-                {
-                    "detail": {
-                        "response": "Error while validation question",
-                        "cause": "Failed to handle request to https://bam-api.res.ibm.com/v2/text",
-                    },
-                },
-                {
-                    "detail": {
-                        "response": "Error retrieving conversation history",
-                        "cause": "Invalid conversation ID 1237-e89b-12d3-a456-426614174000",
-                    },
-                },
-            ]
+            "examples": [
+                {
+                    "detail": {
+                        "response": "Error while validating question",
+                        "cause": "Failed to handle upstream request to https://example.com/api",
+                    },
+                },
+                {
+                    "detail": {
+                        "response": "Error retrieving conversation history",
+                        "cause": "Invalid conversation ID 123e4567-e89b-12d3-a456-426614174000",
+                    },
+                },
+            ]

475-497: Consider deduplicating error payload models.

NotAvailableResponse and ErrorResponse have identical shapes (detail: dict[str, str]) with different examples. Consider unifying to a single ErrorResponse (with multiple example sets) to reduce duplication and keep schemas consistent.

src/app/endpoints/feedback.py (2)

28-44: Responses mapping alignment: LGTM; minor wording nit (“cannot”).

  • 200 now returns FeedbackResponse: good.
  • 401/403 descriptions updated: good.
  • 500 added with ErrorResponse: good.
  • Nit: prefer “cannot” over “can not” for consistency.
-    500: {
-        "description": "User feedback can not be stored",
+    500: {
+        "description": "User feedback cannot be stored",
         "model": ErrorResponse,
     },

120-132: Validate and guard feedback storage path (prevent accidental writes to CWD).

When feedback_storage is unset, Path("") resolves to the current working directory. Consider validating the config and failing fast with 500 instead of writing into CWD.

-    storage_path = Path(
-        configuration.user_data_collection_configuration.feedback_storage or ""
-    )
+    storage_root = configuration.user_data_collection_configuration.feedback_storage
+    if not storage_root:
+        logger.error("Feedback storage path is not configured")
+        raise HTTPException(
+            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
+            detail={
+                "response": "Error storing user feedback",
+                "cause": "Feedback storage path is not configured",
+            },
+        )
+    storage_path = Path(storage_root)

I can update the OpenAPI example text for the 500 to match this cause if you adopt it.

docs/openapi.json (2)

305-343: Feedback endpoint responses updated correctly; nit on “cannot.”

The 200/401/403 updates and 500 with ErrorResponse align with the code. Please change “User feedback can not be stored” to “User feedback cannot be stored” for consistency.

-                        "description": "User feedback can not be stored",
+                        "description": "User feedback cannot be stored",

1193-1223: ErrorResponse schema: description scope + example polish (grammar, UUID).

  • Description says “for query endpoint” but it’s reused (feedback 500). Make it generic.
  • Grammar: “Error while validation question” → “Error while validating question”.
  • Fix example UUID to the commonly used valid sample.
-            "ErrorResponse": {
+            "ErrorResponse": {
                 "properties": {
@@
-                "title": "ErrorResponse",
-                "description": "Model representing error response for query endpoint.",
+                "title": "ErrorResponse",
+                "description": "Generic error response payload used across endpoints.",
                 "examples": [
                     {
                         "detail": {
-                            "cause": "Failed to handle request to https://bam-api.res.ibm.com/v2/text",
-                            "response": "Error while validation question"
+                            "cause": "Failed to handle upstream request to https://example.com/api",
+                            "response": "Error while validating question"
                         }
                     },
                     {
                         "detail": {
-                            "cause": "Invalid conversation ID 1237-e89b-12d3-a456-426614174000",
+                            "cause": "Invalid conversation ID 123e4567-e89b-12d3-a456-426614174000",
                             "response": "Error retrieving conversation history"
                         }
                     }
                 ]
             },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a59de96 and 2f13263.

📒 Files selected for processing (3)
  • docs/openapi.json (4 hunks)
  • src/app/endpoints/feedback.py (2 hunks)
  • src/models/responses.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/app/endpoints/feedback.py (1)
src/models/responses.py (4)
  • ErrorResponse (475-497)
  • FeedbackResponse (189-212)
  • UnauthorizedResponse (271-285)
  • ForbiddenResponse (288-300)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: e2e_tests
🔇 Additional comments (1)
src/app/endpoints/feedback.py (1)

14-19: Import addition looks correct.

Importing ErrorResponse to wire the 500 schema is aligned with the OpenAPI changes.

Copy link
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

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

LGTM

@tisnik tisnik merged commit 0976655 into lightspeed-core:main Aug 12, 2025
18 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 12, 2025
15 tasks
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.

2 participants