fix(mcp): set_fields rejects reserved keys; add top-level description#158
Open
fix(mcp): set_fields rejects reserved keys; add top-level description#158
Conversation
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Rivet Criterion Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 00e997b | Previous: 60d728a | Ratio |
|---|---|---|---|
store_lookup/1000 |
25029 ns/iter (± 222) |
19280 ns/iter (± 48) |
1.30 |
diff/1000 |
717685 ns/iter (± 3324) |
584274 ns/iter (± 2706) |
1.23 |
query/100 |
773 ns/iter (± 3) |
619 ns/iter (± 1) |
1.25 |
query/1000 |
6826 ns/iter (± 20) |
5174 ns/iter (± 14) |
1.32 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
9701cf9 to
00e997b
Compare
…tion` setter
Two related MCP correctness bugs in `rivet_modify`:
1. `set_fields` silently wrote reserved top-level keys (description, title,
status, ...) under the `fields:` sub-map — corrupting the artifact's
shape. Values containing backticks or newlines additionally broke the
YAML emitter, which used unquoted `format!("{key}: {value}")` lines.
2. There was no way to set the top-level `description` (or other top-level
metadata) via MCP — `set_fields` was the only "generic setter" and, by
design, targets only the domain `fields:` map.
Design: keep `set_fields` scoped to the `fields:` sub-map and expose
dedicated setters for top-level metadata. `validate_modify` now rejects
any `set_fields` key listed in `RESERVED_TOP_LEVEL_KEYS` (id, type, title,
description, status, tags, links, fields, provenance, source-file) with a
hint pointing at the right parameter. A new `description` parameter on
`rivet_modify` routes through `ModifyParams::set_description`, which
emits YAML-safe scalars — multi-line values become block-literal (`|-`)
scalars, single-line values with YAML-significant characters are
double-quoted with proper escapes. `set_field` in the editor was extended
to splice multi-line values into the line buffer so block scalars stay
well-formed.
Tests (added failing first, now green):
- `test_set_fields_rejects_reserved_description` / `_all_reserved_top_level_keys`
- `test_modify_sets_top_level_description`
- `test_modify_description_with_backticks_and_newlines`
- `test_validate_modify_rejects_reserved_top_level_in_set_fields`
- `test_yaml_quote_inline_scalar_*`, `test_set_field_writes_*_as_*_scalar`
Fixes: REQ-002
00e997b to
c2e56f7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two related MCP bugs
Bug 1 — `yaml_edit.rs::modify_artifact_yaml` unconditionally nested every `set_fields` key under `fields:` using `format!("{key}: {value}")`. Passing `description=...` wrote `fields: {description: ...}` instead of touching top-level, and raw-interpolation corrupted YAML when the value contained backticks or newlines.
Bug 2 — MCP `ModifyParams` exposed only `status`, `title`, `add_tags`, `remove_tags`, `set_fields`. Top-level `description` (and `source-file`, `provenance`, full tag replacement) were unreachable via MCP at all.
Fix
Test plan
Depends-on: #157 for clean main.rs merge.
🤖 Generated with Claude Code