Skip to content

Conversation

@ayushjain17
Copy link
Collaborator

@ayushjain17 ayushjain17 commented Jan 9, 2026

Problem

No validation on the type of function given in input for validation or compute function attachment to default config and dimension

Probably needs some refactoring in all these logic

Summary by CodeRabbit

  • Refactor

    • Unified how function kinds are passed and honored across backend validation and retrieval paths for more consistent behavior.
    • Frontend form code refactored to use a shared helper for populating function dropdowns, simplifying state handling.
  • Bug Fixes / Validation

    • Enforced runtime checks to ensure retrieved functions match their declared kind, surfacing mismatches as validation errors.

✏️ Tip: You can customize this high-level summary in your review settings.

@ayushjain17 ayushjain17 requested a review from a team as a code owner January 9, 2026 15:53
@semanticdiff-com
Copy link

semanticdiff-com bot commented Jan 9, 2026

@coderabbitai
Copy link

coderabbitai bot commented Jan 9, 2026

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.

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

Walkthrough

Threads a FunctionType parameter through function lookup and validation paths so published functions are fetched and checked by explicit type (ValueValidation / ValueCompute) across backend helpers, validations, default-config handlers, and frontend function-name utilities.

Changes

Cohort / File(s) Summary
Function retrieval core
crates/context_aware_config/src/api/functions/helpers.rs
Added f_type: FunctionType to get_published_function_code and get_published_functions_by_names; runtime checks ensure fetched FunctionInfo.function_type == f_type.
Context helpers
crates/context_aware_config/src/api/context/helpers.rs
get_functions_map signature updated to accept function_type: FunctionType; call sites now pass FunctionType::ValueValidation.
Default-config handlers
crates/context_aware_config/src/api/default_config/handlers.rs
Imported FunctionType; validate_fn_published gained f_type param; calls to get_published_function_code and validation now pass explicit function types (ValueCompute / ValueValidation).
Dimension validations
crates/context_aware_config/src/api/dimension/validations.rs
check_fn_published and callers updated to accept/propagate FunctionType; validation uses ValueValidation, compute uses ValueCompute.
Helpers / cohort dependency
crates/context_aware_config/src/helpers.rs
evaluate_remote_cohorts_dependency now requests published function code with FunctionType::ValueCompute.
Function metadata type
crates/context_aware_config/src/api/functions/types.rs
FunctionInfo struct gained function_type: FunctionType field.
Frontend types & utils
crates/frontend/src/types.rs, crates/frontend/src/utils.rs
Renamed FunctionsNameFunctionName; added get_fn_names_by_type(functions, f_type); updated set_function and imports to use FunctionName/FunctionType.
Frontend components
crates/frontend/src/components/default_config_form.rs, crates/frontend/src/components/dimension_form.rs
Updated components to use FunctionName and to populate dropdowns via get_fn_names_by_type instead of manual mutation.

Sequence Diagram(s)

sequenceDiagram
    participant Frontend
    participant API as Backend API
    participant FuncHelper as functions::helpers
    participant DB as Database

    Frontend->>API: submit config / select function (includes FunctionType)
    API->>FuncHelper: validate_fn_published(name, FunctionType)
    FuncHelper->>DB: query published functions by name + FunctionType
    DB-->>FuncHelper: FunctionInfo (with function_type)
    FuncHelper-->>API: validation result (error if type mismatch)
    API-->>Frontend: success / validation error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • knutties

Poem

🐰 I threaded types through creek and glen,
ValueCompute, Validation — one by one,
From dropdown to DB my whiskers hop,
Ensuring functions land the right spot. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.62% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding function type validation to dimension and default config attachment logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/frontend/src/components/default_config_form.rs (1)

439-459: FunctionType-filtered dropdown options look correct; consider avoiding concat() allocations.

Filtering by FunctionType::ValueValidation / FunctionType::ValueCompute matches the PR objective and prevents wrong-type attachments. If you want to avoid intermediate allocations, you can build the vectors via iterator chaining.

Proposed refactor (optional)
-                        let validation_function_names: Vec<FunctionsName> = [
-                            vec!["None".to_string()],
-                            functions
-                                .iter()
-                                .filter(|ele| {
-                                    ele.function_type == FunctionType::ValueValidation
-                                })
-                                .map(|ele| ele.function_name.clone())
-                                .collect(),
-                        ]
-                            .concat();
-                        let value_compute_function_names: Vec<FunctionsName> = [
-                            vec!["None".to_string()],
-                            functions
-                                .iter()
-                                .filter(|ele| ele.function_type == FunctionType::ValueCompute)
-                                .map(|ele| ele.function_name.clone())
-                                .collect(),
-                        ]
-                            .concat();
+                        let validation_function_names: Vec<FunctionsName> =
+                            std::iter::once("None".to_string())
+                                .chain(
+                                    functions
+                                        .iter()
+                                        .filter(|f| f.function_type == FunctionType::ValueValidation)
+                                        .map(|f| f.function_name.clone()),
+                                )
+                                .collect();
+                        let value_compute_function_names: Vec<FunctionsName> =
+                            std::iter::once("None".to_string())
+                                .chain(
+                                    functions
+                                        .iter()
+                                        .filter(|f| f.function_type == FunctionType::ValueCompute)
+                                        .map(|f| f.function_name.clone()),
+                                )
+                                .collect();
crates/frontend/src/components/dimension_form.rs (1)

529-549: FunctionType-filtered dropdown options look correct; optional micro-refactor to avoid concat().

Same as default-config: the filtering logic is correct and matches the backend’s FunctionType-aware behavior. If desired, you can switch to iter::once(...).chain(...).collect() to avoid intermediate Vec allocations (see similar suggestion in default_config_form.rs).

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac19e62 and db4ab28.

📒 Files selected for processing (7)
  • crates/context_aware_config/src/api/context/helpers.rs
  • crates/context_aware_config/src/api/default_config/handlers.rs
  • crates/context_aware_config/src/api/dimension/validations.rs
  • crates/context_aware_config/src/api/functions/helpers.rs
  • crates/context_aware_config/src/helpers.rs
  • crates/frontend/src/components/default_config_form.rs
  • crates/frontend/src/components/dimension_form.rs
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-01-07T20:38:53.153Z
Learnt from: ayushjain17
Repo: juspay/superposition PR: 827
File: crates/superposition_core/src/config.rs:154-154
Timestamp: 2026-01-07T20:38:53.153Z
Learning: Deprecate jsonlogic-based context conditions and migrate to simple key-value pair map conditions across the codebase. Replace jsonlogic::apply usage with superposition_types::apply for condition evaluation. Update all relevant modules (notably Rust files under crates) to use the new approach, remove jsonlogic dependencies where applicable, and run full compilation and tests to catch regressions. Ensure context evaluation logic consistently uses key-value maps and that the architectural change is reflected in unit/integration tests.

Applied to files:

  • crates/context_aware_config/src/api/dimension/validations.rs
  • crates/frontend/src/components/default_config_form.rs
  • crates/frontend/src/components/dimension_form.rs
  • crates/context_aware_config/src/api/default_config/handlers.rs
  • crates/context_aware_config/src/api/context/helpers.rs
  • crates/context_aware_config/src/helpers.rs
  • crates/context_aware_config/src/api/functions/helpers.rs
📚 Learning: 2026-01-05T12:37:05.828Z
Learnt from: ayushjain17
Repo: juspay/superposition PR: 815
File: crates/frontend/src/components/datetime.rs:70-95
Timestamp: 2026-01-05T12:37:05.828Z
Learning: Documentation should reflect build-target dependent behavior. For functions that differ between wasm32 and non-wasm32 (e.g., datetime parsing/normalization), explicitly document the intent and the platform-specific logic in the code and/or a nearby comment. Prefer using cfg attributes to clearly separate implementations for wasm32 vs non-wasm32 and add tests that cover both builds. In this case, the function should be noted as: wasm32 -> local midnight interpreted then converted to UTC; non-wasm32 (SSR) -> UTC midnight directly. Ensure any related behavior is consistent with the SSR/CSR architecture and that downstream code relies on the clarified semantics.

Applied to files:

  • crates/frontend/src/components/default_config_form.rs
  • crates/frontend/src/components/dimension_form.rs
🧬 Code graph analysis (3)
crates/context_aware_config/src/api/dimension/validations.rs (1)
crates/context_aware_config/src/api/functions/helpers.rs (1)
  • get_published_function_code (26-42)
crates/context_aware_config/src/api/default_config/handlers.rs (1)
crates/context_aware_config/src/api/functions/helpers.rs (1)
  • get_published_function_code (26-42)
crates/context_aware_config/src/api/functions/helpers.rs (1)
crates/context_aware_config/src/api/functions/handlers.rs (1)
  • functions (137-141)
🔇 Additional comments (16)
crates/context_aware_config/src/api/dimension/validations.rs (4)

10-17: Import update for FunctionType is consistent with the new validation contract.

No issues here.


243-259: Type-scoped publication check is the right fix for “wrong function type attached”.

check_fn_published now enforces (name, type) when checking published code, which closes the gap described in the PR objectives.


290-300: Validation function check now correctly enforces ValueValidation type.

This prevents “compute fn attached as validation fn” (and vice versa).


261-289: This concern is not applicable—FunctionType derives Copy.

The FunctionType enum explicitly derives Copy (along with Clone, Debug, PartialEq, Deserialize, Serialize, Default, and strum macros). Since it implements Copy, the pattern of binding fn_type once and reusing it across multiple match arms is valid and idiomatic Rust. No changes are needed.

crates/context_aware_config/src/api/functions/helpers.rs (3)

1-3: Diesel imports updated appropriately for composed boolean predicates.

Looks fine.


26-42: Good: published function lookup is now constrained by (name, type).

This is the core behavioral fix (prevents retrieving a different-type function with the same name).


44-61: Good: bulk lookup now also enforces function type.

Same benefit as the single-function path; avoids mixed-type maps when names overlap. All callers properly updated to pass FunctionType.

crates/context_aware_config/src/helpers.rs (1)

398-408: Good: remote cohort evaluation now explicitly fetches ValueCompute functions.

This aligns the runtime lookup with the semantics of data.value_compute_function_name and prevents accidentally resolving a same-named function of a different type.

crates/context_aware_config/src/api/context/helpers.rs (3)

155-160: LGTM! Correct function type for dimension validation.

The addition of FunctionType::ValueValidation correctly ensures that only value validation functions are fetched when validating dimension values. This prevents accidentally using a compute function where a validation function is expected.


255-260: LGTM! Correct function type for override validation.

The addition of FunctionType::ValueValidation ensures that validation functions from default configs are correctly fetched by type. This maintains consistency with the dimension validation logic.


290-321: LGTM! Clean signature update with proper propagation.

The function signature is correctly updated to accept and propagate the function_type parameter. The implementation maintains the existing logic while adding type-based filtering at the database query level.

crates/context_aware_config/src/api/default_config/handlers.rs (5)

32-32: LGTM! Required import for function type validation.

The import of FunctionType is correctly added to support the function type parameter threading.


130-135: LGTM! Correct validation of compute function on creation.

The create handler correctly validates that the compute function exists and is published by passing FunctionType::ValueCompute. This prevents attaching non-existent or wrong-type functions to default configs.


251-256: LGTM! Consistent validation in update handler.

The update handler correctly validates the compute function type when updating value_compute_function_name. The conditional validation (only when provided) is appropriate for partial updates.


294-314: LGTM! Well-refactored validation function.

The signature update makes validate_fn_published reusable for different function types while maintaining clear error messages. The function now ensures type-safe validation of function existence and publication status.


328-333: LGTM! Correct function type for validation path.

The call to get_published_function_code correctly specifies FunctionType::ValueValidation for fetching value validation functions. This ensures that only validation functions can be used for validating default config values.

@ayushjain17 ayushjain17 force-pushed the fix/function/attachment branch from db4ab28 to bd22b70 Compare January 9, 2026 17:31
@ayushjain17 ayushjain17 force-pushed the fix/function/attachment branch from bd22b70 to e627507 Compare January 10, 2026 15:44
@ayushjain17 ayushjain17 requested a review from knutties January 10, 2026 15:45
@ayushjain17 ayushjain17 force-pushed the fix/function/attachment branch 2 times, most recently from dd1117c to 549786f Compare January 10, 2026 18:30
@ayushjain17 ayushjain17 requested a review from knutties January 10, 2026 18:32
@ayushjain17
Copy link
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jan 10, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
crates/context_aware_config/src/api/functions/helpers.rs (2)

25-45: Improve type-mismatch error: include expected + actual.
This will cut debugging time when a function name is reused incorrectly.

Proposed tweak
@@
-    if function.function_type != f_type {
+    if function.function_type != f_type {
         return Err(validation_error!(
-            "Function type mismatch for function: {}",
-            f_name
+            "Function type mismatch for function: {} (expected: {:?}, found: {:?})",
+            f_name,
+            f_type,
+            function.function_type,
         ));
     }

47-66: Nice guardrail: bulk fetch now rejects any returned function with the wrong type.
Optional follow-up: consider also detecting and erroring on missing function names (today they’ll just be absent from the returned vector).

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db4ab28 and 549786f.

📒 Files selected for processing (10)
  • crates/context_aware_config/src/api/context/helpers.rs
  • crates/context_aware_config/src/api/default_config/handlers.rs
  • crates/context_aware_config/src/api/dimension/validations.rs
  • crates/context_aware_config/src/api/functions/helpers.rs
  • crates/context_aware_config/src/api/functions/types.rs
  • crates/context_aware_config/src/helpers.rs
  • crates/frontend/src/components/default_config_form.rs
  • crates/frontend/src/components/dimension_form.rs
  • crates/frontend/src/types.rs
  • crates/frontend/src/utils.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/frontend/src/components/default_config_form.rs
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-01-07T20:38:53.153Z
Learnt from: ayushjain17
Repo: juspay/superposition PR: 827
File: crates/superposition_core/src/config.rs:154-154
Timestamp: 2026-01-07T20:38:53.153Z
Learning: Deprecate jsonlogic-based context conditions and migrate to simple key-value pair map conditions across the codebase. Replace jsonlogic::apply usage with superposition_types::apply for condition evaluation. Update all relevant modules (notably Rust files under crates) to use the new approach, remove jsonlogic dependencies where applicable, and run full compilation and tests to catch regressions. Ensure context evaluation logic consistently uses key-value maps and that the architectural change is reflected in unit/integration tests.

Applied to files:

  • crates/frontend/src/types.rs
  • crates/context_aware_config/src/helpers.rs
  • crates/context_aware_config/src/api/functions/helpers.rs
  • crates/context_aware_config/src/api/context/helpers.rs
  • crates/context_aware_config/src/api/default_config/handlers.rs
  • crates/frontend/src/components/dimension_form.rs
  • crates/frontend/src/utils.rs
  • crates/context_aware_config/src/api/dimension/validations.rs
  • crates/context_aware_config/src/api/functions/types.rs
📚 Learning: 2026-01-05T12:37:05.828Z
Learnt from: ayushjain17
Repo: juspay/superposition PR: 815
File: crates/frontend/src/components/datetime.rs:70-95
Timestamp: 2026-01-05T12:37:05.828Z
Learning: Documentation should reflect build-target dependent behavior. For functions that differ between wasm32 and non-wasm32 (e.g., datetime parsing/normalization), explicitly document the intent and the platform-specific logic in the code and/or a nearby comment. Prefer using cfg attributes to clearly separate implementations for wasm32 vs non-wasm32 and add tests that cover both builds. In this case, the function should be noted as: wasm32 -> local midnight interpreted then converted to UTC; non-wasm32 (SSR) -> UTC midnight directly. Ensure any related behavior is consistent with the SSR/CSR architecture and that downstream code relies on the clarified semantics.

Applied to files:

  • crates/frontend/src/components/dimension_form.rs
🧬 Code graph analysis (4)
crates/context_aware_config/src/api/default_config/handlers.rs (1)
crates/context_aware_config/src/api/functions/helpers.rs (1)
  • get_published_function_code (25-45)
crates/frontend/src/components/dimension_form.rs (1)
crates/frontend/src/utils.rs (2)
  • set_function (328-336)
  • get_fn_names_by_type (424-436)
crates/context_aware_config/src/api/dimension/validations.rs (1)
crates/context_aware_config/src/api/functions/helpers.rs (1)
  • get_published_function_code (25-45)
crates/context_aware_config/src/api/functions/types.rs (1)
crates/context_aware_config/src/api/functions/handlers.rs (1)
  • functions (137-141)
🔇 Additional comments (23)
crates/context_aware_config/src/api/functions/types.rs (2)

1-5: Adding FunctionType to the CAC model import is consistent with the type-aware validation change.


7-14: No issues found. All FunctionInfo queries properly use FunctionInfo::as_select() (helpers.rs lines 33, 55, 104), which ensures function_type is compiled into the column selection. All destructuring patterns use .. catch-all, making them forward-compatible with new fields.

crates/context_aware_config/src/api/dimension/validations.rs (3)

10-17: FunctionType import aligns with the new typed function validation.


243-259: Good: check_fn_published now enforces published-by-type via get_published_function_code.
This makes the type mismatch fail fast (instead of silently accepting a wrong function).


261-300: Good: compute vs validation paths are now explicitly typed.
ValueCompute and ValueValidation are correctly separated at call sites.

crates/context_aware_config/src/api/functions/helpers.rs (1)

1-10: Importing validation_error is appropriate for typed validation failures.

crates/context_aware_config/src/helpers.rs (1)

398-407: Good: remote cohort value compute now fetches published code with FunctionType::ValueCompute.

crates/context_aware_config/src/api/context/helpers.rs (3)

155-160: Good: dimension validation functions are now fetched/validated as ValueValidation.


255-260: Good: default-config validation functions are now fetched/validated as ValueValidation.


290-321: get_functions_map signature change is clean; passing function_type down is the right abstraction boundary.

crates/context_aware_config/src/api/default_config/handlers.rs (5)

32-32: LGTM: FunctionType import added.

The import correctly adds FunctionType to support function type validation in this module.


130-135: LGTM: ValueCompute function validation added.

The validation correctly uses FunctionType::ValueCompute to ensure the attached function is of the correct type for computing values in the create handler.


251-256: LGTM: ValueCompute function validation added to update handler.

Consistent with the create handler, the update path now validates that the value compute function is of type ValueCompute.


294-314: LGTM: Function signature updated with type parameter.

The validate_fn_published function now correctly accepts f_type: FunctionType and passes it to get_published_function_code, enabling type-specific function lookup and validation. The error handling remains appropriate.


328-333: LGTM: ValueValidation type used correctly.

The call to get_published_function_code correctly specifies FunctionType::ValueValidation for validation functions attached to default config values.

crates/frontend/src/types.rs (1)

145-153: LGTM: Type alias renamed for consistency.

The rename from FunctionsName to FunctionName (singular) is a sensible naming improvement that aligns with Rust naming conventions.

crates/frontend/src/components/dimension_form.rs (3)

24-44: LGTM: Imports updated for type-safe function handling.

The imports correctly add FunctionName and get_fn_names_by_type to support the new function-type-aware dropdown population logic.


131-137: LGTM: Closure parameter types updated.

Both closure signatures correctly use FunctionName instead of the old FunctionsName, maintaining consistency with the renamed type.


532-539: LGTM: Function lists now filtered by type.

The new logic correctly uses get_fn_names_by_type to populate separate dropdown lists for ValueValidation and ValueCompute functions, ensuring users can only select functions of the appropriate type for each purpose.

crates/frontend/src/utils.rs (4)

11-14: LGTM: Imports extended for function type handling.

The imports correctly add Function and FunctionType from superposition_types to support the new type-aware function filtering logic.


23-23: LGTM: FunctionName import updated.

The import correctly references the renamed FunctionName type.


328-336: LGTM: Function signature updated.

The set_function signature correctly uses FunctionName instead of FunctionsName, maintaining consistency with the type rename.


424-436: LGTM: Type-aware function name helper added.

The new get_fn_names_by_type helper correctly filters functions by FunctionType and prepends "None" as the first option, enabling type-safe function selection in the UI. The implementation is clean and efficient.

@ayushjain17 ayushjain17 force-pushed the fix/function/attachment branch from 549786f to 5aeb236 Compare January 11, 2026 18:28
@ayushjain17 ayushjain17 requested a review from knutties January 11, 2026 18:28
@ayushjain17 ayushjain17 force-pushed the fix/function/attachment branch from 5aeb236 to 43af0ad Compare January 12, 2026 11:49
@ayushjain17 ayushjain17 force-pushed the fix/function/attachment branch from 43af0ad to 6a84cfd Compare January 14, 2026 17:21
@ayushjain17 ayushjain17 added bug Something isn't working quick win An item or task that can be quickly closed and gives us an easy win UI things relating to the UI labels Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working quick win An item or task that can be quickly closed and gives us an easy win UI things relating to the UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants