feat(cohorts): apply membership deltas to edge identities in batches - #8213
feat(cohorts): apply membership deltas to edge identities in batches#8213gagantrivedi wants to merge 27 commits into
Conversation
for more information, see https://pre-commit.ci
# Conflicts: # api/cohorts/models.py
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change adds optional system traits to identity models and DynamoDB mappings. It adds conditional DynamoDB methods to set and unset system traits with retries. It adds services and a task to apply pending cohort additions and removals in bounded batches. The task handles eligibility checks, throttling backoff, re-queuing, metrics, and structured logs. Unit tests cover trait writes, mapping, membership processing, task errors, and batch continuation. Observability catalogues document the new events and metric. Estimated code review effort: 4 (Complex) | ~45 minutes Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8213 +/- ##
========================================
Coverage 98.71% 98.72%
========================================
Files 1531 1542 +11
Lines 61263 61679 +416
========================================
+ Hits 60475 60891 +416
Misses 788 788 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…p-applier # Conflicts: # api/cohorts/models.py # api/tests/unit/cohorts/test_models.py
for more information, see https://pre-commit.ci
Docker builds report
|
|
@themis-blindfold review |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 562b1faa-9d78-4bbc-baff-dd83b4f4a90d
📒 Files selected for processing (19)
api/cohorts/constants.pyapi/cohorts/metrics.pyapi/cohorts/models.pyapi/cohorts/services.pyapi/cohorts/tasks.pyapi/environments/dynamodb/constants.pyapi/environments/dynamodb/wrappers/exceptions.pyapi/environments/dynamodb/wrappers/identity_wrapper.pyapi/tests/unit/cohorts/conftest.pyapi/tests/unit/cohorts/test_services.pyapi/tests/unit/cohorts/test_tasks.pyapi/tests/unit/environments/dynamodb/wrappers/test_unit_dynamodb_identity_wrapper.pyapi/tests/unit/util/mappers/test_unit_mappers_dynamodb.pyapi/tests/unit/util/mappers/test_unit_mappers_sdk.pyapi/util/engine_models/identities/models.pyapi/util/mappers/dynamodb.pyapi/util/mappers/sdk.pydocs/docs/deployment-self-hosting/observability/_events-catalogue.mddocs/docs/deployment-self-hosting/observability/_metrics-catalogue.md
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19020 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
🗂️ Previous results✅ private-cloud · depot-ubuntu-latest-16 — run #19020 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #19020 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
✅ oss · depot-ubuntu-latest-16 — run #19020 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
✅ private-cloud · depot-ubuntu-latest-16 — run #19018 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #19018 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19018 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Skipped testsfirefox › tests/onboarding-tests.pw.ts › Onboarding › New user connects via the single-page onboarding flow @oss ✅ oss · depot-ubuntu-latest-16 — run #19018 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19017 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
✅ private-cloud · depot-ubuntu-latest-16 — run #19017 (attempt 1)Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
✅ oss · depot-ubuntu-latest-arm-16 — run #19017 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
✅ oss · depot-ubuntu-latest-16 — run #19017 (attempt 1)Playwright Test Results (oss - depot-ubuntu-latest-16)Details
|
Visual Regression19 screenshots compared. See report for details. |
⚖️ Themis review: ✅ Ship itThird PR in the cohort sync stack: a task-processor applier that drains pending ledger rows into DynamoDB
📝 Walkthrough
🧪 How to verify
Automate: all of the above are already covered by the CI unit test matrix (3.11/3.12/3.13). Product take: Internal infrastructure for cohort-based segment membership on Edge. No user-visible change yet — the task is registered but unreachable until ingestion PRs land. When it ships, it enables syncing uploaded identifier lists to Edge identities without polling, which is a meaningful capability for customers with large cohort-driven segments. 🧭 Assumptions & unverified claims
A conditional write that never has to fire is the best kind of defensive code — may your races remain theoretical. · reviewed at 931e8d5 |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/environments/dynamodb/wrappers/identity_wrapper.py (1)
125-167: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winDo not recreate an identity after a delete race.
If the first read finds an identity and a concurrent delete occurs before the conditional write, the write fails and line 167 retries. The next strongly consistent read returns no document, so lines 125-135 successfully
put_itemand recreate the deleted identity.Track that this invocation previously observed a document. If a later retry finds it absent, return without creating a replacement document. Add a regression test for read → delete → conditional-write failure → retry.
Based on PR objectives: system-trait writes must not resurrect deleted identities.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 91db7765-a725-48c0-ac87-c8de88fda6af
📒 Files selected for processing (3)
api/environments/dynamodb/constants.pyapi/environments/dynamodb/wrappers/identity_wrapper.pyapi/tests/unit/environments/dynamodb/wrappers/test_unit_dynamodb_identity_wrapper.py
💤 Files with no reviewable changes (1)
- api/environments/dynamodb/constants.py
Zaimwa9
left a comment
There was a problem hiding this comment.
Solid work and crystal clear, nothing to add!
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Third PR of the cohort sync feature: the task-processor applier that materialises pending ledger rows as
system_traitson DynamoDB identity documents. Stacked on #8211 (merged) and #8212 (open — its commits appear in this diff until it merges, after which this will be rebased).DynamoIdentityWrapper.set_system_trait/unset_system_trait: idempotent single-attribute conditional writes (SET/REMOVE system_traits.<key>,trait_valueparam defaulting toTrue) — concurrent SDK writes to other attributes are never clobbered, and deleted identities never resurrect as ghost documentsapply_cohort_membership_deltastask: lock-free batches of 100, up to 10 batches per run then self-re-enqueues; DynamoDB throttling (all three throttle codes) maps toTaskBackoffErrorcohorts.membership.*events and a deltas-applied counter; docgen catalogues regeneratedNot production-reachable yet: nothing enqueues this task until the ingestion PRs land, and Edge must tolerate
system_traitsbefore real cohorts ship (#8212). Identifier byte-length validation is deliberately an ingestion-boundary concern, not an applier one.How did you test this code?
18 cohort unit tests plus 14 wrapper tests against a real moto DynamoDB table: add/remove/merge paths, condition-failure retries and exhaustion, guarded flips, throttle backoff, batch-loop + re-enqueue drain, metric and structured-event assertions.