Skip to content

fix(apps): validate EventsCompactionConfig.compaction_interval > 0#6399

Open
hiroakis wants to merge 1 commit into
google:mainfrom
hiroakis:fix/compaction-interval-validation
Open

fix(apps): validate EventsCompactionConfig.compaction_interval > 0#6399
hiroakis wants to merge 1 commit into
google:mainfrom
hiroakis:fix/compaction-interval-validation

Conversation

@hiroakis

Copy link
Copy Markdown
Contributor

Summary

Add validation to EventsCompactionConfig so compaction_interval must be > 0 and overlap_size must be >= 0, consistent with the sibling fields token_threshold (gt=0) and event_retention_size (ge=0).

Currently compaction_interval=0 (or negative) is silently accepted and makes the sliding-window trigger fire on every invocation, because the guard len(new_invocation_ids) < config.compaction_interval in _run_compaction_for_sliding_window can never hold.

Fixes #6397

Changes

  • _configs.py: compaction_interval: int = Field(gt=0), overlap_size: int = Field(ge=0)
  • Tests: reject compaction_interval=0/-1 and overlap_size=-1; allow overlap_size=0

Test

pytest tests/unittests/apps/test_compaction.py — 52 passed. pre-commit hooks pass.

Note

This PR intentionally keeps the fields required and only adds bounds. Making the sliding-window pair optional (to disable it without a sentinel) is tracked separately in #6398.

compaction_interval and overlap_size were plain required ints with no
validation, unlike their sibling fields token_threshold (gt=0) and
event_retention_size (ge=0).

A compaction_interval of 0 (or negative) silently makes the sliding-window
trigger fire on *every* invocation, because the guard in
_run_compaction_for_sliding_window,

    if len(new_invocation_ids) < config.compaction_interval:
        return None

can never hold. This is an easy foot-gun and is inconsistent with the
validated sibling fields.

Add Field(gt=0) to compaction_interval and Field(ge=0) to overlap_size
(0 = no overlap, which is valid), plus tests.
@adk-bot adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Jul 15, 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.

EventsCompactionConfig.compaction_interval accepts 0/negative, silently compacting on every invocation

3 participants