Skip to content

feat: support starts_with and ends_with operators in local evaluation - #229

Draft
haacked wants to merge 1 commit into
mainfrom
posthog-code/starts-with-ends-with-operators
Draft

feat: support starts_with and ends_with operators in local evaluation#229
haacked wants to merge 1 commit into
mainfrom
posthog-code/starts-with-ends-with-operators

Conversation

@haacked

@haacked haacked commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

💡 Motivation and Context

PostHog/posthog#72992 added four case-insensitive property filter operators — starts_with, not_starts_with, ends_with, not_ends_with — across HogQL, the flags service, and the UI. The UI surface is gated behind a feature flag until server-side SDKs can evaluate these operators locally; on SDK versions without support, flags using them fall back to remote evaluation.

This adds local evaluation support for the four operators, mirroring icontains: both sides are stringified and lowercased, and the not_ variants are exact negations. Filter values are single strings — server-side validation rejects list values for these operators, matching the flags service behavior.

💚 How did you test it?

New unit tests mirror the flags service's own test matrix for these operators: case-insensitive anchored matching, mid-string non-matches (prevalue does not match starts_with: "Val"), numeric stringification (323 matches starts_with: "3", 123 does not), negation inverses, and missing-key inconclusive behavior.

bundle exec rspec spec/posthog/feature_flag_spec.rb passes locally (106 examples), and bundle exec rubocop reports no offenses on the changed files.

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Added a changeset file (minor, posthog-ruby package)

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Implemented with PostHog Code as part of rolling out local evaluation for these operators across all server-side SDKs. The implementation deliberately mirrors the existing icontains branch in this repo (same string coercion and case folding) and the reference behavior in the Rust flags service (rust/feature-flags/src/properties/property_matching.rs in PostHog/posthog). The changeset file was written by hand following the repo's existing format.


Created with PostHog Code

Adds local evaluation for the starts_with, not_starts_with, ends_with,
and not_ends_with property filter operators (PostHog/posthog#72992).
Matching is case-insensitive and mirrors icontains: both sides are
stringified and lowercased, and the not_ variants are exact negations.

Generated-By: PostHog Code
Task-Id: ef980bb5-ff81-4191-a7df-796e932b8251
@haacked haacked self-assigned this Jul 31, 2026
@github-actions

Copy link
Copy Markdown

posthog-ruby Compliance Report

Date: 2026-07-31 02:44:16 UTC
Duration: 98478ms

✅ All Tests Passed!

46/46 tests passed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 110ms
Format Validation.Event Has Uuid 106ms
Format Validation.Event Has Lib Properties 108ms
Format Validation.Distinct Id Is String 107ms
Format Validation.Token Is Present 107ms
Format Validation.Custom Properties Preserved 106ms
Format Validation.Event Has Timestamp 107ms
Retry Behavior.Retries On 503 5314ms
Retry Behavior.Does Not Retry On 400 2108ms
Retry Behavior.Does Not Retry On 401 2109ms
Retry Behavior.Respects Retry After Header 8116ms
Retry Behavior.Implements Backoff 15722ms
Retry Behavior.Retries On 500 5212ms
Retry Behavior.Retries On 502 5211ms
Retry Behavior.Retries On 504 5212ms
Retry Behavior.Max Retries Respected 15522ms
Deduplication.Generates Unique Uuids 111ms
Deduplication.Preserves Uuid On Retry 5211ms
Deduplication.Preserves Uuid And Timestamp On Retry 10417ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5214ms
Deduplication.No Duplicate Events In Batch 113ms
Deduplication.Different Events Have Different Uuids 109ms
Compression.Sends Gzip When Enabled 107ms
Batch Format.Uses Proper Batch Structure 106ms
Batch Format.Flush With No Events Sends Nothing 4ms
Batch Format.Multiple Events Batched Together 112ms
Error Handling.Does Not Retry On 403 2109ms
Error Handling.Does Not Retry On 413 2108ms
Error Handling.Retries On 408 5212ms

Feature_Flags Tests

17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 108ms
Request Payload.Flags Request Uses V2 Query Param 107ms
Request Payload.Flags Request Hits Flags Path Not Decide 106ms
Request Payload.Flags Request Omits Authorization Header 107ms
Request Payload.Token In Flags Body Matches Init 106ms
Request Payload.Groups Round Trip 107ms
Request Payload.Groups Default To Empty Object 107ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 107ms
Request Payload.Disable Geoip Omitted Defaults To False 108ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 109ms
Request Lifecycle.No Flags Request On Init Alone 3ms
Request Lifecycle.No Flags Request On Normal Capture 105ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 110ms
Request Lifecycle.Mock Response Value Is Returned To Caller 106ms
Retry Behavior.Retries Flags On 502 209ms
Retry Behavior.Retries Flags On 504 250ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 108ms

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.

1 participant