Skip to content

feat(maintenance): typed scope filters (#1196) - #1323

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/maintenance-scope-filters-1196-v2
May 18, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/maintenance-scope-filters-1196-v2

Conversation

@Sinity

@Sinity Sinity commented May 18, 2026

Copy link
Copy Markdown
Owner

Summary

Replace the always-empty JSONDocument filter on MaintenanceScope with a typed MaintenanceScopeFilter Pydantic model carrying the named scope dimensions called out in #996 AC #1, and plumb it through every maintenance surface (CLI, daemon HTTP, MCP) so the same shape round-trips end to end.

Problem

polylogue/maintenance/planner.py defined MaintenanceScope with targets: tuple[str, ...] and a free-form filter: JSONDocument. No surface (CLI maintenance plan/run, /api/maintenance/plan, /api/maintenance/run, MCP maintenance_preview / maintenance_execute) accepted or emitted any filter content — the filter was always {}. #996 AC #1 explicitly requires the planner to "enumerate candidate replay scopes by source root, raw artifact, provider/source family, failure kind, parser/materializer version, time range." None of those dimensions were reachable, and the P2 follow-ups (#1195/#1197/#1198) depend on having this typed contract first.

Solution

  • New polylogue/maintenance/scope.py defines MaintenanceScopeFilter (frozen Pydantic model, extra="forbid") with eight typed dimensions: conversation_ids, provider, source_family, source_root, raw_artifact_id, time_range, failure_kind, parser_version. The model exposes to_dict / from_dict for surface round-trips and is_empty() for fast-path checks.
  • MaintenanceScope.filter is the typed model (no longer JSONDocument); MaintenanceScope.from_dict round-trips the typed filter back from a JSON payload.
  • preview_backfill, execute_backfill, and execute_replay all accept scope_filter=... and surface it on the returned BackfillOperation.scope. Preview narrows affected_rows when conversation_ids is set; replay forwards the filter into the per-target dispatch.
  • repair_session_insights learns to honor conversation_ids, narrowing the rebuild to that conversation set instead of touching the full archive.
  • CLI polylogue maintenance plan / run gain --conversation-id (repeatable), --provider, --source-family, --source-root, --raw-artifact, --since/--until, --failure-kind, --parser-version. The CLI parsing helper is shared so plan and run cannot drift.
  • Daemon HTTP POST /api/maintenance/{plan,run} parse the same fields from the body. Both a nested {"scope":{"filter":{...}}} envelope and a flat top-level shape are accepted; invalid filters return 400.
  • MCP maintenance_preview / maintenance_execute expose typed parameters mirroring the CLI flags.
  • The shared MaintenanceOperationEnvelope.scope.filter carries the typed filter dict so CLI, daemon HTTP, and MCP all emit byte-identical JSON for the same operation. MaintenanceScopePayload's docstring now points at the typed model as the contract source.
  • polylogue/maintenance/cost_migration.py is migrated off the legacy free-form filter onto MaintenanceScopeFilter(conversation_ids=...). The legacy cost_basis / dry_run fields are kept on per-result rows where they belong.

Non-honored dimensions (everything other than conversation_ids on session_insights) pass through the executor unchanged: each repair fn that learns to narrow on a new dimension pins that dimension's contract — the typed envelope is the place where each future PR (#1195/#1197/#1198) plugs in.

Verification

  • python -m pytest tests/unit/maintenance/ tests/unit/cli/test_maintenance_registration.py tests/unit/daemon/test_maintenance_endpoints.py tests/unit/mcp/ tests/unit/cost/test_contract_suite.py -q → 370 passed.
  • devtools verify --quick → exit_code: 0 (format, ruff, mypy strict, render-all check, all manifest/lint gates).
  • New tests/unit/maintenance/test_scope_filter.py covers: field/frozen-ness/extra-field-rejection contract on the model; to_dict/from_dict round-trip across every dimension combination; planner attaches the filter to the returned scope; affected_rows shrinks when conversation_ids narrows the scope; cross-surface parity — CLI, daemon HTTP, MCP all serialize the same typed filter to the same envelope payload.
  • tests/data/witnesses/mcp-tool-schemas.json regenerated for the new MCP tool parameters.

Closes #1196
Ref #996

🤖 Generated with Claude Code

@Sinity
Sinity enabled auto-merge (squash) May 18, 2026 15:17
@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 50 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: d16027b0-0c56-448b-9a50-190e5d4a7528

📥 Commits

Reviewing files that changed from the base of the PR and between 31ae6cc and 3ea0b03.

📒 Files selected for processing (17)
  • docs/plans/file-size-budgets.yaml
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • docs/verification-catalog.md
  • polylogue/cli/commands/maintenance.py
  • polylogue/daemon/http.py
  • polylogue/maintenance/cost_migration.py
  • polylogue/maintenance/envelope.py
  • polylogue/maintenance/planner.py
  • polylogue/maintenance/replay.py
  • polylogue/maintenance/scope.py
  • polylogue/mcp/server_maintenance_tools.py
  • polylogue/storage/repair.py
  • tests/data/witnesses/mcp-tool-schemas.json
  • tests/unit/cost/test_contract_suite.py
  • tests/unit/maintenance/test_planner_contract.py
  • tests/unit/maintenance/test_scope_filter.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/maintenance-scope-filters-1196-v2

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.

Replace the always-empty JSONDocument `MaintenanceScope.filter` with a
typed `MaintenanceScopeFilter` Pydantic model carrying the named scope
dimensions called out in #996 AC #1: `conversation_ids`, `provider`,
`source_family`, `source_root`, `raw_artifact_id`, `time_range`,
`failure_kind`, `parser_version`.

The typed filter is plumbed through:

- planner `preview_backfill` / `execute_backfill` accept `scope_filter`
  and surface it on the returned `BackfillOperation.scope`;
- replay `execute_replay` forwards the filter to per-target repair
  dispatch; `repair_session_insights` now honors `conversation_ids` so a
  one-session scope only rebuilds that session;
- CLI `polylogue maintenance plan` / `run` gain `--conversation-id`
  (repeatable), `--provider`, `--source-family`, `--source-root`,
  `--raw-artifact`, `--since`/`--until`, `--failure-kind`,
  `--parser-version`;
- daemon HTTP `POST /api/maintenance/{plan,run}` parse the same fields
  from the body (both nested `scope.filter` and flat top-level shapes);
- MCP `maintenance_preview` / `maintenance_execute` expose typed
  parameters mirroring the CLI flags;
- the shared `MaintenanceOperationEnvelope` serializes the typed
  filter so every surface emits byte-identical JSON.

`MaintenanceScope.from_dict` round-trips the typed filter back through
the boundary. `tests/unit/maintenance/test_scope_filter.py` pins:

- field/frozen-ness/extra-field-rejection contract on
  `MaintenanceScopeFilter`;
- `to_dict`/`from_dict` round-trip across every dimension combination;
- planner attaches the filter to the returned scope and narrows
  `affected_rows` when `conversation_ids` shrinks the scope;
- cross-surface parity — CLI, daemon HTTP, MCP all serialize the same
  typed filter to the same envelope payload.

P2 maintenance pipeline foundation — #1195/#1197/#1198 depend on
this typed contract.

Closes #1196
Ref #996

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity force-pushed the feature/feat/maintenance-scope-filters-1196-v2 branch from 878f5b7 to 3ea0b03 Compare May 18, 2026 15:21
@Sinity
Sinity merged commit ceecf5b into master May 18, 2026
2 of 4 checks passed
@Sinity
Sinity deleted the feature/feat/maintenance-scope-filters-1196-v2 branch May 18, 2026 15:22

@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: 878f5b7183

ℹ️ 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".

Comment thread polylogue/daemon/http.py Resolved
Comment thread polylogue/daemon/http.py Resolved
@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

  • 62.F079 / P1: fixed-already at the checked revision: The old free-form maintenance scope parser has been retired. Current mutation payloads forbid extra fields at polylogue/operations/daemon_protocol.py:91 and are model-validated before dispatch at line 2755, so a nested malformed scope cannot silently become an empty whole-archive filter.
  • 62.F080 / P1: stale at the checked revision: The execute_backfill maintenance-run endpoint and its ignored scope_filter contract no longer exist. Current destructive maintenance resolves explicit reset targets at polylogue/operations/daemon_mutations.py:298 and passes those exact targets to its actuator at line 302; a request with no selected target is refused at line 219 rather than widened to archive scope.

Only the rows listed above are dispositioned. Held findings remain open.

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.

feat(maintenance): typed scope filters — conversation_ids, provider, date range, source root

1 participant