Repository navigation
fix(flags): clamp relative month and year lookbacks after every step - #1212
Conversation
Month and year lookbacks jumped straight to the target and clamped once. The SDK spec requires one unit at a time with a clamp after every step, so 2m on March 31 is January 28, and 4y on February 29 is February 28.
marandaneto
left a comment
There was a problem hiding this comment.
The code looks good; no qualifying findings. Verdict: correct.
SDK performance: posthog-pythonBenchmarks completed. No changes flagged for review. Flags require at least a 5% change in the median and all six pairs agreeing on direction. This is a noise filter, not proof of a performance change or a CI gate. View all results
Values are medians of paired measurements. Not flagged does not mean unchanged. Unavailable means a measurement could not be provided, not zero. Estimated allocation measurements retain their instrumentation uncertainty. RSS measures the whole process, not just SDK allocations; observed peaks are sampled checkpoints. Paired ranges in the diagnostics describe variability, not confidence intervals. Each shard uses its own runner; compare Before PR against With PR within a row, not across shards. Compared 102 metric rows; 102 rows shown in all results. Omitted or shortened data remain in |
💡 Motivation and Context
_subtract_monthswent straight to the target month and clamped once, so a2mfilter evaluated on March 31 resolved to January 31. The local evaluator spec subtracts one unit at a time and clamps after every step, and its scenario for that clock and condition expects2025-01-28T12:00:00Z. The Rust flags service (rust/feature-flags/src/properties/relative_date.rs) also gives January 28, so the SDK and the service could resolve the same filter up to three days apart.Years had the same problem on a leap day:
4yon February 29, 2024 gave February 29, 2020 and now gives February 28.1mand1yresults don't change, so the clamp from #540 still holds for them.Two divergences I left alone. The spec asks for subtraction on the team's wall clock and the SDK still uses UTC. And
posthog/models/property/relative_date.pyin the main repo does a singlerelativedeltajump, which gives January 31 where the spec and the Rust service give January 28.💚 How did you test it?
Six of the ten new subtests fail without the fix (five month cases and
4yon a leap day). The other four are cases that must not move, and two more assertions cover0mand0y. I ran the same twelve inputs throughparse_relative_date_naivefrom the Rust file, compiled as is, and it returned the expected date for all of them.I also compared both functions against a plain one-unit-at-a-time loop for every day from 2019 through 2028, with lookbacks from 0 to 129 plus 4000 and 9999: 964,392 comparisons, no differences.
In
python:3.12-slimwith the lockfile:pytest posthog/test(6164 passed, 64 skipped),ruff format --check .andruff check .on 0.12.2,mypy ... | mypy-baseline filter, andpython -W error -c "import posthog". I didn't run the acceptance harness, since this scenario is@serverand usesis_date_exact, which the SDK doesn't implement.📝 Checklist
If releasing new changes
sampo add)🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Claude Code (Claude Opus 5.5) wrote the change and ran the checks, and Luan Taraschi directed the work and reviewed it. The bug came up while comparing the SDK with sdk-specs. The loop stops at day 28 because no month can clamp further, which keeps large lookbacks cheap.