Skip to content

fix(query): reject invalid date filters - #710

Merged
Sinity merged 1 commit into
masterfrom
feature/fix/query-date-filter-validation
May 2, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/fix/query-date-filter-validation

Conversation

@Sinity

@Sinity Sinity commented May 2, 2026

Copy link
Copy Markdown
Owner

Summary

Make storage-level since/until filter pushdown reject malformed date values instead of silently treating them as epoch zero.

Problem

The low-level conversation filter builder converted invalid date strings to 0.0. A malformed since/until value could therefore broaden to a near-unbounded query and look like a successful filter.

Solution

After ISO and numeric parsing both fail, _iso_to_epoch() now raises ValueError with a format hint. Storage filter tests cover both since and until.

Verification

  • ruff check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py
  • ruff format --check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py
  • pytest -q tests/unit/storage/test_schema_safety.py::TestConversationFilterSQL
  • git push pre-push hook: devtools verify --quick passed

Ref #621

Problem: storage filter pushdown converted invalid since/until values to epoch 0.0. That made malformed date filters behave like an extremely broad query instead of reporting bad input.

What changed: make invalid date values raise ValueError with a clear format hint after ISO and numeric parsing both fail. Add storage filter coverage for since and until.

Verification: ruff check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; ruff format --check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; pytest -q tests/unit/storage/test_schema_safety.py::TestConversationFilterSQL

Ref #621
Copilot AI review requested due to automatic review settings May 2, 2026 15:44
@coderabbitai

coderabbitai Bot commented May 2, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 12 minutes and 8 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: b5e15024-234f-4992-866a-e1b666a8b380

📥 Commits

Reviewing files that changed from the base of the PR and between e802e9f and 01c2a45.

📒 Files selected for processing (2)
  • polylogue/storage/backends/queries/filter_builder.py
  • tests/unit/storage/test_schema_safety.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/query-date-filter-validation

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
Review rate limit: 0/1 reviews remaining, refill in 12 minutes and 8 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

Polylogue Proof Pack

Refs: origin/master..HEAD
Changed paths: 2

Affected Domains

  • none with affected claims

Focused Gates

  • none

Required PR Gates

  • devtools verify --quick — full PR gate remains explicit
  • devtools verify — full PR gate remains explicit

Optional Confidence Gates

  • devtools build-package — deployment readiness gate; run when packaging or release confidence matters
  • nix flake check — deployment readiness gate; run when packaging or release confidence matters

Known Gaps

  • none for domains with affected claims

Oracle / Cost

  • oracle mix: {}
  • cost tier: {}
  • stable affected obligations: 0
  • agent judgment cells: 0

@Sinity
Sinity merged commit af9fe06 into master May 2, 2026
14 of 15 checks passed
@Sinity
Sinity deleted the feature/fix/query-date-filter-validation branch May 2, 2026 15:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens storage-level conversation date filtering by making malformed since/until values fail fast (rather than silently broadening queries by treating them as epoch zero), and adds unit tests to enforce the new behavior.

Changes:

  • Update _iso_to_epoch() to raise ValueError when both ISO and numeric parsing fail (instead of returning 0.0).
  • Add unit tests asserting invalid since and invalid until inputs raise.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
polylogue/storage/backends/queries/filter_builder.py Changes date parsing to raise on invalid since/until values instead of defaulting to epoch zero.
tests/unit/storage/test_schema_safety.py Adds regression tests for invalid since/until date filter inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +416 to +428
def test_build_filters_rejects_invalid_since_filter(self) -> None:
"""Invalid date filters should not silently broaden to epoch zero."""
from polylogue.storage.backends.queries.filter_builder import _build_conversation_filters

with pytest.raises(ValueError, match="Invalid date filter value"):
_build_conversation_filters(since="not-a-date")

def test_build_filters_rejects_invalid_until_filter(self) -> None:
"""Invalid date filters should not silently broaden to epoch zero."""
from polylogue.storage.backends.queries.filter_builder import _build_conversation_filters

with pytest.raises(ValueError, match="Invalid date filter value"):
_build_conversation_filters(until="not-a-date")
Comment on lines 14 to +25
def _iso_to_epoch(iso_str: str) -> float:
"""Convert an ISO date string to epoch seconds for SQL comparison."""
from datetime import datetime

try:
return datetime.fromisoformat(iso_str).timestamp()
except (ValueError, TypeError):
try:
return float(iso_str)
except (ValueError, TypeError):
return 0.0
pass
try:
return float(iso_str)
except (ValueError, TypeError):
raise ValueError(f"Invalid date filter value {iso_str!r}. Use ISO 8601 format (e.g., 2026-01-01).") from None
Comment on lines +22 to +25
try:
return float(iso_str)
except (ValueError, TypeError):
raise ValueError(f"Invalid date filter value {iso_str!r}. Use ISO 8601 format (e.g., 2026-01-01).") from None
Comment on lines +22 to +25
try:
return float(iso_str)
except (ValueError, TypeError):
raise ValueError(f"Invalid date filter value {iso_str!r}. Use ISO 8601 format (e.g., 2026-01-01).") from None
Sinity added a commit that referenced this pull request May 7, 2026
Summary: Make storage-level since/until filter pushdown reject malformed date values instead of silently treating them as epoch zero.

Problem: The low-level conversation filter builder converted invalid date strings to 0.0. A malformed since/until value could therefore broaden to a near-unbounded query and look like a successful filter.

Solution: After ISO and numeric parsing both fail, _iso_to_epoch() now raises ValueError with a format hint. Storage filter tests cover both since and until.

Verification: ruff check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; ruff format --check polylogue/storage/backends/queries/filter_builder.py tests/unit/storage/test_schema_safety.py; pytest -q tests/unit/storage/test_schema_safety.py::TestConversationFilterSQL; git push pre-push hook ran devtools verify --quick and passed.

Ref #621
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