Skip to content

feat(mcp): add delete_event and reports_action over a report setter - #1222

Merged
chappie-daemon merged 16 commits into
rewrite/mainfrom
factory/036-mcp-writes
Nov 21, 2026
Merged

chappie-daemon merged 16 commits into
rewrite/mainfrom
factory/036-mcp-writes

Conversation

@chappie-daemon

@chappie-daemon chappie-daemon commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Slice 3 of #1183. Two write tools on the MCP door, and the store seams they need.

delete_event

Soft delete through delete_by_pubkey_and_ids — the store's own single-row delete — with four
outcomes (deleted, already_deleted, not_deleteable for kind 62, not_found) and the event
row read back after the call. The outcome is decided by the row as it stands after the call,
so two concurrent deletes answer already_deleted rather than not_deleteable.

The description states what the store actually does: the event leaves REQ and COUNT, keeps its
row, and get_event / list_events still return it with deleted_at set — unless an
actionable report hides it
, in which case it stays hidden until the report is allowed.

reports_action

Acts on a report's own kind-1984 event id through find_by_event_id, setting
Report.actionable for hide and allow across every row that event wrote, and answers
changed — the rows whose value actually moved — with every row of the event sorted by id by
the handler, not by either backend's order. The LMDB arm removes the three denormalised
reports_actionable_* index entries in the same write, which is what keeps the NIP-56 filter
honest; allow cannot re-publish a target that another actionable report still names.

The seams

  • ReportRepository::set_actionable, implemented by LMDB, Postgres, InMemory, Unavailable and
    Noop, reached through a new ServiceStores.reports field (one field at ten construction
    sites) rather than a third AdminState field.
  • EventRepository::find_stored(&EventId) — one ungated exact-id read, LMDB one get, Postgres
    one SELECT ... WHERE event_id = $1. The NIP-56 gate is a read's, and the delete path must see
    the row a report hides: with the gated read, "hide the report, then delete the event" answered
    not_found and deleted nothing, which made the two tools incoherent with each other. Its doc
    says who may call it, and an acceptance leg counts .find_stored( call sites — two, both the
    handler's — so a third caller in the method-call form fails the criterion. The leg is a
    deterrent rather than a proof: a fully qualified EventRepository::find_stored spells past it,
    as the parity cases themselves do, and the record says so.
  • Both tools sit at Requires::Write and audit through the existing path: mcp.delete_event /
    mcp.reports_action with detail {"tool": ...} and nothing else.

Record

ADR 0017 with D1–D6, each with its cost; ADR 0014's scope column, D7's bundle and D18's table
brought current; CONFIGURATION.md's write-scope table now names all three write tools and what
they reach; the eleven count sites; the two absent-name inversions moved to user_admin;
changeset added.

Verification

cargo fmt --all --check, both clippy passes, cargo test --workspace --all-features
(1 781 passed / 0 failed / 9 ignored) and a release build, all exit 0. The oracle is
crates/nostream-mcp/tests/write_tools.rs (18 cases), five new parity_lmdb cases plus two
#[ignore]d Postgres ones that CI runs, an audit case and a real-binary case. Each load-bearing
assertion was made to fail once: the four delete outcomes, the hidden-event delete, the post-call
read-back, the write gate on both tools, the ordering sort through a reversed repository seam,
each of the three index removals, the cross-report rule and the mixed-row count. The reds are in
the job record.

Known and stated rather than fixed here: the raced double-delete (two deletes of one row in
flight) has no deterministic case — the branch is correct by the post-read, and no test claims a
proof it cannot make; the Postgres setter arm runs only in CI, where a database exists.

Out of scope, deliberately: the hidden-content mirror's 30 s refresh (per-query reads are already
gated, so the only consequence is a bounded disclosure the description names), and reports_list,
which no slice owns.

Implements #1183 (slice 3 of 5).

…r (incomplete)

The storage half of slice 3: `ReportRepository::set_actionable` in the trait and its
four other implementors (LMDB removes the three `reports_actionable_*` keys and
rewrites through `report_write`; Postgres is one `UPDATE`), `ServiceStores.reports`
at all ten construction sites, and the MCP harness opening its store with the
settings it serves.

The surface half: both tools with their constants, `TOOLS` rows at `Requires::Write`,
`parses` functions, handlers, the `MCP_INSTRUCTIONS` sentence, and the descriptions,
argument docs and payload literals the spec words verbatim. `ReportAction` implements
`schemars::JsonSchema` by hand so the published schema states the closed set as
`enum` rather than a `oneOf` of `const` variants.

Incomplete: the new `write_tools` target, the parity cases, the daemon's stdio case,
the remaining count sites, ADR 0017 / ADR 0014 D18 and the changeset are not in this
commit. See the job's build.md.
The oracle: `tests/write_tools.rs` with the fourteen cases (four delete outcomes, the
read-back, the count leaving V13, both refusals, and `hide`/`allow` moving the LMDB
indexes behind the NIP-56 gate), four `set_actionable_*` cases in `parity_lmdb`, the
`#[ignore]`d Postgres arm, and the daemon's `the_write_tools_report_the_unwired_store`.

The sites that pin the tool count read seven, the two absent-name inversions move to
`user_admin`, `--help` names all three writing tools, and both tool names now occur on
exactly five lines of `server.rs` (the instructions sentence among them).

The record: ADR 0017 with D1–D6, ADR 0014's audit table and its two sentences, and one
empty changeset.
…rules

Rework 1's findings, from `round-1/review-code.md`.

The ordering case read a real LMDB store, whose `(event_id, report_id)` walk is ascending
by construction, so removing the handler's sort left it green. The harness gains a report
repository seam, and the case reads through a store that answers newest id first: with the
sort removed the payload's ids descend and the case fails.

The read-only case called with an id no report row carried, so its "moved nothing"
assertion had no subject; it now names the seeded report event and asserts the row is
still actionable. Flipping the fixture's grant to `write` reddens it.

Two cases the gate measured green with throwaway copies now pin the behaviour: an `allow`
leaves a target hidden while another actionable report still names it, and a report with
one already-false row and one true row answers `changed: 1` with both rows listed.
`a_read_only_document_is_refused_both_writes` sent `hide` at a row already `actionable:
true`, which the store skips, so a leaked report gate answered `changed: 0` and left the
row true: the "moved nothing" assertion had no write to be the subject of. It now sends
`allow`, and the state assertions come before the refusals, so the store's own read is
what fails when either gate leaks — the delete's at the deleted row, the report's at the
row's flag.

The case's header says three fixtures carry the NIP-56 gate, which is the count now.
@changeset-bot

changeset-bot Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0a01867

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af64703e-8f10-4e64-b77f-6ecaf4b0f7f5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@greptile-apps

greptile-apps Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; both earlier delete issues are addressed.

Summary

Adds delete_event and reports_action as MCP tools that require write access.

  • Operators can soft-delete a stored event by its exact id.
  • Operators can hide or allow every target named by one report event.
  • The MCP door exposes both write tools through shared report storage.

Both earlier findings are addressed in the current code. No new actionable issues or repository-rule violations were found.

Reviews (6) · Last reviewed commit: "docs(adr): a false double reddens its ca..." · Reviewed by Greptile

Comment thread crates/nostream-mcp/src/server.rs Resolved
Comment thread crates/nostream-mcp/src/server.rs Resolved
An event an actionable report hides resolved through `get_event`'s gated read to
`not_found`, so `reports_action hide` followed by `delete_event` deleted nothing: the pair
this slice ships contradicted itself. `EventRepository` gains `find_stored(&EventId)` —
LMDB one `get` on the events table, Postgres one `SELECT … WHERE event_id = $1` — whose
doc says it bypasses the NIP-56 gate and that only the delete path may call it. All nine
implementors carry it; the delegating double calls it fully qualified so the ungated read
keeps exactly one call site in the workspace.

`deleted()` now runs the 64-character criterion, reads through `find_stored`, and takes
its outcome from the row as it stands after the call, so a row a concurrent delete already
marked answers `already_deleted` rather than `not_deleteable`. R5's description gains the
hidden-event exception, and a case pins a hidden event's delete plus the read tools still
hiding it afterwards.
R5's sentence and `DeleteEventArgs.id`'s field doc now say a prefix shorter than 64
characters is refused rather than widened to whatever the store's range would match, which
is the answer the handler already gives. The snapshot follows both: the tool's description
and its id field's schema description are regenerated from the attributes.
greptile-apps[bot]
greptile-apps Bot previously approved these changes Nov 21, 2026
…ive sentences

The outcome's second condition was reached only at a zero count, where the pre-read and the
read-back agree, so the amendment's subject was unobservable. `ZeroCountDeleter` is the store
that disagrees with itself — the real soft delete, a count of zero — and the case reads it as
`already_deleted`; the pre-read subject answers `not_deleteable` there.

The rest is text: four gate fixtures in the module header, the case table catching up with the
17th and 18th cases and with the prefix refusal, the relay double's `UPDATE` sentence back on
`delete_by_pubkey_and_ids`, and the two kind-62 citations moved to where the skips now are.
@greptile-apps
greptile-apps Bot dismissed their stale review November 21, 2026 21:19

Dismissed because a newer commit was pushed; Greptile will re-review the current head.

@chappie-daemon
chappie-daemon merged commit a8cef4a into rewrite/main Nov 21, 2026
18 checks passed
@chappie-daemon
chappie-daemon deleted the factory/036-mcp-writes branch November 21, 2026 21:42
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