Skip to content

Qt starts ACP agents through the shared agent owners; Android declares it starts none - #2111

Merged
trissim merged 6 commits into
mainfrom
fork-qt-acp-agents
Nov 18, 2026
Merged

trissim merged 6 commits into
mainfrom
fork-qt-acp-agents

Conversation

@trissim

@trissim trissim commented Nov 18, 2026 •

Copy link
Copy Markdown

Desktop Qt now starts ACP agents and runs a full agent turn the way the TUI does, through owners both frontends inherit. Android declares through its connection that it starts none.

The five pieces

  1. Qt surface binding (toad/qt/agent_surface.py). QtSurfaceBinding is the Qt SurfaceBinding, and the agent attaches it through AgentConversation.agent_surface.
    • Agent events: the agent's stream reaches the view on Qt's loop (subscribe_agent → AgentEventSubscription → the view's declared handlers). This replaces Textual's post_message.
    • Tool calls are live rows drawn by history's own tool presentation (QtLiveToolFragment(QtToolTranscriptFragment) → AgentActivityPresentation.tool: title and ✓, details behind the disclosure).
    • Terminals (QtTerminalBlock) are the same presentation with their output open, attached by TerminalExecution.attach as its view. This replaces Textual's TerminalTool path.
    • Shared event handlers: AgentTurnEvents (new) holds the Update / Thinking / RequestPermission / ToolCall / AvailableCommandsUpdate handlers once. Textual's Conversation and Qt's QtConversation both inherit them, and the Textual copies are deleted.
  2. Agent creation in a neutral owner.
    • OperationalSessionSources.create_agent asks app.agent_processes. spawn_agent builds and binds the Agent; agent_refused says why and presents the view without one. Creation moved out of session_presentation.
    • AgentProcesses (new, a light module) is a capability the Core connection owns. LocalCoreConnection (in toad.client.local_connection since client: the local route's Core lives in its own module; Qt never imports it #2108: this machine's own bus) spawns agents. RemoteCoreConnection, reached through a UI profile, refuses: the ACP child writes its prompts under the local route's maintenance gate, which a remote client does not hold.
  3. QtAcpSessionView implements AgentConversation.
    • AgentConversation now holds the concrete start chain once (attach_launch, resume_agent_session, start_native_session, start_unbound_session, _start_agent). Each frontend answers only present_without_agent, defer_agent_start and agent_surface.
    • The Qt view calls launch.attach_to(self, self) when first shown.
    • Session titles are shared too (SessionTitles / FirstPromptTitle, for both MainScreen and the Qt view).
  4. Qt launch and New Session attach an agent.
    • The desktop entry toad.qt.main, after its first frame, selects its Core with local_connection.select_connection, as toad does, and hands it to client_start.serve_launch. --comms-profile PROFILE gives a remote Core; otherwise this machine's bus, or --comms-root ROOT.
    • Only that entry imports local_connection. The shared Qt modules (client_start, window, …) never do, and Android's start, always remote, never loads it (checked in-process: toad.client.local_connection is absent from sys.modules after importing toad.qt.android, client_start and window).
    • -a NAME attaches through AgentBinding.launched, which toad -a now uses too.
    • New Session starts the launch's agent through the shared session_navigation.start_agent_session.
    • A chosen bus is read by the window's own connection (CoreConnection.chosen: select_connection on LocalCoreConnection, its own member on a remote one), so a local desktop window switches buses and Android keeps decoding in place.
  5. Permission review and terminal output on Qt.
    • Every permission asks through the view's QtQuestion (a ChoiceQuestion), and the answer goes back through PermissionRequest.answer. A file-write review also notifies the desktop, as Textual's does: notify is now shared InputAttention (each frontend answers deliver), and Qt answers app_focus.
    • Terminal output: see piece 1.
    • Android connects remotely, so RemoteCoreConnection.agent_processes (NoAgentProcesses) refuses with a reason. There is no getandroidapilevel check.

Failures Qt was hiding, now surfaced and fixed

  • Answering a permission did nothing; the failure was swallowed.
    • QtConversation.run_worker (the shared AsyncioPublications.run_worker) kept each worker task in _workers and never read its result.
    • The permission presentation raised AttributeError: 'QtWindowAttention' object has no attribute 'notify'. PermissionRequest.present retired its projection and re-raised, but nothing read the raise. The question stayed on screen and its answer was refused (binding in _projections was False).
    • Fix: run_worker now shows and saves a failed worker (app.show_error), as a failed Textual worker ends that app. notify exists on Qt. present's retire-then-raise is unchanged: it re-raises, and it lets a failed presentation be presented again.
  • A turn never ended on Qt. QtConversation.call_later called a coroutine callback without awaiting it, so AgentSubmissionExecution.complete never ran (Python warned the coroutine was never awaited). It now awaits it, as Textual's call_later does.
  • A closed Qt agent tab left its agent drawing into deleted widgets. QtWorkspaceViews.finish now retires the agent surface (retire_surface), as Textual's unmount does. QtConversation.close_core_events retires the history for every Qt conversation; thread views skipped this, so their reads outlived the window.
  • QtAcpSessionView.mode read session_details.identity.mode, which never existed. It now reads session_details.mode_name.

Evidence: one stub turn, both frontends (no model)

The tests' scripted ACP peer gains a terminal step. support.agents.FULL_TURN is one turn of every kind: a reply, a thought, a completed tool call with output, a permission question, a terminal running echo, and a closing line.

  • TUI: tests/app/test_full_agent_turn.py sends FULL_TURN, answers Allow, and checks the terminal output, the answer at the peer (Allow) and the terminal exit (0). It passes.
  • Qt: tools/qt_drive.py agent_session OUT --comms-root ROOT, on a freshly seeded scratch root with fresh XDG state, offscreen, sends the same FULL_TURN. Its rows:
    • 1-agent-ready: agent='Test peer'.
    • 2-permission-asked: Agent / TURN_REPLY one two three, TURN_THOUGHT, ▶ 🔧 TURN_TOOL read ✔; question TURN_PERMISSION.
    • 3-turn-over, after clicking Allow: ▼ 🔧 $ echo TURN_TERMINAL_OUTPUT ✔ / $ echo TURN_TERMINAL_OUTPUT / TURN_TERMINAL_OUTPUT, · 🔧 echo TURN_TERMINAL_OUTPUT ✔, Agent / TURN_DONE; question_visible=False busy=False.
    • The peer recorded answered: Allow and terminal_exit: 0. stderr was empty and no error notices were saved.
  • Render comparison: the Qt end-of-turn grab and the TUI screenshot of the same turn show the same elements in the same order: the reply under an Agent header, the dimmed thought, the tool row with its ✓ and collapsed output, the terminal with its command and output, and the closing line.

qt_drive now selects its Core like the app: SCENARIO OUTDIR (--comms-profile PROFILE | --comms-root ROOT), and shipped_run passes --comms-profile.

Gates (once, on 9116ace, rebased onto 3712ef8)

  • tools/shadow_check.py: shadowing 0 (baseline 0), exit 0.
  • tools/qt_inherit_ratchet.py: Textual-loading shared modules 11 (baseline 11); toad.qt importing widgets/screens 0 (baseline 0); bare Qt classes 21 (baseline 21); parallel copies 0 (baseline 0); exit 0.
  • tools/android/check.sh, assembled into a folder holding an older build's leftovers (apk: assemble owns the app folder; leftovers of older builds are removed and excluded #2109): function-local imports reaching an unshipped package or Textual UI 15 (baseline 15; KNOWN_LAZY did not grow). The shipped app ran every view kind and bound key on a scratch bus, rc 0. No APK was built.
  • The agent_session drive on this head gave the rows above; the peer recorded answered: Allow and terminal_exit: 0; stderr was empty and no error notices were saved.
  • TUI agent-path subset (20 files; run on c4e25bd before this rebase, which changed only connection wiring): 6 failures, the same 6 that fail on origin/main in the same run. No new failures.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3

trissim and others added 6 commits November 18, 2026 02:38
AgentConversation owns attach/resume/start; AgentTurnEvents owns the
agent-event handlers both Conversation and QtConversation inherit;
SessionTitles/FirstPromptTitle own titling for MainScreen and the Qt
ACP view. Agent spawning moves to OperationalSessionSources.spawn_agent
behind AgentProcesses (Android: NoAgentProcesses refuses). Qt gets a
QtSurfaceBinding (tool/terminal live blocks, permission asks through
QtQuestion), and --agent on toad.qt.main attaches a launch binding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
… surface

The connection owns whether agents spawn (LocalCoreConnection does, a UI
profile does not), and toad.qt.main / qt_drive select their connection as
the TUI does. AgentBinding.launched resolves -a for both. Qt's run_worker
shows a failed worker instead of holding it unread, call_later awaits a
coroutine callback, notify is shared InputAttention, a closed Qt view
retires its agent surface, and the scripted peer gains a terminal step for
one FULL_TURN that the TUI test and the Qt drive both send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
…close as Textual's

A live tool call is a QtToolTranscriptFragment (AgentActivityPresentation.tool:
title, status, details behind the disclosure), a terminal the same with its
output open; no row_markdown copies in tool_output. Qt's workspace finish
closes a view's receivers and history reads before deleting it, as
Textual's teardown does; QtConversation owns the history retirement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
… -a, chosen buses

toad.qt.main (now split, client_start loading after the first frame) selects
its connection with CoreConnection.select and attaches -a through
AgentBinding.launched; a chosen bus is read by the connection the window runs
on (CoreConnection.chosen), so a local desktop window switches buses as
Textual does and Android keeps decoding in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
detach already closes them (forget -> close_core_events); a second close
unsubscribed the activity rows twice. The history's reads end there now
that QtConversation.close_core_events retires the history for every
Qt conversation, thread views included.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
…ntry only

After #2108 the local route lives in toad.client.local_connection. It is
this machine's own bus, the one connection agents start under: its
LocalCoreConnection carries SpawnsAgentProcesses and reads a chosen bus
with select_connection. toad.qt.main (the desktop entry, after its first
frame) selects the connection and hands it to client_start.serve_launch,
so the shared Qt modules and Android's start never import it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RnH6dT7wdh7i4tjJZQdFu3
@trissim
trissim merged commit 7752071 into main Nov 18, 2026
1 of 2 checks passed
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