Skip to content

LCORE-3323: Fixed QuestionValidity Shield - #2275

Open
jrobertboos wants to merge 1 commit into
lightspeed-core:feature/upgrade-ogx-to-1.0.2from
jrobertboos:lcore-3323
Open

LCORE-3323: Fixed QuestionValidity Shield#2275
jrobertboos wants to merge 1 commit into
lightspeed-core:feature/upgrade-ogx-to-1.0.2from
jrobertboos:lcore-3323

Conversation

@jrobertboos

Copy link
Copy Markdown
Contributor

Description

The QuestionValidity shield capability short-circuited rejected user turns without ever recording them in conversation history — when a question was blocked as off-topic, the rejection message was returned to the caller but the turn (user question + refusal) never made it into the underlying Llama Stack/OGX conversation. This left conversation history incomplete for rejected turns, which is misleading for later inspection/auditing and breaks continuity for follow-up turns that rely on history.

This fix pulls the active Llama Stack conversation ID out of the agent's model settings (extra_body.conversation) when a question is rejected, and persists the rejected turn (user message + the configured invalid_question_response) to that conversation via append_turn_to_conversation. It also seeds the in-memory GraphAgentState.message_history with the same user/response pair so the rejected turn is reflected consistently in both the persisted conversation and the local agent state. If no conversation ID can be determined (e.g. capability used outside a Llama Stack-backed agent), persistence is skipped and a warning is logged instead of raising.

Type of change

  • Bug fix
  • Refactor
  • New feature
  • 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

  • Assisted-by: Cursor
  • Generated by: N/A

Related Tickets & Documents

  • Related Issue: LCORE-3323
  • Closes: LCORE-3323

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

  • Ran locally and confirmed that rejected (off-topic) turns now show up correctly in the conversation history via the OGX/Llama Stack conversation API, instead of being silently dropped.
  • Added/updated unit tests in tests/unit/pydantic_ai_lightspeed/capabilities/question_validity/test_capability.py:
    • TestExtractConversationId: covers extracting the conversation ID from model settings, including missing settings, missing extra_body, non-dict extra_body, and non-string conversation values.
    • TestWrapRun: new cases verifying that a rejected question persists the turn to the conversation, that persistence is skipped (without crashing) when no conversation ID is available, and that an allowed question never triggers persistence.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d45ce7c9-0934-447c-a8a6-8111b90367e0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@asimurka asimurka 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

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