Skip to content

fix(tui): wait for default agent before startup prompt - #63256

Open
gongfpp wants to merge 3 commits into
anomalyco:devfrom
gongfpp:fix-prompt-agent
Open

gongfpp wants to merge 3 commits into
anomalyco:devfrom
gongfpp:fix-prompt-agent

Conversation

@gongfpp

@gongfpp gongfpp commented Nov 11, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #63192

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Wait for the Location's plugin inventory before submitting a home-screen --prompt, then refresh agents so the configured default wins over the temporary Build fallback. Refresh on plugin.updated; show waiting/error feedback instead of silently hanging. Offer manual submission only when an agent/model is ready, without silently falling back to Build. Server handlers remain non-blocking. No experimental flag applies.

How did you verify your code works?

  • Bun 1.4.4 on Windows. bun run check and the TUI's official bun run typecheck:tsc passed; the push hook also passed without bypassing it.
  • Lifecycle/client-data tests: 89 passed, 2 skipped. Both automatic recovery and explicit manual submission passed in 10 fresh processes; the regression includes a failed inventory request and visible waiting/error feedback. Original code fails the same regression by submitting early.
  • Real TUI with an isolated simulated provider: a 4-second plugin selects Build before the fix and Reviewer after; normal startup still selects Reviewer. This checks session metadata and rendered UI, not an external model's reply.
  • Full TUI comparison at the same base/dependencies (initial startup fix, before the feedback follow-up): original 1645 passed / 16 skipped / 2 failed; fixed 1644 / 16 / 3. Both have the same two zh-CN-dependent model-menu ordering failures (the test assumes English collation). The fixed run also hit a group-view 20-frame wait limit. The four earlier session-tab 2-second timeouts passed in both sequential full runs. Isolated tab/group-view suites pass 28/28 on both original and fixed code; temporarily requesting English collation makes both menu tests pass. All diagnostic edits were restored; these unrelated tests are unchanged.

AI-assisted implementation and verification; the human owner followed development. Changes are limited to the client startup flow and its lifecycle regressions.

Visual

<svg xmlns="http://www.w3.org/2000/svg" width="240" height="72" viewBox="0 0 240 72">
  <title>Startup prompt waits for the default agent</title>
  <g fill="none" stroke="currentColor" opacity=".7">
    <rect x="3" y="8" width="66" height="39" rx="7"/>
    <rect x="85" y="8" width="66" height="39" rx="7"/>
    <rect x="167" y="8" width="70" height="39" rx="7"/>
    <path d="M69 28h16m66 0h16"/>
  </g>
  <g fill="currentColor" font-family="system-ui,sans-serif" font-size="10" text-anchor="middle">
    <text x="36" y="31">--prompt</text>
    <text x="118" y="25">Plugins</text>
    <text x="118" y="38" opacity=".6">ready</text>
    <text x="202" y="31">Reviewer</text>
    <text x="120" y="65" opacity=".6">Wait, refresh agents, submit once</text>
  </g>
  <circle cx="36" cy="52" r="3" fill="currentColor">
    <animate attributeName="cx" values="36;118;118;202;202" keyTimes="0;.2;.65;.85;1" dur="4s" repeatCount="indefinite"/>
    <animate attributeName="opacity" values=".3;1;.3" dur="4s" repeatCount="indefinite"/>
  </circle>
</svg>

Screenshots / recordings

Actual isolated TUI captures with the same 4-second plugin:

Before: Build After: configured Reviewer
Original TUI submits the startup prompt using Build Fixed TUI submits the startup prompt using Reviewer

Pending activation now has visible feedback (the manual-send hint appears only once submission is possible):

Waiting for server plugins without silently choosing Build

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #63130, #56265

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This fixes the issue. I ran the issue's reproduction from source: with the 4-second plugin, base starts the --prompt session on Build and this PR starts it on Reviewer. Without the slow plugin it still starts on Reviewer. app-lifecycle.test.tsx passes (40/40), and the new test fails on base as it should. tsc -b for packages/tui passes.

Public API: unchanged. The change is TUI-only and uses the existing plugin.list endpoint and plugin.updated event.

One concern, inline: when the plugin list is empty or the request fails, --prompt now waits until a plugin.updated event arrives. If that event never comes (activation never finishes, as in #63130, or the request fails), the prompt is never sent and the user gets no message. Before this change it was sent, just on the wrong agent.

Related: #63130, #56265

Before

After

Comment thread packages/tui/src/routes/home.tsx Outdated
async (target) => {
try {
const plugins = await client.api.plugin.list({ location: target })
if (!plugins.data.length) return false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Both return false paths (an empty list here, and the catch below) wait until a plugin.updated event refetches. Activation can hang (#63130 keeps the plugin list empty forever), and a request can fail. In both cases the --prompt text sits in the composer and is never sent, with nothing telling the user. Before this change it was at least sent. Could the error path fall back to submitting (return true)? A bounded wait for the empty-list case would also help, so a stuck plugin degrades to the old behaviour instead of a silent hang.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed the silent-wait concern with visible waiting/error feedback. The prompt remains editable, and the Enter-to-send hint appears only once the current agent/model can actually submit. Manual submission remains an explicit user choice; the automatic path still waits for activation and a fresh agent snapshot. Returning true on failure or timeout would silently reintroduce #63192's Build fallback.

The lifecycle regression now covers an inventory request failure, an empty inventory, recovery with a held agent refresh, exactly-once automatic submission, and explicit manual submission while the inventory request is failing. No server-side waiting was added.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, I've looked at 0c737fbb1. Showing "Press Enter to send manually" only once an agent and model are ready makes sense. The waiting and error hints still appear either way, and the automatic send still waits for a fresh agent list. I agree that a visible wait with a manual option is better than quietly falling back to Build. This thread is resolved from my side.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new commit addresses my earlier point. When the plugin list is empty or the request fails, the home screen now says the prompt is waiting for plugins (or that they could not be loaded) and that Enter sends it manually, so the user is no longer left with a silent hang. I re-ran the issue's reproduction: the hint shows while the slow plugin loads, and the session then starts on Reviewer (base starts on Build). app-lifecycle.test.tsx passes (40/40) and tsc -b for packages/tui is clean.

Public API: unchanged.

No new concerns.

Before

After

Screenshot

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new commit is fine. The waiting and error hints still show, and "Press Enter to send manually" now only appears once a send can actually go through. I re-ran the issue's reproduction on this head and the session still starts on Reviewer (base: Build). app-lifecycle.test.tsx passes (41/41) and tsc -b for packages/tui is clean.

Public API: unchanged.

No new concerns.

Before

After

@dstull

dstull commented Nov 18, 2026

Copy link
Copy Markdown

Reporter of #63192 here. We're still hitting this on v2.3.2. That release's packages/tui/src/routes/home.tsx still auto-submits --prompt as soon as local.agent.current() is set, so the default agent can still be missed. Our tool launches review sessions with opencode <dir> --prompt=... and relies on default_agent, so those sessions keep starting on build.

The bot's re-runs confirm this PR fixes the repro, and checks are green. Could a maintainer take a look when there's a chance? Happy to test a build if that helps. Thanks @gongfpp for picking it up.

This branch has not been deployed

No deployments
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.

tui: --prompt sessions start with build instead of default_agent when agents are still loading (2.2.7)

2 participants