Repository navigation
Conversation
Local regex matching now stays within the subset on which Python's re and
the flags service's engine agree, as the sdk-specs local evaluator requires.
A criterion outside it is inconclusive, so the flag falls back to /flags or
is unresolved in local-only mode, and not_regex or cohort negation never
turns it into a match.
Newly deferred: non-ASCII patterns; non-ASCII values under any shorthand
class, including \d; repeated groups that hold an assertion or an
alternation; and patterns whose counted repetitions expand beyond a fixed
budget, such as \w{210}, which the flags service rejects as too large to
compile.
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 |
Compare each deferred condition’s possible rollout and variant with the first later match. Keep the deferral through cohorts and flag dependencies when the outcomes can differ. Cache pattern-only deferrals and stop scanning at the flags service’s group nesting limit.
💡 Motivation and Context
The sdk-specs local evaluator limits local regex matching to a portable subset on which the SDK's engine agrees with the flags service (
fancy_regexover theregexcrate, with a 10,000-step backtracking budget). Outside that subset the criterion is inconclusive, even when Python'srewould decide it. The v1 regex helpers, which the config version 2 evaluator also uses, still decided some of these cases locally:^\d+$against"١٢٣": any non-ASCII value under\d,\D,\s,\S,\wor\Wnow defers;\w{210}: the flags service rejects it as too large to compile, sonot_regexmatched locally where the service reports an invalid pattern. Counted repetitions are now bounded (see below);^,$or an alternation.A deferred criterion falls back to
/flags, or is unresolved withonly_evaluate_locally=True.not_regex, negation and cohortnot_innever turn it into a match.Details for reviewers
The size bound. The flags service compiles a pattern with its regex engine's size limit and treats a larger one as invalid. I measured that limit with the crate versions the service builds with (fancy-regex 0.17.0, regex 1.12.4) and the same builder settings: it accepts at most 209 copies of
\w, 208 of[\w\s](the largest class this SDK keeps local), 2,046 of\d, 10,485 of., 87,379 of[a-zA-Z0-9._%+-]and 327,673 ofa. The cost adds up across a pattern:\w{105}\w{105}and\w{50}|\w{50}|\w{50}|\w{50}|\w{50}are rejected too. So the translator counts each atom after multiplying out counted repetitions ({n}is n copies,{n,m}is m,{n,}is n + 1,*,+and?one) and summing over alternatives. A class that can match a non-ASCII character (., a shorthand class, a negated class, or a class holding a shorthand) costs 100, and any other atom 1. A pattern stays local while the total is at most 10,000: at most 100 Unicode classes or 10,000 ASCII atoms, so under half of the limit for any mix. That leaves room for later Unicode tables and other crate versions. It keeps patterns such as^[a-f0-9]{64}$,^\d{3}-\d{4}$and^.{0,100}$local;^.{0,255}$now goes to the service.Repeated alternation. The spec lists nested quantification among the shapes that can exceed the SDK's own resource limits. Python's backtracking takes exponential time on a repeated group whose alternatives overlap:
^(a|a)+$against 24aand abtakes 0.65 s, and each extra character doubles it. The service's engine has no such problem. So*,+and counted repetitions of a group that holds an alternation now defer.?on such a group stays local. Existing rows that kept^(?:a|aa)+$and^(?:ab|cd){2,3}$local now expect a deferral, as do the rows for^é+$and for non-ASCII values under shorthand classes.Repeated assertions.
^*and$?already deferred. A group that holds an assertion, such as(?:^a)*bor(?:a|$){2}, now defers too.Unchanged. A non-ASCII value without a shorthand class stays local (
^caf.$against"café",[^a]against"é"), because.and ASCII or negated classes have the same membership in both engines. The known-absent and invalid-pattern rules are unchanged.Contract corpus. No vendored corpus case or config fixture moves from decided to inconclusive: their patterns (
[,^[0-9]+$,^bl(ue)$,^red$,blue) are all in the subset.Cross-SDK. posthog-node already defers non-ASCII patterns and every non-ASCII value. It accepts repeat counts up to 4,294,967,295, so it still decides
\w{210}and repeated alternations locally.💚 How did you test it?
test_feature_flags_regex.pyandtest_feature_flags_v2.py(the spec's "Engine-divergent regex evaluation defers to the service" rows, each class above, the bound on both sides, negation and cohortnot_in, the public getters in both modes, and the config version 2 evaluator) failed before the change (125 failures) and pass after.main, 1,500 of the patterns with large repeat counts already gave 224 that the SDK decides and the service rejects as too large.test_metrics_autocapture.pyfail on macOS onmaintoo),ruff format --check .,ruff check ., mypy with the baseline,make public_api_check(unchanged) andpython -W error -c "import posthog".📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
\w{105}\w{105}local, which the service rejects.🤖 Generated with Claude Code