Repository navigation
refactor(cli): converge mutation output onto MutationResultPayload (#1818) - #1907
Conversation
Problem: the CLI emitted ad-hoc {"mode":"mutation", ...} dicts for tag,
metadata, and delete mutations while MCP and the daemon already used the
shared typed MutationResultPayload. The CLI was the lone outlier, so #1818's
"one machine-output mutation contract" did not hold.
What changed:
- Extend MutationResultPayload additively with two optional fields
(operation, session_ids), both defaulting to None so MCP/daemon
exclude_none=True dumps are byte-unchanged. No mcp/ or daemon/ call
site is touched.
- Converge all six cli/archive_query.py {mode:mutation} sites onto
MutationResultPayload: changed->affected_count, matched->session_count,
deleted->affected_count, dry_run/aborted->status ("preview"/"aborted"),
session_ids->new field, operation->new field. The combined tag+metadata
case maps tags->tag_count and metadata->applied_count (documented inline).
- Update the two CLI tests asserting the old shape to the new shape.
Ref #1818
Co-Authored-By: Claude Opus 4.8 <[email protected]>
… sweep The provider->origin fallback removal in #1810 (#1901) left 3 tests in test_query_exec_laws.py red on master (PR CI skips the test job, so it wasn't caught): they passed {provider: codex} and expected origin mapping that no longer happens. Swap their inputs to origin/exclude_origin vocabulary, matching the now origin-only public query contract. (Bundled here because this PR already edits the same file for the mutation-envelope work, avoiding a merge conflict.) Co-Authored-By: Claude <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthrough
ChangesMutation Result Payload Standardization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fff77e460f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| MutationResultPayload( | ||
| status="ok", | ||
| operation="mutate", | ||
| tag_count=changes.get("tags"), |
There was a problem hiding this comment.
Avoid overloading tag_count with changed rows
When a combined CLI mutation sets metadata and adds tags, changes["tags"] is the return value of ArchiveStore.add_user_tags(), which is the number of tag rows inserted, but the shared mutation contract already uses tag_count as the requested tag cardinality via BulkTagMutationResult (polylogue/api/archive.py sets it to len(tags)). For a query matching two sessions with one tag, this emits tag_count: 2 instead of 1, so clients consuming CLI and MCP results through MutationResultPayload will interpret the same field differently. Use a separate changed-row field or keep tag_count tied to the input tag count.
Useful? React with 👍 / 👎.
Summary
Converges the CLI's 6 ad-hoc
{mode:"mutation",...}JSON outputs onto the shared typedMutationResultPayload(the contract MCP and the daemon already use), completing #1818 P4. Also fixes 3 unrelated master-red tests (see below).Problem
The CLI emitted hand-rolled mutation dicts (
archive_query.py), diverging from theMutationResultPayloadMCP/daemon use — #1818 wants one machine-output mutation contract.Solution (option A — additive)
surfaces/payloads.py:MutationResultPayloadgains two optional fields, both defaultNoneso MCP/daemonexclude_none=Truedumps are byte-unchanged (no mcp/daemon call site touched):operation: str | None(bulk-mutation discriminator) andsession_ids: tuple[str,...] | None(dry-run enumeration).statusdocstring notes the newpreview/abortedCLI values.cli/archive_query.py: all 6 sites buildMutationResultPayloadand emit.to_json(exclude_none=True)(one finite JSON value). Mappings:changed→affected_count,matched→session_count,deleted→affected_count,dry_run/aborted→status, combined tag+meta →tag_count+applied_count(documented inline).Bundled fix (master-red, #1810 regression)
3 tests in
test_query_exec_laws.pywere left red on master by the #1810 provider sweep (#1901) — they fed{provider: codex}expecting origin mapping that was intentionally removed; PR CI missed it (test job is PR-skipped). Their inputs are updated toorigin/exclude_origin. Bundled here because this PR already edits that file (avoids a conflict).Verification
No snapshots/baselines pin the mutation shape (confirmed).
Ref #1818
Summary by CodeRabbit
Release Notes
New Features
Refactor
origininstead ofprovider.Tests