Skip to content

Stream generated MCP/event Flight bytes before render completion #686

Description

@ScriptedAlchemy

Priority and scope

P2 — production live-render parity. Follow-up to #600, #643, and #666. Related but separate: #680 owns executable selection; #681 owns retained-history bounds.

Audited commit: b435f7b9179271cbff81d3e40d14ee342cbd65dd.

Evidence level: the buffering behavior is visible in generated-source code; the proposed end-to-end timing regression has not been run by the reviewer. This is not a claim that Workbench has no streaming infrastructure.

Problem

The generated route Flight worker collects renderAgentFlight(...) through:

const renderedBytes = new Uint8Array(await new Response(flight).arrayBuffer());

It sends the completed bytes after collection. The production Workbench consumer already accepts chunk messages, but cannot display the authored Suspense fallback/replacements incrementally when this producer withholds Flight bytes until completion.

A running status or a separate progress notification does not prove that the authored Flight document is being streamed.

Source evidence

  • entry-shell.ts: generatedRouteFlightWorkerSource() buffers the MCP/shared-event Flight response. Existing rendered CLI/script generation provides a chunked-path comparison.
  • route-invocation-production.ts: streamFromWorker() already handles chunk, complete, and end messages through the runtime dispatcher.

Required correction

Forward Flight chunks through the existing worker/dispatcher transport instead of buffering the entire response first. Preserve request context, provider/state lifetime, byte order, error completion, cancellation, and bounded flow control. Apply the correction to generated event execution where it shares this worker, and verify all consumers of the changed transport.

Deterministic acceptance

  • Build a real MCP tool with an authored Suspense fallback and a child blocked on an externally controlled test gate.
  • Invoke through Workbench's production MCP surface, not unit-render.
  • Assert the actual authored fallback content arrives and is visible before releasing the gate; a generic running indicator is insufficient.
  • Release the gate and assert replacement and final document match normal completed execution.
  • Repeat for generated event execution where rendering is applicable, with valid manifest-selected host/preflight behavior.
  • Use the existing chunked CLI/script path as a parity control.
  • Cancel while blocked and prove worker/request/state/provider resources are released and no stale terminal output is published.
  • Exercise a failing render and verify one truthful terminal outcome, without hangs or duplicate completion.
  • Verify slow consumers do not create a new unbounded queue; coordinate with Bound Workbench producer / completed-envelope render history end to end #681 rather than duplicating retention policy.

Test owners

Extend packages/agent-bundle/tests/entry-shell.test.ts, packages/agent-bundle/tests/route-invocation-dev-server.test.ts, and existing Workbench browser acceptance. Assert behavior from actual compiled output, not only source-string shape.

Non-goals

No second renderer, new execution mode, fabricated progress, mocked stream producer as sole proof, or changes to plugin business behavior. Do not satisfy acceptance merely by observing a running status or replaying buffered events after completion.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions