Skip to content

fix(sessions): Reject negative recent-event limits - #6687

Open
JunweiJia wants to merge 1 commit into
google:mainfrom
JunweiJia:codex/fix-negative-session-event-limit
Open

fix(sessions): Reject negative recent-event limits#6687
JunweiJia wants to merge 1 commit into
google:mainfrom
JunweiJia:codex/fix-negative-session-event-limit

Conversation

@JunweiJia

Copy link
Copy Markdown

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_events documents only None, 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):] becomes events[1:]), while SQL backends can interpret LIMIT -1 as no limit and return every event.

Steps to reproduce:

  1. Construct GetSessionConfig(num_recent_events=-1).
  2. Pass it to different session service implementations.
  3. Observe that configuration succeeds and backend-specific filtering produces different results.

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=0 field constraint to the public configuration model. This is the smallest common validation boundary and keeps every backend consistent without duplicating checks.

Environment:

  • Source revision: dd0de522
  • Desktop OS: macOS
  • Python: 3.12.13
  • Model information: N/A (session configuration validation does not invoke a model)
  • Frequency: Always

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Results:

  • Regression test before the fix: 1 failed (DID NOT RAISE ValueError)
  • Regression test after the fix: 1 passed
  • tests/unittests/sessions/test_session_service.py: 166 passed
  • tests/unittests/sessions: 311 passed
  • Changed-file pre-commit checks: ruff, isort, pyink, addlicense, and codespell passed. Two repository-level sparse-checkout hooks could not run because their scripts were not present locally; no hook reported a changed-file failure.

Manual 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

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas (no additional comment was needed for the declarative constraint).
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing relevant unit tests pass locally with my changes.
  • I have manually verified the configuration behavior before and after the fix.
  • No dependent downstream changes are required.

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.

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.
@google-cla

google-cla Bot commented Aug 12, 2026

Copy link
Copy Markdown

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.

@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants