Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agents): keep the last agent while its availability loads (#7029)

teo23bd31cb632e
diff --git a/apps/web/src/features/agents-view/queries/agent-roster-source.ts b/apps/web/src/features/agents-view/queries/agent-roster-source.ts
index 5ab7da5a5c..19b52c7d87 100644
--- a/apps/web/src/features/agents-view/queries/agent-roster-source.ts
+++ b/apps/web/src/features/agents-view/queries/agent-roster-source.ts
@@ -10,6 +10,8 @@ export type AgentRosterSource = {
roster: Accessor<RosterAgent[]>;
/** The saved agents are still on their first load. */
loading: Accessor<boolean>;
+ /** Runtime or Cursor connection status is not known yet. */
+ availabilityLoading: Accessor<boolean>;
/** The saved agents failed to load; the first-party ones are still listed. */
error: Accessor<boolean>;
cursorConnected: Accessor<boolean>;
@@ -58,6 +60,8 @@ export function createAgentRosterSource(): AgentRosterSource {
return {
roster,
loading: () => agentsQuery.isPending,
+ availabilityLoading: () =>
+ harnessesQuery.isPending || cursorStatus.isPlaceholderData,
error: () => agentsQuery.isError,
cursorConnected,
};
diff --git a/apps/web/src/features/agents-view/views/AgentsView.tsx b/apps/web/src/features/agents-view/views/AgentsView.tsx
index bb49c1f032..b240ddf2fc 100644
--- a/apps/web/src/features/agents-view/views/AgentsView.tsx
+++ b/apps/web/src/features/agents-view/views/AgentsView.tsx
@@ -311,6 +311,7 @@ function AgentsWorkspace(props: { initialRoute?: AgentsRoute }) {
<NewChatPage
roster={rosterSource.roster()}
rosterLoading={rosterSource.loading()}
+ availabilityLoading={rosterSource.availabilityLoading()}
onStart={startConversation}
onOpenRoster={openRoster}
/>
diff --git a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
index 4a5caaadf7..7344a95cac 100644
--- a/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
+++ b/apps/web/src/features/agents-view/views/NewChatPage.test.tsx
@@ -137,7 +137,11 @@ vi.mock('../components/ChatComposer', () => ({
),
}));
-function page(connected = true, agents: PersistedAgentLike[] = []) {
+function page(
+ connected = true,
+ agents: PersistedAgentLike[] = [],
+ availabilityLoading = false
+) {
const onStart = vi.fn();
render(() => (
<NewChatPage
@@ -150,6 +154,7 @@ function page(connected = true, agents: PersistedAgentLike[] = []) {
cursorDefaultModel: 'cursor-default',
})}
rosterLoading={false}
+ availabilityLoading={availabilityLoading}
onStart={onStart}
onOpenRoster={vi.fn()}
/>
@@ -528,6 +533,14 @@ describe('agent-led new conversation', () => {
);
expect(screen.getByTestId('drawer').hasAttribute('hidden')).toBe(false);
});
+ it('keeps the most recent agent while its connection status loads', () => {
+ mocks.recentIds = [CURSOR_BOT_ID];
+ page(false, [], true);
+ expect(
+ screen.getByRole('heading', { name: 'What should we build?' })
+ ).toBeTruthy();
+ expect(screen.getByTestId('drawer').hasAttribute('hidden')).toBe(false);
+ });
it('offers Cursor setup when disconnected without switching to an unavailable agent', async () => {
page(false);
await selectAgent(/Cursor/);
diff --git a/apps/web/src/features/agents-view/views/NewChatPage.tsx b/apps/web/src/features/agents-view/views/NewChatPage.tsx
index 7086b9accb..1e26c65d16 100644
--- a/apps/web/src/features/agents-view/views/NewChatPage.tsx
+++ b/apps/web/src/features/agents-view/views/NewChatPage.tsx
@@ -41,6 +41,8 @@ export function NewChatPage(props: {
registerFocus?: (focus: () => void) => void;
roster: RosterAgent[];
rosterLoading: boolean;
+ /** Agents are listed but whether they can start is still unknown. */
+ availabilityLoading?: boolean;
onStart: (start: StartConversation) => void;
/** Opens the roster page on the given kind's tab. */
onOpenRoster: (kind: AgentKind) => void;
@@ -61,15 +63,17 @@ export function NewChatPage(props: {
const setDraft = (text: string) =>
props.onDraftChange ? props.onDraftChange(text) : setLocalDraft(text);
const [branchOverride, setBranchOverride] = createSignal<string>();
+ const recentAgentId = () => {
+ const ids = recentAgents.ids();
+ // Falling back to Macro before availability is known would open the
+ // compact composer, then swap to the last agent's layout once it settles.
+ if (props.rosterLoading || props.availabilityLoading) return ids[0];
+ return ids.find((id) =>
+ options().some((agent) => agent.id === id && !agent.unavailableReason)
+ );
+ };
const selected = createMemo(() => {
- const wanted =
- agentId() ??
- recentAgents
- .ids()
- .find((id) =>
- options().some((agent) => agent.id === id && !agent.unavailableReason)
- ) ??
- MACRO_PERSONA_ID;
+ const wanted = agentId() ?? recentAgentId() ?? MACRO_PERSONA_ID;
return options().find((agent) => agent.id === wanted) ?? options()[0];
});
const macro = () => options().find((agent) => agent.id === MACRO_PERSONA_ID);
diff --git a/apps/web/src/features/home/home-agent-composer.test.tsx b/apps/web/src/features/home/home-agent-composer.test.tsx
index b589de6834..eec2ea90cc 100644
--- a/apps/web/src/features/home/home-agent-composer.test.tsx
+++ b/apps/web/src/features/home/home-agent-composer.test.tsx
@@ -43,7 +43,11 @@ vi.mock('@core/component/Toast/Toast', () => ({
toast: { failure: mocks.failure },
}));
vi.mock('../agents-view/queries/agent-roster-source', () => ({
- createAgentRosterSource: () => ({ roster: () => [], loading: () => false }),
+ createAgentRosterSource: () => ({
+ roster: () => [],
+ loading: () => false,
+ availabilityLoading: () => false,
+ }),
}));
vi.mock('./queries/home-agent-prompt', () => ({
buildHomeAgentPrompt: mocks.buildPrompt,
diff --git a/apps/web/src/features/home/home-agent-composer.tsx b/apps/web/src/features/home/home-agent-composer.tsx
index 2745491668..fbfc23b559 100644
--- a/apps/web/src/features/home/home-agent-composer.tsx
+++ b/apps/web/src/features/home/home-agent-composer.tsx
@@ -83,6 +83,7 @@ export function HomeAgentComposer(props: { autoFocus?: boolean }) {
<NewChatPage
roster={roster.roster()}
rosterLoading={roster.loading()}
+ availabilityLoading={roster.availabilityLoading()}
draft={draft()}
onDraftChange={(value) => {
draftVersion++;