warp icon indicating copy to clipboard operation
warp copied to clipboard

[orch-viewer-polling] Migrate viewer pill-bar to ancestor SSE

Open cephalonaut opened this issue 6 months ago • 2 comments

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

  1. Streamer: ancestor SSE consumer. AgentEventSource gains a new AncestorRunId filter and a corresponding stream_agent_events_for_ancestor dispatch. A new per-orchestrator AncestorForwardingConsumer owns 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 out ChildSpawned / ChildStatusChanged events on its existing event bus.

  2. Viewer model: thin event consumer. OrchestrationViewerModel registers with the streamer at construction and subscribes to ChildSpawned / ChildStatusChanged filtered on its parent_task_id. Spawns flow through the existing register_child path; status changes are routed to the right placeholder via a run_id → AIConversationId reverse index. Pane teardown unregisters from the streamer so the ancestor SSE can refcount down.

  3. 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_sequence so SSE resume works on reconnect.

Follow-ups (separate PRs)

  • Migrate the existing owner-side OrchestrationEventStreamer flow, 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-LifecycleEventType dispatch, and new_message drop.

  • New viewer-model tests cover unknown/malformed run_id handling, status updates routed via the local map, parent_task_id filtering 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]

cephalonaut avatar May 20 '26 13:05 cephalonaut

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 avatar May 26 '26 14:05 cephalonaut

@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

warp-for-oss[bot] avatar May 27 '26 03:05 warp-for-oss[bot]