Skip to content

fix(runtime): emit servers.changed after tool approval (#438) - #444

Merged
Dumbris merged 1 commit into
mainfrom
fix/tool-approval-emit-servers-changed
Apr 30, 2026
Merged

Dumbris merged 1 commit into
mainfrom
fix/tool-approval-emit-servers-changed

Conversation

@Dumbris

@Dumbris Dumbris commented Apr 30, 2026

Copy link
Copy Markdown
Member

Companion to #443 (frontend mergeServers stale-field clear). Together they close #438.

Background

Issue #438 — when a user clicks Approve all tools on the Server Detail page, the Servers/overview page kept showing the "N pending approval" quarantine badge until a manual reload.

  • fix(ui/store): clear missing server fields on merge (#438) #443 fixes the case where the user navigates to Servers in the same tab/session — the click handler already calls `serversStore.fetchServers()`, but the merge logic didn't clear the now-missing `quarantine` field.
  • This PR fixes the cross-tab / cross-session case: a Servers tab open in another window has no way to know it should re-fetch unless we tell it.

Fix

`Runtime.ApproveTools` (`internal/runtime/tool_quarantine.go`) now publishes a `servers.changed` runtime event with `reason="tools_approved"` after successfully updating approval records. The event is already emitted for every other server-state mutation in this codebase (enable/disable, restart, quarantine toggle, sync, server connected/disconnected, tools indexed — see `internal/runtime/lifecycle.go`); this fills in the one missing call site.

Properties of the emit:

  • Once per call, after the loop, gated on `approved > 0`. Bulk approval of 50 tools doesn't spam 50 events. A no-op call (tools without records) emits nothing.
  • Payload includes `server`, `approved_count`, `approved_by` so consumers can render targeted toasts without a follow-up GET.

```go
if approved > 0 {
r.emitServersChanged("tools_approved", map[string]any{
"server": serverName,
"approved_count": approved,
"approved_by": approvedBy,
})
}
```

Tests (`internal/runtime/tool_approval_event_test.go`)

  • `TestApproveTools_EmitsServersChanged` — pre-seed a pending record, subscribe via the same `SubscribeEvents` channel the SSE handler uses, call `ApproveTools`, assert one `servers.changed` (reason=tools_approved) within 2s with the expected payload.
  • `TestApproveTools_NoEventOnNoOp` — call `ApproveTools` for a tool with no record (warn-and-continue path), assert no event is published.

Test plan

  • `go test -race -count=1 -run 'TestApproveTools_Emits|TestApproveTools_NoEvent' ./internal/runtime/` — both pass
  • `go test -race ./internal/runtime/...` — full suite green
  • `go build ./cmd/mcpproxy` — clean

Why split from #443

The frontend merge fix is necessary on its own (without it, even the same-tab Approve flow leaves a stale badge after `fetchServers`). The SSE emit is purely additive and could ship independently. Per project convention, keeping the surface of each PR small.

🤖 Generated with Claude Code

Companion to PR #443 (frontend mergeServers stale-field clear).

Background — issue #438: when a user clicks "Approve all tools" on the
Server Detail page, the Servers/overview page (open in another tab, or
reached via client-side navigation) keeps showing the "N pending
approval" quarantine badge until a manual reload. PR #443 fixes the
specific case where the user navigates to Servers in the SAME session,
because the click handler explicitly calls serversStore.fetchServers().

This PR fixes the cross-tab / cross-session case: ApproveTools now
publishes a servers.changed runtime event with reason="tools_approved"
after successfully updating tool approval records. The event already
exists for every other server-state mutation (enable/disable, restart,
quarantine toggle, sync, server connected/disconnected, tools indexed —
see internal/runtime/lifecycle.go); this fills in the one missing call
site so any subscribed UI surface (web UI in another tab, tray, future
clients) re-fetches authoritative state without depending on the
acting tab to broadcast.

The emit:
- happens once per ApproveTools call, after the loop, gated on
  approved > 0 — bulk approval of 50 tools doesn't spam 50 events;
  a no-op call (e.g. tools that don't have records) emits nothing
- includes server, approved_count, and approved_by in the payload so
  consumers can render targeted toasts ("3 tools approved on github
  by user@…") without needing a follow-up GET

Tests in internal/runtime/tool_approval_event_test.go:
  * TestApproveTools_EmitsServersChanged — pre-seed a pending record,
    subscribe to the bus, call ApproveTools, assert one
    servers.changed (reason=tools_approved) within 2s, with the
    expected payload fields.
  * TestApproveTools_NoEventOnNoOp — call ApproveTools on a tool with
    no record (warn-and-continue path), assert NO event is published.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

@Dumbris Dumbris mentioned this pull request Apr 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/tool-approval-emit-servers-changed

Available Artifacts

  • archive-darwin-amd64 (26 MB)
  • archive-darwin-arm64 (23 MB)
  • archive-linux-amd64 (15 MB)
  • archive-linux-arm64 (13 MB)
  • archive-windows-amd64 (26 MB)
  • archive-windows-arm64 (23 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (19 MB)
  • installer-dmg-darwin-arm64 (18 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 25181025260 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit 3e4d895 into main Apr 30, 2026
23 checks passed
@Dumbris
Dumbris deleted the fix/tool-approval-emit-servers-changed branch April 30, 2026 18:13
Dumbris added a commit that referenced this pull request May 2, 2026
…#445)

The release-notes generator (scripts/generate-release-notes.sh) feeds
commit subjects to Claude with no edition context, and Claude has been
inventing edition annotations from thin air:

- v0.29.0: "*Note: The onboarding improvements primarily affect the
  **Personal Edition** desktop application.*"
- v0.29.1: "**Personal Edition (macOS)**" header
- v0.29.2: "*Note: All changes in this release apply to the Teams
  edition only.*" — wrong, all three PRs (#442, #443, #444) modify
  shared code (internal/runtime/, frontend/) and ship in both editions

This patch updates the prompt to:

1. Briefly explain the two-edition build model so the model doesn't have
   to guess from training data.
2. Forbid edition-only annotations unless a commit subject explicitly
   says so (e.g. contains "(server)", "(teams)", "server-only").
3. Forbid speculation from subject keywords (ui/runtime/oauth/etc).
4. Use "Server edition", not "Teams edition" — Teams is an internal
   package name.
5. Default to BOTH editions when unsure.

The v0.29.2 release body has been hand-corrected separately.

Co-authored-by: Claude Code <[email protected]>
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.

[BUG] Stale cache issues

2 participants