Skip to content

RFC: activity lifecycle API and MCP Apps failure UX — core maintainer input #7459

Open

Description

@yannj-fr

Decision requested

Before opening the MCP Apps failure-lifecycle follow-up PR, I would like input from the core maintainers on two questions:

  1. Should core expose whether an activity is still being produced, has settled, or comes from history?
  2. What core API and integration contract should support reporting an MCP Apps failure to the model, so the model handles communication with the end user?

This follows Ben's review of #7161. The F8 commits have been removed from that PR and preserved on feat/mcp-apps-failure-lifecycle. #7161 is back to consolidation only. #6823 covers the shared host package; it does not establish agreement on automatic explanations or new core API. The implementation on the separate branch is a proposal, not an agreed contract.

The problem

A rejected activity can disappear at the activity-registry validation step, before its renderer mounts and can display an error. A malformed result can also arrive later through a widget-initiated tools/call.

We want a visible, understandable outcome without treating a partially streamed result as a terminal failure. A renderer mounted after an activity was created cannot reconstruct the earlier run events by subscribing at mount time. Replayed history also needs to be distinguished from a live exchange so that simply reopening a conversation does not unexpectedly start another model turn.

Why this applies beyond MCP Apps

MCP Apps exposed the problem, but the lifecycle information and the proposed feedback loop are reusable for other activity types, including A2UI, Open Generative UI, and custom activity renderers. When an activity cannot be rendered or completed, its renderer can report a bounded failure to the model, and the model can communicate with the user under the existing language, tone, and instructions. Each activity implementation still defines what constitutes a failure and whether its UI can recover; MCP-specific validation and widget-retirement rules should not become universal core policy.

This is the reason for proposing an activity-type-independent core contract rather than keeping run-state reconstruction inside the MCP Apps renderer. MCP Apps is the first implemented consumer; adoption by other activity types is a proposed extension, not something this branch already implements.

The missing state propagation we encountered

While implementing failure handling, we found that the renderer-facing activity content did not carry enough lifecycle information to decide whether an invalid value was a temporary streaming fragment or the final state after a run ended or failed.

In particular, a run can end with RUN_ERROR, fail, or finalize after an abort without another activity-content update. A consumer watching content changes alone then has no signal to re-evaluate the incomplete or invalid activity. The run events exist upstream; the gap is their propagation as usable lifecycle state and a notification to activity consumers, not a claim that the protocol never emits errors.

The proposed tracking records which run last updated the activity and whether that run is still open. onActivityRunSettled notifies consumers on closure even if the content did not change, so they can re-read the state and apply the appropriate failure or cancellation policy. settled means the producing run has ended, not that the activity succeeded, and an abort does not by itself mean an error should be reported to the user.

There is a second gap before rendering: registry validation can reject an activity before its renderer mounts, so an error callback inside that renderer cannot report the rejection. The MCP Apps prototype addresses both paths: access to lifecycle state and delivery of failures that would otherwise be lost before the renderer could handle them.

Ordinary tool failures must remain with the widget

Ben identified a problem in the current F8 implementation: it retires a widget after a proxied result with isError: true. A checkout app receiving “Payment declined” must remain available so the user can retry.

I agree with preserving the widget and delivering that result to it. Any retirement policy on the proxy path should be limited to results the host cannot parse. The preserved F8 branch still contains the contested behavior; it needs to change before the follow-up PR.

For an initial activity with isError: true, preserving the app so it can render its own error state also seems preferable. Please confirm whether that should be the shared rule.

Core API proposal

The prototype adds activity-type-independent tracking in CopilotKitCore, with MCP Apps as its first consumer:

  • getActivityExchangeState(agentId, threadId, messageId, agent) returning untracked | unknown | pending | settled.
  • isRunActive(...) and isAgentInstanceObserved(...).
  • An onActivityRunSettled subscriber event, including when a run closes without changing the activity content.

It tracks the last dedicated activity event's run and currently open runs. The existing message-to-run association records the creating run; it does not answer whether a later run is updating that activity. An unobserved agent instance remains unknown, rather than being assumed settled.

Is this responsibility appropriate for core? Which parts, if any, should be public API? Would a smaller activity-lifecycle interface or an existing mechanism be preferable to exposing all three accessors and the event?

The prototype was exercised with per-run runAgent pipelines. connectAgent semantics still need verification before claiming a general core contract.

User-facing failure policy

The F8 prototype removes an unusable activity with setMessages, adds a bounded English developer message with addMessage, and starts a model turn to explain the failure. That has consequences requiring an explicit product decision:

  • A paid model turn starts without a user action.
  • The renderer mutates conversation history.
  • The developer message is an internal failure report, not user-facing copy. The model should communicate the failure using the conversation’s language, tone of voice, and applicable instructions.
  • The demonstrated BuiltInAgent integration requires forwardDeveloperMessages: true; without it, the explanation request does not reach the model.
  • Deduplication and history reloads need a defined contract. The prototype's terminal markers currently live only for the page session.

Proposed product behavior

Our intended behavior is to report the error to the model and let the model handle communication with the end user. This preserves the user's language, the application's tone of voice, and any applicable conversation or agent instructions. The host supplies a bounded, factual error report; it does not replace the model with a fixed user-facing error message.

Automatic reporting to the model is the proposed behavior, not a local error placeholder by default and not an explanation gated behind a user action. The model decides how to communicate the failure in context. The internal report's language should not dictate the language of the user-facing response.

We are asking maintainers to review this proposal and help define the right core boundary, trigger, and integration contract: how to deliver the report reliably, schedule the model turn, avoid duplicate reports on remount or history reload, and preserve thread isolation. The automatic turn's cost and the current forwardDeveloperMessages requirement are explicit tradeoffs to resolve, not reasons to substitute a different product preference.

Please also advise whether the original activity should remain in history with a failed-render state or be removed, and which layer should own delivery of the failure report to the model.

Scope and next step

This discussion is separate from the shared-host consolidation, display-mode support, and sandbox-origin work. No approval of F8 is assumed from the earlier extraction reviews.

Once the policy and core boundary are agreed, I will adapt the preserved implementation, keep ordinary isError results usable by the widget, and open a separate follow-up PR linking this decision. The tests should cover streaming versus settled content, history reloads, thread changes, and the agreed behavior across React, Vue, and Angular.

Correction: The initial version of this issue incorrectly attributed a preference for local error UI and opt-in explanations to the author. The intended proposal is model-mediated communication as described above.

Activity

  1. copilotkit-outpost-bot commented on Sep 25, 2026

    @copilotkit-outpost-bot

    ⚠️ This is an AI-generated response. We've escalated this to our engineering team — someone will follow up in this thread shortly.

    This is a design decision that belongs with the core maintainers, and I'm not in a position to make or endorse architectural calls on their behalf. What I can do is note what the current code actually establishes, so the discussion starts from a shared factual baseline.

    What the code currently does

    The activity content schema (MCPAppsActivityContentSchema in both the React and Vue renderers) carries result.isError as an optional boolean. The session layer (packages/mcp-apps-renderer/src/session.ts) exposes McpAppSessionHooks with onError, onInitialized, onResource, and onSizeChanged — but nothing that distinguishes a live run from a history replay, and nothing that surfaces activity-exchange state to the host. There is no existing getActivityExchangeState, isRunActive, or onActivityRunSettled in the retrieved source; those are entirely new surface area.

    The docs confirm that MCP App UI is re-derived client-side on history hydration — the renderers run again on replay with no separate store (ag2, mastra, crewai-flows, llamaindex). That confirms the live-vs-history distinction problem you've identified is real: nothing in the current protocol tells a renderer whether it mounted during a live exchange or a replay.

    On the specific questions

    The three questions — whether core should own exchange-state tracking, what the failure policy should be, and where the explanation trigger lives — are product and architecture decisions. I can confirm the code does not currently answer any of them, so there is no existing contract to preserve or break. The maintainers are starting from a clean slate on all three.

    Engineering will need to weigh in directly. If you haven't already, the CopilotKit Discord is where the core team is most reachable for synchronous design discussion.


    🤖 Generated by CopilotKit AI Support · Documentation


    Was this helpful? React with 👍 or 👎

  2. kvnloo commented on Sep 27, 2026

    @kvnloo
    Contributor

    For the core surface, I would keep the lifecycle contract smaller than MCP Apps policy.

    A minimal state shape could answer only:

    • pending — still being produced / can still change;
    • settled — this exchange is terminal;
    • historical — rendered from replay/hydration rather than the live exchange;
    • unknown — core cannot establish the lifecycle safely.

    Then each activity type decides what "failure" means and whether it can recover.

    The main rule I'd pin is that replay must never trigger a new model-facing failure report just because a historical renderer mounts. Model feedback should require a live, terminal, activity-owned failure receipt.

    That would give MCP Apps the information it needs without making MCP-specific validation or retirement rules part of core.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions