Skip to content

fix: Filtering for list context and experiments#924

Merged
ayushjain17 merged 1 commit intomainfrom
fix/filter
Mar 20, 2026
Merged

fix: Filtering for list context and experiments#924
ayushjain17 merged 1 commit intomainfrom
fix/filter

Conversation

@ayushjain17
Copy link
Collaborator

@ayushjain17 ayushjain17 commented Mar 20, 2026

Changelog

Fix of fix

Summary by CodeRabbit

  • Refactor
    • Optimized dimension filtering logic to use original request keys instead of evaluated keys, reducing redundant operations and removing unnecessary length constraints in dimension matching.

@ayushjain17 ayushjain17 requested a review from a team as a code owner March 20, 2026 11:34
Copilot AI review requested due to automatic review settings March 20, 2026 11:34
@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 20, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  crates/superposition_types/src/contextual.rs  49% smaller
  crates/context_aware_config/src/api/context/handlers.rs  0% smaller
  crates/experimentation_platform/src/api/experiments/handlers.rs  0% smaller

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fca6148f-7e18-4dd8-aaaf-73a24819218f

📥 Commits

Reviewing files that changed from the base of the PR and between 600e6a2 and 4db243c.

📒 Files selected for processing (3)
  • crates/context_aware_config/src/api/context/handlers.rs
  • crates/experimentation_platform/src/api/experiments/handlers.rs
  • crates/superposition_types/src/contextual.rs

Walkthrough

The PR refactors dimension-based filtering across three files by capturing original request dimension keys before evaluation and passing them as references instead of owned strings. The filter_by_dimension trait method signature is simplified to remove the request_keys_len parameter, with callers in both handler files updated to match the new contract.

Changes

Cohort / File(s) Summary
Handler filtering callsites
crates/context_aware_config/src/api/context/handlers.rs, crates/experimentation_platform/src/api/experiments/handlers.rs
Both handlers now extract original_req_keys from dimension_params before cohort evaluation, and pass these original keys (as references) to filter_by_dimension instead of evaluated keys and request length.
Contextual trait definition
crates/superposition_types/src/contextual.rs
Updated filter_by_dimension signature to accept original_dimension_keys: &[&String] instead of dimension_keys: &[String] and request_keys_len: usize. Removed the length-based constraint check and refactored logic to dereference string references. Unit tests updated to pass slices of references without cloning.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • fix: filter logic #920: Implements opposing changes to the same filtering callchain—adds request_keys_len and dimensions_info while this PR removes them.
  • fix: exp and config partial apply #831: Also modifies the filtering flow by updating callers to use original dimension keys and switching to evaluate_local_cohorts_skip_unresolved with signature changes to filter_by_dimension.

Suggested labels

bug, quick win

Suggested reviewers

  • Datron
  • sauraww
  • mahatoankitkumar

Poem

🐰 We hop through keys before they're bent,
Original paths, not circumvent!
References dance where owned once stood,
Simpler signatures, misunderstood?
No—just cleaner filtering, really good! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Filtering for list context and experiments' directly summarizes the main change across all modified files, which refactor filtering logic in context and experiment list handlers.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/filter
📝 Coding Plan
  • Generate coding plan for human review comments

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates dimension-based filtering used by list endpoints so filtering is driven by the original requested dimension keys (pre local-cohort evaluation), and relaxes the previous length-based constraint.

Changes:

  • Adjust Contextual::filter_by_dimension signature/logic to iterate over original request dimension keys and remove the request_keys_len <= variables.len() condition.
  • Update context and experiment list handlers to pass original request keys into filter_by_dimension.
  • Update unit tests for the new filter_by_dimension signature.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
crates/superposition_types/src/contextual.rs Changes filter_by_dimension API/logic and updates tests accordingly.
crates/experimentation_platform/src/api/experiments/handlers.rs Passes original request keys into experiment list filtering pipeline.
crates/context_aware_config/src/api/context/handlers.rs Passes original request keys into context list filtering pipeline.

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

Comment on lines 37 to 40
fn filter_by_dimension(
contexts: Vec<Self>,
dimension_keys: &[String],
request_keys_len: usize,
original_dimension_keys: &[&String],
dimensions_info: &HashMap<String, DimensionInfo>,
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

filter_by_dimension now takes &[&String], which forces callers to keep the backing map/vec alive for the duration of filtering and makes call sites much harder to write correctly (and can easily lead to borrow-checker issues when the source map is later shadowed/mutated). Consider changing this parameter to an owned/key-like type (e.g., &[String] or &[&str]) so callers can pass cloned keys or string slices without tying lifetimes to the original request map.

Copilot uses AI. Check for mistakes.
Comment on lines +1189 to 1193
let original_req_keys = dimension_params.keys().collect::<Vec<_>>();
let dimension_params = evaluate_local_cohorts_skip_unresolved(
&dimensions_info,
&dimension_params,
);
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

original_req_keys is collected as Vec<&String> from dimension_params.keys(), and then dimension_params is immediately shadowed by the evaluated map. The shadowing drops the original dimension_params, so the references inside original_req_keys can’t remain valid; this should fail to compile. Fix by collecting owned keys (e.g., clone into Vec<String>) or avoid shadowing by storing the evaluated map in a separate variable so the original map outlives original_req_keys.

Copilot uses AI. Check for mistakes.
let dimensions_info =
fetch_dimensions_info_map(&mut conn, &workspace_context.schema_name)?;
let original_request_len = dimension_params.len();
let original_req_keys = dimension_params.keys().collect::<Vec<_>>();
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

original_req_keys is collected as Vec<&String> from dimension_params.keys(), and then dimension_params is shadowed with the evaluated map. That shadowing drops the original dimension_params, so original_req_keys ends up holding invalid references (this should be rejected by the borrow checker). Fix by cloning the keys into an owned Vec<String> or by keeping the original dimension_params binding alive (store the evaluated result in a different variable name).

Suggested change
let original_req_keys = dimension_params.keys().collect::<Vec<_>>();
let original_req_keys = dimension_params.keys().cloned().collect::<Vec<String>>();

Copilot uses AI. Check for mistakes.
@ayushjain17 ayushjain17 added this pull request to the merge queue Mar 20, 2026
Merged via the queue into main with commit 63eb506 Mar 20, 2026
25 checks passed
@ayushjain17 ayushjain17 deleted the fix/filter branch March 20, 2026 12:25
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.

4 participants