Skip to content

fix(ui/store): clear missing server fields on merge (#438) - #443

Merged
Dumbris merged 1 commit into
mainfrom
fix/server-store-clear-stale-fields
Apr 30, 2026
Merged

Dumbris merged 1 commit into
mainfrom
fix/server-store-clear-stale-fields

Conversation

@Dumbris

@Dumbris Dumbris commented Apr 30, 2026

Copy link
Copy Markdown
Member

Closes #438. Generalises the previously-special-cased last_error clear in the Pinia mergeServers helper to handle every conditionally-emitted optional field on Server.

The bug Jason hit

After clicking Approve all tools on the Server Detail page, navigating to the Servers overview kept showing the "5 pending approval" quarantine badge. A hard browser refresh fixed it. He also flagged seeing similar stale-state in several other places.

Root cause

frontend/src/stores/servers.ts::mergeServers updates each existing server in place via Object.assign(existing, incoming). The backend's enrichServersWithQuarantineStats (internal/httpapi/server.go:1143-1148) only sets Quarantine when pending > 0 || changed > 0:

```go
if pending > 0 || changed > 0 {
servers[i].Quarantine = &contracts.QuarantineStats{
PendingCount: pending,
ChangedCount: changed,
}
}
```

After the user approves everything the field disappears from the JSON entirely. Object.assign adds and overwrites — it never deletes. The stale quarantine: { pending_count: 5 } therefore survives on the reactive object and ServerCard's server.quarantine?.pending_count keeps rendering the badge.

The author of this code already noticed the pattern for last_error and special-cased it. The same trap exists for every other optional field the backend conditionally emits:

Field Emitted only when
quarantine pending > 0 || changed > 0
last_error non-empty (already handled)
oauth_status, token_expires_at OAuth in use
user_logged_out true
health, diagnostic, error_code conditional
security_scan scan exists
connected_at, last_reconnect_at, reconnect_count conditional

Fix

Replace the one-field special case with a general key-sync: for each key on the existing server that is absent on the incoming server, delete it before Object.assign. The API response is authoritative; this treats it that way. The existing object reference is still preserved so ServerCard's v-memo keeps stable identity and the list does not visually re-render.

Tests (frontend/tests/unit/servers-store.spec.ts)

5 new + 3 existing = 8 passing:

  • drops the stale quarantine field when the backend stops emitting it
  • drops last_error on recovery (regression coverage for the previous special case)
  • drops oauth_status / token_expires_at / user_logged_out together
  • preserves the existing object reference across merges (identity stability for v-memo)
  • sanity: still updates and adds present fields

Test plan

  • `npx vitest run tests/unit/servers-store.spec.ts` — 8/8 pass
  • `npm run build` clean
  • Will verify end-to-end via Chrome MCP after CI is green (reproduce: server with pending tools → Approve All → navigate to /ui/servers → assert no badge)

Note on cross-tab updates

A complementary backend change — emit `servers.changed` SSE after `ApproveTools` — will land in a separate PR so a Servers/overview tab open elsewhere also reactively updates without depending on the Approve flow's explicit `fetchServers()` call. This PR is the primary fix Jason saw; the SSE one is the cross-tab improvement.

🤖 Generated with Claude Code

Reported by Jason Landbridge (issue #438): after clicking "Approve all
tools" on a server, navigating to the Servers overview page kept showing
the "5 pending approval" quarantine badge even though everything was
approved. A hard refresh fixed it.

Root cause is a generalisation of the previously-special-cased
last_error bug:

The Pinia stores/servers.ts mergeServers helper updates each existing
server in place via Object.assign(existingServer, incomingServer). The
backend's enrichServersWithQuarantineStats (internal/httpapi/server.go)
only sets `Quarantine` when `pending > 0 || changed > 0`; once all tools
are approved the field disappears from the JSON entirely. Object.assign
adds and overwrites — it never deletes. The stale `quarantine: { pending_count: 5 }`
therefore survived on the in-place reactive object and ServerCard's
`server.quarantine?.pending_count` kept rendering the badge until a full
page reload replaced the array.

The author had already special-cased `last_error` for this exact reason.
The same pattern affects every conditional optional field — `quarantine`,
`oauth_status`, `token_expires_at`, `user_logged_out`, `health`,
`security_scan`, `diagnostic`, `error_code`, etc. — and Jason flagged
that he sees similar staleness "in several areas of the UI."

Fix: replace the one-field special case with a general key-sync. For
each key on the existing server that is absent on the incoming server,
delete it before Object.assign. This treats the API response as
authoritative (which it is) and works for every conditional field
without enumerating them. The existing object reference is still
preserved, so v-memo on ServerCard keeps its stable identity and the
list does not visually rerender.

Tests in frontend/tests/unit/servers-store.spec.ts:
  * drops the stale quarantine field when the backend stops emitting it
  * drops last_error on recovery (regression coverage for the original
    special case the new code subsumes)
  * drops oauth_status / token_expires_at / user_logged_out together
  * preserves the existing object reference across merges (identity
    stability for v-memo)
  * sanity: still updates and adds present fields

  8 tests, all passing (5 new + 3 existing).

Note: a complementary backend change — emit `servers.changed` SSE on
tool approval — is in a separate PR so a Servers/overview page open in
another tab also reactively updates without depending on the Approve
flow's explicit fetchServers() call. This PR is the primary fix; the
SSE one is the cross-tab improvement.

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

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/server-store-clear-stale-fields

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 25180916256 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit b541321 into main Apr 30, 2026
24 checks passed
@Dumbris
Dumbris deleted the fix/server-store-clear-stale-fields branch April 30, 2026 18:13
Dumbris added a commit that referenced this pull request Apr 30, 2026
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 Code <[email protected]>
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