RSPEED-2978: refactor Responses API shared side effects#1649
RSPEED-2978: refactor Responses API shared side effects#1649tisnik merged 2 commits intolightspeed-core:mainfrom
Conversation
|
@tisnik I meant to do this when I added the splunk stuff, but then I got caught up in Summit deliverables. 🤪 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📜 Recent review details⏰ 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). (7)
🧰 Additional context used📓 Path-based instructions (5)tests/unit/**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
tests/**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/app/**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
src/app/endpoints/**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (1)📚 Learning: 2026-04-06T20:18:07.852ZApplied to files:
🔇 Additional comments (16)
WalkthroughRefactored ChangesError Handling & Telemetry Consolidation
🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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. Review rate limit: 0/1 reviews remaining, refill in 60 minutes.Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/app/endpoints/responses.py`:
- Around line 1168-1181: The completion side effects are run in the wrong order
here—call _store_response_query_results(...) before
_queue_completed_response_event(...) to match generate_response()'s streaming
path; update the sequence in the non-streaming branch so
_store_response_query_results(api_params, context, turn_summary, completed_at,
topic_summary) executes first and only then call
_queue_completed_response_event(api_params, context, turn_summary, completed_at,
output_text) with the same arguments and ordering.
- Around line 384-387: The snippet unconditionally calls get_topic_summary when
context.generate_topic_summary is true, which can trigger another model call for
requests already blocked by the shield; update the guard to also check the
shield-block indicator on the context (e.g., context.shield_blocked or the
existing moderation/shield flag present on Context) and return None if the
request was shield-blocked before calling get_topic_summary(context.input_text,
context.client, api_params.model) so that topic-summary generation is skipped
for rejected inputs.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7c607f27-fb46-4faa-8854-81479813f8cb
📒 Files selected for processing (2)
src/app/endpoints/responses.pytests/unit/app/endpoints/test_responses_splunk.py
📜 Review details
⏰ 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). (7)
- GitHub Check: E2E: library mode / ci / group 2
- GitHub Check: E2E: library mode / ci / group 3
- GitHub Check: E2E: server mode / ci / group 3
- GitHub Check: E2E: library mode / ci / group 1
- GitHub Check: E2E: server mode / ci / group 2
- GitHub Check: E2E: server mode / ci / group 1
- GitHub Check: build-pr
🧰 Additional context used
📓 Path-based instructions (5)
tests/unit/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
tests/unit/**/*.py: Use pytest for all unit and integration tests
Usepytest-mockfor AsyncMock objects in unit tests
Use markerpytest.mark.asynciofor async tests
Files:
tests/unit/app/endpoints/test_responses_splunk.py
tests/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Do not use unittest - pytest is the standard testing framework for this project
Files:
tests/unit/app/endpoints/test_responses_splunk.py
src/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
src/**/*.py: Use absolute imports for internal modules:from authentication import get_auth_dependency
All modules start with descriptive docstrings explaining purpose
Uselogger = get_logger(__name__)fromlog.pyfor module logging
Type aliases defined at module level for clarity
Use Final[type] as type hint for all constants
All functions require docstrings with brief descriptions
Complete type annotations for function parameters and return types
Use Union types with modern syntax:str | int
UseOptional[Type]for optional type hints
Use snake_case with descriptive, action-oriented function names (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns: return new data structures instead of modifying parameters
Useasync deffor I/O operations and external API calls
Uselogger.debug()for detailed diagnostic information
Uselogger.info()for general information about program execution
Uselogger.warning()for unexpected events or potential problems
Uselogger.error()for serious problems that prevented function execution
All classes require descriptive docstrings explaining purpose
Use PascalCase for class names with descriptive names and standard suffixes:Configuration,Error/Exception,Resolver,Interface
Abstract classes use ABC with@abstractmethoddecorators
Complete type annotations for all class attributes, use specific types, notAny
Follow Google Python docstring conventions for all modules, classes, and functions
Docstring Parameters section documents function parameters
Docstring Returns section documents function return values
Docstring Raises section documents exceptions that may be raised
Use black for code formatting
Use pylint for static analysis with source-roots configuration set to "src"
Use pyright for type checking
Use ruff for fast linting
Use pydocstyle for docstring style validation
Use mypy for additional type checking
Use bandit for security issue detection
Files:
src/app/endpoints/responses.py
src/app/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Use FastAPI dependencies:
from fastapi import APIRouter, HTTPException, Request, status, Depends
Files:
src/app/endpoints/responses.py
src/app/endpoints/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Use FastAPI
HTTPExceptionwith appropriate status codes for API endpoint error handling
Files:
src/app/endpoints/responses.py
🧠 Learnings (2)
📚 Learning: 2026-04-29T15:45:22.854Z
Learnt from: CR
Repo: lightspeed-core/lightspeed-stack PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-04-29T15:45:22.854Z
Learning: Applies to src/app/**/*.py : Use FastAPI dependencies: `from fastapi import APIRouter, HTTPException, Request, status, Depends`
Applied to files:
src/app/endpoints/responses.py
📚 Learning: 2026-04-06T20:18:07.852Z
Learnt from: major
Repo: lightspeed-core/lightspeed-stack PR: 1463
File: src/app/endpoints/rlsapi_v1.py:266-271
Timestamp: 2026-04-06T20:18:07.852Z
Learning: In the lightspeed-stack codebase, within `src/app/endpoints/` inference/MCP endpoints, treat `tools: Optional[list[Any]]` in MCP tool definitions as an intentional, consistent typing pattern (used across `query`, `responses`, `streaming_query`, `rlsapi_v1`). Do not raise or suggest this as a typing issue during code review; changing it in isolation could break endpoint typing consistency across the codebase.
Applied to files:
src/app/endpoints/responses.py
🔇 Additional comments (1)
src/app/endpoints/responses.py (1)
298-300: This review comment is based on an incorrect understanding of Python exception re-raise semantics.The verification script demonstrates that
raise error(raising by name) in Python 3.12+ actually preserves the full exception traceback, including both the original exception site and the re-raise site. A bareraise(without the exception variable) would show less traceback context, not more.Additionally, the function has no internal
exceptblock, making a bareraisesyntactically impossible in this context. The currentraise erroris appropriate for re-raising unmapped exceptions unchanged, and the code correctly usesraise http_exception from errorto establish explicit chaining for mapped exceptions.> Likely an incorrect or invalid review comment.
64670e6 to
21779f4
Compare
asimurka
left a comment
There was a problem hiding this comment.
Great work with refactoring in overall.
For discussion: The endpoint has become quite long. We should consider creating separate module for all the utility functions dedicated to this endpoint to keep it lightweight. Anyway, it is not necessary for this PR.
Signed-off-by: Major Hayden <major@redhat.com>
21779f4 to
0c79c65
Compare
Signed-off-by: Major Hayden <major@redhat.com>
0c79c65 to
26ce9b9
Compare
|
/ok-to-test |
Description
Refactor the Responses API endpoint so streaming and non-streaming handlers reuse the same side-effect helpers for error telemetry, blocked response persistence, previous response continuation, result storage, and completed telemetry. This brings
handle_non_streaming_responsedown to radon A while keeping the behavior exercised through the existing handler tests.Type of change
Tools used to create PR
Identify any AI code assistants used in this PR (for transparency and review context)
Related Tickets & Documents
Checklist before requesting a review
Testing
uv run pyright src/app/endpoints/responses.py tests/unit/app/endpoints/test_responses_splunk.pyuv run pytest tests/unit/app/endpoints/test_responses.py tests/unit/app/endpoints/test_responses_splunk.py, 85 passeduv run make verifygit diff --check origin/main...HEADuv run radon cc -s -a src/app/endpoints/responses.py, average A,handle_non_streaming_responseA (5)user_agentfinding, fixed in this branch with assertions intest_responses_splunk.py.Summary by CodeRabbit
Release Notes
Bug Fixes & Improvements
Tests