Skip to content

Conversation

@AkhileshNegi
Copy link
Collaborator

@AkhileshNegi AkhileshNegi commented Aug 11, 2025

Summary

Target issue is #317
Explain the motivation for making this change. What existing problem does the pull request solve?

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Summary by CodeRabbit

  • New Features

    • Response payloads now include additional request fields (e.g., callback_url) directly in data for both async and sync endpoints.
    • Error responses are standardized and more informative, including extra request context when available.
    • Improved handling of missing API keys: extra request details are returned in data, with metadata omitted when not needed.
  • Tests

    • Expanded tests validate callback_url appears in data across scenarios and confirm metadata is omitted in credential-less cases.

@AkhileshNegi AkhileshNegi self-assigned this Aug 11, 2025
@AkhileshNegi AkhileshNegi added the bug Something isn't working label Aug 11, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 11, 2025

Walkthrough

Refactors response construction in backend/app/api/routes/responses.py to build custom success and error payloads that merge additional request data via get_additional_data. Updates tests to validate inclusion of callback_url in data and confirm metadata=None in specific error scenarios. No public signatures changed.

Changes

Cohort / File(s) Summary
API response payload refactor
backend/app/api/routes/responses.py
Replaced failure_response calls with explicit error payloads; merged additional_data into success payloads for /responses and /responses/sync; prepared request_dict and additional_data earlier; standardized metadata=None in error paths; introduced consistent get_additional_data usage.
Tests aligned with payload changes
backend/app/tests/api/routes/test_responses.py
Extended tests to assert callback_url presence in data across scenarios; verified metadata=None where credentials are missing; adapted expectations to new payload structure.

Sequence Diagram(s)

sequenceDiagram
  participant C as Client
  participant API as /responses
  participant U as get_additional_data

  C->>API: POST /responses (payload)
  API->>API: Build request_dict
  API->>U: Extract additional_data
  U-->>API: additional_data
  alt Valid API key / success
    API-->>C: 200 { data: {status, message, ...additional_data}, success:true }
  else Missing/invalid API key
    API-->>C: 401 { success:false, data: additional_data|null, error: message, metadata:null }
  end
Loading
sequenceDiagram
  participant C as Client
  participant API as /responses/sync
  participant U as get_additional_data

  C->>API: POST /responses/sync (payload)
  API->>API: Build request_dict
  API->>U: Extract additional_data
  U-->>API: additional_data
  alt Success
    API-->>C: 200 { ...APIResponse, ...additional_data }
  else Error
    API-->>C: 4xx/5xx { success:false, data: additional_data|null, error: message, metadata:null }
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Suggested labels

enhancement, ready-for-review

Suggested reviewers

  • kartpop
  • avirajsingh7

Poem

A hop, a merge, a tidy payload tune,
I tuck extra fields beneath the moon.
No metadata crumbs, just data so bright—
callback trails twinkle in the night.
With paws on keys and ears alert,
I ship neat errors—none inert.
Thump-thump: responses now assert.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhancement/consistent-client-context

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.

@codecov
Copy link

codecov bot commented Aug 11, 2025

Codecov Report

❌ Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/api/routes/responses.py 33.33% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AkhileshNegi AkhileshNegi force-pushed the enhancement/consistent-client-context branch from f7319d6 to 2a2f082 Compare August 11, 2025 13:25
Copy link

@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 (1)
backend/app/tests/api/routes/test_responses.py (1)

110-296: Include callback_url in the response payload

The get_additional_data helper is currently excluding "callback_url", so none of the /responses branches ever include it in the returned data field—causing the existing tests to fail. To satisfy the tests’ expectations:

• In backend/app/api/routes/responses.py, locate the get_additional_data function (around line 103)
• Remove "callback_url" from the async_exclude_keys set (currently on line 106) so that it remains in the returned dict
• Verify all /responses return paths (success, credential-missing, error) now spread additional_data containing callback_url into their "data" objects

After making this change, rerun the test_responses.py suite to confirm the callback_url assertions pass.

🧹 Nitpick comments (1)
backend/app/api/routes/responses.py (1)

103-124: Consider a more robust request type detection mechanism.

The current implementation determines request type by checking for the presence of assistant_id, which could be fragile if request structures change in the future.

Consider passing an explicit request type parameter or using isinstance checks:

-def get_additional_data(request: dict) -> dict:
+def get_additional_data(request: dict, request_type: str = None) -> dict:
     """Extract additional data from request, excluding specific keys."""
     # Keys to exclude for async request (ResponsesAPIRequest)
     async_exclude_keys = {"assistant_id", "callback_url", "response_id", "question"}
     # Keys to exclude for sync request (ResponsesSyncAPIRequest)
     sync_exclude_keys = {
         "model",
         "instructions",
         "vector_store_ids",
         "max_num_results",
         "temperature",
         "response_id",
         "question",
     }

     # Determine which keys to exclude based on the request structure
-    if "assistant_id" in request:
+    if request_type == "async" or (request_type is None and "assistant_id" in request):
         exclude_keys = async_exclude_keys
     else:
         exclude_keys = sync_exclude_keys

     return {k: v for k, v in request.items() if k not in exclude_keys}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cae70be and f7319d6.

📒 Files selected for processing (2)
  • backend/app/api/routes/responses.py (7 hunks)
  • backend/app/tests/api/routes/test_responses.py (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
backend/app/tests/api/routes/test_responses.py (1)
backend/app/tests/api/routes/test_threads.py (1)
  • test_process_run_variants (89-132)
🪛 GitHub Actions: AI Platform CI
backend/app/tests/api/routes/test_responses.py

[error] 1-1: Test 'test_responses_endpoint_success' failed: response data did not include 'callback_url' as expected; data contained only 'status' and 'message'.


[error] 1-1: Test 'test_responses_endpoint_without_vector_store' failed: response data did not include 'callback_url' as expected; data contained only 'status' and 'message'.


[error] 1-1: Test 'test_responses_endpoint_no_openai_credentials' failed: response data is None in error path; test attempts to check for 'callback_url' in data.


[error] 1-1: Test 'test_responses_endpoint_missing_api_key_in_credentials' failed: response data is None in error path; test attempts to check for 'callback_url' in data.

🔇 Additional comments (11)
backend/app/api/routes/responses.py (7)

244-258: LGTM: Success path correctly merges additional data.

The success response construction properly includes additional request data via the spread operator, maintaining backward compatibility while extending the response structure.


268-276: Consistent error response structure with metadata standardization.

The error response now uses a standardized structure with metadata=None and includes additional data in the data field. This aligns with the PR objective of standardizing API responses.


321-327: LGTM: Error path standardization implemented correctly.

The error response now properly extracts and includes additional request data in the data field while setting metadata=None, consistent with the standardization objectives.


358-367: LGTM: Success path spreads additional data appropriately.

The success response correctly merges additional request data into the response payload using the spread operator, maintaining the existing structure while adding extra fields.


396-403: LGTM: Sync endpoint error handling standardized.

The error response structure matches the async endpoint pattern with metadata=None and additional data in the data field.


474-489: LGTM: Sync endpoint success path includes additional data.

The success response properly extracts and spreads additional request data, maintaining consistency with the async endpoint.


502-509: LGTM: OpenAI error handling follows standardized pattern.

The error response structure is consistent with other error paths, properly including additional data and setting metadata=None.

backend/app/tests/api/routes/test_responses.py (4)

110-112: LGTM: Test validates additional data inclusion in success responses.

The test correctly verifies that callback_url from the request is included in the response data field, validating the standardization implementation.


189-191: LGTM: Consistent additional data validation across test scenarios.

The test properly validates callback_url inclusion in the response data, maintaining consistency with other success scenario tests.


256-259: LGTM: Error scenario validation matches standardized response structure.

The test correctly verifies that in error scenarios, callback_url is included in the data field and metadata is set to None, validating the standardized error response structure.


293-296: LGTM: Comprehensive error scenario validation.

The test ensures consistent validation of the standardized error response structure across different credential-related error conditions, maintaining test coverage completeness.

@AkhileshNegi AkhileshNegi merged commit 3a3247e into main Aug 11, 2025
3 of 4 checks passed
@AkhileshNegi AkhileshNegi deleted the enhancement/consistent-client-context branch August 11, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant