Skip to content

fix(store): add missing "lt" operator to PG filter parser#6140

Merged
gustavosbarreto merged 1 commit intomasterfrom
fix/device-cleanup-filter
Apr 8, 2026
Merged

fix(store): add missing "lt" operator to PG filter parser#6140
gustavosbarreto merged 1 commit intomasterfrom
fix/device-cleanup-filter

Conversation

@gustavosbarreto
Copy link
Copy Markdown
Member

What

Added the missing "lt" (less than) operator to the PostgreSQL
filter property parser, which was silently discarding the filter
condition used by the device cleanup cron job.

Why

The device cleanup cron (runs daily at 2 AM UTC) filters devices
with removed_at < 30 days ago. Since the PG filter parser had
no handler for the "lt" operator, it fell through to the default
case returning an empty condition without error. The cleanup then
ran unfiltered, deleting all devices. Agents reconnecting
afterward created new pending devices, causing every accepted
device to revert to pending status every morning.

Fixes #6134

Changes

  • store/pg/internal/filters.go: added fromLt() with support
    for numeric types, time.Time, and string values
  • store/pg/internal/filters.go: added time.Time case to the
    existing fromGt() for consistency

The device cleanup cron job uses a "lt" (less than) filter to
select devices with removed_at older than 30 days. The PG
filter parser did not handle the "lt" operator, silently
falling through to the default case which returned an empty
condition. This caused the cleanup to run without any filter,
deleting all devices regardless of their status.

When agents reconnected after the cleanup, they created new
devices as pending, making all previously accepted devices
appear unapproved every morning at 2 AM UTC.

Also add time.Time support to the existing "gt" operator for
consistency.

Fixes: #6134
@gustavosbarreto gustavosbarreto requested a review from a team as a code owner April 8, 2026 18:48
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Claude finished @gustavosbarreto's task in 1m 46s —— View job


Code Review Complete

Reviewed 1 file across code quality, security, testing, Go patterns, and architecture — no issues found. The code looks good as-is.

The new fromLt() correctly mirrors the existing fromGt() with < instead of >, handles the same type set (numeric, time.Time, string-to-number), uses parameterized queries via bun's ? placeholders, and has no cross-repo impact (cloud's MongoDB filter parser is independent and already supports "lt").


To request another review round, comment /review.

@gustavosbarreto gustavosbarreto merged commit 4c1be14 into master Apr 8, 2026
13 checks passed
@gustavosbarreto gustavosbarreto deleted the fix/device-cleanup-filter branch April 8, 2026 19:11
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.

After upgrade from 0.22.0 to 0.24.0 (Mongo→Postgres migration) devices become pending/unapproved automatically

1 participant