fix(sessions): Reject negative recent-event limits - #6687
Open
JunweiJia wants to merge 1 commit into
Open
Conversation
Negative limits are interpreted differently by session backends: list slicing can drop the oldest event while SQL LIMIT -1 can return all events. Validate the public session configuration so unsupported values fail consistently before reaching a backend.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to Issue or Description of Change
No existing issue or pull request covers this case. I searched open and closed issues and pull requests for
num_recent_events,GetSessionConfig, negative limits, and validation before submitting.Problem:
GetSessionConfig.num_recent_eventsdocuments onlyNone, zero, and positive values, but currently accepts negative integers. Those values behave inconsistently across session backends: Python list slicing can drop the oldest event (for example,events[-(-1):]becomesevents[1:]), while SQL backends can interpretLIMIT -1as no limit and return every event.Steps to reproduce:
GetSessionConfig(num_recent_events=-1).Expected behavior:
Unsupported negative limits should fail at configuration time, before a session backend handles them.
Observed behavior:
Negative limits are accepted and can either omit events or return all events depending on the backend.
Solution:
Add a Pydantic
ge=0field constraint to the public configuration model. This is the smallest common validation boundary and keeps every backend consistent without duplicating checks.Environment:
dd0de522Testing Plan
Unit Tests:
Results:
1 failed(DID NOT RAISE ValueError)1 passedtests/unittests/sessions/test_session_service.py:166 passedtests/unittests/sessions:311 passedManual End-to-End (E2E) Tests:
N/A. The change is deterministic validation on a public Pydantic configuration model and is covered directly by an isolated unit test; no external service or model is involved.
Checklist
Additional context
AI assistance was used to investigate the cross-backend behavior, search for duplicate issues and pull requests, implement the focused change, and run verification. I reviewed the final diff and test results before submission.