Skip to content

Add meta field to ModelMeasure and Aggregation#83

Merged
ZmeiGorynych merged 3 commits into
mainfrom
egor/add-meta-to-measure-and-aggregation
May 4, 2026
Merged

Add meta field to ModelMeasure and Aggregation#83
ZmeiGorynych merged 3 commits into
mainfrom
egor/add-meta-to-measure-and-aggregation

Conversation

@ZmeiGorynych
Copy link
Copy Markdown
Member

@ZmeiGorynych ZmeiGorynych commented May 4, 2026

Summary

Column and SlayerModel already carry meta: Optional[Dict[str, Any]] for caller bookkeeping (linking entities back to their source, owner tags, etc). ModelMeasure and Aggregation did not, which means a downstream caller (e.g. the bird-interact-agents translate-kb skill) that wants to stamp every encoded entity uniformly with a source identifier couldn't.

This PR adds the same field to both classes:

meta: Optional[Dict[str, Any]] = None

Default None preserves backward compat — existing YAML loads unchanged. The MCP create_model / edit_model docstrings are updated to mention the new optional meta key on measures / aggregations dicts.

Concrete motivation: the BIRD-Interact translation skill (DEV-1318) stamps meta={"kb_id": <id>} on every entity it creates from a KB entry, so a downstream verifier can confirm every KB id is accounted for and a HARD-8 task-time preprocessor can mask entities by kb_id. Without this field, KB entries that produce a ModelMeasure (R-MEASURE recipe) or a custom Aggregation (R-AGG recipe) have no place to carry the link.

Test plan

  • poetry run pytest — 1696 passed (45 Postgres integration errors are environmental, unrelated)
  • No existing tests construct ModelMeasure/Aggregation in a way that would care about the new optional field

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Measures and aggregations now support optional metadata fields for attaching custom bookkeeping/context to model definitions.
  • Documentation

    • Model creation and editing tool docs updated to describe usage of the new optional metadata fields.
  • Tests

    • Added a test to verify metadata passed with measures is persisted unchanged.
  • Chores

    • Package version bumped to 0.4.2.

`Column` and `SlayerModel` already carry `meta: Optional[Dict[str, Any]]`
for caller bookkeeping (linking entities back to their source, owner
tags, etc). `ModelMeasure` and `Aggregation` did not, which means a
downstream caller (e.g. the bird-interact-agents translate-kb skill)
that wants to stamp every encoded entity uniformly couldn't.

Add the same `meta: Optional[Dict[str, Any]] = None` field to both
classes. Default None preserves backward compat — existing YAML loads
unchanged.

Update `mcp.create_model` and `mcp.edit_model` docstrings to mention
the new optional `meta` key on `measures` / `aggregations` dicts.

No test changes needed — existing tests construct these classes
positionally / by-kwarg and don't pass `meta`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 02594105-2bf6-4090-8357-9d3e1de4a42f

📥 Commits

Reviewing files that changed from the base of the PR and between 160dd02 and 4d8f3c2.

📒 Files selected for processing (3)
  • pyproject.toml
  • slayer/mcp/server.py
  • tests/test_mcp_server.py
✅ Files skipped from review due to trivial changes (1)
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • slayer/mcp/server.py

📝 Walkthrough

Walkthrough

Two optional meta: Optional[Dict[str, Any]] fields were added to the Pydantic models ModelMeasure and Aggregation. MCP server tool signatures were slightly widened for measure typing and docstrings updated to document meta. A test was added and the package version bumped.

Changes

Meta Field Support for Measures and Aggregations

Layer / File(s) Summary
Data Shape
slayer/core/models.py
ModelMeasure and Aggregation each gain an optional meta: Optional[Dict[str, Any]] field for opaque caller bookkeeping.
Type Annotation
slayer/mcp/server.py
create_model parameter measures widened from List[Dict[str, str]] to List[Dict[str, Any]] to allow meta payloads.
Tool Documentation
slayer/mcp/server.py
create_model and edit_model docstrings updated to document an optional meta field on measure and aggregation definitions described as opaque caller bookkeeping data.
Tests
tests/test_mcp_server.py
Adds test_create_with_measure_meta_dict asserting create_model persists a measure meta dict unchanged.
Release Metadata
pyproject.toml
Bumps project.version from 0.4.1 to 0.4.2.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • DEV-1261: Meta fields #33: Adds meta: Optional[Dict[str, Any]] fields to measure/aggregation schemas and updates MCP tooling; closely related scope.

Poem

🐰 I tucked a little meta in a measure's hat,
A secret pouch for notes and this-and-that,
Models keep the whispers safe and neat,
Persistence holds them snug and sweet. 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 'Add meta field to ModelMeasure and Aggregation' directly and clearly summarizes the main change in the pull request, which adds optional meta fields to both the ModelMeasure and Aggregation classes.
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.

✏️ 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 egor/add-meta-to-measure-and-aggregation

Review rate limit: 4/5 reviews remaining, refill in 12 minutes.

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

Copy link
Copy Markdown
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@slayer/mcp/server.py`:
- Around line 1562-1567: The create_model parameter annotation restricts
measures to Dict[str, str] but the docstring allows an opaque meta dict with
non-string values; update the annotation on create_model (the measures parameter
and any related local vars/returns) from List[Dict[str, str]] (or Dict[str,
str]) to List[Dict[str, Any]] or List[Mapping[str, Any]] and import Any from
typing so callers can pass arbitrary values in the measure["meta"] dict; ensure
any helper functions or type aliases that reference the old Dict[str, str] are
likewise widened to use Any.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9188ac3c-e442-4ae8-b49a-187b5a9e7222

📥 Commits

Reviewing files that changed from the base of the PR and between feafc77 and 160dd02.

📒 Files selected for processing (2)
  • slayer/core/models.py
  • slayer/mcp/server.py

Comment thread slayer/mcp/server.py
ZmeiGorynych and others added 2 commits May 4, 2026 11:12
… review)

The MCP create_model tool documents `meta` as an opaque dict on each measure,
but the parameter annotation restricted measures to Dict[str, str], so FastMCP's
generated schema would reject any caller passing a dict-valued `meta`. Match the
already-correct edit_model annotation by widening to Dict[str, Any].

Pinned by tests/test_mcp_server.py::TestCreateModel::test_create_with_measure_meta_dict.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

@ZmeiGorynych ZmeiGorynych merged commit b8746d1 into main May 4, 2026
4 checks passed
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.

1 participant