Repository navigation
Closed
Labels
area:cliCLIarea:coreCore runtime and shared infrastructurearea:mcpMCPphase:architectureArchitecture and design spinetheme:command-surfaceCLI and control-plane command taxonomytype:refactorCode restructuring
Description
Problem
Polylogue treats user metadata, tags, and conversation deletion as surface-level mutations in several places. The behavior is not consistently expressed as one archive operation contract.
Current audit evidence:
- Python API mutation helpers live in
polylogue/api/archive.pyand reach into repository/write mixins directly:delete_conversation()usesself.filter().id(...).delete().add_tag()/remove_tag()/get_metadata()/update_metadata()cast the repository toRepositoryWriteMixin.
- CLI query mutations apply metadata and tags through the query execution store / repository protocol directly:
polylogue/cli/query_actions.py:apply_modifiers()polylogue/cli/query_actions.py:delete_conversations()
- MCP mutation tools mix paths:
add_tag,remove_tag,set_metadata, anddelete_conversationmostly callPolylogue.bulk_tag_conversationscallshooks.get_tag_store().bulk_add_tags()directly.delete_metadataresolves via query store and deletes via tag store directly.
- Daemon HTTP reset/delete path calls
poly.delete_conversation()through a hand-shaped reset endpoint:polylogue/daemon/http.py:_handle_reset()
- Tag listing already has API/MCP/CLI surfaces, but mutation result semantics, idempotency, confirmation/safety, and bulk behavior are not centralized.
This matters because tags/metadata are explicitly user-owned archive state and are excluded from content hash. They need stable semantics across surfaces without binding every adapter to repository implementation details.
Scope
Define a shared user-mutation operation contract for tags, metadata, and conversation deletion.
Likely files:
polylogue/api/archive.pypolylogue/operations/archive.pyor a dedicated mutation operations modulepolylogue/cli/query_actions.pypolylogue/cli/query.pypolylogue/cli/commands/tags.pypolylogue/mcp/server_mutation_tools.pypolylogue/mcp/payloads.pypolylogue/daemon/http.pyif reset/delete stays exposed therepolylogue/protocols.pypolylogue/storage/repository/archive/repository_writes.pytests/unit/core/test_facade_api.pytests/unit/cli/test_query_exec*.pytests/unit/mcp/test_tool_contracts.py- storage tag/metadata/delete tests where operation behavior depends on repository guarantees
Implementation shape
- Add typed request/result models or simple dataclasses for:
- add/remove tag;
- bulk add tags;
- set/delete metadata;
- delete conversation.
- Define idempotency semantics explicitly:
- adding an existing tag;
- removing a missing tag;
- setting the same metadata value;
- deleting an already-missing conversation.
- Keep user metadata out of content hash; this issue should reinforce that boundary rather than changing archive content identity.
- Move API helpers to
ArchiveOperations/ mutation operations first, then adapt CLI/MCP/daemon surfaces. - Preserve surface-specific confirmation UX in CLI/MCP, but make the actual mutation result shape shared.
- Decide whether bulk operations return
applied_count, per-item results, or both, and make CLI/MCP/API consistent enough for agents to reason about partial success. - Avoid a generic CRUD abstraction. The contract should be archive-specific and small.
Non-goals
- Do not change content-hash semantics for user metadata or tags.
- Do not solve provider-event/content write-bundle honesty; refactor(storage): make conversation writes bundle/hash-honest #841 owns canonical conversation write units.
- Do not redesign read query envelopes; refactor(api): define shared query/status contracts for all read surfaces #859 owns query/status read contracts.
- Do not solve import/index maintenance operations; refactor(ingest): define shared import and maintenance operation contracts #861 owns those.
- Do not remove CLI/MCP confirmation safeguards; unify the mutation beneath them.
Dependencies and coordination
- Coordinate with refactor(storage): make conversation writes bundle/hash-honest #841 for lower-level repository write guarantees and metadata/tag storage invariants.
- Coordinate with refactor(api): define shared query/status contracts for all read surfaces #859 when mutation targets come from shared query selections.
- Coordinate with fix(mcp): add pagination envelopes and structured resource errors #819 for MCP mutation/resource error envelope cleanup.
- Coordinate with refactor(surfaces): route read adapters through shared archive APIs #860 if moving surface code away from direct repository/tag-store access triggers structural import-boundary changes.
- Coordinate with chore(backlog): daemon-first execution graph after #847 #852 for mass-execution sequencing.
Acceptance criteria
- API, CLI query modifiers, MCP mutation tools, and daemon delete/reset path all use a shared mutation operation or explicitly documented adapter exception.
- Mutation result semantics are tested for idempotency and not-found behavior.
- Bulk tag behavior is defined and tested consistently enough that
applied_count/ per-item success cannot be misread by an agent or caller. - CLI/MCP safety confirmations remain surface concerns, but the underlying delete result contract is shared.
- No changed surface adds new direct
RepositoryWriteMixin,TagStore, or repository mutation access unless it is the operation boundary or an explicitly justified adapter exception. - User metadata/tag changes remain excluded from content hash and do not trigger re-import/replacement semantics.
Verification
Focused checks while iterating:
pytest tests/unit/core/test_facade_api.py tests/unit/cli/test_query_exec.py tests/unit/cli/test_query_exec_laws.py tests/unit/mcp/test_tool_contracts.py -q- storage tag/metadata/delete tests when repository behavior changes
rg -n "RepositoryWriteMixin|bulk_add_tags|add_tag\(|remove_tag\(|update_metadata\(|delete_conversation\(|delete_metadata" polylogue/api polylogue/cli polylogue/mcp polylogue/daemon polylogue/operations tests/unitdevtools verify-layering --jsonif import-boundary rules changedevtools render-all --checkif CLI/MCP docs/generated references changedevtools verify --quick, then fulldevtools verifybefore PR readiness unless using chore(backlog): daemon-first execution graph after #847 #852's intermediate/draft override
Metadata
Metadata
Assignees
Labels
area:cliCLIarea:coreCore runtime and shared infrastructurearea:mcpMCPphase:architectureArchitecture and design spinetheme:command-surfaceCLI and control-plane command taxonomytype:refactorCode restructuring
Activity
Sinity commentedon May 7, 2026
Gap-audit split: tags/delete vs reader marks/saved views
#867 now owns reader marks, annotations, saved views, and recall packs.
Interpretation for #862: keep this issue focused on shared tag metadata and delete/mutation contracts. #867 should reuse the idempotency, not-found, delete-safeguard, and result-envelope conventions from #862 where they fit, but it should not hide marks/annotations/saved views inside generic tag metadata or opaque blobs.
Refs #867 #852.
Sinity commentedon May 7, 2026
Reconnaissance Report: Centralize Tag Metadata and Delete Contracts
Auditor: automated recon pass against
polylogue/mcp/server_mutation_tools.py,polylogue/cli/commands/tags.py,polylogue/storage/repository/archive/repository_writes.py,polylogue/protocols.py,polylogue/surfaces/payloads.py. No code changes.Current State of Play
Tag operations (MCP):
server_mutation_tools.pyregistersadd_tag,remove_tag,bulk_tag_conversations,list_tags:add_tagandremove_tag(lines 18-57): ReturnMCPMutationStatusPayload(status="ok", conversation_id=..., tag=...). UseConversationNotFoundErrorcatch path.bulk_tag_conversations(lines 60-83): Returns inlineMCPRootPayloaddict withstatus: "ok",conversation_count,tag_count,applied_count. Theapplied_countis the count of conversations whose tags actually changed.status="ok".Metadata operations (MCP):
server_mutation_tools.pyregistersget_metadata,set_metadata,delete_metadata:get_metadata(lines 95-101): ReturnsMCPMetadataPayload.from_document(metadata)— a bare JSON doc, no envelope.set_metadata(lines 104-126): ReturnsMCPMutationStatusPayload(status="ok"). CatchesConversationNotFoundError. Triesjson.loads(value)for number/boolean/json parsing with silent fallback to string.delete_metadata(lines 130-145): Usesresolve_id(strict=True)pattern (different from add_tag/remove_tag which use the Poly facade). ReturnsMCPMutationStatusPayload(status="ok"). No indication whether the key existed.Delete operation (MCP):
server_mutation_tools.pyregistersdelete_conversation:confirm=Trueguard. ReturnsMCPMutationStatusPayload(status="deleted" or "not_found"). Uses the Poly facade (_get_polylogue) rather than the consistent store pattern.CLI surface:
cli/commands/tags.pyis read-only — lists tags with optional provider/count filter. No mutation commands exist in CLI for tags or metadata.Underlying store (RepositoryWriteMixin):
storage/repository/archive/repository_writes.py:add_tag(line 136-153): False return on duplicate tag (not used by MCP adapter)remove_tag(line 204-216): Mutes if tag absentbulk_add_tags(line 155-202): Returnsapplied_count— conversations changeddelete_metadata(line 127-134): Mutes if key absentdelete_conversation(line 231-232): Delegates todelete_conversation_via_backendupdate_metadata(line 120-125): Write-through with read-modify-writeInconsistency pattern:
add_tag/remove_taguse Poly facade →ConversationNotFoundErrorcatchdelete_metadatauses directresolve_id(strict=True)store accessdelete_conversationuses_get_polylogue()(same as Poly, but different pattern)Build This
Shared mutation result envelope across tag, metadata, delete:
MCPMutationResultpayload (extend or replaceMCPMutationStatusPayload) with:status: Literal["ok", "deleted", "not_found", "unchanged", "partial"]conversation_id: str | Nonedetail: str | None(machine-readable detail like "already_present", "key_not_found")affected_count: int | None(for bulk operations)skipped_count: int | Nonetag: str | None,key: str | None(context for single-resource ops)Idempotency semantics:
add_tagon already-present tag: returnstatus="unchanged"with detail"already_present"remove_tagon absent tag: returnstatus="not_found"with detail"tag_not_present"delete_metadataon absent key: returnstatus="not_found"with detail"key_not_found"delete_conversationon nonexistent: returnstatus="not_found"Consistent conversation-not-found pattern:
resolve_id(strict=True)or Poly facade consistently).ConversationNotFoundErrorfor not-found with structured error envelope.CLI mutation parity (optional but recommended):
tagscommand could add--add-tag/--remove-tagflags, but if this expands scope too far, defer to feat(cli): add fast status/bare invocation and optional aliases #825 (CLI polish).Delete contract safeguards:
delete_conversation.status="not_found", not"ok".Do NOT Build This
add_tag/remove_tagto return richer results if that would break refactor(storage): make conversation writes bundle/hash-honest #841 write-bundle expectations — coordinate.Files to Touch
polylogue/surfaces/payloads.pyMutationResultPayloadmodel extendingMachineSuccessPayload/SurfacePayloadModelwith the fields listed above.polylogue/mcp/payloads.pyMCPMutationStatusPayloadin favor of sharedMutationResultPayload, or keep both with adapter.polylogue/mcp/server_mutation_tools.pypolylogue/storage/repository/archive/repository_writes.pyadd_tag/remove_tagalready-present signals to callers.polylogue/operations/specs.pyOperationSpecentries for mutation operations (tag-add, tag-remove, metadata-set, metadata-delete, delete-conversation) with appropriate effects.polylogue/cli/commands/tags.pypolylogue/protocols.pyTagStoreprotocol return types for idempotency.Coordination
add_tag/set_metadatado not touch the content hash path.MutationResultPayloadconventions.Focused Tests
Acceptance Criteria
MutationResultPayloaddefines status, affected_count, skipped_count, detail, context fieldsadd_tagreturnsunchangedwhen tag already presentremove_tagreturnsnot_foundwhen tag absent or conversation not founddelete_metadatareturnsnot_foundwhen key absentdelete_conversationreturnsnot_foundwhen conversation nonexistent (notdeleted)devtools verify --quickpasses; fulldevtools verifybefore PR readinessrefactor(mutations): centralize tag/metadata/delete result envelopes (#…
fix: resolve mypy errors from agent PR merges
fix: close remaining gaps — allowlist doc, inventory, daemon reset (#864
15 remaining items
Sinity commentedon May 9, 2026
PR #978 adds the idempotency outcome field to tag mutation payloads.
Landed:
outcomefield onMutationResultPayloadandMCPMutationStatusPayloadadded,no_op,removed,not_presentStill open: shared mutation contract centralization (metadata, delete, bulk), consistent conversation-not-found patterns, operation specs — tracked in #861.
Refs #862.
Sinity commentedon May 9, 2026
Certification — PR #978
WORK
Acceptance criterion (subset of #862):
REALIZATION
DECLARATION
I declare the WORK item above to be fully realized by the matching REALIZATION entry. AC #2 of #862 (centralize mutation contract across all surfaces) is OUT OF SCOPE for this PR — tracked in #972. Verified by: pytest tests/unit/mcp/ tests/unit/cli/ tests/unit/storage/ -k tag -q → 129 passed; mypy strict: clean.
feat: add idempotency outcome to tag mutation payloads (#862) (#978)
Sinity commentedon May 9, 2026
Certification — PR #991
WORK: Centralize tag mutation operations across surfaces
REALIZATION: polylogue/surfaces/payloads.py (shared contract) + CLI/MCP/API routing
DECLARATION: Fully realized. Verified by pytest.
refactor(mutations): centralize tag operations through shared contract (
Sinity commentedon May 9, 2026
All AC satisfied. Idempotency outcome via PR #978, centralized tag operations via PR #991. Closing.
chore: restore master verify --quick baseline (rendered docs, budgets…
Sinity commentedon May 15, 2026
Reopened from the 2026-05-15 issue-set streamlining pass. #972 was tracking this residual indirectly; the mutation contract work belongs here. Remaining scope: shared mutation operation/result contract across CLI/API/MCP/daemon surfaces, with explicit idempotency/no-op/not-found outcomes rather than surface-local repository/tag-store calls. #978 covered part of the idempotency behavior; closeout should cite exact result envelopes and focused tests across the surfaces.
refactor(surfaces): route read adapters through shared archive API (#860
refactor(mutations): centralize validation through ArchiveMutationsMi…
feat(reader): bulk operations on conversation selection (#1119) (#1162)