Skip to content

fix(assignment-rules): four edge cases found during the Java port - #67

Merged
joalves merged 5 commits into
mainfrom
fix/assignment-rules-edge-cases
Nov 7, 2026
Merged

joalves merged 5 commits into
mainfrom
fix/assignment-rules-edge-cases

Conversation

@joalves

@joalves joalves commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes four edge cases in custom assignment rules found while porting the feature to Java (absmartly/java-sdk#17). Each fix comes with a test that failed before the change.

# Bug Fix Test
1 _assign kept returning a rule-matched variant after a refresh removed the experiment A cached rule-won assignment is rebuilt once its experiment is gone, like any unknown experiment (java-sdk af53fe6) rules evaluation › should not keep a rule variant for an experiment removed on refresh
2 _evaluateAudience failed open when the audience filter threw A throw is a mismatch, so audienceStrict gives variant 0. A malformed audience that the matcher returns null for is still indeterminate (java-sdk dc4be23) treatment() › should treat an audience that throws as a mismatch so strict audiences fail closed
3 assignmentRules JSON was re-parsed on every lookup after attribute() AudienceMatcher.parseRules / evaluateParsedRules. The parsed rules are cached on the experiment's index entry, which is rebuilt on every data install, so a refresh invalidates the cache (java-sdk d3f2a8e) rules evaluation › should parse assignment rules once per context data, not on every lookup
4 System attributes had setAt = publish time, and overrode a user attribute with the same name They are stamped with the earliest exposure or goal time in the batch and left out when the user set the same name (java-sdk 7f875df) includeSystemAttributes › should stamp system attributes with the earliest event in the batch, › should not send a system attribute the user has set

README notes are updated for 2 and 4.

Verification

  • npm run build (prettier check, eslint, tsc, jest with coverage, ES/CJS/browser bundles) passes: 37 suites, 515 tests.
  • eslint reports 1 warning, which was already on main (client.test.js:1147).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Audience filters that fail during evaluation are now treated as mismatches. With strict audience handling enabled, the unit receives variant 0.
    • System attributes now use the earliest relevant exposure or goal time in a publish and are omitted when a user-defined attribute has the same name.
    • After a refresh, removed experiments no longer retain a variant assigned by a rule.
  • Documentation
    • Clarified system-attribute timing and override behaviour, and documented how audience evaluation failures affect assignment.

lux worker and others added 4 commits November 6, 2026 12:06
… the context data

A rule-won assignment is not flagged assigned, so after a refresh removed its
experiment it was treated like a cached not-running assignment and kept
returning the rule's variant. It is now rebuilt like any unknown experiment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_evaluateAudience returned null when evaluation threw, which left
audienceMismatch false and let a strict audience assign the unit anyway.
A throw is now a mismatch, matching the java-sdk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every lookup after an attribute change re-parsed the experiment's
assignmentRules JSON. The parsed rules are now cached on the experiment's
index entry, which is rebuilt whenever context data is installed, so a
refresh still picks up changed rules.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t and keep user-set values

System attributes were stamped with the publish time. The collector only
applies attributes whose setAt is at or before an event, so they were missing
from every event in the batch, and as the latest duplicate they superseded an
attribute the user set with the same name. They now carry the earliest
exposure or goal time in the batch and are left out when the user set the
same name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds cached assignment-rule parsing and evaluation. Audience evaluation exceptions now count as mismatches. System attributes use the earliest event time in the publish batch and are omitted when a user-defined attribute has the same name. Tests cover these changes, assignment refresh, and publishing when native Set is unavailable. The README documents the updated behaviour.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • absmartly/javascript-sdk#61: Handles indeterminate audience results as mismatches for new and cached assignments.
  • absmartly/javascript-sdk#66: Adds split actions to assignment rules and changes rule evaluation, which relates to the parsed-rule evaluation and caching in this change.
Merge Risk: Minimal · up to e344c

No issue requiring a change before merge was identified; proceed with normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title identifies fixes for assignment-rule edge cases, which matches the main change.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 3 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

src/__tests__/context.test.js

ast-grep timed out on this file

ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.

A rabbit checks the rules at dawn,
And caches each one before it’s gone.
If audiences fail, the mismatch shows,
While event-time stamping calmly flows.
Duplicate names step out of sight,
And tests confirm the publish is right.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: cc417a8e-00ad-4c90-9b1c-693f1a6f7abd
Commits

Reviewing files that changed from the base of the PR and between ab73d16 and e344c5c.

Files selected for processing: 3

  • src/__tests__/context.test.js
  • src/context.ts
  • src/matcher.ts
Files with no reviewable changes: 1

  • src/matcher.ts

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

@joalves
joalves marked this pull request as ready for review November 6, 2026 13:25
@jervasion-absmartly

jervasion-absmartly commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Review submitted

The automated review has been submitted. See the review for the verdict and any findings.

Head: e344c5cb6bb3 | Updated: 2026-11-06 14:05 UTC

@jervasion-absmartly jervasion-absmartly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

❌ Changes requested

The four fixes pass the SDK suite, but one browser compatibility regression blocks merge: publishing with system attributes now requires Set, which the supported IE 10 target does not provide.

Next step: Restore browser publishing without a native Set.

Must fix

  1. Preserve IE 10 publishing compatibility — system-attribute construction throws before events reach the publisher. src/context.ts:1105

Suggestions (optional)

  • One performance simplification and two comment blocks to tidy — see review details.

What I checked

  • ✅ Full local build passes: formatting, lint, TypeScript, 37 suites / 515 tests, and ES/CommonJS/browser bundles. Lint reports the existing client.test.js warning.
  • ✅ Exact-head CI passes both format and build.
  • ✅ Reviewed refresh invalidation, removed rule assignments, fresh/cached audience failures, rule reevaluation, and system-attribute timestamps and collisions.
  • ❌ Built browser bundle with Set unavailable: publish() rejects with Set is not a constructor, zero publisher calls and one goal still pending.
Review details

Head: ab73d16d222e79a9ddd564f012c8496bdc02a784. Base and merge-base: 7fbfa808bdc1bb7b8c78d60a6ddd51ac43c0d258. Initial review, round 1; all four commits reviewed.

Intent: discard removed experiments' rule assignments, treat audience exceptions as mismatches while retaining null behavior, cache parsed rules per data installation, and stamp system attributes at the earliest queued event while honoring user names. Actual affected consumers are public treatment/peek/variable assignment and event publishing, including the browser distribution. No rollout flag or release-order requirement is declared.

Evidence:

  • npm ci: successful, lockfile unchanged.
  • git diff --check 7fbfa808..HEAD: passed.
  • npm run build: passed; 37 suites, 515 tests.
  • Exact-head Actions run 42219144980: format and build completed successfully. Commit statuses contain no contexts; the empty aggregate pending value is not a pending job.
  • Loaded freshly built dist/absmartly.js in a Node VM with Set: undefined and Promise available. Constructed a context with includeSystemAttributes: true, queued track("goal"), called publish(): rejected as above. Independent differential source reproduction succeeds at base and fails at head. This simulates the missing primitive, not a full IE session. Browser Babel configuration targets IE 10 and excludes es.set.*.
  • Independent error specialist completed audience exception/null handling, parse failure/cache invalidation, removed assignments, and publishing recovery inspection. Primary packaging verification established the browser defect.
  • Added tests exercise the intended changed public behaviors at the existing unit-test practice level; no tests deleted.

Passes (non-blocking): run: core runtime/API/performance (independent pass and primary verification), error handling/messages (dedicated specialist completed), tests/CI/packaging, cross-cutting simplicity, comment hygiene, diff composition | not run: deployment/operations/observability (no deployment or emission changes), shared frontend components (no UI source), behaviour-bearing data/policy (no runtime configuration or policy changes).

Comment hygiene (non-blocking): 9 comment / 141 code lines, ratio ~1:15.7, 2 blocks flagged.
threshold T=5; restatements counted: no (10 × C < E)

  • src/context.ts:577: restates the false/mismatch catch behavior.
  • src/matcher.ts:51: restates the parse/evaluate separation.
    Other added blocks explain cache lifetime, the non-obvious assignment flag distinction, and external collector semantics. No promotion threshold reached.

Diff composition (non-blocking): every file is required for the change; none flagged. The pinned introduced_blobs.py helper succeeded; inspected all 11 content writes across four commits, including intermediate versions. No scratch artifacts or credential-bearing content introduced.

Simplifications (non-blocking): 1 candidate

  • Gate timestamp reductions on includeSystemAttributes: currently each default-configured publish performs one extra iteration and Math.min per exposure and goal despite not using the result. Smaller alternative: an explicit conditional around the two loops. LOC delta: approximately +2; this reduces work rather than line count and is non-blocking.

Run a simplification pass locally before pushing: these candidates cost less to address now than as a further review round.

Comment thread src/context.ts Resolved
Also skip the event-timestamp scan when system attributes are off, and drop
two comments that restated the code.
@jervasion-absmartly
jervasion-absmartly dismissed their stale review November 6, 2026 14:05

Verified at e344c5c: both built browser bundles publish without native Set; prior acceptance criterion is satisfied.

@jervasion-absmartly jervasion-absmartly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Approved

The earlier browser-publishing blocker is fixed. Publishing with system attributes succeeds without native Set, and the full SDK build and exact-head CI pass. No blocking issues remain.

Next step: None — ready to merge.

What I checked

  • ✅ Full local build: formatting, lint, TypeScript, 37 suites / 516 tests, and ES/CommonJS/browser bundles pass. Lint retains the existing client.test.js warning.
  • ✅ Both freshly built browser bundles publish with Set unavailable, preserve the user's application value, stamp system attributes at the queued goal time, and clear pending events.
  • ✅ Reviewed removed-experiment refresh behavior, fresh/cached audience failures, parsed-rule cache invalidation, and system-attribute collisions and timing.
  • ✅ Exact-head CI: format and build both pass.
Review details

Head: e344c5cb6bb3213843692d57c501046d7a1d0be1. Base and merge-base: 7fbfa808bdc1bb7b8c78d60a6ddd51ac43c0d258. Round 2, changes-requested follow-up; all five commits and the full merge-base-to-head change reviewed.

Intent and scope: discard rule assignments when their experiment disappears, fail closed for audience evaluation exceptions while preserving null handling, cache parsed assignment rules per context-data installation, and publish system attributes with event-effective timestamps without replacing user values. Affected consumers include public treatment/peek/variable assignment and publishing in Node and browser distributions. No rollout flag or release-order dependency is declared. The author reports a full build with 516 tests; local verification agrees.

Earlier acceptance criterion: publishing with system attributes must work without native Set. The object lookup and own-property check satisfy it, and the new absent-Set test passes. The optional timestamp-scan gate and two comment cleanups are also addressed.

Verification:

  • npm ci: successful; tracked lockfile unchanged.
  • git diff --check 7fbfa808..HEAD: passed.
  • npm run build: passed, including formatter, ESLint, compilation, all 37 suites / 516 tests with coverage, and all distributions.
  • Node VM harness loaded both dist/absmartly.js and dist/absmartly.min.js with Set: undefined and Promise available. Public SDK/context methods queued a goal with system attributes enabled and user attributes named application and hasOwnProperty. Verified one publisher call, zero pending events, only the user's application value, application-version inclusion, and system timestamp equal to goal time. Set remained unavailable throughout publication. This simulates the missing primitive, not a full IE browser session.
  • Exact-head Actions run 42229362079: jobs 127930960526 (build) and 127930961210 (format) completed successfully. Commit statuses contain no contexts; their empty aggregate pending value is not a pending job. CodeRabbit reports no actionable finding; its auxiliary tool timeouts are covered by successful local lint/test execution.
  • Independent runtime/API/performance and simplicity pass completed. Dedicated error specialist completed static audience throws/nulls, malformed rules, cache lifetime, removed assignments, and publication recovery review; primary executed the full build and browser harness. No surviving findings.
  • Added behavioral tests match the repository's existing unit-level practice; no tests deleted.

Passes (non-blocking): run: core runtime/API/security/data/performance (executable assignment and publication changes; independent and primary review), error handling/messages (throw/parse/publish failure paths; dedicated specialist completed), tests/CI/packaging (changed tests and browser-visible behavior), cross-cutting simplicity (cache, lookup and timestamp computation), comment hygiene, diff composition | not run: deployment/operations/observability (no deployment or telemetry emission changes), shared-component blast radius (no UI components), behaviour-bearing data/policy (no runtime configuration or policy changes).

Comment hygiene (non-blocking): 8 comment / 172 code lines, ratio ~1:21.5, none flagged.
threshold T=5; restatements counted: no (10 × C < E)
Remaining comments explain cache lifetime, a non-obvious assignment flag distinction, external collector semantics, and the IE 10 constraint.

Diff composition (non-blocking): every file is required for the change; none flagged. The pinned introduced_blobs.py helper succeeded; reviewed all 14 content writes across five commits, including intermediate versions. No scratch artifacts or credential-bearing content introduced.

Simplifications (non-blocking): none. The earlier default-path timestamp scan is now gated; the cache, name lookup, helper and local timestamp each serve a distinct requirement.

@marcio-absmartly marcio-absmartly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the complete base-to-head change at e344c5c (base 7fbfa80). No actionable regressions found.

Checked assignment lifecycle/cache invalidation, rule parsing/evaluation, thrown versus indeterminate audiences, event-time system attributes, and user-name collisions. The parsed rule tree is read-only under the evaluator, entries are rebuilt on refresh, and the default publish path avoids the timestamp scans. The earlier absent-Set browser issue is fixed.

Verification on a fresh exact-head checkout on macmini:

  • Full npm run build passed: formatter, lint, TypeScript, 37 suites / 516 tests, ES/CommonJS and both browser bundles. The existing client.test.js lint warning remains.
  • 13 additional runtime probes passed: changed/removed rules on refresh (including rule variant 0), real nested-variable audience exceptions on fresh/cached assignments, non-strict exception metadata, malformed JSON behavior, parse reuse and AST immutability, repeated publish timestamps, all system-name overrides plus prototype-shaped names, and failed-batch recovery.
  • Both freshly built browser bundles successfully publish with native Set absent; user application value, event-effective timestamp, and pending-queue clearing verified. This is a Node VM missing-primitive check, not an actual IE 10 browser run.
  • Exact-head GitHub format/build checks are green.

Review limitation: the independent OpenCode test reviewer completed npm ci and the full 516-test build, but its subsequent provider call was rate-limited before it produced a final findings report. I did not count that as an independent approval; the completed primary review, full build and extra executable probes above support this verdict.

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.

3 participants