Skip to content

feat(ui): route every new chat to the flagship agent - #4187

Merged
kovtcharov-amd merged 2 commits into
kalin/ui-design-languagefrom
kalin/ui-simplify-shell
Sep 24, 2026
Merged

kovtcharov-amd merged 2 commits into
kalin/ui-design-languagefrom
kalin/ui-simplify-shell

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Opening an old document or code chat quietly changed what your next chat would be. The agent picker syncs itself to whichever session you are viewing, and "New Task" read the picker — so the agent of the conversation you just left became the agent of the one you started. Now a new chat always runs the flagship gaia agent unless you deliberately pick something else, and the conversation you navigated away from keeps the agent it was created with.

This is the routing half of milestone 2 in the UI redesign plan. The shell simplification (welcome screen, sidebar, settings reachability) follows in a separate PR so each is reviewable on its own.

Stacked on #4186 — review that one first.

Test plan

  • cd src/gaia/apps/webui && npx vitest run — 514 pass, 53 files
  • npm run build — tsc clean, build succeeds
  • Open an existing non-flagship chat (a doc or code session), click New Task, confirm the new session runs gaia
  • Confirm the old chat still shows its original agent and was not rewritten
  • Pick an agent from the Agent Hub and start a task — it still gets that agent, not gaia
  • Click New Task twice in a row — the second click reuses the empty draft instead of stacking a second one
🔍 Technical details

The fix. handleNewTask passed store.activeAgentId as the new session's agent_type. An effect in App.tsx sets activeAgentId from the selected session's agent_type, so after opening a legacy chat the picker — and therefore the next create — carried that agent. The create path now takes an explicit explicitAgentId?: string; omitting it means the flagship. Only the deliberate entry points (Agent Hub launch, agent switch) pass one.

That effect is left alone on purpose: after this change it only drives picker display, not routing.

Why a separate module. The decision lives in utils/newTask.ts as a pure planNewTask, so it can be tested without mounting the shell (polling, SSE, onboarding fetches and all).

Two test layers, and why the second is the one that matters. newTask.test.ts (14 cases) pins the planner's contract. App.newTask.test.tsx (3 cases) renders <App />, clicks the real button, and asserts what createSession was actually called with. The planner tests alone would be tautological — they can't stop someone re-adding explicitAgentId: activeAgentId at the call site, which is precisely how the bug worked. Verified by mutation: restoring the old line fails 2 of the 3 App tests and none of the 14 planner tests.

FLAGSHIP_AGENT_ID vs DEFAULT_AGENT_ID. Kept separate, with a test asserting they differ. DEFAULT_AGENT_ID (chat) answers "who owns a session row with no agent_type?" and has to keep matching the backend's legacy backfill (database.py, sessions.py). FLAGSHIP_AGENT_ID (gaia) answers "what does a new chat get?". Collapsing them would either reroute existing conversations or stop new ones reaching the flagship.

Backend untouched. The server's chat default still applies to rows that arrive without an agent — the frontend just stops relying on it for new chats.

Known gap, deferred: undo-delete in Sidebar.tsx re-creates the session without its agent_type, so undoing a deleted doc chat resurrects it as chat. Pre-existing on main and untouched here; it belongs with the sidebar PR, which needs a test harness for that file anyway.

f added 2 commits September 24, 2026 12:45
Opening an old document or code chat quietly changed what the next new
chat would be. The agent picker syncs itself to whichever session you are
viewing, and "New Task" read the picker, so the agent of the conversation
you just left became the agent of the one you started.

New chats now ask for `gaia` unless an agent was chosen deliberately, and
existing conversations keep the agent they were created with -- nothing is
rewritten or rerouted on the way past.

The decision moves out of the shell into `planNewTask`, so the rule can be
tested without mounting App. Two layers of test: the planner's contract,
and a rendered-App check that the shell actually sends `gaia`. The second
one is the guard that matters -- the planner can be perfect while the call
site still hands it the picker's id, which is exactly how the bug worked.

`FLAGSHIP_AGENT_ID` stays separate from `DEFAULT_AGENT_ID`. They answer
different questions -- "what does a new chat get?" versus "who owns a row
with no agent_type?" -- and the latter has to keep matching the backend's
legacy backfill. Collapsing them breaks one side or the other.
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

Good fix for the reported bug, but it breaks the other half of the same feature: picking an agent on the welcome screen and starting a chat now lands you on the flagship instead of the agent you picked.

The blocking issue. The welcome screen has its own copy of the Agent Hub. Choosing an agent there and hitting "Start chat" — or clicking one of that agent's suggested prompts — used to create a session with that agent, because the old code read the picker. Now the picker is ignored everywhere, and this path was never switched over to pass the chosen agent explicitly, so a deliberate choice silently becomes a flagship chat. The Agent Hub page (the full-screen one) was updated correctly; the welcome-screen copy was missed. The test-plan item "pick an agent from the Agent Hub and start a task — it still gets that agent" passes on one screen and fails on the other.

Fix is small: route the welcome screen's agent-start through the same deliberate-choice path the Hub page already uses, and add one App-level test for it — the new App test file is the right place, and it is exactly the kind of regression that file was written to catch.

Everything else reads well. Pulling the decision into a pure planner with its own tests, plus App-level tests that assert what actually gets sent, is the right shape — the PR is explicit that the planner tests alone would be tautological, and that's correct.

Real-world evidence

The evidence bundle exercised the HTTP layer under the changed code live on a no-inference runner: GET /api/agents confirms gaia is a real registered id with the model_tiers shape the planner reads; POST /api/sessions was driven through every path the new create logic can take, including the read-back showing the new session persists as gaia while the legacy doc chat keeps its own agent. It also shows a mistyped flagship id fails loudly (422 with the valid id list) rather than silently rerouting, and that omitting the agent still resolves to chat server-side — which is why this change has to happen client-side. Rendered Agent UI pixels are marked pending strix-halo lane; a screenshot should follow there.

Important caveat: the evidence covers the backend contract, not the button wiring. The welcome-screen regression above lives entirely in the frontend and is not something this lane could have caught — that finding rests on static review.

🔍 Technical details

🔴 Critical — the welcome screen's agent picker no longer routes (src/gaia/apps/webui/src/components/WelcomeScreen.tsx:169)

WelcomeScreen renders its own HubPage and starts chats through the agent-agnostic props:

onStartChat={(id, prompt) => {
    setActiveAgentId(id);
    if (prompt) onSendPrompt(prompt);   // -> handleNewTaskWithPrompt -> createTask()
    else onNewTask();                   // -> createTask()
}}

Both handleNewTask and handleNewTaskWithPrompt now call createTask() with no explicitAgentId (App.tsx:499, App.tsx:512), so planNewTask resolves FLAGSHIP_AGENT_ID. Before this PR the chosen agent survived because createTask read store.activeAgentId, which setActiveAgentId(id) had just set synchronously.

Same path for the suggestion chips at WelcomeScreen.tsx:217 — suggestions is derived from the active agent's conversation_starters (WelcomeScreen.tsx:50), so after selecting email on the welcome hub you get an email starter prompt running on gaia.

App.tsx:711 (the full-screen Hub) is wired to handleStartAgentTask and is correct; only the embedded copy was missed.

Suggested shape — add an explicit-choice prop and use it in the embedded hub:

                                <WelcomeScreen
                                    onNewTask={handleNewTask}
                                    onSendPrompt={handleNewTaskWithPrompt}
                                    onStartAgentTask={handleStartAgentTask}
                                    onCreateAgent={handleNewBuilderTask}
                                />

then in WelcomeScreen.tsx, onStartChat={onStartAgentTask} (drop the local setActiveAgentId — handleStartAgentTask already does it). Worth a fourth case in App.newTask.test.tsx: select a non-flagship agent on the welcome screen, start a chat, assert createSession was called with that agent.

🟢 Nits

  1. Duplicated prompt-launch logic (App.tsx:522) — handleStartAgentTask now inlines the log.chat.info(...) + setPendingPrompt(prompt) pair that handleNewTaskWithPrompt also does. If handleNewTaskWithPrompt grows an optional agent id (see above), both call sites collapse back into it and the duplication goes away.

  2. The flagship is a separate wheel — gaia-agent-gaia is in AGENT_WHEEL_PACKAGES (setup.py:30), not the core install, so on a checkout without it every New Task 422s and the UI shows "Failed to create task. Is the server running?" (App.tsx:491) — which points the user at the wrong thing. Not a regression (chat was equally hub-only), and the evidence bundle shows the 422 is at least explicit server-side. planNewTask already receives agents, so a membership check could turn this into an actionable message; fine as a follow-up.

Strengths

  • The planner/shell split is the right call, and the PR is explicit about why the App-level tests are the load-bearing ones. The stated mutation check (restore the old line → 2 of 3 App tests fail, 0 of 14 planner tests) is exactly the evidence that claim needs.
  • FLAGSHIP_AGENT_ID vs DEFAULT_AGENT_ID is kept apart with a test asserting they differ, and the comment explains which question each answers — that pair is genuinely easy to "helpfully" unify later.
  • Draft reuse (feat(webui): session-state polish — stale pre-connect replies, phantom empty tasks, unconditional first-run tip #2119) now keys off the resolved agent rather than the picker, which also fixes reuse of a draft belonging to a different agent; the legacy-draft-with-no-agent_type case is covered.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve 🟢

Fixes a genuine regression cleanly: new chats silently inherited the agent of whatever conversation you last opened, because handleNewTask read activeAgentId from the store — a value synced from the selected session. Extracting the routing decision into a pure planNewTask separates it from display state, and the two-layer test strategy (14 unit cases for the planner + 3 <App /> shell tests that assert createSession's actual call args) is exactly right. The author notes the planner tests alone would be tautological — they wouldn't catch explicitAgentId: activeAgentId being re-added at the call site — and verified that by mutation.

No correctness issues found. Logic, model-tier resolution, draft-reuse guard, and the FLAGSHIP_AGENT_ID / DEFAULT_AGENT_ID separation are all handled correctly and well-tested.

🟢 Nit — screenshot deferred: the test plan shows vitest + CLI evidence but no rendered before/after screenshot in the PR body. That's adequate for CI-lane merge per the rubric; a screenshot in the strix-halo lane (or a follow-up on this PR once available) would complete the evidence. Not a blocker.

🔍 Technical details

One minor style duplication: the log.chat.info(…) + setPendingPrompt(prompt) block is inlined twice — once in handleNewTaskWithPrompt and again verbatim in handleStartAgentTask. Not a bug; they serve different call signatures and can't share a helper without complicating the useCallback deps. Calling it out so the sidebar PR author knows the pattern and can decide whether to consolidate.

handleNewTask's comment ("Takes no arguments on purpose … so any parameter here would be a MouseEvent") is the right guard; without it someone will eventually pass createTask directly to onClick and get MouseEvent as explicitAgentId, which || would silently coerce to 'gaia' anyway — but the intent would be wrong.

@kovtcharov-amd
kovtcharov-amd merged commit d4dc07a into kalin/ui-design-language Sep 24, 2026
36 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/ui-simplify-shell branch September 24, 2026 20:59
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator Author

Confirmed and fixed — this landed after the squash-merge, so the fix is on the base PR (#4186) as 629ca2b0a.

The review was right: picking an agent on the welcome screen, either from its hub card or from one of its own suggestion chips, started a flagship chat instead. Both controls were carrying the choice through the agent picker, which this PR had just stopped reading.

🔍 Technical details

WelcomeScreen now takes an onStartAgentTask(agentId, prompt?) prop wired to App's handleStartAgentTask, so the id reaches createTask(agentId) instead of being inferred. The suggestion chips track which agent their starters came from (starterOf) and route to the same handler; the generic fallback list belongs to no agent and still goes to the flagship.

The gap that let it through: App.newTask.test.tsx mocked listAgents as empty, so the welcome screen's embedded HubPage never rendered in any suite, and WelcomeScreen.tsx had no test file of its own. Three cases were added with agents present — hub card, agent-specific chip, generic chip — each confirmed to fail against the old handler before the fix was restored.

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