Repository navigation
feat(047): cut idle CPU 92% — scanner cache + SSE payload embed + coalescer - #450
Merged
Merged
Conversation
…lescer Profile of MCPProxy.app + 30-server config + 1.06 GB BBolt + 91k activity records showed 47% sustained CPU, with 56% of cycles inside bbolt.(*DB).View and 50%+ in encoding/json.checkValid. The driver: every tray-triggered GET /api/v1/servers walked the entire scan-job bucket via BoltDB.ListScanJobs and JSON-unmarshalled every record before filtering. This PR ships three fixes that take steady-state CPU from 47% (60s sample) to 3.78% on the same scenario, without any storage migration: - A1 (scanner negative cache): cacheScanSummary now stores a nil sentinel for servers with no scans, distinguished from "not in map" by the existing (value, ok) lookup. findLatestPassJobs returns errNoScans for the empty-bucket case so transient I/O failures don't pollute the cache. internal/security/scanner/service.go. - B1 (SSE payload embed): emitServersChanged calls the management service once per coalesced event window and embeds the post-redaction server list + stats in the payload. Subscribers (Swift tray, Web UI) consume directly and skip the GET /api/v1/servers refetch. internal/runtime/event_bus.go. - B2 (event coalescer): a single drainer goroutine + atomic.Pointer collapses retry-storm bursts into one publish per ~50ms, last-write- wins. internal/runtime/event_bus.go (new serversChangedCoalescer). Plus a pprof endpoint at /debug/pprof/ on the parent mux (API-key gated; zero overhead until hit) so future regressions can be diagnosed without a custom build. internal/server/server.go. Client wiring: the Swift tray (CoreProcessManager.swift) and the Vue Pinia servers store consume payload.servers when present and fall back to GET /api/v1/servers when running against an older core. New ServersChangedPayload + ServersChangedEnvelope decode structs in API/Models.swift. Verification (specs/047-cpu-hotpath-fix/verification/): bbolt.(*DB).View no longer in top-15 cum. encoding/json.checkValid flat down from 13.05% to 8.37%. Cumulative cputime delta 19s/60s -> 2.91s/60s. Web UI live console capture confirms zero refetch after servers.changed events. Tests: TDD-first across all three sub-changes — TestGetScanSummary_* (scanner), TestEmitServersChanged_* + TestCoalescer_* (runtime). Full go test -race ./internal/... green; -tags server suite green; linter clean. Pre-existing 10 failures in test-api-e2e.sh confirmed identical on main; unrelated to this PR. Out of scope (deferred to follow-up specs): in-memory (serverName, pass)->latestJobID index; activity-log retention/pagination; scan-job bucket re-keying; encoding/json replacement; PGO build. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Deploying mcpproxy-docs with
|
| Latest commit: |
ad67788
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5c41c86a.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://047-cpu-hotpath-fix.mcpproxy-docs.pages.dev |
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 25567130853 --repo smart-mcp-proxy/mcpproxy-go
|
Live capture against the swap-in MCPProxy-047.app on the user's real
30-server config:
Web UI (Chrome MCP):
- Toggled context7 disable via REST. Cleared network log first.
- 10 SSE servers.changed events processed by the new handler.
- 0 follow-up GET /api/v1/servers requests (network log empty).
- Visible UI deltas: header counter 14/30 -> 10/30, context7
card switched from "Connected (2 tools)/Disable" to
"Disabled/Enable", Total Tools 123 -> 188.
macOS Tray (mcpproxy-ui-test, driven via stdio JSON-RPC since the
MCP server isn't registered in this session):
- check_accessibility: trusted.
- context7 menu state captured at three points:
baseline: "Connected (2 tools)" / button "Disable"
after disable + 2s: "Disabled" / button "Enable"
after enable + 5s: "Connected (2 tools)" / button "Disable"
- The accessibility tree renders directly from appState.servers,
which is now populated by the embedded SSE payload — no HTTP
refetch was issued.
Three tray PNGs (baseline + after-disable + after-reenable) are
saved alongside this report; they show the top-level menu (context7
lives in the Servers submenu so the visual deltas live in the
accessibility tree, not the screenshot pixels — see visual.md).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two PR-hygiene fixes: 1. Removed binary verification artifacts that the previous commits accidentally bundled into specs/047-cpu-hotpath-fix/verification/: pprof *.pb.gz profiles, *.txt dumps, and tray screenshots. Total ~6 MB of build output that doesn't belong in git history. The textual conclusions remain in report.md and visual.md; reproduce the artifacts locally via quickstart.md. 2. Restored web/frontend/dist/ to its main-branch state. The previous make build run produced a different set of hash-named asset files and orphaned the old ones; git interpreted that as deletions and I committed them. That cleanup was unintentional and out of scope for this PR — the dist/ contents at this branch tip now match main exactly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
5 of 7 tasks
Dumbris
added a commit
that referenced
this pull request
May 8, 2026
Spec 047 (PR #450, v0.29.4) eliminated the burst-storm refetch path (servers.changed -> refetch). This PR addresses the residual: 5 other call sites in the Swift tray that still hit /api/v1/servers, totaling ~8 GETs per 60 s at idle on a 30-server config. All 5 sites now read SSE-driven appState.servers in place of fetching: - CoreProcessManager case "status": no longer refetches on connected_count change. Inline stats are merged unconditionally; per-server state arrives via the spec 047 servers.changed payload within ~50 ms of any actual transition. - refreshState (30 s periodic) drops the refreshServers() call. refreshActivity / refreshSessions / refreshTokenMetrics / refreshSecurityStatus stay (SSE doesn't cover those domains). - refreshSecurityStatus's Docker fallback now reads appState.servers synchronously instead of issuing another GET. - MCPProxyApp's 10 s server-refresh Timer is removed entirely. - menuWillOpen no longer refetches on every tray click. The menu rebuilds from in-memory state only. In their place: a single 5-minute Combine timer in MCPProxyApp.swift calls a new CoreProcessManager.refreshServersForSafetyNet() — pure defense-in-depth in case SSE drops events past the 256-event buffer. Verification (specs/048-tray-refetch-elimination/verification/report.md) on the same MCPProxy.app + 30-server scenario as spec 047: - 0 GETs / 60 s at idle (was ~8) - context7 disable propagates to tray menu in 1 s - context7 enable propagates in 2 s - 0 GETs during the entire toggle window Spec, plan, research, data-model, quickstart, tasks all under specs/048-tray-refetch-elimination/. No core / Go changes. Backward-compatible with older cores (spec 047 fallback path retained). Co-authored-by: Claude Code <[email protected]>
13 of 18 tasks
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.
Summary
bbolt.(*DB).Viewand 50%+ inencoding/json.checkValid. The driver: every tray-triggeredGET /api/v1/serverswalked the entire scan-job bucket viaBoltDB.ListScanJobsand JSON-unmarshalled every record before filtering.cacheScanSummarystores a nil sentinel for servers with no scans;findLatestPassJobsreturnserrNoScansfor the empty-bucket case so transient I/O failures don't pollute the cache (internal/security/scanner/service.go).emitServersChangedcalls the management service once per coalesced event and embeds the post-redaction server list + stats in the payload. Subscribers consume directly and skip theGET /api/v1/serversrefetch (internal/runtime/event_bus.go).atomic.Pointercollapses retry-storm bursts into one publish per ~50ms, last-write-wins./debug/pprof/on the parent mux (API-key gated, zero overhead until hit) so future regressions can be diagnosed without a custom build.CoreProcessManager.swift) and Vue Pinia servers store consumepayload.serverswhen present; fall back toGET /api/v1/serverson older cores.Verification
specs/047-cpu-hotpath-fix/verification/contains the post-fix profile artifacts.bbolt.(*DB).Viewcum CPUencoding/json.checkValidflatWeb UI live console capture confirmed zero refetch after
servers.changedevents.Test plan
go test -race ./internal/...— green (full Go suite)go test -tags server ./internal/teams/...— green (server edition)go vet ./...cleangofmt -lcleangolangci-lint0 issuesmake build(personal) builds cleango build -tags server ./cmd/mcpproxybuilds cleanmake buildre-embeds frontend dist; Web UI loads with new SSE handlerTestGetScanSummary_*(3 tests),TestEmitServersChanged_*(4 tests),TestCoalescer_*(6 tests) all green; failing-first → passingservers.changedevents captured with full payload during acontext7toggleservers.changedarrives, store updates, no follow-up/api/v1/serversfetchThe pre-existing 10 failures in
./scripts/test-api-e2e.shwere verified unchanged onmainand are unrelated to this PR.Out of scope (deferred to follow-up specs)
(serverName, pass) → latestJobIDindex — true O(1) lookup, eliminates cold-cache spikesecurity_scan_jobsbucket re-keying — clean root-cause fix, needs migrationencoding/jsonreplacement (goccy/go-json or sonic) on storage hot pathsSpec & artifacts
specs/047-cpu-hotpath-fix/spec.mdspecs/047-cpu-hotpath-fix/plan.mdspecs/047-cpu-hotpath-fix/tasks.mdspecs/047-cpu-hotpath-fix/research.mdspecs/047-cpu-hotpath-fix/contracts/sse-events.mdspecs/047-cpu-hotpath-fix/verification/report.md🤖 Generated with Claude Code