Skip to content

refactor(cli): converge mutation output onto MutationResultPayload (#1818) - #1907

Merged
Sinity merged 2 commits into
masterfrom
feature/refactor/cli-mutation-envelope-1818
Jun 15, 2026
Merged

Sinity merged 2 commits into
masterfrom
feature/refactor/cli-mutation-envelope-1818

Conversation

@Sinity

@Sinity Sinity commented Jun 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Converges the CLI's 6 ad-hoc {mode:"mutation",...} JSON outputs onto the shared typed MutationResultPayload (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 the MutationResultPayload MCP/daemon use — #1818 wants one machine-output mutation contract.

Solution (option A — additive)

  • surfaces/payloads.py: MutationResultPayload gains two optional fields, both default None so MCP/daemon exclude_none=True dumps are byte-unchanged (no mcp/daemon call site touched): operation: str | None (bulk-mutation discriminator) and session_ids: tuple[str,...] | None (dry-run enumeration). status docstring notes the new preview/aborted CLI values.
  • cli/archive_query.py: all 6 sites build MutationResultPayload and 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.py were 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 to origin/exclude_origin. Bundled here because this PR already edits that file (avoids a conflict).

Verification

devtools test test_query_exec_laws test_verb_cardinality   # 99 passed (3 ex-red now green)
devtools verify --quick   # exit 0

No snapshots/baselines pin the mutation shape (confirmed).

Ref #1818

Summary by CodeRabbit

Release Notes

  • New Features

    • Mutation operations now support additional status indicators for dry-run previews and user-aborted confirmations.
  • Refactor

    • Standardized response format for mutation and deletion operations.
    • Updated archive filtering parameters to use origin instead of provider.
  • Tests

    • Updated test suite to match revised operation response formats.

Sinity and others added 2 commits June 15, 2026 15:43
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]>
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

MutationResultPayload gains two optional fields (operation, session_ids) and two new status values (preview, aborted). All CLI archive mutation emitters (_emit_mutation, _emit_user_mutations, _emit_delete) are refactored to use MutationResultPayload.to_json(exclude_none=True) instead of hand-built json.dumps dicts. Unit tests are updated to assert the new envelope shape and to use origin/exclude_origin filter parameters.

Changes

Mutation Result Payload Standardization

Layer / File(s) Summary
MutationResultPayload contract extension
polylogue/surfaces/payloads.py
Adds optional operation (CLI bulk-mutation discriminator) and session_ids (enumerated session ids) fields to MutationResultPayload, and extends the status docstring to document preview and aborted for CLI bulk-delete flows.
CLI archive mutation emitters refactored
polylogue/cli/archive_query.py
Imports MutationResultPayload and rewrites _emit_mutation, _emit_user_mutations combined tag+metadata branch, and all _emit_delete branches (count==0, dry-run, aborted, deleted/ok) to emit MutationResultPayload.to_json(exclude_none=True) instead of hand-built json.dumps dicts.
Unit test assertions updated
tests/unit/cli/test_query_exec_laws.py, tests/unit/cli/test_verb_cardinality.py
Replaces mode/changed/dry_run/matched/deleted envelope assertions with status/operation/affected_count/session_count; updates filter parameter names from provider/exclude_provider to origin/exclude_origin across stats, search, and multi-origin tests.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 Hoppity-hop, the old JSON's gone,
mode and changed — now moved along!
status: "preview" for the dry-run show,
affected_count tells what you need to know.
The rabbit stamps payloads neat and right,
exclude_none=True — what a tidy delight! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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
Title check ✅ Passed The title clearly identifies the main change: refactoring the CLI mutation output to use a shared MutationResultPayload type, which is the primary objective of this PR.
Description check ✅ Passed The description includes all required sections: Summary, Problem, Solution, Verification, and a Changelog note. The explanation is detailed and comprehensive, covering the refactoring work and bundled test fixes.
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 feature/refactor/cli-mutation-envelope-1818

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.

@Sinity
Sinity merged commit 686a83f into master Jun 15, 2026
12 of 13 checks passed
@Sinity
Sinity deleted the feature/refactor/cli-mutation-envelope-1818 branch June 15, 2026 13:54

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

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