Skip to content

[FIX][UI]: Display CRUD changes on Users and Teams pages without full reload#3157

Closed
crivetimihai wants to merge 1 commit intomainfrom
2691-teams-users-page-not-updated
Closed

[FIX][UI]: Display CRUD changes on Users and Teams pages without full reload#3157
crivetimihai wants to merge 1 commit intomainfrom
2691-teams-users-page-not-updated

Conversation

@crivetimihai
Copy link
Copy Markdown
Member

Note: This PR was re-created from #3011 due to repository maintenance. Your code and branch are intact. @marekdano please verify everything looks good.

🐛 Bug-fix PR


📌 Summary

Fixes stale UI data on Teams and Users admin pages when running multiple gateway replicas behind nginx. The root cause was three layers of caching preventing CRUD changes from being reflected:

  1. Cross-replica cache invalidation gap — auth_cache published invalidation messages to mcpgw:auth:invalidate but CacheInvalidationSubscriber only listened on mcpgw:cache:invalidate, so other replicas never cleared their in-memory auth caches.
  2. Missing HTMX refresh triggers — Create team and delete user endpoints returned responses without HX-Trigger headers, so the frontend never knew to refresh the lists
  3. Nginx/browser caching — Nginx's proxy_cache_valid 200 5s and add_header Cache-Control "private, max-age=5" always caused stale responses for all /admin GET requests. Since nginx overrides backend Cache-Control headers, this was solved client-side with _t=Date.now() cache-busting query parameters.
  4. Removed all 6 Cache-Control/Pragma/Expires header additions from partial endpoints — these are unnecessary since the _t=Date.now() timestamp cache-busting in admin.js already bypasses both nginx proxy cache and browser cache

🔁 Reproduction Steps

Users Page

  1. Go to http://localhost:8080/admin
  2. Navigate to the Users page
  3. Create, Edit, Delete User(s)
  4. Observe that a new / updated / deleted user is not updated on the page. The page has to be reloaded to see the change.

Teams Page

  1. Go to http://localhost:8080/admin
  2. Navigate to the Teams page
  3. Create, Edit, Activate / Deactivate, Delete Team(s)
  4. Add / Remove members to / from Teams
  5. Observe that a new / updated / deleted teams or updated members are not updated on the page. The page has to be reloaded to see the change.

🐞 Root Cause

CRUD operations on Users and Teams are cached behind the nginx 5s cache time. So when the operations are executed on the admin UI, the changes are not reflected on the UI. The whole page must be reloaded to see them.

💡 Fix Description

Changes by file

mcpgateway/cache/registry_cache.py

  • Subscribe CacheInvalidationSubscriber to both mcpgw:cache:invalidate and mcpgw:auth:invalidate channels
  • Route messages by channel in _listen_loop
  • Add _process_auth_invalidation() to clear L1 in-memory auth caches (_user_cache, _team_cache, _role_cache, _teams_list_cache, _revocation_cache, _context_cache, _revoked_jtis) across replicas

mcpgateway/admin.py

  • Add HX-Trigger header to admin_create_team to refresh teams list
  • Add HX-Trigger header to admin_delete_user to refresh users list
  • Add _t cache-busting timestamp to server-rendered hx-get URLs for members/non-members partials and their infinite scroll next_page_url

mcpgateway/static/admin.js

  • Add _t=Date.now() cache-busting to teams partial, users partial, members partial, non-members partial, team edit, user edit, and team members refresh fetches

mcpgateway/templates/admin.html

  • Add _t cache-busting to loadTeamMembersView(), loadAddMembersView(), and editTeamSafe() HTMX ajax calls

mcpgateway/templates/users_partial.html

  • Add hx-on::config-request to dynamically append _t on the user edit button's hx-get request

tests/unit/mcpgateway/cache/test_cache_invalidation_subscriber.py

  • Update FakePubSub subscribe/unsubscribe signatures to accept *channels (matching the new two-channel subscription)

tests/js/admin-search.test.js

  • Update user edit modal test assertions to use expect.stringContaining() to accommodate the _t query parameter

🧪 Verification

Check Command Status
Lint suite make lint
Unit tests make test
Coverage ≥ 80 % make coverage
Manual regression no longer fails steps / screenshots

📐 MCP Compliance (if relevant)

  • Matches current MCP spec
  • No breaking change to MCP clients

✅ Checklist

  • Code formatted (make black isort pre-commit)
  • No secrets/credentials committed

@crivetimihai crivetimihai added this to the Release 1.0.0-GA milestone Feb 24, 2026
@crivetimihai crivetimihai added bug Something isn't working SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release labels Feb 24, 2026
@marekdano marekdano force-pushed the 2691-teams-users-page-not-updated branch from 3455955 to 3cc3749 Compare February 25, 2026 17:14
- Add Cache-Control: no-cache headers to teams and users endpoints
- Update admin.js to handle cache-busting properly
- Fix ESLint issues in admin.js
- Update users_partial.html template
- Add cache invalidation tests

Closes #2691

Signed-off-by: Marek Dano <mk.dano@gmail.com>
@marekdano marekdano force-pushed the 2691-teams-users-page-not-updated branch from 3cc3749 to 3b2e358 Compare February 25, 2026 17:20
@gcgoncalves
Copy link
Copy Markdown
Collaborator

The description mentions mcpgateway/cache/registry_cache.py, mcpgateway/templates/admin.html and ests/unit/mcpgateway/cache/test_cache_invalidation_subscriber.py, but there are no changes to these files on the PR.

@marekdano
Copy link
Copy Markdown
Collaborator

I'm closing this issue. I've lost the changes from PR #3011

I've opened two new PRs #3309 and #3330 that cover the fixes

@marekdano marekdano closed this Feb 27, 2026
@crivetimihai crivetimihai self-assigned this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working SHOULD P2: Important but not vital; high-value items that are not crucial for the immediate release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants