Skip to content

Agents Manager: Wait for agent config before initializing#109432

Open
wellyshen wants to merge 5 commits intotrunkfrom
fix/agents-manager-wait-for-agent-config
Open

Agents Manager: Wait for agent config before initializing#109432
wellyshen wants to merge 5 commits intotrunkfrom
fix/agents-manager-wait-for-agent-config

Conversation

@wellyshen
Copy link
Contributor

@wellyshen wellyshen commented Mar 20, 2026

Part of BSKY-1825

Proposed Changes

  • Return isLoading from useAgentConfig while the default agent ID is being resolved.
  • Skip initializeAgent in AgentSetup until the config is ready, preventing a redundant initialization with the wrong agent ID.

Why are these changes being made?

useAgentConfig depends on an async query (useUnifiedAiChat) to determine the default agent ID. Before the query resolves, the hook returns a temporary fallback, causing the agent to initialize twice — first with the wrong ID, then with the correct one.

Testing Instructions

  • Check out this PR
  • Run cd apps/agents-manager && yarn dev --sync
  • Go to /wp-admin
  • Go to the chat history review, reload the page multiple times, and verify the conversation list is consistent each time

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you tested accessibility for your changes? Ensure the feature remains usable with various user agents (e.g., browsers), interfaces (e.g., keyboard navigation), and assistive technologies (e.g., screen readers) (PCYsg-S3g-p2).
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

Skip `initializeAgent` while `useAgentConfig` is still resolving the default
agent ID, preventing a redundant initialization with the wrong agent.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wellyshen wellyshen marked this pull request as ready for review March 20, 2026 20:40
@wellyshen wellyshen self-assigned this Mar 20, 2026
@matticbot
Copy link
Contributor

matticbot commented Mar 20, 2026

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • agents-manager
  • help-center
  • notifications
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/agents-manager-wait-for-agent-config on your sandbox.

@wellyshen wellyshen requested a review from a team March 20, 2026 21:12
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants