Skip to content

fix: Refresh metadata after creating new connection in local mode#1582

Merged
pulpdrew merged 3 commits intomainfrom
drew/fix-metadata-in-local-mode
Jan 13, 2026
Merged

fix: Refresh metadata after creating new connection in local mode#1582
pulpdrew merged 3 commits intomainfrom
drew/fix-metadata-in-local-mode

Conversation

@pulpdrew
Copy link
Copy Markdown
Contributor

@pulpdrew pulpdrew commented Jan 9, 2026

Closes HDX-3177

Summary

This PR fixes a bug in local mode (used, for example, in the play environment) that caused metadata queries to fail due to lack of authentication details (eg. username) in the request parameters.

The cause was that metadata instances are created prior to the creation of the demo connection, which creates the metadata with an un-authenticated ClickHouse client. Those metadata instances (and their ClickHouse clients) were then never updated once the connection was created, resulting in continued failures to load metadata, even after creating the connection.

This PR adds an event listener to the useMetadataWithSettings hook which is triggered when the local connection data is updated. This matches a similar listener created on the search page. The event handler (a) recreates the metadata with a new (auth'd) ClickHouse client and (b) clears the react query cache so that any cached requests that previously errored are refetched.

Notes for Claude:

  • I'm clearing all query state, not just useMetadata query state, because other non-metadata queries are likely to have failed as well.
  • setLocalConnections dispatches an event which will be sent to the current tab.

Before

Note the continued errors in metadata queries after creating the demo connection

Screen.Recording.2026-01-09.at.10.08.42.AM.mov

After

Note the errors stop and the filters / other data loads without issue after creating the demo connection

Screen.Recording.2026-01-09.at.10.18.04.AM.mov

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 9, 2026

🦋 Changeset detected

Latest commit: 9ebdc62

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
hyperdx-v2-oss-app Ready Ready Preview, Comment Jan 12, 2026 7:46pm

@claude
Copy link
Copy Markdown

claude Bot commented Jan 9, 2026

PR Review: Refresh metadata after creating new connection in local mode

Overall Assessment: No critical issues found. The implementation correctly addresses the bug where metadata queries fail in local mode due to stale unauthenticated ClickHouse clients.

Minor Observations

Potential consideration (not blocking):

  • ⚠️ queryClient.resetQueries() clears all query state globally in useMetadata.tsx:48 → Consider scoping to specific query keys if there are unrelated queries that should not be invalidated (e.g., user profile data). However, the PR description justifies this approach for local mode.

Pattern consistency:

  • ✅ Follows established pattern from DBSearchPage.tsx:978-990 for storage event listening
  • ✅ Properly passes metadata parameter through all affected functions instead of relying on singleton getMetadata()
  • ✅ Tests updated to reflect new function signatures

Implementation quality:

  • ✅ Proper cleanup of event listeners in useEffect
  • ✅ Browser environment check before adding listeners
  • ✅ Thread-safe state management with useState for metadata instance
  • ✅ Changeset included for release notes

Code quality:

  • ✅ Type-safe additions with proper TypeScript usage
  • ✅ Consistent with project patterns per CLAUDE.md guidelines
  • ✅ No security concerns (proper authentication flow)

Recommendation: Approve and merge. The global query reset is acceptable for local mode's connection-change scenario.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 9, 2026

E2E Test Results

All tests passed • 60 passed • 4 skipped • 756s

Status Count
✅ Passed 60
❌ Failed 0
⚠️ Flaky 0
⏭️ Skipped 4

Tests ran across 4 shards in parallel.

View full report →

@pulpdrew pulpdrew force-pushed the drew/fix-metadata-in-local-mode branch from 24061b3 to e6a2db3 Compare January 9, 2026 15:56
@pulpdrew pulpdrew requested review from a team and wrn14897 and removed request for a team January 9, 2026 16:03
Comment thread packages/app/src/hooks/useMetadata.tsx Outdated
Comment thread packages/app/src/hooks/useMetadata.tsx
Copy link
Copy Markdown
Member

@wrn14897 wrn14897 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I'd suggest doing a bit more testing with the preview before merging

@pulpdrew pulpdrew merged commit f39fcda into main Jan 13, 2026
18 of 23 checks passed
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.

3 participants