Repository navigation
fix(core): reopen MCP Apps while native approvals are pending - #7900
Conversation
|
Size Change: +31 B (0%) Total Size: 1.82 MB 📦 View Changed
ℹ️ View Unchanged
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
@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/intelligence-langgraph
@copilotkit/intelligence-mastra
@copilotkit/learning
@copilotkit/mcp-apps-renderer
@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: |
| ? this.clone().runAgent(resourceParameters) | ||
| : this.runAgent(resourceParameters); | ||
| if (this.runtimeMode !== RUNTIME_MODE_INTELLIGENCE) { | ||
| return this.runAgent(resourceParameters); |
There was a problem hiding this comment.
The non-Intelligence branch still runs the read on the conversation agent itself, so the pendingInterrupts check in AbstractAgent.onInitialize would reject it the same way whenever an SSE run finished with an interrupt outcome (the AG-UI client sets pendingInterrupts from RUN_FINISHED regardless of transport). The description says SSE is left unchanged on purpose. Is that because an SSE runtime can't end up with pending interrupts here, or would it make sense to read through the same disposable clone in both modes?
There was a problem hiding this comment.
Following up on the SSE question above: SSE mode hits the same guard. I called ɵrunMcpResourceRead directly with one pending interrupt. The fetch stub throws on any call.
runtimeMode |
Result | fetch called |
|---|---|---|
sse |
Thread has 1 pending interrupt(s) not addressed by resume: p1 |
0 |
intelligence |
passes the guard, reaches transport | 1 |
AbstractAgent.runAgent applies the pendingInterrupts guard in every transport. RUN_FINISHED with an interrupt outcome also sets that list in every transport. So an SSE thread with an unanswered approval cannot reopen its MCP App either.
Can the SSE branch use the same throwaway clone? The read does not resume the conversation in either mode. Clearing pendingInterrupts on a clone is as safe there. Please add an SSE case to mcp-resource-read-isolation.test.ts. If SSE is out of scope on purpose, please give the reason in the code comment.
BenTaylorDev
left a comment
There was a problem hiding this comment.
The fix works for Intelligence. I ran the new test with and without the agent.ts change. Without it, 2 of 3 cases fail with Thread has 2 pending interrupt(s) not addressed by resume. With it, all 3 pass.
One gap remains, inline below. I suggest that we close it in this PR before merge.
Frontend tools can finish while the SDK still reports their calls as pending interrupts. Previously automatic follow-up omitted the required resume entries, and a later `useInterrupt.resolve()` appended a second tool result—even when the handler had already returned an empty string. Reuse each existing result by its original call ID and carry its actual content in the resume array. Automatic continuation waits until every pending interrupt has an outcome, leaving unanswered native approvals and child questions pending. React, Angular, and core share the batch's accumulated decisions and a single resume claim, so either approval-first or frontend-first completion continues exactly once. Reconnect reuses saved successes before applying handler replay policy, preserves saved failure/Stop semantics, and rechecks connection, thread, abort, and batch ownership after framework updates. The shared state retains adopted canonical content when a same-thread reconnect snapshot omits a local result, reconstructing empty text, raw text, and structured parts verbatim. Adoption is validated together with responses and cleared on batch reset; genuinely new explicit answers retain their existing serialization. A handler that remains active across a same-thread reconnect retains its continuation ownership; an explicit new run supersedes it. React and Angular warn and ignore answers aimed at an already-successful frontend call. Failed results require an explicit replacement answer or cancellation, including when that decision arrives before a sibling handler finishes; failure history remains unchanged and no duplicate result is appended. Successful saved results remain immutable, and duplicate results still fail validation. Structured saved content is compared by value without depending on object key order; changed content and conflicting decisions still fail. Expired interrupts can be cancelled, while expired resolutions remain blocked. React hooks mounted after an interruption hydrate the shared pending batch. Response lookup treats prototype-named IDs as ordinary IDs, and duplicate interrupt IDs, frontend-call ownership, and assistant call definitions fail validation before tool execution. Touched functions and test helpers include docstrings. Validation covers empty and non-empty results, parallel calls, mixed native/child interrupts, reconnects during pending handlers, approval-first and frontend-first ordering, saved failures/Stop, explicit failure replacement/cancellation in either completion order, expired cancellation, late-mounted hooks, prototype-named IDs, duplicate/conflict rejection, structured-content clones, manual-resume races, thread switches, controller teardown, and direct SDK runs reusing interrupt IDs. Core, React, and Angular suites plus final focused regressions passed, along with explicit typechecks, builds, formatting/lint, publint, ATTW, and React built-export checks. Checks ran sequentially with bounded workers; no provider calls were used. Angular retains one unchanged pre-existing skipped test. This is a companion to the SDK recovery adapter fix; it does not change the MCP resource-read scope of CopilotKit#7900. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **Bug Fixes** * Resolving or cancelling an approval now preserves tool results already received, preventing duplicate messages when a run resumes. * Runs wait for unanswered interrupts and continue when required decisions are available, whether tool results or approvals finish first. * Conflicting or duplicate tool results are rejected, and saved results remain available after reconnecting. * Empty tool results are preserved when resolving related interrupts. * Stale restoration work no longer overrides a reconnect, thread change, or manual resume. * Decisions for already-completed tool calls are ignored until the remaining approvals are answered. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Problem and change
A saved MCP App cannot reopen while its conversation has an unanswered native approval: the read-only resource client inherits
pendingInterrupts, and AG-UI rejects the request before transport. Clear that list only on the disposable Intelligence resource-read clone, after the dedicated path validatesresources/read. Conversation agents and ordinary clones retain the normal approval guard; SSE behavior is unchanged.Regression coverage uses the real AG-UI client and deterministic localhost HTTP transport for REST and single-route requests, mixed completed/pending tool history, two pending approvals, a remaining sibling, repeated reads, and fresh-client rehydration. It checks unchanged messages/state/interrupts, no conversation subscriber events, no resume payload, and ordinary-run rejection before transport. Runtime MCP coverage additionally asserts that reading a resource never calls the downstream agent.
Validation and acceptance boundary
The new regression fails before the fix with the same unaddressed-pending-interrupt error reported in PNI-690. Exact check results will be recorded below. Source package version: 1.79.1; installed AG-UI client/core: 1.0.2; locked MCP Apps middleware: 0.1.1; aimock: 1.19.1.
This PR addresses the shared client defect. Five-implementation native acceptance, actual native allow/deny transitions, browser refresh and cold API/adapter/native-worker restart remain for the coordinator on the integrated heads and intended dependency versions. Fresh-client test rehydration is not a full cold-restart claim. No paid provider calls, merge, release, or Linear Done transition were performed. The campaign's saved real-provider evidence remains unchanged.
PNI-690 · Parent acceptance: PNI-646
Final scoped checks: formatting and lint passed (one existing no-shadow warning);
nx run @copilotkit/core:check-typesand uncached core build passed; 133 core tests and 15 runtime tests passed, with one worker. The broad pre-commit package fan-out was excluded in favor of these bounded checks; full CI/package-export checks remain outstanding. This implementation is ready for review. Combined native acceptance remains a release prerequisite.Summary by CodeRabbit