Skip to content

Conversation

@radofuchs
Copy link
Contributor

@radofuchs radofuchs commented Nov 19, 2025

Description

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 #LCORE-945
  • Closes #LCORE-945

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 user-facing toggle (generate_topic_summary, default: true) to control automatic topic summary generation for new conversations.
    • Streaming responses now persist transcripts when transcript storage is enabled.
  • Tests

    • Added tests covering default topic-summary generation and explicit suppression.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Warning

Rate limit exceeded

@radofuchs has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 10 minutes and 50 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ecd4ca6 and be18bd1.

📒 Files selected for processing (6)
  • src/app/endpoints/query.py (1 hunks)
  • src/models/requests.py (3 hunks)
  • src/utils/endpoints.py (1 hunks)
  • tests/unit/app/endpoints/test_query.py (1 hunks)
  • tests/unit/models/requests/test_query_request.py (1 hunks)
  • tests/unit/utils/test_endpoints.py (1 hunks)

Walkthrough

QueryRequest gained a new optional field generate_topic_summary (default True). Topic summary generation paths in query and streaming endpoints (and cleanup_after_streaming) are now gated by this field; tests and utilities updated to cover default and explicit suppression behavior.

Changes

Cohort / File(s) Summary
Request Model
src/models/requests.py
Added generate_topic_summary: Optional[bool] to QueryRequest (default True) and updated example payloads/schema.
Query endpoint logic
src/app/endpoints/query.py
Topic summary generation for new conversations is now conditional on query_request.generate_topic_summary; when False, topic_summary is set to None and a debug log is emitted.
Streaming endpoint logic
src/app/endpoints/streaming_query.py
Moved transcript persistence earlier, added completed_at for turns, and for new conversations topic summary generation is gated by query_request.generate_topic_summary; removed post-streaming cleanup wrapper.
Endpoint utilities
src/utils/endpoints.py
cleanup_after_streaming updated so topic summary generation is conditional on query_request.generate_topic_summary; added injectable functions for topic generation/transcript persistence.
Endpoint tests
tests/unit/app/endpoints/test_query.py
Added tests verifying default generation (True) and explicit suppression (False) for topic-summary behavior in query endpoint. (Note: diff shows merge conflict markers around the new tests.)
Utils tests
tests/unit/utils/test_endpoints.py
Added tests for cleanup_after_streaming asserting topic-summary generated by default and suppressed when generate_topic_summary=False; injects mocked helper funcs.
Model tests
tests/unit/models/requests/test_query_request.py
Added tests asserting QueryRequest accepts and reflects generate_topic_summary True/False.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant QueryEndpoint
  participant ConversationStore
  participant TopicSvc as get_topic_summary
  participant TranscriptStore

  Client->>QueryEndpoint: send QueryRequest (generate_topic_summary: opt)
  QueryEndpoint->>ConversationStore: fetch conversation by id
  alt conversation exists
    QueryEndpoint->>TranscriptStore: (maybe) persist transcript
    QueryEndpoint->>QueryEndpoint: proceed without topic-summary generation
  else new conversation
    opt generate_topic_summary == true
      QueryEndpoint->>TopicSvc: get_topic_summary(query, conversation context)
      TopicSvc-->>QueryEndpoint: topic_summary
    end
    opt generate_topic_summary == false
      QueryEndpoint-->>QueryEndpoint: set topic_summary = None
    end
    QueryEndpoint->>TranscriptStore: persist turn (includes topic_summary if any)
  end
  QueryEndpoint-->>Client: stream/return response (includes topic_summary field)
Loading

Estimated code review effort

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

  • Areas needing extra attention:
    • src/app/endpoints/streaming_query.py — verify transcript timing, removed cleanup wrapper, and interaction order.
    • src/utils/endpoints.py — new injectable params and their defaults; ensure compatibility with callers.
    • Tests showing unresolved merge conflict markers in tests/unit/app/endpoints/test_query.py — must be resolved before merge.

Possibly related PRs

Suggested reviewers

  • tisnik
  • eranco74

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'LCORE-945: optional topic summary' clearly and specifically describes the main change: making topic summary generation optional rather than always required.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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 and usage tips.

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

🧹 Nitpick comments (1)
tests/unit/models/requests/test_query_request.py (1)

158-168: Consider adding a test for the default value.

The tests properly verify explicit True and False values, but there's no test verifying that the default value is True when the field is not provided. Consider adding:

def test_generate_topic_summary_default(self) -> None:
    """Test that generate_topic_summary defaults to True."""
    qr = QueryRequest(query="Tell me about Kubernetes")
    assert qr.generate_topic_summary is True

This would ensure the default behavior is explicitly tested and documented.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db45d8c and a13b239.

📒 Files selected for processing (5)
  • src/app/endpoints/query.py (1 hunks)
  • src/app/endpoints/streaming_query.py (1 hunks)
  • src/models/requests.py (3 hunks)
  • tests/unit/app/endpoints/test_query.py (1 hunks)
  • tests/unit/models/requests/test_query_request.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/unit/app/endpoints/test_query.py (6)
tests/unit/app/endpoints/test_conversations.py (1)
  • dummy_request (34-44)
src/utils/types.py (1)
  • TurnSummary (89-163)
src/utils/token_counter.py (1)
  • TokenCounter (18-41)
tests/unit/app/endpoints/test_streaming_query.py (1)
  • mock_database_operations (72-85)
src/app/endpoints/query.py (1)
  • query_endpoint_handler (438-460)
src/models/requests.py (1)
  • QueryRequest (73-233)
src/app/endpoints/streaming_query.py (1)
src/app/endpoints/query.py (1)
  • get_topic_summary (184-214)
tests/unit/models/requests/test_query_request.py (1)
src/models/requests.py (1)
  • QueryRequest (73-233)
⏰ 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). (3)
  • GitHub Check: e2e_tests (azure)
  • GitHub Check: e2e_tests (ci)
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
🔇 Additional comments (7)
src/models/requests.py (3)

84-84: LGTM!

The docstring correctly documents the new generate_topic_summary attribute.


150-154: LGTM!

The field definition is correct with appropriate type, default value, description, and examples. The default value of True ensures backward compatibility.


174-174: LGTM!

Including generate_topic_summary in the model configuration examples ensures it's properly documented in the API schema.

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

315-327: LGTM!

The conditional topic summary generation logic is well-implemented:

  • Properly checks the generate_topic_summary flag
  • Includes helpful debug logging for both paths
  • Explicitly sets topic_summary to None when disabled for clarity
src/app/endpoints/streaming_query.py (1)

865-876: LGTM!

The conditional topic summary generation logic is correctly implemented and consistent with the non-streaming endpoint in query.py.

tests/unit/app/endpoints/test_query.py (2)

2266-2311: LGTM!

The test properly verifies that topic summary generation occurs by default for new conversations. The test setup and assertions are correct.


2314-2360: LGTM!

The test properly verifies that topic summary generation is skipped when explicitly disabled. The use of assert_not_called() correctly validates the expected behavior.

@radofuchs radofuchs requested a review from tisnik November 19, 2025 10:11
@radofuchs radofuchs force-pushed the LCORE_945_optional_topic_summary branch from a5274f0 to ecd4ca6 Compare November 19, 2025 10:17
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

🧹 Nitpick comments (2)
src/models/requests.py (1)

84-85: Clarify generate_topic_summary semantics; consider non‑optional bool

The new field is nicely documented and used downstream, but its current typing gives it subtle tri‑state behavior:

  • Declared as Optional[bool] = True, but consumed via truthiness checks.
  • This means:
    • Field omitted → True (generate summary).
    • Explicit False → don’t generate (as intended).
    • Explicit null → also treated as “don’t generate” (because None is falsy).

If you don’t need a distinct “null disables” state, simplifying to a plain bool makes the contract clearer and avoids accidental disabling via null:

-    generate_topic_summary: Optional[bool] = Field(
-        True,
-        description="Whether to generate topic summary for new conversations",
-        examples=[True, False],
-    )
+    generate_topic_summary: bool = Field(
+        True,
+        description="Whether to generate topic summary for new conversations (default: True)",
+        examples=[True, False],
+    )

This keeps the default and opt-out behavior but removes the extra None state and documents the default explicitly.

Also applies to: 150-154, 174-175

tests/unit/utils/test_endpoints.py (1)

1041-1140: New cleanup_after_streaming tests accurately cover default vs explicit opt‑out

The two async tests do a good job of isolating the new behavior:

  • Default construction of QueryRequest (no flag) triggers topic-summary generation and persists the generated value.
  • Explicit generate_topic_summary=False cleanly skips the generator and persists topic_summary=None.

The mocking of get_session, create_referenced_documents_with_metadata, and store_conversation_into_cache keeps the tests focused on the gating logic and propagation into persist_user_conversation_details_func.

If you want even stronger coverage, you could also assert that store_conversation_into_cache is called with the expected topic_summary, but that’s optional given the current assertions.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eae3d67 and ecd4ca6.

📒 Files selected for processing (7)
  • src/app/endpoints/query.py (1 hunks)
  • src/app/endpoints/streaming_query.py (1 hunks)
  • src/models/requests.py (3 hunks)
  • src/utils/endpoints.py (1 hunks)
  • tests/unit/app/endpoints/test_query.py (2 hunks)
  • tests/unit/models/requests/test_query_request.py (1 hunks)
  • tests/unit/utils/test_endpoints.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/app/endpoints/streaming_query.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/unit/models/requests/test_query_request.py
  • src/app/endpoints/query.py
  • tests/unit/app/endpoints/test_query.py
🧰 Additional context used
🧬 Code graph analysis (1)
tests/unit/utils/test_endpoints.py (2)
src/models/requests.py (1)
  • QueryRequest (73-233)
src/utils/endpoints.py (1)
  • cleanup_after_streaming (598-717)
⏰ 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). (4)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests (azure)
  • GitHub Check: e2e_tests (ci)
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
🔇 Additional comments (1)
src/utils/endpoints.py (1)

674-684: Topic-summary gating logic in cleanup_after_streaming looks consistent

The new generate_topic_summary gate for new conversations is wired correctly: it only runs for non-existing conversations, calls get_topic_summary_func when truthy, and cleanly skips with a debug log otherwise. This aligns with the new flag and the added tests that cover default True and explicit False behavior.

If you expect generate_topic_summary=None (explicit JSON null) to behave differently from False, you may want to double-check upstream usage and, if needed, special-case None instead of relying on raw truthiness.

@radofuchs radofuchs force-pushed the LCORE_945_optional_topic_summary branch from 5a8f80f to 2e91d95 Compare November 19, 2025 10:23
Radovan Fuchs added 2 commits November 19, 2025 11:27
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 8c127b3 into lightspeed-core:main Nov 20, 2025
21 of 23 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.

2 participants