Skip to content

Conversation

@danielaskdd
Copy link
Collaborator

Refact: Auto-refresh of Popular Labels When Pipeline Completes

Summary

This PR implements automatic refresh of popular labels in the graph viewer when the document processing pipeline transitions from busy to idle state. This ensures users always see the most up-to-date entity labels without manual intervention.

Problem Statement

Previously, after uploading and processing new documents, the popular labels dropdown would still show outdated labels until users manually refreshed. This created a disconnect between the newly processed knowledge graph and the available label suggestions.

Solution

Implemented pipeline state monitoring with automatic label refresh:

  1. Pipeline State Monitoring: Added monitoring of pipelineBusy state using refs to detect transitions from busy → idle
  2. Smart Refresh Flag: Introduced shouldRefreshPopularLabelsRef to mark when refresh is needed
  3. Multiple Trigger Points:
    • Auto-refresh when dropdown opens (if no specific label selected)
    • Auto-refresh during manual refresh operations
  4. AsyncSelect Enhancement: Added onBeforeOpen callback support for async operations before dropdown opens

Technical Details

GraphLabels.tsx Changes:

  • Added useBackendState hook to monitor pipeline status
  • Implemented reloadPopularLabels() helper function
  • Added handleDropdownBeforeOpen() callback for pre-open refresh
  • Enhanced existing refresh logic to respect the refresh flag
  • Proper error handling with fallback labels

AsyncSelect.tsx Changes:

  • Added onBeforeOpen?: () => void | Promise<void> prop
  • Implemented handleOpenChange() to trigger callback before opening
  • Maintains backward compatibility (callback is optional)

Benefits

  • ✅ Improved UX: Popular labels automatically update after document processing
  • ✅ Reduced manual intervention: No need to manually refresh after uploads
  • ✅ Consistent state: Dropdown always reflects current knowledge graph
  • ✅ Error resilience: Fallback labels ensure dropdown always works
  • ✅ Performance: Only refreshes when actually needed (flag-based)

Testing Suggestions

  1. Upload a document and wait for processing to complete
  2. Open the labels dropdown → should show new entities
  3. Select a specific label and refresh → should work as before
  4. Manually refresh with * label → should reload popular labels

• Monitor pipeline busy->idle transitions
• Reload labels on dropdown open if needed
• Add onBeforeOpen callback to AsyncSelect
• Clear refresh flags after processing
• Improve label sync with backend state
@danielaskdd
Copy link
Collaborator Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielaskdd danielaskdd merged commit 08b0283 into HKUDS:main Oct 30, 2025
1 check passed
@danielaskdd danielaskdd deleted the reload-popular-labels branch October 30, 2025 21:24
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.

1 participant