Skip to content

feat(mcp): the maintenance tools, the counts the pass drops, and the run record - #1226

Merged
chappie-daemon merged 10 commits into
rewrite/mainfrom
factory/038-mcp-maintenance
Nov 22, 2026
Merged

chappie-daemon merged 10 commits into
rewrite/mainfrom
factory/038-mcp-maintenance

Conversation

@chappie-daemon

Copy link
Copy Markdown
Collaborator

Slice 5 of #1183: maintenance_run and maintenance_last_run, the retention purge's counts through the seam, and a last-run record.

The API change the family carried. MaintenanceService::clear_old_events answers EventPurgeCounts instead of (), the MaintenanceTasks trait's future carries them, MaintenanceRunner passes them through, and PassOutcome gains counts: Option<EventPurgeCounts> — None on a failed, panicked or timed-out purge, never zeros. crates/nostream-storage is untouched: both backends already answered the counts, and no EventRepository implementor moves. The counts are handed on as one named value (record_maintenance_run(counts: EventPurgeCounts)), so a transposed deleted/expired pair is a call the compiler refuses.

The door. maintenance_run (write scope) runs the purge step through MaintenanceService — the function the worker's MaintenanceTasks arm delegates to, since a MaintenanceRunner needs the outbox dispatcher, payments service and relay key source the stdio mode does not compose — and records the run. maintenance_last_run (read scope) answers {"run": null} before any run in this process and {"run": {ranAt, deleted, expired, retained}} after one. The record is process memory in AdminState: replace, never sum.

The limit, stated not hidden. The stdio door is its own process, so the record is this process's own. Run beside a daemon, {"run": null} means "this process has not run one" and the daemon's passes are invisible — a known blind spot, and the tool's description says so. ADR 0019's Consequences names the durable cross-process record as that decision's successor, and prices it: an amendment to ADR 0016's five-key document plus a writer at the loop, which already holds the counts and discards them (MaintenanceTasks → run_pass's PassOutcome at workers/maintenance.rs:178).

Record. ADR 0019 (six decisions, each with its cost), ADR 0014/0017/0018 amended, the absent-name example retired to no_such_tool (no #1183 name is absent now), CONFIGURATION.md, --help and MCP_INSTRUCTIONS at fourteen tools / nine reads / five writes, one empty changeset.

Measured. mcp 101 over 9 targets (96/8 at base); services maintenance 7 (6); mcp_stdio 20 (19); workspace 1 808 passed / 0 failed over 105 targets (1 801/0 over 104); fmt, both clippy passes and --release clean; tools/list snapshot rendered from the live server and compared.

Sixteen criteria a wrong implementation could have satisfied were rewritten before the build (the two-pass cap), and the two findings that mattered were both introduced by a fix: a positional-count swap all five new cases stayed green through, and a cost paragraph whose premise a neighbouring ADR refuted. Rounds: 1 full (five lenses), 2 and 3 confirmation, two reworks, approver APPROVE at 2a116117.

Rust only: no version bump. Closes #N is inert on this repository's integration branch; #1183 is closed by hand with the merge sha.

MaintenanceService::clear_old_events answers EventPurgeCounts; the guard's arm answers three zeros without calling the store. The MaintenanceTasks future carries the counts, MaintenanceRunner passes them through, and PassOutcome gains counts: Option<EventPurgeCounts> — None on the error, panic and timeout arms, because zeros there would be a fake.
MaintenanceRun holds ranAt and the three purge counts; record_maintenance_run replaces the previous value and answers the record it stored, latest_maintenance_run reads it, and the field sits on AdminRuntime beside the heartbeats and the probe ring. WorkerHeartbeat and the status document are untouched.
maintenance_run is a write row that runs the purge step through MaintenanceService in the answering process and records it; maintenance_last_run is a read row that answers {run} from AdminState. The crate takes nostream-services as a real dependency, McpError gains a transparent Services variant, the surface is fourteen names (nine reads, five writes), and the absent-name example moves to no_such_tool.
…pipe

Over a config with limits.event.retention.maxDays: 7, maintenance_run answers the store's Phase-1 message while maintenance_last_run answers {run: null}: a failed run records nothing. Both tools/list counts move to 14.
ADR 0019 carries the six decisions; ADR 0014's audit table gains both actions and its scope sentence now points at the TOOLS table; ADRs 0017 and 0018 gain the forward line naming 0019.
…tion

The --help lists and CONFIGURATION.md's read and write rows name maintenance_run and maintenance_last_run, and the write row reads five.
@changeset-bot

changeset-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2a11611

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 22, 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: 08a0d64c-0a30-4005-8c23-4327c72ea84f

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 22, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect MCP maintenance calls and the shared maintenance-pass count contract.

The PR appears safe to merge, with a non-blocking test gap around the named deletion counts.

Findings

  1. P2 Swapped counts escape tests ▶

Summary

Adds maintenance_run and maintenance_last_run, and carries purge counts through the service and worker.

  • MCP callers can run retention and read this process’s latest result.
  • Maintenance passes now keep the purge counts they receive.

Acknowledgment: chappie-daemon explicitly accepts that daemon passes are invisible to this process-local record. The PR names a durable cross-process record as future work.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Call[maintenance_run] --> Gate[Credential and write-scope check]
  Gate --> Service[MaintenanceService.clear_old_events]
  Worker[MaintenanceRunner] --> Service
  Service --> Store[EventRepository]
  Store --> Counts[EventPurgeCounts]
  Counts --> Record[Replace AdminState record]
  Record --> Answer[Return run]
  Read[maintenance_last_run] --> Record
Loading

Reviews (1) · Last reviewed commit: "docs(adr): price the sixth key on the co..." · Reviewed by Greptile

assert_eq!(result.is_error, Some(false), "{}", text(&result));
assert_eq!(
payload(&result),
run(NOW_RAN_AT, [1, 1, 1]),

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 Swapped counts escape tests

The new MCP tests always give deleted and expired equal counts. Swapping those fields in record_maintenance_run would leave every new case green while showing operators the wrong breakdown. Seed different numbers of deleted and expired events, then check both tools’ named fields.

@chappie-daemon
chappie-daemon merged commit 6d1454b into rewrite/main Nov 22, 2026
17 of 18 checks passed
@chappie-daemon
chappie-daemon deleted the factory/038-mcp-maintenance branch November 22, 2026 06:55
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