Skip to content

[LEADS-267] fix: metric metadata override only changes given key#192

Open
asamal4 wants to merge 1 commit intolightspeed-core:mainfrom
asamal4:fix-override
Open

[LEADS-267] fix: metric metadata override only changes given key#192
asamal4 wants to merge 1 commit intolightspeed-core:mainfrom
asamal4:fix-override

Conversation

@asamal4
Copy link
Collaborator

@asamal4 asamal4 commented Mar 18, 2026

Description

Metric metadata override from eval data should only override given key, not replace complete metadata

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Unit tests improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: (e.g., Claude, CodeRabbit, Ollama, etc., N/A if not used)
  • Generated by: (e.g., tool name and version; N/A if not used)

Related Tickets & Documents

  • Related Issue #
  • Closes #

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Improved metric metadata handling to properly merge system-level defaults with level-specific overrides, ensuring default values and unmodified fields are preserved while appropriate customization is applied.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

Walkthrough

The get_metric_metadata method in the metrics manager now implements a merge strategy for metadata retrieval. System-level metadata serves as the base, with level-specific overrides applied on top. Override keys take precedence while non-overridden keys from the base are preserved, changing the logic from early return to merge-based composition.

Changes

Cohort / File(s) Summary
Metric Metadata Merge Logic
src/lightspeed_evaluation/core/metrics/manager.py
Modified get_metric_metadata to merge system-level base metadata with level-specific overrides rather than returning overrides directly; non-overridden keys are now preserved.
Metadata Retrieval Tests
tests/unit/core/metrics/test_manager.py
Updated test expectations and assertions to validate merge semantics, confirming that preserved fields from system defaults coexist with overridden values at turn and conversation levels.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 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 clearly and specifically describes the main bug fix: metric metadata overrides should only change the specified key rather than replacing the entire metadata object.
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 unit tests (beta)
  • Create PR with unit tests
📝 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.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

Copy link
Contributor

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

🧹 Nitpick comments (1)
src/lightspeed_evaluation/core/metrics/manager.py (1)

77-85: Consider returning a copy of base to avoid leaking mutable config state.

When no override is present, returning base directly exposes the underlying SystemConfig metadata dict by reference. Returning a shallow copy keeps behavior safer and consistent with the merged branch.

♻️ Proposed hardening change
-            return {**base, **override} if override else base
+            return {**base, **override} if override else dict(base)

-        return base if base else None
+        return dict(base) if base else None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lightspeed_evaluation/core/metrics/manager.py` around lines 77 - 85, The
current logic in manager.py returns the original `base` dict from
`system_metadata.get(metric_identifier)` which can leak mutable state; update
the return paths in the block that computes `base` and `level_metadata` (using
`_get_level_metadata`) so that whenever `base` is returned (including the
`return base if base else None` path and the `return {**base, **override} if
override else base` fallback) you return a shallow copy (e.g., `base.copy()` or
`dict(base)`) instead of the original object, while keeping the merged `{**base,
**override}` behavior as-is.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lightspeed_evaluation/core/metrics/manager.py`:
- Around line 77-85: The current logic in manager.py returns the original `base`
dict from `system_metadata.get(metric_identifier)` which can leak mutable state;
update the return paths in the block that computes `base` and `level_metadata`
(using `_get_level_metadata`) so that whenever `base` is returned (including the
`return base if base else None` path and the `return {**base, **override} if
override else base` fallback) you return a shallow copy (e.g., `base.copy()` or
`dict(base)`) instead of the original object, while keeping the merged `{**base,
**override}` behavior as-is.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7e7767d9-590b-4e9a-91e0-c3ed8f3d62e4

📥 Commits

Reviewing files that changed from the base of the PR and between 3049752 and 963e6ce.

📒 Files selected for processing (2)
  • src/lightspeed_evaluation/core/metrics/manager.py
  • tests/unit/core/metrics/test_manager.py

Copy link
Collaborator

@bsatapat-jpg bsatapat-jpg left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks

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