Repository navigation
feat(channels-intelligence): measure render-frame push latency (refs OSS-648) - #6212
Merged
BenTaylorDev merged 4 commits intoJul 28, 2026
Merged
Conversation
Channel replies are slow in proportion to how many tokens they contain. The run renderer pushes one render frame per AG-UI event and awaits its durable acceptance receipt before sending the next, so a streaming reply costs one round trip per token. Nothing recorded that, so the cost was invisible: no frame counts, no per-push latency, no measure of how much of a turn was spent waiting. Add opt-in instrumentation at the renderer's serial push chain, the one point every frame passes through, so it covers the HTTP render-accept transport and the realtime-gateway transport with one seam. Set COPILOTKIT_CHANNELS_RENDER_METRICS=summary for a per-turn summary, or =frames to also log a line per frame. Unset means off and no collector is built. The summary reports frame counts by kind, characters carried per text_delta frame, total/mean/p50/p95/max push latency, and the share of the turn spent blocked on receipts. charsPerTextFrame and pushBlockedPct are the two numbers that show whether a batching change helped: one round trip per token reads as a single-digit charsPerTextFrame and a pushBlockedPct near 100. Measurement only. No change to frame ordering, sequencing, or delivery.
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
Contributor
|
Size Change: 0 B Total Size: 1.19 MB ℹ️ View Unchanged
|
…rame (OSS-648) A streaming reply emitted one render frame per AG-UI token and awaited each durable acceptance receipt before sending the next, so reply latency scaled with token count: a 100-token reply cost 100 serialized round trips. Against a hosted API that is tens of seconds for a long reply, and it dominated every other cost in the egress path. Frames now land in a buffer that a single pump drains, folding adjacent text deltas for the same message into one frame. The buffer only ever holds what arrived while a push was already in flight, which is exactly the set the old serial chain kept queued, so this waits on no timer and adds no latency. Batch size self-tunes: the slower the round trip, the more deltas merge. Ordering is preserved by keeping seq allocation at enqueue time, so a discrete post or update interleaved mid-run still orders correctly against the run's own frames. A merged frame carries the seq of the last delta it absorbed; skipped seqs are never pushed, and the accepted high-water mark still advances. Only adjacent same-message deltas merge, so a tool call or a second message ends the run. Merged text is capped at 12k chars, under the platform's 40k delta limit and within one Slack appendStream call. Measured with the instrumentation from the previous commit, on a 40-token reply with a 100ms round trip and tokens arriving every 10ms: 42 frames and 4242ms before, 7 frames and 706ms after, with 40 deltas folded into 5 pushes and no text lost.
BenTaylorDev
marked this pull request as ready for review
July 28, 2026 22:39
BenTaylorDev
requested review from
jpr5,
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
July 28, 2026 22:39
BenTaylorDev
marked this pull request as draft
July 28, 2026 22:55
… with tokens (refs OSS-648) Coalescing adjacent text deltas cut a 120-token reply from 123 frames to 4 and took a production turn from an extrapolated ~59s to 3.4s, but it broke replay. A turn's id is a pure function of its delivery id (turn_<deliveryId>, which app-api enforces) and the adapter resets the per-turn seq counter on every dispatch, so a redelivery replays into the same seq space. app-api treats that space as an idempotency key: the same payload at a given seq is duplicate_accepted, a different payload is CHANNEL_RENDER_FRAME_CONFLICT, which nacks the delivery. Merge boundaries depend on wall-clock arrival, so a replay cuts them differently and collides — attempt 1 stores "abcd" at seq 4, attempt 2 pushes "d" there. Before coalescing, deltas were 1:1 with AG-UI events and a replay was byte-identical, so this worked; the regression is mine. Keep the instrumentation, which is what found the problem and is what will measure the replacement. Add the replay-stability test as a standing guard: it passes with frames 1:1 and fails for any change that makes a frame's payload at a given seq depend on timing. The cost problem is real and unfixed. The replacement is to batch the TRANSPORT (many frames per request) rather than merge frame CONTENT: it collapses the same number of round trips, keeps seq k carrying delta k so replay stays byte-identical, and keeps seqs dense so the outbox can later require contiguity (OSS-653). That needs an app-api batch accept and a gateway envelope, so it ships after launch with its own deploy ordering rather than two days before.
…oalescing revert (refs OSS-648)
BenTaylorDev
marked this pull request as ready for review
July 28, 2026 23:36
tylerslaton
approved these changes
Jul 28, 2026
3 tasks done
AlemTuzlak
added a commit
that referenced
this pull request
Jul 29, 2026
## What does this PR do? Fixes a fleet-wide false red on `mcp-apps` D5/D6: red on all 18 integrations that support the feature since `first_failure_at` 2026-07-28 23:03Z, while the demos rendered correctly by hand. **Root cause.** The `completeOnMount` gate added in d70d48a named the `mcp-app-iframe` testid, which only Angular's `copilot-mcp-apps-widget` declares. `react-core` and `vue` build the sandbox iframe imperatively (`document.createElement("iframe")`) with no testid, so the settle gate could never be satisfied — every React/Vue integration timed the turn out at 30s with `reason=surface-missing` and never reached `assertIframePresent`, whose `iframe[sandbox]` fallback would have passed. `crewai-crews` and `langroid` stayed green only because they skip the feature (`errorClass: "skipped-incapable"`). Verified against live staging (`showcase-built-in-agent-staging`, after clicking the "Sketch a system diagram" pill): ``` oldGate_testIdOnly: 0 <- what the probe waited for newGate_cascade: 1 <- the surface that was there all along allIframes: [{ sandbox: "allow-scripts allow-same-origin allow-forms", testid: null, hasSrcdoc: true }] ``` **Fixed on both sides of the contract:** 1. **Product** — `react-core` and `vue` `MCPAppsActivityRenderer` now set `data-testid="mcp-app-iframe"` and `title="Interactive MCP application"` on the host-created iframe, matching Angular. Pinned by a new test in each package, so dropping the attribute fails in the package that owns it rather than silently reddening the fleet a day later. 2. **Harness** — `completeOnMount` accepts CSS `selectors` alongside `testIds`, so the probe settles on the cascade its own module doc and assertion already declare: ```ts completeOnMount: { selectors: ['[data-testid="mcp-app-iframe"], iframe[sandbox]'] } ``` `querySelectorAll` unions comma-separated branches, so one entry expresses "any conforming form of this surface" while the conjunctive-across-entries and `minNewMounts` delta semantics stay exactly as before; `testIds: ["x"]` is now sugar for `selectors: ['[data-testid="x"]']`, so every other probe is untouched. This half matters on its own: the integrations pin `@copilotkit/[email protected]`, so a testid-only fix would leave 18 cells red until a release plus a fleet redeploy. Also: a `completeOnMount` spec naming no surface now throws instead of burning the whole turn budget and reporting a misleading `surface-missing`. The trap is recorded in `showcase/GOTCHAS.md` next to the sibling `copilot-assistant-message` testid gotcha. ## Verification - harness `conversation-runner.test.ts` + `d5-mcp-apps.test.ts` — 101/101, including new red-green pairs: a `selectors` cascade greens, a never-mounting cascade still reds `surface-missing`, a leftover-only surface still reds, an empty spec fails loud - `@copilotkit/vue` `MCPAppsActivityRenderer.test.ts` — 6/6 - `@copilotkit/react-core` `MCPAppsActivityRenderer.e2e.test.tsx` — 17/17 - `oxfmt` clean, `check-types` clean on both packages - Pre-existing and unrelated (fail identically on an untouched worktree on Windows): harness `typecheck` wants the gitignored generated `showcase/shell/src/data/frontend-catalog.json`; 6 `src/probes` tests assert POSIX path separators ## Related PRs and Issues - Regressed by #6212-era commit d70d48a ("test(showcase): add deterministic Angular parity audit") ## Checklist - [x] I have read the Contribution Guide - [x] If the PR changes or adds functionality, I have updated the relevant documentation (`showcase/GOTCHAS.md`) - [x] "Allow edits by maintainers" is checked 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is now
Opt-in instrumentation for the channel egress path, plus a replay-stability guard. Measurement and safety only — no behaviour change to how frames are sent.
It started as a fix too. That fix is reverted here; see below.
The problem it measures
A streaming reply pushes one render frame per AG-UI token and awaits each durable acceptance receipt before sending the next, so reply latency scales with token count. Nothing recorded that, so the cost was invisible and got attributed to the Connector Outbox's 400ms poll instead.
Unset means off and no collector is allocated. Output goes to the transport
logcallback when configured, else the console.What it found, measured against production
Hosted api + realtime gateway, local runtime, fixture agent emitting exactly 120 deltas 15ms apart:
478ms per round trip against an ~85ms network RTT, so roughly 390ms of every push is server-side work — the
lookupClerkOrgIdquery, the off-cluster ops-api entitlement call, the read-model build, and the Redis publish. Intelligence#627 removes those fortext_deltaframes.At 478ms a push, a 120-token reply costs ~123 round trips ≈ 59s. That matches the original "sometimes many seconds" report.
Why the fix was reverted
Coalescing adjacent text deltas worked — 123 frames to 4, a production turn from ~59s to 3.4s — and broke replay.
A turn's id is a pure function of its delivery id (
turn_<deliveryId>, enforced by app-api) and the adapter resets the per-turn seq counter on every dispatch, so a redelivery replays into the same seq space. app-api treats that space as an idempotency key: same payload at a seq isduplicate_accepted, a different payload isCHANNEL_RENDER_FRAME_CONFLICT, which nacks the delivery. Merge boundaries depend on wall-clock arrival, so a replay cuts them differently:"a","b","c"→ INSERT ✓text_delta "abcd"text_delta "d"→ CONFLICT ✗Before coalescing, deltas were 1:1 with AG-UI events and a replay was byte-identical. I verified both directions: the new test passes on the pre-coalescing adapter and fails with coalescing. The regression was mine.
render-frame-replay.test.tsstays as a standing guard — it passes with frames 1:1 and fails for any change that makes a frame's payload at a given seq depend on timing.The replacement
Batch the transport, don't merge frame content: send the buffered frames as an array in one request. Same collapse in round trips,
seq kstill carriesdelta kso replay stays byte-identical, and seqs stay dense so the outbox can later require contiguity (OSS-653).That needs an app-api batch accept and a gateway envelope, so it ships after launch with its own deploy ordering (app-api → gateway → SDK) rather than two days before.
Also found, filed separately
OSS-653 — the outbox advances an in-memory cursor to the highest seq it read (
WHERE seq > cursor ORDER BY seq ASC), so a frame accepted out of order is skipped and never rendered. Pre-existing and independent of this PR. Not durable corruption: thread history is rebuilt from all acceptance rows ordered by seq, independent of that cursor, so threads read back complete.Validation
216 tests pass (12 files), check-types and build clean,
oxlintclean on all changed files.refs OSS-648