fix(security): make scan report latency independent of scan history (MCP-2205)#655
Merged
Conversation
…MCP-2205) GetScanReportByJobID and the latest-report path resolved companion/latest Pass-1/Pass-2 jobs via storage.ListScanJobs(serverName), which deserializes every scan job for the server — each carrying large scanner stdout/stderr in ScannerStatuses. Cold report latency therefore grew with a server's scan history (measured ~2.0s cold for a 13.8KB report on a server with 50 jobs). Introduce a lightweight persisted ScanJobMeta index (security_scan_job_index bucket), maintained on SaveScanJob/DeleteScanJob/DeleteServerScanJobs and backfilled on open for pre-existing databases. Companion and latest-job lookups now read this index (small fixed-size records, no stdout/stderr) and fetch only the one or two full jobs actually needed, so report latency no longer scales with scan-output size or history depth. Deterministic tests assert the report hot paths never invoke the full-history ListScanJobs, plus storage-level coverage for the index (projection, filtering, delete maintenance, and backfill).
Deploying mcpproxy-docs with
|
| Latest commit: |
aa7d4c8
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://185de16a.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-mcp-2205-scan-report-lat.mcpproxy-docs.pages.dev |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 27487929829 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem (MCP-2205)
Opening a security scan report is slow and gets slower the more a server is scanned. Reported by Algis:
GET /api/v1/security/scans/{id}/reportmeasured 2.0s cold / 0.7s warm for a tiny 13.8KB payload (5 scanner statuses, small stdout/stderr) oncom.pulsemcp/google-flights(50 jobs accrued Apr 10 → Jun 14).Root cause
GetScanReportByJobID(and the latest-report path viafindLatestPassJobs) resolved companion/latest Pass-1/Pass-2 jobs withstorage.ListScanJobs(serverName), which deserializes every scan job for the server. EachScanJobcarries large scannerstdout/stderrinScannerStatuses, so cold latency is dominated by reading/deserializing the entire scan history — cost grows with how often the server has been scanned, not with the report being viewed.Fix (option (a) from the issue — index by job/started_at)
security_scan_job_indexstoringScanJobMeta(id, server, status, scan_pass, started/completed) — no stdout/stderr.SaveScanJob/DeleteScanJob/DeleteServerScanJobs, and backfilled on DB open for databases created before the index (idempotent: only runs when the index is empty but jobs exist).GetScanReportByJobIDresolves the companion Pass-2 job via the index (findCompanionPass2JobID) and fetches only that one job's reports.findLatestPassJobsresolves the newest Pass-1/Pass-2 via the index and then does at most two targetedGetScanJobloads.Report latency is now independent of scan-output size and history depth. Report contents are unchanged.
Tests (TDD)
internal/security/scanner: deterministic guards that both report hot paths perform zero full-historyListScanJobscalls even with 100+ historical jobs, while still merging companion Pass-2 findings correctly.internal/storage:ListScanJobMetasprojection + server filtering, index maintenance on delete/delete-server, and backfill from a pre-index database.GetScanSummarynegative-cache tests to track the lightweight probe (ListScanJobMetas) the code now uses; the caching contract is unchanged.Verification
go test ./internal/security/scanner/ ./internal/storage/— pass (incl.-race)./scripts/run-linter.sh— 0 issuesgo build ./...(personal),go build -tags server ./internal/storage/... ./internal/security/...,go vet— cleanNote: the pre-existing
internal/teams/brokerserver-edition build break (undefined: CredentialStore) is present onorigin/mainand unrelated to this change.Related MCP-2205