Skip to content

fix(mcp): filter find_incidents by status in SQL, not after the limit (audit M8) - #438

Merged
passcod merged 2 commits into
mainfrom
claude/pr-370-fix-m8-mcp-find-incidents
Aug 1, 2026
Merged

fix(mcp): filter find_incidents by status in SQL, not after the limit (audit M8)#438
passcod merged 2 commits into
mainfrom
claude/pr-370-fix-m8-mcp-find-incidents

Conversation

@passcod

@passcod passcod commented Aug 1, 2026

Copy link
Copy Markdown
Member

Fixes M8 (medium) from the audit in #370.

The bug

Incident::list_open_since orders by opened_at desc with a SQL LIMIT (default 100). find_incidents then applied the open/resolved filter in Rust, on that already-truncated page — so status: "open" returned only the open incidents among the 100 most recently opened rows.

The lookback window commonly holds more sub-grace flap rows than the limit, and those sort by opened_at alongside everything else. A still-open incident that opened six days ago sits below them and is omitted entirely — from the list and from count and published_count. An active incident goes invisible in the tool built for triage.

The fix

The filter moves into the query as an IncidentStatusFilter (All / Open / Resolved), so the limit bounds the filtered set. Semantics are unchanged: open is "not closed", resolved is "operator-resolved", and they overlap because an operator can resolve an incident that's still open.

Tests

New crates/database/tests/it/incident_list_status.rs:

  • the_status_filter_is_applied_before_the_limit — one incident opened six days ago and still open, ten closed flap rows from the last hour, limit 5: the open one still comes back.
  • the_status_filter_selects_the_right_incidents — All/Open/Resolved pick the right rows, including the resolved-but-not-closed overlap.

Note for reviewers: the second test uses two groups because a partial unique index (incidents_open_by_group) allows only one open incident per group.

Third of four in the audit's "filter-after-LIMIT in the MCP layer" pattern (M7, M8, M9, L14).


Generated by Claude Code

claude added 2 commits August 1, 2026 08:45
`Incident::list_open_since` orders by `opened_at desc` with a SQL `LIMIT`
(100 by default); `find_incidents` then applied the open/resolved filter in
Rust, on that already truncated page. So `status: "open"` returned only the
open incidents *among the 100 most recently opened rows*.

The lookback window commonly holds more sub-grace flap rows than the limit,
and they sort by `opened_at` alongside everything else. A still-open incident
that opened six days ago therefore sits below them and is omitted entirely —
from the list and from both counts. An active incident becomes invisible in
the tool built for triage.

The filter moves into the query as an `IncidentStatusFilter`, so the limit
bounds the filtered set. `open` stays "not closed" and `resolved` stays
"operator-resolved"; those overlap, since an operator can resolve an incident
that is still open, and that is unchanged.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SGfH1cdFKPnKpM7ytRThft
@passcod
passcod marked this pull request as ready for review August 1, 2026 22:12
@passcod
passcod added this pull request to the merge queue Aug 1, 2026
Merged via the queue into main with commit 45e4e56 Aug 1, 2026
7 checks passed
@passcod
passcod deleted the claude/pr-370-fix-m8-mcp-find-incidents branch August 1, 2026 23:13
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.

2 participants