Repository navigation
fix(assignment-rules): four edge cases found during the Java port - #67
Conversation
… 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>
|
No actionable comments were generated in the recent review. WalkthroughThe 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 Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Merge Risk:
|
|
Review submitted The automated review has been submitted. See the review for the verdict and any findings. Head: |
jervasion-absmartly
left a comment
There was a problem hiding this comment.
❌ 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
- 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.jswarning. - ✅ Exact-head CI passes both
formatandbuild. - ✅ Reviewed refresh invalidation, removed rule assignments, fresh/cached audience failures, rule reevaluation, and system-attribute timestamps and collisions.
- ❌ Built browser bundle with
Setunavailable:publish()rejects withSet 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:formatandbuildcompleted successfully. Commit statuses contain no contexts; the empty aggregate pending value is not a pending job. - Loaded freshly built
dist/absmartly.jsin a Node VM withSet: undefinedand Promise available. Constructed a context withincludeSystemAttributes: true, queuedtrack("goal"), calledpublish(): 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 excludeses.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 andMath.minper 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.
Also skip the event-timestamp scan when system attributes are off, and drop two comments that restated the code.
Verified at e344c5c: both built browser bundles publish without native Set; prior acceptance criterion is satisfied.
jervasion-absmartly
left a comment
There was a problem hiding this comment.
✅ 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.jswarning. - ✅ Both freshly built browser bundles publish with
Setunavailable, preserve the user'sapplicationvalue, 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:
formatandbuildboth 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.jsanddist/absmartly.min.jswithSet: undefinedand Promise available. Public SDK/context methods queued a goal with system attributes enabled and user attributes namedapplicationandhasOwnProperty. Verified one publisher call, zero pending events, only the user's application value, application-version inclusion, and system timestamp equal to goal time.Setremained unavailable throughout publication. This simulates the missing primitive, not a full IE browser session. - Exact-head Actions run
42229362079: jobs127930960526(build) and127930961210(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
left a comment
There was a problem hiding this comment.
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 buildpassed: 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.
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.
_assignkept returning a rule-matched variant after a refresh removed the experimentaf53fe6)rules evaluation › should not keep a rule variant for an experiment removed on refresh_evaluateAudiencefailed open when the audience filter threwaudienceStrictgives variant 0. A malformed audience that the matcher returnsnullfor is still indeterminate (java-sdkdc4be23)treatment() › should treat an audience that throws as a mismatch so strict audiences fail closedassignmentRulesJSON was re-parsed on every lookup afterattribute()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-sdkd3f2a8e)rules evaluation › should parse assignment rules once per context data, not on every lookupsetAt= publish time, and overrode a user attribute with the same name7f875df)includeSystemAttributes › should stamp system attributes with the earliest event in the batch,› should not send a system attribute the user has setREADME 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.main(client.test.js:1147).🤖 Generated with Claude Code
Summary by CodeRabbit