Skip to content

feat(user_cohort): add user cohort#1116

Open
sauraww wants to merge 1 commit into
mainfrom
feat/user-cohort
Open

feat(user_cohort): add user cohort#1116
sauraww wants to merge 1 commit into
mainfrom
feat/user-cohort

Conversation

@sauraww

@sauraww sauraww commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

Superposition currently supports cohorts whose definitions are shared across the workspace. This does not support cases where cohort boundaries differ by merchant.

For example, amount_bucket may be derived from amount, but merchant saurav may define low_value as an amount below 1,000, while another merchant may use 2,000.

The existing single-pass resolution cannot first select the merchant-specific definitions and then use those definitions to calculate the cohort.

Solution

Introduce a new USER_COHORT dimension type with an explicit based_on dimension.

For example:

{
  "USER_COHORT": "amount"
}

Creating an amount_bucket user cohort:

  • Stores its ordered cohort options and default definitions in the dimension schema.
  • Atomically creates a generated default-config key named amount_bucket.
  • Uses context overrides on this generated key to store merchant-specific definitions.
  • Prevents the generated key from being created, updated, or deleted through the default-config APIs.
  • Updates or deletes the generated key only through the corresponding dimension operation.

Resolution now happens in two passes:

  1. Resolve the generated definition key for the incoming merchant context.
  2. Evaluate amount_bucket using the resolved definitions and then resolve the final configuration.

Generated definition keys remain internal and are removed from the final resolved response.

The implementation also adds:

  • Structural parsing validation for local, remote, and user cohort dimension types.
  • Validation that definitions match the dimension enum and only reference the declared based_on dimension.
  • Validation of merchant-specific definition overrides.
  • UI support for creating and viewing user cohorts.
  • JSON/TOML import-export validation for the dimension and generated-key pair.
  • SDK and provider support for the new USER_COHORT variant.

Cohort enum order defines priority. If multiple definitions match, the first matching option wins. otherwise remains the final fallback.

Environment variable changes

No environment variables need to be added or changed.

Pre-deployment activity

No database migration or data backfill is required.

The Smithy-generated SDKs, provider, backend, and frontend should be released together because they must all understand the new USER_COHORT dimension variant.

Post-deployment activity

No mandatory post-deployment activity is required.

Recommended smoke test:

  1. Create an amount_bucket user cohort derived from amount.
  2. Add a merchant-specific override for its generated definition key.
  3. Resolve configuration using that merchant and an amount.
  4. Verify that the expected cohort-specific configuration is returned.
  5. Verify that the generated definition key is absent from the resolved response.

Summary by CodeRabbit

  • New Features

    • Added support for defining and managing user cohort dimensions.
    • User cohort dimensions can now generate and maintain their associated configuration values automatically.
    • Configuration evaluation now resolves user cohort data and applies matching overrides.
    • Added user cohort options across supported SDKs and API schemas.
  • Bug Fixes

    • Improved validation for user cohort definitions and overrides.
    • Prevented direct editing of configurations managed by user cohort dimensions.
    • Clarified access-denied error handling.

@sauraww
sauraww requested a review from a team as a code owner July 22, 2026 11:10
Copilot AI review requested due to automatic review settings July 22, 2026 11:10
@semanticdiff-com

semanticdiff-com Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  docs/docs/api/list-versions.StatusCodes.json  99% smaller
  docs/docs/api/get-version.StatusCodes.json  99% smaller
  docs/docs/api/get-config.StatusCodes.json  98% smaller
  docs/docs/api/update-dimension.StatusCodes.json  98% smaller
  docs/docs/api/create-dimension.StatusCodes.json  98% smaller
  docs/docs/api/list-dimensions.StatusCodes.json  98% smaller
  docs/docs/api/get-dimension.StatusCodes.json  97% smaller
  docs/docs/api/create-dimension.RequestSchema.json  96% smaller
  crates/frontend/src/components/dimension_form.rs  77% smaller
  crates/frontend/src/pages/dimension.rs  74% smaller
  crates/context_aware_config/src/helpers.rs  65% smaller
  crates/context_aware_config/src/api/context/helpers.rs  41% smaller
  crates/frontend/src/pages/default_config.rs  41% smaller
  crates/context_aware_config/src/api/dimension/validations.rs  34% smaller
  crates/superposition_types/src/config.rs  32% smaller
  crates/superposition_types/src/logic.rs  27% smaller
  crates/superposition_types/src/logic/tests.rs  25% smaller
  crates/superposition_core/src/config.rs  15% smaller
  crates/context_aware_config/src/api/context/validations.rs  14% smaller
  crates/superposition_types/src/database/models/cac.rs  14% smaller
  crates/context_aware_config/src/api/dimension/handlers.rs  13% smaller
  crates/superposition_core/src/format.rs  8% smaller
  clients/java/sdk/src/main/java/io/juspay/superposition/model/DimensionType.java  7% smaller
  crates/superposition_provider/src/utils.rs  5% smaller
  clients/python/sdk/superposition_sdk/models.py  1% smaller
  Cargo.lock Unsupported file format
  clients/haskell/sdk/Io/Superposition/Model/DimensionType.hs Unsupported file format
  clients/java/sdk/src/main/java/io/juspay/superposition/client/SuperpositionAsyncClientImpl.java  0% smaller
  clients/java/sdk/src/main/java/io/juspay/superposition/client/SuperpositionClientImpl.java  0% smaller
  clients/javascript/sdk/src/commands/CreateDimensionCommand.ts  0% smaller
  clients/javascript/sdk/src/commands/GetConfigCommand.ts  0% smaller
  clients/javascript/sdk/src/commands/GetDimensionCommand.ts  0% smaller
  clients/javascript/sdk/src/commands/GetVersionCommand.ts  0% smaller
  clients/javascript/sdk/src/commands/ListDimensionsCommand.ts  0% smaller
  clients/javascript/sdk/src/commands/ListVersionsCommand.ts  0% smaller
  clients/javascript/sdk/src/commands/UpdateDimensionCommand.ts  0% smaller
  clients/javascript/sdk/src/models/models_0.ts  0% smaller
  clients/python/sdk/superposition_sdk/_private/schemas.py  0% smaller
  crates/context_aware_config/Cargo.toml Unsupported file format
  crates/context_aware_config/src/api/config/helpers.rs  0% smaller
  crates/context_aware_config/src/api/default_config.rs  0% smaller
  crates/context_aware_config/src/api/default_config/handlers.rs  0% smaller
  crates/frontend/src/types.rs  0% smaller
  crates/superposition_core/src/format/tests/json.rs  0% smaller
  crates/superposition_core/src/format/tests/toml.rs  0% smaller
  crates/superposition_core/tests/format_integration.rs  0% smaller
  crates/superposition_sdk/src/protocol_serde/shape_dimension_type.rs  0% smaller
  crates/superposition_sdk/src/types/_dimension_type.rs  0% smaller
  docs/docs/api/Superposition.openapi.json  0% smaller
  docs/docs/api/create-dimension.api.mdx Unsupported file format
  docs/docs/api/get-config.api.mdx Unsupported file format
  docs/docs/api/get-dimension.api.mdx Unsupported file format
  docs/docs/api/get-version.api.mdx Unsupported file format
  docs/docs/api/list-dimensions.api.mdx Unsupported file format
  docs/docs/api/list-versions.api.mdx Unsupported file format
  docs/docs/api/update-dimension.api.mdx Unsupported file format
  smithy/models/dimension.smithy Unsupported file format

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eece2aa1-acbf-47fb-ada0-66330417a525

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

Changes

User cohort dimension support

Layer / File(s) Summary
Dimension contracts and SDK serialization
smithy/models/dimension.smithy, clients/*/sdk/..., docs/docs/api/*
Adds the USER_COHORT dimension variant across internal models, Haskell, Java, Python, JavaScript, Rust serialization, OpenAPI schemas, and API examples.
Cohort evaluation pipeline
crates/superposition_types/src/logic.rs, crates/superposition_core/src/config.rs, crates/superposition_core/src/format.rs
Centralizes cohort evaluation, validates and resolves user-cohort definitions, updates prefix filtering, and routes configuration evaluation through cohort-aware APIs.
Dimension and override lifecycle
crates/context_aware_config/src/api/..., crates/context_aware_config/src/helpers.rs
Generates, updates, and deletes user-cohort default configs; validates overrides and dependencies; and rejects direct default-config operations for user-cohort-owned keys.
Provider and frontend integration
crates/superposition_provider/src/utils.rs, crates/frontend/src/...
Maps and evaluates user-cohort dimensions in the provider and adds cohort-specific dimension forms, rendering, ownership badges, and edit restrictions.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • juspay/superposition#1079: Both changes modify the configuration-resolution path in crates/superposition_core/src/config.rs.

Suggested labels: P0

Suggested reviewers: copilot, datron, mahatoankitkumar

Poem

A rabbit hops through cohorts bright,
With schemas tucked beneath moonlight.
Values resolve and configs gleam,
Generated keys fade from the stream.
“USER_COHORT!” the burrow sings—
New paths sprout on SDK wings.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding user cohort support.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/user-cohort

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new USER_COHORT dimension type to support merchant-specific cohort definitions (via context overrides on a generated, system-owned default-config key), and updates resolution/validation so cohorts can be evaluated using merchant-resolved definitions in a second pass. The change spans the Smithy model + generated SDKs, backend validation + CRUD rules around the generated key, core evaluation logic, and frontend UI/UX for creating/viewing user cohorts.

Changes:

  • Add USER_COHORT to the Smithy DimensionType union and propagate it through OpenAPI/docs and all generated SDKs (Rust/JS/Python/Java/Haskell).
  • Implement user cohort definition validation + two-pass cohort evaluation (resolve definitions first, then evaluate cohorts), and remove generated definition keys from resolved config output.
  • Enforce “generated key is dimension-owned” behavior: create/update/delete generated default-config keys only via dimension operations; block default-config APIs from mutating user-cohort-owned keys; update frontend to reflect locked ownership.

Reviewed changes

Copilot reviewed 56 out of 57 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
smithy/models/dimension.smithy Adds USER_COHORT to the Smithy DimensionType union.
docs/docs/api/update-dimension.StatusCodes.json Updates API schema docs to include USER_COHORT.
docs/docs/api/update-dimension.api.mdx Regenerates API docs (patch payload updated).
docs/docs/api/Superposition.openapi.json Updates OpenAPI schema to include USER_COHORT variant.
docs/docs/api/list-versions.StatusCodes.json Updates API schema docs to include USER_COHORT.
docs/docs/api/list-versions.api.mdx Regenerates API docs (patch payload updated).
docs/docs/api/list-dimensions.StatusCodes.json Updates API schema docs to include USER_COHORT.
docs/docs/api/list-dimensions.api.mdx Regenerates API docs (patch payload updated).
docs/docs/api/get-version.StatusCodes.json Updates API schema docs to include USER_COHORT.
docs/docs/api/get-version.api.mdx Regenerates API docs (patch payload updated).
docs/docs/api/get-dimension.StatusCodes.json Updates API schema docs to include USER_COHORT.
docs/docs/api/get-dimension.api.mdx Regenerates API docs (patch payload updated).
docs/docs/api/get-config.StatusCodes.json Updates API schema docs to include USER_COHORT.
docs/docs/api/get-config.api.mdx Regenerates API docs (patch payload updated).
docs/docs/api/create-dimension.StatusCodes.json Updates API schema docs to include USER_COHORT.
docs/docs/api/create-dimension.RequestSchema.json Updates create-dimension request schema docs to include USER_COHORT.
docs/docs/api/create-dimension.api.mdx Regenerates API docs (patch payload updated).
crates/superposition_types/src/logic/tests.rs Updates tests for renamed start-dimension function and local cohort evaluation helper.
crates/superposition_types/src/logic.rs Adds user cohort evaluation/validation helpers and two-pass cohort evaluation support.
crates/superposition_types/src/database/models/cac.rs Adds DimensionType::UserCohort, parsing/display updates, and tests for strict parsing.
crates/superposition_types/src/config.rs Ensures prefix filtering accounts for user cohort generated keys during filtering.
crates/superposition_sdk/src/types/_dimension_type.rs Adds Rust SDK DimensionType::UserCohort variant helpers.
crates/superposition_sdk/src/protocol_serde/shape_dimension_type.rs Adds serde (de)serialization support for USER_COHORT.
crates/superposition_provider/src/utils.rs Switches provider-side evaluation to core eval_cac and adds SDK→types conversion for UserCohort.
crates/superposition_core/tests/format_integration.rs Adds JSON import/export round-trip tests for user cohort + generated key pairing and override validation.
crates/superposition_core/src/format/tests/toml.rs Adjusts error expectations for malformed cohort dimension types.
crates/superposition_core/src/format/tests/json.rs Adjusts error expectations for malformed cohort dimension types.
crates/superposition_core/src/format.rs Adds import/export validation for user cohort dimensions and generated-key constraints + override validation.
crates/superposition_core/src/config.rs Implements two-pass resolution entrypoints and removes generated keys from resolved output.
crates/frontend/src/types.rs Adds frontend enum option for “User Cohort”.
crates/frontend/src/pages/dimension.rs Updates dimension view to handle/display user cohort similarly to local cohort.
crates/frontend/src/pages/default_config.rs Locks default-config edit/delete UI for system-owned user cohort definition keys.
crates/frontend/src/components/dimension_form.rs Adds form support for user cohort type; disables value-compute fn selection for cohort types.
crates/context_aware_config/src/helpers.rs Updates cohort evaluation entrypoints to new start-dimension function; skips local/user cohort in remote cohort dependency evaluation.
crates/context_aware_config/src/api/dimension/validations.rs Adds user cohort override validation and updates cohort base-dimension validation rules.
crates/context_aware_config/src/api/dimension/handlers.rs Creates/updates/deletes generated default-config keys for user cohort dimensions and validates overrides.
crates/context_aware_config/src/api/default_config/handlers.rs Blocks default-config create/update/delete when key is owned by a user cohort dimension.
crates/context_aware_config/src/api/default_config.rs Re-exports key-usage lookup for dimension deletion checks.
crates/context_aware_config/src/api/context/validations.rs Validates user cohort definition overrides placed in contexts.
crates/context_aware_config/src/api/context/helpers.rs Replaces cac_client::merge usage with core merge and updates start-dimension function reference.
crates/context_aware_config/src/api/config/helpers.rs Switches to core eval functions and resolves user cohorts for “explain” flows.
crates/context_aware_config/Cargo.toml Removes cac_client dependency.
clients/python/sdk/superposition_sdk/models.py Adds Python SDK union variant model for USER_COHORT.
clients/python/sdk/superposition_sdk/_private/schemas.py Adds Python SDK schema member for USER_COHORT.
clients/javascript/sdk/src/models/models_0.ts Adds JS SDK DimensionType.USER_COHORTMember and visitor support.
clients/javascript/sdk/src/commands/UpdateDimensionCommand.ts Updates JS SDK docs/examples to include USER_COHORT.
clients/javascript/sdk/src/commands/ListVersionsCommand.ts Updates JS SDK docs/examples to include USER_COHORT.
clients/javascript/sdk/src/commands/ListDimensionsCommand.ts Updates JS SDK docs/examples to include USER_COHORT.
clients/javascript/sdk/src/commands/GetVersionCommand.ts Updates JS SDK docs/examples to include USER_COHORT.
clients/javascript/sdk/src/commands/GetDimensionCommand.ts Updates JS SDK docs/examples to include USER_COHORT.
clients/javascript/sdk/src/commands/GetConfigCommand.ts Updates JS SDK docs/examples to include USER_COHORT.
clients/javascript/sdk/src/commands/CreateDimensionCommand.ts Updates JS SDK docs/examples to include USER_COHORT.
clients/java/sdk/src/main/java/io/juspay/superposition/model/DimensionType.java Adds Java SDK UserCohortMember union member and builder wiring.
clients/java/sdk/src/main/java/io/juspay/superposition/client/SuperpositionClientImpl.java Minor ordering change in Java client type registry.
clients/java/sdk/src/main/java/io/juspay/superposition/client/SuperpositionAsyncClientImpl.java Minor ordering change in Java async client type registry.
clients/haskell/sdk/Io/Superposition/Model/DimensionType.hs Adds Haskell SDK UserCohort variant and parser error message update.
Cargo.lock Removes cac_client lock entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 326 to 330
pub fn filter_by_prefix(self, prefix_list: &HashSet<String>) -> Self {
let filtered_default_config = self.filter_default_by_prefix(prefix_list);
let mut effective_prefixes = prefix_list.clone();
effective_prefixes.extend(user_cohort_dimension_names(&self.dimensions));
let filtered_default_config = self.filter_default_by_prefix(&effective_prefixes);

Comment on lines +317 to +320
let rows = contexts::dsl::contexts
.schema_name(schema_name)
.load::<Context>(conn)?;

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/context_aware_config/src/api/dimension/handlers.rs`:
- Around line 790-796: Update the generated default-config deletion in the
is_user_cohort branch to use the same optional-result handling as the preceding
dimension deletion, so an absent row does not propagate Diesel’s NotFound error.
Preserve the existing delete filter, schema_name, and transaction flow.

In `@crates/frontend/src/pages/default_config.rs`:
- Around line 37-41: Update the dimension ownership check around dimensions::get
so lookup errors are not collapsed into false: treat only a confirmed missing
dimension as non-user-owned, while propagating transient, authorization, and
other failures. Preserve the existing UserCohort dimension match for successful
lookups and adjust the surrounding async flow to return the error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 85bb8eb0-c5cb-4b05-b847-dd7aa5259ba2

📥 Commits

Reviewing files that changed from the base of the PR and between d673227 and 71c6483.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (56)
  • clients/haskell/sdk/Io/Superposition/Model/DimensionType.hs
  • clients/java/sdk/src/main/java/io/juspay/superposition/client/SuperpositionAsyncClientImpl.java
  • clients/java/sdk/src/main/java/io/juspay/superposition/client/SuperpositionClientImpl.java
  • clients/java/sdk/src/main/java/io/juspay/superposition/model/DimensionType.java
  • clients/javascript/sdk/src/commands/CreateDimensionCommand.ts
  • clients/javascript/sdk/src/commands/GetConfigCommand.ts
  • clients/javascript/sdk/src/commands/GetDimensionCommand.ts
  • clients/javascript/sdk/src/commands/GetVersionCommand.ts
  • clients/javascript/sdk/src/commands/ListDimensionsCommand.ts
  • clients/javascript/sdk/src/commands/ListVersionsCommand.ts
  • clients/javascript/sdk/src/commands/UpdateDimensionCommand.ts
  • clients/javascript/sdk/src/models/models_0.ts
  • clients/python/sdk/superposition_sdk/_private/schemas.py
  • clients/python/sdk/superposition_sdk/models.py
  • crates/context_aware_config/Cargo.toml
  • crates/context_aware_config/src/api/config/helpers.rs
  • crates/context_aware_config/src/api/context/helpers.rs
  • crates/context_aware_config/src/api/context/validations.rs
  • crates/context_aware_config/src/api/default_config.rs
  • crates/context_aware_config/src/api/default_config/handlers.rs
  • crates/context_aware_config/src/api/dimension/handlers.rs
  • crates/context_aware_config/src/api/dimension/validations.rs
  • crates/context_aware_config/src/helpers.rs
  • crates/frontend/src/components/dimension_form.rs
  • crates/frontend/src/pages/default_config.rs
  • crates/frontend/src/pages/dimension.rs
  • crates/frontend/src/types.rs
  • crates/superposition_core/src/config.rs
  • crates/superposition_core/src/format.rs
  • crates/superposition_core/src/format/tests/json.rs
  • crates/superposition_core/src/format/tests/toml.rs
  • crates/superposition_core/tests/format_integration.rs
  • crates/superposition_provider/src/utils.rs
  • crates/superposition_sdk/src/protocol_serde/shape_dimension_type.rs
  • crates/superposition_sdk/src/types/_dimension_type.rs
  • crates/superposition_types/src/config.rs
  • crates/superposition_types/src/database/models/cac.rs
  • crates/superposition_types/src/logic.rs
  • crates/superposition_types/src/logic/tests.rs
  • docs/docs/api/Superposition.openapi.json
  • docs/docs/api/create-dimension.RequestSchema.json
  • docs/docs/api/create-dimension.StatusCodes.json
  • docs/docs/api/create-dimension.api.mdx
  • docs/docs/api/get-config.StatusCodes.json
  • docs/docs/api/get-config.api.mdx
  • docs/docs/api/get-dimension.StatusCodes.json
  • docs/docs/api/get-dimension.api.mdx
  • docs/docs/api/get-version.StatusCodes.json
  • docs/docs/api/get-version.api.mdx
  • docs/docs/api/list-dimensions.StatusCodes.json
  • docs/docs/api/list-dimensions.api.mdx
  • docs/docs/api/list-versions.StatusCodes.json
  • docs/docs/api/list-versions.api.mdx
  • docs/docs/api/update-dimension.StatusCodes.json
  • docs/docs/api/update-dimension.api.mdx
  • smithy/models/dimension.smithy
💤 Files with no reviewable changes (1)
  • crates/context_aware_config/Cargo.toml

Comment on lines +790 to +796
if is_user_cohort {
diesel::delete(
default_configs::table.filter(default_configs::key.eq(&name)),
)
.schema_name(&workspace_context.schema_name)
.get_result::<DefaultConfig>(transaction_conn)?;
}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Use .optional() when deleting the generated default config.

get_result::<DefaultConfig>(transaction_conn)? hard-fails with NotFound if the generated row is ever absent (e.g. data drift), rolling back the whole transaction and leaving the dimension undeletable. The dimension deletion just above (L785-788) already uses .optional(); mirror it here.

🛡️ Proposed fix
             if is_user_cohort {
                 diesel::delete(
                     default_configs::table.filter(default_configs::key.eq(&name)),
                 )
                 .schema_name(&workspace_context.schema_name)
-                .get_result::<DefaultConfig>(transaction_conn)?;
+                .get_result::<DefaultConfig>(transaction_conn)
+                .optional()?;
             }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if is_user_cohort {
diesel::delete(
default_configs::table.filter(default_configs::key.eq(&name)),
)
.schema_name(&workspace_context.schema_name)
.get_result::<DefaultConfig>(transaction_conn)?;
}
if is_user_cohort {
diesel::delete(
default_configs::table.filter(default_configs::key.eq(&name)),
)
.schema_name(&workspace_context.schema_name)
.get_result::<DefaultConfig>(transaction_conn)
.optional()?;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/context_aware_config/src/api/dimension/handlers.rs` around lines 790 -
796, Update the generated default-config deletion in the is_user_cohort branch
to use the same optional-result handling as the preceding dimension deletion, so
an absent row does not propagate Diesel’s NotFound error. Preserve the existing
delete filter, schema_name, and transaction flow.

Comment on lines +37 to +41
dimensions::get(key, workspace, org_id)
.await
.is_ok_and(|dimension| {
matches!(dimension.dimension_type, DimensionType::UserCohort(_))
});

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Do not treat dimension lookup failures as user-owned.

is_ok_and converts every dimensions::get error into false, so a transient/authorization failure exposes Edit and Delete controls for a user-cohort-owned key. Treat only a confirmed missing dimension as non-system-owned; propagate other failures.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/frontend/src/pages/default_config.rs` around lines 37 - 41, Update the
dimension ownership check around dimensions::get so lookup errors are not
collapsed into false: treat only a confirmed missing dimension as
non-user-owned, while propagating transient, authorization, and other failures.
Preserve the existing UserCohort dimension match for successful lookups and
adjust the surrounding async flow to return the error.

@sauraww
sauraww force-pushed the feat/user-cohort branch from 71c6483 to 2dd5a67 Compare July 22, 2026 22:14
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.

2 participants