mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
5de391fa27
## Summary `setRuntimeTransport` was not idempotent on the **requested** transport mode. Auto-detect resolves the requested `"auto"` to a concrete transport (`"rest"`/`"single"`) and writes that back to `_runtimeTransport`; the guard then compared against that **resolved** value. So re-applying the same requested mode — which the provider effect does on **every render** — compared unequal and **re-ran the entire `/info` handshake**, rebuilding the runtime agents mid-session. When that re-sync lands during a turn, `useAgent` hands the UI a freshly-rebuilt (empty) agent for a render, **blanking the whole transcript** (and any per-message UI bound to it — e.g. the intelligence indicator) until it replays. ## Fix Track the **requested** mode separately (`_requestedTransport`) and guard on it. Re-applying an unchanged requested transport — including `"auto"` after auto-detect has resolved it — is now a no-op, so no redundant `/info` re-sync fires. ## Tests `packages/core/src/__tests__/agent-registry-resync.test.ts`: re-applying `"auto"` after auto-detect resolves it does **not** refetch `/info`. ## Scope / risk Touches only `packages/core` (`core/agent-registry.ts` + the test). **No public API change.** Genuine transport *changes* still re-sync exactly as before; only redundant re-applications of the same requested mode are skipped. > **Verified live:** this idempotency guard *alone* eliminates the mid-turn re-sync in the e-commerce intelligence demo — instrumentation shows no `/info` handshake fires during a turn, and the transcript/indicator no longer flickers. (An earlier draft also made the re-sync itself non-destructive as defense-in-depth; that was dropped because, with this guard, no mid-turn re-sync occurs for it to protect against.)