Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RHIDP-14304: add GET endpoint for saved prompts config#2093

Merged
tisnik merged 5 commits into
lightspeed-core:mainfrom
Jdubrick:add-saved-prompts-config-get
Jul 9, 2026
Merged

RHIDP-14304: add GET endpoint for saved prompts config#2093
tisnik merged 5 commits into
lightspeed-core:mainfrom
Jdubrick:add-saved-prompts-config-get

Conversation

@Jdubrick

@Jdubrick Jdubrick commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Description

  • Adds a new GET endpoint to fetch the values configured for saved prompts
    • Lets consuming services fetch the values the server will be validating off of for consistency
  • Fixes some unrelated errors I discovered when running make verify

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
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: Cursor
  • Generated by: (e.g., tool name and version; N/A if not used)

Related Tickets & Documents

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

    • Added a new API endpoint to retrieve saved prompts configuration limits, including maximum prompts per user, display name length, and content length.
    • Saved prompts endpoints are now grouped under a dedicated API tag for clearer documentation and discovery.
  • Bug Fixes

    • Improved handling when configuration is unavailable, returning a clearer error response.
    • Added coverage for authentication and authorization responses to ensure the endpoint behaves consistently.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Jdubrick, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 52 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5033c41b-65c8-48dd-ae83-c1bc72c8f776

📥 Commits

Reviewing files that changed from the base of the PR and between 8dfc973 and daa700b.

📒 Files selected for processing (3)
  • docs/openapi.json
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/endpoints/test_saved_prompts.py

Walkthrough

Adds a new GET /v1/saved-prompts/config REST endpoint returning saved-prompts configuration limits (max prompts per user, display name length, content length), protected by authorization. Includes a new response model, router registration, OpenAPI documentation, and unit/integration tests. Also fixes an unrelated test variable initialization and adds type annotations to a test helper.

Changes

Saved prompts config endpoint

Layer / File(s) Summary
Response model
src/models/api/responses/successful/saved_prompts.py, src/models/api/responses/successful/__init__.py
Adds SavedPromptsConfigResponse Pydantic model with three integer limit fields and exports it from the successful responses package.
Endpoint handler and router wiring
src/app/endpoints/saved_prompts.py, src/app/routers.py, src/app/main.py
Adds authorized GET /saved-prompts/config handler that validates configuration and returns limits; registers the router under /v1 and adds the saved-prompts OpenAPI tag.
OpenAPI documentation
docs/openapi.json, tests/integration/test_openapi_json.py
Documents the new path, response schema, and tag in the OpenAPI spec, and updates integration tests validating the spec.
Endpoint and router tests
tests/unit/app/endpoints/test_saved_prompts.py, tests/unit/app/test_routers.py
Adds unit tests for success, error, and authorization scenarios; updates router registration tests to expect the new router.

Estimated code review effort: 2 (Simple) | ~15 minutes

Unrelated test maintenance

Layer / File(s) Summary
Test utility fixes
tests/e2e/utils/prow_utils.py, tests/unit/pydantic_ai_lightspeed/llamastack/test_model.py
Initializes temp_path to None before use in update_config_configmap; adds type annotations to _make_mock_response_stream and _async_iter helpers.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Router
  participant Handler as get_saved_prompts_config_handler
  participant Auth as authorize(Action.GET_CONFIG)
  participant Config as configuration

  Client->>Router: GET /v1/saved-prompts/config
  Router->>Handler: dispatch request
  Handler->>Auth: check authorization
  Auth-->>Handler: allowed / 401/403
  Handler->>Config: check_configuration_loaded
  Config-->>Handler: saved_prompts limits
  Handler-->>Client: SavedPromptsConfigResponse
Loading

Possibly related PRs

Suggested reviewers: tisnik

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the primary change: adding a new GET endpoint for saved prompts configuration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/app/endpoints/saved_prompts.py Fixed
Comment thread src/app/endpoints/saved_prompts.py Fixed
Comment thread src/app/endpoints/saved_prompts.py Fixed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/openapi.json`:
- Around line 6934-7096: The OpenAPI spec for the saved-prompts endpoint is
stale and must be regenerated from source to match the current handler
docstring. Update docs/openapi.json by regenerating it with
scripts/generate_openapi_schema.py so the /v1/saved-prompts/config entry,
including the description and examples, matches
src/app/endpoints/saved_prompts.py and any other affected sections referenced by
CI.

In `@src/app/endpoints/saved_prompts.py`:
- Around line 75-77: Replace the three `assert` guards in the saved prompts
endpoint with explicit `None` checks so they are not stripped under Python
optimization flags. In the code that reads `max_prompts_per_user`,
`max_display_name_length`, and `max_content_length`, raise a clear configuration
error if any value is `None` before building the response. Keep the check close
to the existing validation logic in the saved prompts handler so the failure
remains explicit and easy to trace.
🪄 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: 8dc20cf8-ef0f-4f82-82ed-416f85c11d03

📥 Commits

Reviewing files that changed from the base of the PR and between 52f2d12 and 8dfc973.

📒 Files selected for processing (11)
  • docs/openapi.json
  • src/app/endpoints/saved_prompts.py
  • src/app/main.py
  • src/app/routers.py
  • src/models/api/responses/successful/__init__.py
  • src/models/api/responses/successful/saved_prompts.py
  • tests/e2e/utils/prow_utils.py
  • tests/integration/test_openapi_json.py
  • tests/unit/app/endpoints/test_saved_prompts.py
  • tests/unit/app/test_routers.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_model.py
📜 Review details
⏰ Context from checks skipped due to timeout. (14)
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: build-pr
  • GitHub Check: Pylinter
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-7-on-pull-request
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
⚠️ CI failures not shown inline (1)

GitHub Actions: OpenAPI (Spectral) / 0_spectral.txt: RHIDP-14304: add GET endpoint for saved prompts config

Conclusion: failure

View job details

##[group]Run set -euo pipefail
 �[36;1mset -euo pipefail�[0m
 �[36;1muv run python scripts/generate_openapi_schema.py /tmp/openapi-generated.json�[0m
 �[36;1mif ! diff -u docs/openapi.json /tmp/openapi-generated.json; then�[0m
 �[36;1m  echo "::error::docs/openapi.json is out of date. Regenerate with: uv run scripts/generate_openapi_schema.py docs/openapi.json"�[0m
🧰 Additional context used
📓 Path-based instructions (6)
tests/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.py: Use pytest for all unit and integration tests; do not use unittest
Use pytest.mark.asyncio marker for async tests

Files:

  • tests/e2e/utils/prow_utils.py
  • tests/integration/test_openapi_json.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_model.py
  • tests/unit/app/test_routers.py
  • tests/unit/app/endpoints/test_saved_prompts.py
tests/e2e/**/*.{py,feature}

📄 CodeRabbit inference engine (AGENTS.md)

Use behave (BDD) framework for end-to-end testing with Gherkin feature files

Files:

  • tests/e2e/utils/prow_utils.py
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Use absolute imports for internal modules: from authentication import get_auth_dependency
Llama Stack imports: Use from llama_stack_client import AsyncLlamaStackClient
Check constants.py for shared constants before defining new ones
All modules must start with descriptive docstrings explaining purpose
Use logger = get_logger(__name__) from log.py for module logging
All functions must have complete type annotations for parameters and return types, use modern syntax (str | int), and include descriptive docstrings
Use snake_case with descriptive, action-oriented names for functions (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead of modifying function parameters
Use async def for I/O operations and external API calls
Use standard log levels with clear purposes: debug() for diagnostic info, info() for program execution, warning() for unexpected events, error() for serious problems
All classes must have descriptive docstrings explaining purpose and use PascalCase with standard suffixes: Configuration, Error/Exception, Resolver, Interface
Abstract classes must use ABC with @abstractmethod decorators
Follow Google Python docstring conventions with required sections: Parameters, Returns, Raises, and Attributes for classes

Files:

  • src/models/api/responses/successful/saved_prompts.py
  • src/models/api/responses/successful/__init__.py
  • src/app/routers.py
  • src/app/main.py
  • src/app/endpoints/saved_prompts.py
src/models/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

Pydantic models must use @model_validator and @field_validator for validation and complete type annotations for all attributes, avoiding Any type

Files:

  • src/models/api/responses/successful/saved_prompts.py
  • src/models/api/responses/successful/__init__.py
src/**/__init__.py

📄 CodeRabbit inference engine (AGENTS.md)

Package __init__.py files must contain brief package descriptions

Files:

  • src/models/api/responses/successful/__init__.py
src/app/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/app/**/*.py: FastAPI dependencies: Import from fastapi module for APIRouter, HTTPException, Request, status, Depends
Use FastAPI HTTPException with appropriate status codes for API endpoints and handle APIConnectionError from Llama Stack

Files:

  • src/app/routers.py
  • src/app/main.py
  • src/app/endpoints/saved_prompts.py
🧠 Learnings (5)
📚 Learning: 2026-06-24T13:45:37.249Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.

Applied to files:

  • tests/e2e/utils/prow_utils.py
  • src/models/api/responses/successful/saved_prompts.py
  • src/models/api/responses/successful/__init__.py
  • src/app/routers.py
  • src/app/main.py
  • tests/integration/test_openapi_json.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_model.py
  • src/app/endpoints/saved_prompts.py
  • tests/unit/app/test_routers.py
  • tests/unit/app/endpoints/test_saved_prompts.py
📚 Learning: 2026-01-12T10:58:40.230Z
Learnt from: blublinsky
Repo: lightspeed-core/lightspeed-stack PR: 972
File: src/models/config.py:459-513
Timestamp: 2026-01-12T10:58:40.230Z
Learning: In lightspeed-core/lightspeed-stack, for Python files under src/models, when a user claims a fix is done but the issue persists, verify the current code state before accepting the fix. Steps: review the diff, fetch the latest changes, run relevant tests, reproduce the issue, search the codebase for lingering references to the original problem, confirm the fix is applied and not undone by subsequent commits, and validate with local checks to ensure the issue is resolved.

Applied to files:

  • src/models/api/responses/successful/saved_prompts.py
  • src/models/api/responses/successful/__init__.py
📚 Learning: 2026-02-25T07:46:33.545Z
Learnt from: asimurka
Repo: lightspeed-core/lightspeed-stack PR: 1211
File: src/models/responses.py:8-16
Timestamp: 2026-02-25T07:46:33.545Z
Learning: In the Python codebase, requests.py should use OpenAIResponseInputTool as Tool while responses.py uses OpenAIResponseTool as Tool. This difference is intentional due to differing schemas for input vs output tools in llama-stack-api. Apply this distinction consistently to other models under src/models (e.g., ensure request-related tools use the InputTool variant and response-related tools use the ResponseTool variant). If adding new tools, choose the corresponding InputTool or Tool class based on whether the tool represents input or output, and document the rationale in code comments.

Applied to files:

  • src/models/api/responses/successful/saved_prompts.py
  • src/models/api/responses/successful/__init__.py
📚 Learning: 2026-07-06T15:26:18.398Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2071
File: src/models/config.py:2416-2422
Timestamp: 2026-07-06T15:26:18.398Z
Learning: In this repo’s Python code under src/**, don’t treat differences in string concatenation style as a style inconsistency when Black has effectively forced (or made clearer) use of explicit `+` string concatenation in multi-line logger/string expressions. If adjacent-literal implicit concatenation is avoided/changed specifically to accommodate Black’s formatting in these call sites, accept the `+` usage and don’t recommend converting it solely for consistency with nearby blocks that use implicit concatenation.

Applied to files:

  • src/models/api/responses/successful/saved_prompts.py
  • src/models/api/responses/successful/__init__.py
  • src/app/routers.py
  • src/app/main.py
  • src/app/endpoints/saved_prompts.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/saved_prompts.py
🪛 ast-grep (0.44.1)
tests/unit/app/endpoints/test_saved_prompts.py

[warning] 37-37: Do not make http calls without encryption
Context: "http://test.com:1234"
Note: [CWE-319] Cleartext Transmission of Sensitive Information.

(requests-http)

🪛 GitHub Actions: OpenAPI (Spectral) / 0_spectral.txt
docs/openapi.json

[error] 1-1: CI check failed: docs/openapi.json is out of date versus the generated OpenAPI schema. Regenerate with: uv run python scripts/generate_openapi_schema.py docs/openapi.json

🪛 GitHub Actions: OpenAPI (Spectral) / spectral
docs/openapi.json

[error] 1-1: OpenAPI schema is out of date. 'diff -u docs/openapi.json /tmp/openapi-generated.json' failed. Regenerate with: 'uv run scripts/generate_openapi_schema.py docs/openapi.json'.

🪛 GitHub Check: Bandit
src/app/endpoints/saved_prompts.py

[notice] 75-75:
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


[notice] 76-76:
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.


[notice] 77-77:
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

🔇 Additional comments (10)
tests/e2e/utils/prow_utils.py (1)

290-291: LGTM!

tests/unit/pydantic_ai_lightspeed/llamastack/test_model.py (1)

5-7: LGTM!

Also applies to: 429-429, 649-649

tests/integration/test_openapi_json.py (1)

259-259: LGTM!

Also applies to: 364-364

tests/unit/app/endpoints/test_saved_prompts.py (1)

1-227: LGTM!

tests/unit/app/test_routers.py (1)

31-31: LGTM!

Also applies to: 125-135, 158-158, 167-167, 177-177

src/models/api/responses/successful/saved_prompts.py (1)

1-44: LGTM!

src/models/api/responses/successful/__init__.py (1)

52-52: LGTM!

Also applies to: 93-93

src/app/endpoints/saved_prompts.py (1)

1-74: LGTM!

Also applies to: 79-83

src/app/routers.py (1)

28-28: LGTM!

Also applies to: 67-67

src/app/main.py (1)

61-64: LGTM!

Comment thread docs/openapi.json
Comment thread src/app/endpoints/saved_prompts.py Outdated
Signed-off-by: Jordan Dubrick <[email protected]>

@tisnik tisnik left a comment

Copy link
Copy Markdown
Contributor

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 93e6dc2 into lightspeed-core:main Jul 9, 2026
32 of 34 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.

3 participants