[orch-viewer-polling] Migrate viewer pill-bar to ancestor SSE
Description
Reduces polling traffic from orchestration viewer panes by reusing the
existing OrchestrationEventStreamer SSE infrastructure instead of
having each OrchestrationViewerModel poll REST endpoints on its own
timer.
Previously, every viewer pane in an orchestrated session independently
polled list_ambient_agent_tasks to discover child agents and track
their status, producing redundant REST traffic that scaled with the
number of viewer panes. This PR switches that discovery + status flow to
a single ancestor-scoped SSE stream per orchestrator, fanned out to all
interested viewer panes by the shared streamer.
The change is gated by FeatureFlag::OrchestrationViewerStreamer; the
legacy polling path is preserved verbatim when the flag is off.
High-level structure of the change
-
Streamer: ancestor SSE consumer.
AgentEventSourcegains a newAncestorRunIdfilter and a correspondingstream_agent_events_for_ancestordispatch. A new per-orchestratorAncestorForwardingConsumerowns one SSE per parent run-id. Registration is refcounted by consumer id; the first registration does a cold-start REST fetch to seed the known-child set and event cursor, and the last unregister tears the SSE connection down. The streamer fans outChildSpawned/ChildStatusChangedevents on its existing event bus. -
Viewer model: thin event consumer.
OrchestrationViewerModelregisters with the streamer at construction and subscribes toChildSpawned/ChildStatusChangedfiltered on itsparent_task_id. Spawns flow through the existingregister_childpath; status changes are routed to the right placeholder via arun_id → AIConversationIdreverse index. Pane teardown unregisters from the streamer so the ancestor SSE can refcount down. -
Cursor scope. Viewer-mode placeholders intentionally do not advance the server-side cursor — that belongs to the owner-side conversation — but they still track a local
last_event_sequenceso SSE resume works on reconnect.
Follow-ups (separate PRs)
- Migrate the existing owner-side
OrchestrationEventStreamerflow, which currently opens one SSE per watched child run-id, onto the same ancestor-scoped SSE mechanism. That replaces N per-child subscriptions per orchestrator with a single ancestor stream and is the larger polling/SSE reduction this PR is laying groundwork for. - An event-stream debug endpoint used to validate this change end-to-end will ship in a separate PR.
Testing
-
New streamer tests cover refcounted SSE open/teardown, cold-start REST seed, cursor seed computation, viewer-mode cursor-scope suppression, per-
LifecycleEventTypedispatch, andnew_messagedrop. -
New viewer-model tests cover unknown/malformed
run_idhandling, status updates routed via the local map,parent_task_idfiltering on the shared stream, and flag-on construction. -
Manually validated end-to-end against a multi-child orchestrated session using the upcoming event-stream debug endpoint.
-
[x] I have manually tested my changes locally with
./script/run
Agent Mode
- [x] Warp Agent Mode - This PR was created via Warp's AI Agent Mode
Conversation: https://staging.warp.dev/conversation/4fc64d5e-9953-4033-b789-af1539b8e430
Co-Authored-By: Oz [email protected]
Addressed code-review feedback in 19ff0e7f:
- specs/orch-viewer-polling/TECH.md teardown list now includes DetachType::Closed.
- Top-of-function comment on on_view_detached extended to cover OVM teardown + the deliberate undo-close grace-window trade-off; new comment block uses pane-close (not tab-close).
- Added regression tests in app/src/terminal/shared_session/viewer/terminal_manager_tests.rs covering Closed / HiddenForClose / Moved.
- Force-pushed.
@cephalonaut
I'm starting a first review of this pull request.
You can view the conversation on Warp.
I completed the review and no human review was requested for this pull request.
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz