Skip to content

Send the Metrics screen's time range to every case-metrics read - #3103

Merged
samarmstrong merged 3 commits into
mainfrom
cleanup/2903-send-the-metrics-screen-s-time-2df8a198
Oct 24, 2026
Merged

samarmstrong merged 3 commits into
mainfrom
cleanup/2903-send-the-metrics-screen-s-time-2df8a198

Conversation

@G-r-ay

@G-r-ay G-r-ay commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #2903

The Metrics screen's 7d/30d/90d range reached only the MTTD and MTTR reads. getSummary, getByPriority, getByStatus and getAnalystPerformance in caseMetricsApi took no arguments, so Total, Open, Critical, the priority bars, the status donut and the analyst table showed all-time numbers whatever range was picked.

All six caseMetricsApi methods now take a required MetricsWindow (start_date, end_date), so a caller that leaves out the window does not compile. useCaseMetrics passes its one dateParams to all six. getMTTD and getMTTR also lose the priority option, which no caller passed.

Every location in the issue still held at 052a731c, at moved line numbers (api.ts:382-391, useCaseMetrics.ts:43-50). The issue's caveat about unwindowed SLA counts no longer applies, because get_summary now runs one windowed query and returns no SLA counts.

Callers checked

  • grep -rn caseMetricsApi clients found useCaseMetrics.ts, the module mock in MetricsScreen.test.tsx, and the mock in SocConsole.test.tsx. Both mocks ignore arguments.
  • grep -rn "getSummary\|getMTTD\|getMTTR\|getByPriority\|getByStatus\|getAnalystPerformance" clients found only those files. findingsApi.getSummary and casesApi.getSummary are different objects.
  • grep -rn "metrics/summary\|metrics/by-priority\|metrics/by-status\|analyst-performance\|metrics/mttd\|metrics/mttr" over py, ts, js, sh and md found api.ts, the router, the generated schema.d.ts, and backend tests. No other client, script or infra file calls these routes.

Blast radius

The web client now sends start_date and end_date on four more GET requests. The routes, the response JSON and the DB are unchanged.

  • Safe because: all six routes in core/api/v1/case_metrics_router.py already accept start_date and end_date and filter Case.created_at through _created_window.

  • Tried to break it: if a route ignored the window, a windowed call would return the same rows as an unwindowed one. Summary, by-priority and by-status already had window tests. Analyst-performance had none, so I added test_analyst_performance_respects_the_window. It seeds three analysts, sets start_date after day one, and expects only alice with one case at 4h. It passed, and the file printed 22 passed. On the client side, if api.ts or the hook dropped the window, the new vitest would see a GET with no params. Against the old code it failed with TypeError: Cannot read properties of undefined (reading 'end_date'). With the fix it passes, and all six URLs carry a 7-day span after clicking 7d.

  • Proof: 5. I ran the real app from this branch (uvicorn services.api.main:app with DEV_MODE=true on a throwaway Postgres 16 migrated by python -m core.upgrade, plus Vite on :6988). Then I opened /metrics in headless Chromium, clicked 7d, and recorded every /cases/metrics/* request and the screen text. I seeded 5 cases. Two were created 3 days ago (alice: one critical/new, one high/closed after 4h). Three were created 60 days ago (bob: two critical, open; carol: one low, closed after 10h).

    Before (base 052a731c api.ts + useCaseMetrics.ts, same backend):

    == requests after clicking 7d
    /api/cases/metrics/analyst-performance
    /api/cases/metrics/by-priority
    /api/cases/metrics/by-status
    /api/cases/metrics/mttd?start_date=2026-10-17&end_date=2026-10-24
    /api/cases/metrics/mttr?start_date=2026-10-17&end_date=2026-10-24
    /api/cases/metrics/summary
    == screen text (7d)
    TOTAL CASES | 5 | OPEN CASES | 3 | 3 critical | MTTR | 4.0h | Status distribution | Closed | 2 | In_progress | 1 | New | 2 |
    Analyst performance | 3 analysts | alice 2 1 4.0h 50% | bob 2 0 0m 0% | carol 1 1 10.0h 100%
    

    After (this branch):

    == requests after clicking 7d
    /api/cases/metrics/analyst-performance?start_date=2026-10-17&end_date=2026-10-24
    /api/cases/metrics/by-priority?start_date=2026-10-17&end_date=2026-10-24
    /api/cases/metrics/by-status?start_date=2026-10-17&end_date=2026-10-24
    /api/cases/metrics/mttd?start_date=2026-10-17&end_date=2026-10-24
    /api/cases/metrics/mttr?start_date=2026-10-17&end_date=2026-10-24
    /api/cases/metrics/summary?start_date=2026-10-17&end_date=2026-10-24
    == screen text (7d)
    TOTAL CASES | 2 | OPEN CASES | 1 | 1 critical | MTTR | 4.0h | Status distribution | Closed | 1 | New | 1 |
    Analyst performance | 1 analysts | alice 2 1 4.0h 50%
    

    Before the change, the 7d view counted the 60-day-old cases in Total, Open, Critical, the status donut and the analyst table, and only MTTD and MTTR were windowed. After it, all six reads carry the window and the screen shows only the 2 recent cases. (Timestamps are trimmed from the printed URLs.) The vitest mocks only axios, so the real api.ts, hook and screen run, and the pytest calls the real route handlers against the test DB. That output is in pr-3103/ on the deslop-evidence branch.

  • Severity: low. A wrong window shows wrong counts on one read-only screen.

  • Risks:

    • clients/web/src/services/api.ts:388-398: a new caller must supply a window. Likelihood is low, and the failure is a compile error.
    • core/api/v1/case_metrics_router.py:98: the window filters on created_at, so a case opened before the window and closed inside it drops out of the counts. This always happens, but the impact is low. MTTD and MTTR already worked this way, and it is what the range is meant to mean.
  • Cleared: the SocConsole.test.tsx mock still satisfies the shell tests (69 passed). tsc --noEmit and eslint are clean. The axios request interceptor in api.ts adds only the CSRF header and leaves params alone.

Verification

Ran

  • npx vitest run src/screens/metrics/MetricsScreen.window.test.tsx on the old code: 1 failed, as expected (vitest-window-before-fix.txt).
  • npx vitest run src/screens/metrics src/shell/SocConsole.test.tsx with the fix: 3 files, 78 passed (vitest-after-fix.txt). The SocConsole.test.tsx shell tests (69) pass with the existing mock.
  • npx tsc --noEmit -p .: exit 0 (tsc.txt).
  • npx eslint src/services/api.ts src/screens/metrics: exit 0 (eslint.txt).
  • pytest -q tests/unit/cases/test_case_metrics_aggregates.py: 22 passed (pytest-case-metrics.txt).
  • pytest -q tests/unit/_ratchets: 260 passed, 6 skipped because helm is not installed (pytest-ratchets.txt). No count changed.
  • After removing priority: tsc --noEmit exit 0, and the same vitest run gives 78 passed.

Ran in the app

  • The backend and Vite from this branch against a throwaway Postgres, with the Metrics screen driven in headless Chromium, before and after the change. See Proof above.

Did not run

  • Screenshots. The layout does not change, only the numbers behind it.
  • The full frontend and backend suites. CI runs them.

🤖 Generated with Claude Code

caseMetricsApi.getSummary, getByPriority, getByStatus and
getAnalystPerformance took no arguments, so Total, Open, Critical, the
priority and status charts and the analyst table always showed all-time
numbers while MTTD and MTTR showed the chosen window. All six methods now
take a required MetricsWindow, and the hook passes the same window to each.

Closes #2903

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
G-r-ay pushed a commit that referenced this pull request Oct 24, 2026
@G-r-ay G-r-ay added the cleanup Opened by the cleanup factory label Oct 24, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@G-r-ay

G-r-ay commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

🧹 Proof at 7cd95394df41. Counted by the cleanup factory at this commit; a push or a settled CI run replaces it. Each count says how to reproduce it.

Job: #2903, a fix job in feature case-metrics, from survey 2026-10-22-6035439f-y8bt.

Check Result
Blast radius high: if wrong, several features, or clients outside this repo, break
Size n/a (+76 −10)
Callers of what it deletes pass
Style lint pass
CI pass
Ready for review yes: taken out of draft

Blast radius: high. Touches 4 file(s) in the ui, tests layer(s), across feature(s) cases, case-metrics, http-client. Why:

  • high: spans 3 features: cases, case-metrics, http-client
  • medium: touches what users see: clients/web/src/screens/metrics/MetricsScreen.window.test.tsx, clients/web/src/screens/metrics/useCaseMetrics.ts, clients/web/src/services/api.ts

The author says it is safe because: all six routes in core/api/v1/case_metrics_router.py already accept start_date and end_date and filter Case.created_at through _created_window. (proof level 4 of 5, a claim to check, not a count).

How each count was made, and how to rerun it

Size. +76 −10 over the whole diff, as GitHub counts it. Reproduce with gh pr view 3103 -R Vigil-SOC/vigil --json additions,deletions.

Callers. What the PR deletes and does not define again, searched for across the repo at 7cd95394df41. A symbol is matched as a whole word, and a route by the fixed part of its path.
The PR deletes no function, class, top-level constant, type, or route.

Style lint. No findings in the prose the PR adds.

CI at 7cd95394df41. 23 of 23 pass. Reproduce with gh pr checks 3103 -R Vigil-SOC/vigil.

Evidence. eslint.txt · pytest-case-metrics.txt · pytest-ratchets.txt · tsc.txt · vitest-after-fix.txt · vitest-window-before-fix.txt

Machine-readable
{
  "sha": "7cd95394df413b6aad47071d3e9ba27777b9687d",
  "pr": 3103,
  "job": {
    "issue": 2903,
    "kind": "fix",
    "feature": "case-metrics",
    "survey": "2026-10-22-6035439f-y8bt"
  },
  "blast": {
    "severity": "high",
    "reasons": [
      {
        "severity": "high",
        "what": "spans 3 features: cases, case-metrics, http-client"
      },
      {
        "severity": "medium",
        "what": "touches what users see: clients/web/src/screens/metrics/MetricsScreen.window.test.tsx, clients/web/src/screens/metrics/useCaseMetrics.ts, clients/web/src/services/api.ts"
      }
    ],
    "features": [
      "cases",
      "case-metrics",
      "http-client"
    ],
    "layers": [
      "ui",
      "tests"
    ],
    "routes": [],
    "safeBecause": "all six routes in `core/api/v1/case_metrics_router.py` already accept `start_date` and `end_date` and filter `Case.created_at` through `_created_window`.",
    "proofLevel": 4
  },
  "size": {
    "additions": 76,
    "deletions": 10
  },
  "verdicts": {
    "size": "n/a",
    "callers": "pass",
    "lint": "pass",
    "ci": "pass"
  },
  "callers": [],
  "lint": 0,
  "checks": [
    {
      "name": "Build Frontend",
      "bucket": "pass"
    },
    {
      "name": "Setup Path (ubuntu-latest)",
      "bucket": "pass"
    },
    {
      "name": "Backend Image",
      "bucket": "pass"
    },
    {
      "name": "Security Scan - Python",
      "bucket": "pass"
    },
    {
      "name": "Integration Tests",
      "bucket": "pass"
    },
    {
      "name": "Security Scan - NPM",
      "bucket": "pass"
    },
    {
      "name": "Unit Tests - Backend (DB-backed)",
      "bucket": "pass"
    },
    {
      "name": "Helm Install Schema",
      "bucket": "pass"
    },
    {
      "name": "MCP Runner Image",
      "bucket": "pass"
    },
    {
      "name": "Unit Tests - Backend",
      "bucket": "pass"
    },
    {
      "name": "Setup Path (macos-latest)",
      "bucket": "pass"
    },
    {
      "name": "CodeQL",
      "bucket": "pass"
    },
    {
      "name": "Unit Tests - Agent Layer",
      "bucket": "pass"
    },
    {
      "name": "Generated API Types",
      "bucket": "pass"
    },
    {
      "name": "Unit Tests - Frontend",
      "bucket": "pass"
    },
    {
      "name": "Daemon Image",
      "bucket": "pass"
    },
    {
      "name": "Lint Frontend",
      "bucket": "pass"
    },
    {
      "name": "Lint Backend",
      "bucket": "pass"
    },
    {
      "name": "Lint Dockerfiles",
      "bucket": "pass"
    },
    {
      "name": "Agent Image",
      "bucket": "pass"
    },
    {
      "name": "Analyze (python)",
      "bucket": "pass"
    },
    {
      "name": "Analyze (javascript-typescript)",
      "bucket": "pass"
    },
    {
      "name": "Analyze (actions)",
      "bucket": "pass"
    }
  ],
  "evidence": [
    {
      "name": "eslint.txt",
      "url": "https://github.com/Vigil-SOC/vigil/blob/deslop-evidence/pr-3103/eslint.txt"
    },
    {
      "name": "pytest-case-metrics.txt",
      "url": "https://github.com/Vigil-SOC/vigil/blob/deslop-evidence/pr-3103/pytest-case-metrics.txt"
    },
    {
      "name": "pytest-ratchets.txt",
      "url": "https://github.com/Vigil-SOC/vigil/blob/deslop-evidence/pr-3103/pytest-ratchets.txt"
    },
    {
      "name": "tsc.txt",
      "url": "https://github.com/Vigil-SOC/vigil/blob/deslop-evidence/pr-3103/tsc.txt"
    },
    {
      "name": "vitest-after-fix.txt",
      "url": "https://github.com/Vigil-SOC/vigil/blob/deslop-evidence/pr-3103/vitest-after-fix.txt"
    },
    {
      "name": "vitest-window-before-fix.txt",
      "url": "https://github.com/Vigil-SOC/vigil/blob/deslop-evidence/pr-3103/vitest-window-before-fix.txt"
    }
  ]
}

@G-r-ay G-r-ay added the cleanup:blast-high Blast radius: how bad it is if this PR is wrong label Oct 24, 2026
@G-r-ay
G-r-ay marked this pull request as ready for review October 24, 2026 15:28
@G-r-ay

G-r-ay commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

🏭 Advisory review (claude-haiku-5-5 + opus advisor) — merge 7cd95394df41. Advice only: nothing was merged or closed on it.

PR #3103: merge. Head 7cd95394df41, no pushes needed.

Reviewers

Ran

  • tsc, eslint, vitest (src/screens/metrics, SocConsole.test.tsx), pytest test_case_metrics_aggregates.py, merge-tree vs main.
  • Live: Postgres 16 container, backend on :7100, Vite on :7188, Bifrost unset, 12 seeded cases. Screens: Metrics at 1920 and 1440, default 30d and 7d. Files:
    • /home/gray/Deeptempo/deeptempo-factory/telemetry/evidence/bf81f350-8bcb-4640-93b6-e34f537795b0/metrics-screen-default-30d-1920.png
    • …/metrics-screen-7d-1920.png
    • …/metrics-screen-default-30d-1440.png
    • …/metrics-screen-7d-1440.png

Did not run

  • Before-PR screenshots. Live UI has no all-time option; before state shown by the failing test instead.
  • Full frontend and backend suites (CI).

Not blocking, pre-existing, not from this PR

  • Naive created_at compared to Z timestamps; same as MTTD/MTTR. Result depends on DB timezone.
  • Legend overflows by 6px at 1440. Y-axis repeats tick labels at small counts (2 2 1 1 0).
  • Stale comment services/api/discovery.py:11 points to a missing file.

Pushed: nothing. Scratch files removed.

@G-r-ay

G-r-ay commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

🧹 Asked for proof in the running app, level 5, which a high or critical blast radius needs (1 of 3): a high blast radius proven only to level 4.

@G-r-ay

G-r-ay commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

🏭 Advisory review (claude-haiku-5-5 + opus advisor) — merge 66093a9840e2. Advice only: nothing was merged or closed on it.

Ran (verified on 66093a9840e2, main merged in)

Did not run

  • Narrower than 1440 px. The change alters numbers, not layout.
  • 30d/90d before screenshots.
  • Full frontend and backend suites (CI).
  • Live check: the first core.upgrade attempt hit the owner's Postgres on localhost:5432 with default env vars. It was refused, and the subagent reports nothing was written. Disclosed for transparency.

Pushed

  • 66093a98 is a merge of main (69f6f737, errorText refactor), pushed to the PR branch. Clean merge, no conflicts, no rebase.

Not blocking, not from this PR

  • MTTD shows 0m in every state. Seed data is rough and it was not investigated.
  • Priority chart y-axis repeats tick labels at small counts.

@samarmstrong
samarmstrong merged commit 3bd464f into main Oct 24, 2026
23 checks passed
@samarmstrong

Copy link
Copy Markdown
Collaborator

🏭 Factory review — merged.

The time range on Case Metrics now filters every read, and the screen shows that with real cases. No code change was needed.

caseMetricsApi.getSummary, getByPriority, getByStatus, and getAnalystPerformance took no window, so Total, Open, Critical, the priority bars, the status donut, and the analyst table stayed all-time while only MTTD and MTTR followed 7d/30d/90d. The six routes in core/api/v1/case_metrics_router.py already filter Case.created_at through _created_window. The hook now passes one MetricsWindow to all six, and getMTTD/getMTTR drop a priority option nothing called. That is the whole change. It is already on main (69f6f737), with no conflict.

Ran

  • Case Metrics in the running console (Vite on port 6988, API on port 6987, Postgres). Seeded five cases: alice, two created three days ago (one critical/new, one high/closed after 4h); bob, two critical/open, and carol, one low/closed after 10h, all created 60 days ago.
  • After clicking 7d, all six GET /api/cases/metrics/{summary,mttd,mttr,by-priority,by-status,analyst-performance} requests carried start_date and end_date seven days apart. The screen showed Total 2, Open 1, 1 critical, MTTR 4.0h, status Closed 1 and New 1, and only alice (2 assigned, 1 closed, 4.0h, 50%).
  • 90d sent a 90-day window on the same six reads and showed Total 5, Open 3, 3 critical, MTTR 7.0h, and alice, bob, and carol. 30d matched the 7d counts for this seed.
  • Layout, with real data, at the shell minimum (clients/web/src/shell/shell.css sets .vg-shell to min-width: 1440px) and at 1920:
    • Case Metrics, 7d, 1920
    • Case Metrics, 7d, 1440
    • Case Metrics, 90d, 1920
    • Case Metrics, 90d, 1440, including the analyst table

The page, the shell, and the analyst table have scrollWidth equal to clientWidth at both widths. The status legend measures 6px wider than its box because .legend .li uses a negative horizontal margin for its hover tint. The labels (Closed, New, Open) are fully visible, and that rule is unchanged here.

Did not run

  • The frontend and backend suites. CI runs those on this commit.

Pushed: nothing.

@samarmstrong
samarmstrong deleted the cleanup/2903-send-the-metrics-screen-s-time-2df8a198 branch October 24, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup:blast-high Blast radius: how bad it is if this PR is wrong cleanup Opened by the cleanup factory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Send the Metrics screen's time range to summary, by-priority, by-status and analyst-performance

2 participants