CopilotKit icon indicating copy to clipboard operation
CopilotKit copied to clipboard

Interrupt UI can still disappear when the gate happens before the client joins

Open kvnloo opened this issue 2 months ago • 5 comments

Problem

#6891 fixes an important class of interrupt-loss failures: once the client has observed or replayed a pending gate, React/Vue/Angular can now keep that gate visible across remounts and reconnects.

There is still one gap called out in that PR that seems worth tracking separately:

the client has no authoritative way to ask what a thread is currently waiting on.

Today agent.pendingInterrupts only becomes correct when the relevant event reaches the client. connect can replay from a cursor, but the ordinary run path joins without one. If the graph reaches an interrupt before the browser finishes joining, the backend can be waiting for a human while the frontend has no gate to render.

The resulting UX is particularly bad because nothing necessarily looks failed:

run starts
→ backend reaches interrupt
→ interrupt event happens before client subscription
→ backend waits
→ UI shows no decision surface

The user cannot provide the touch/HITL decision that would let the run continue, and there is no visible explanation for why the agent stopped.

Invariant

Whether a thread currently requires human input should be recoverable from durable thread/run state, not only from having observed the event that first announced it.

Events are useful for low-latency notification. They should not be the sole source of truth for whether an unresolved gate exists.

Smallest proof

A regression could make this deterministic:

  1. Start a run that reaches a standard interrupt before the client subscribes.
  2. Attach/remount the client after the interrupt event has already passed.
  3. Do not inject the original event into that client.
  4. Assert that the client can still discover and render the pending gate.
  5. Resolve it once and verify the originating run resumes once.

The same contract should eventually cover legacy interrupts if they remain supported.

Possible shape

This does not necessarily require changing the run stream itself. A thread/run inspection response could expose unresolved interrupt metadata, or connection setup could include a durable pending-gate snapshot before live events begin.

The important distinction is the contract, not the transport:

  • event = "a gate just appeared"
  • durable state = "this thread is still waiting on this gate"

Related: #6891.

AI-use note: I used an AI assistant to trace the residual recovery boundary documented in #6891 and search the current issue tracker for an existing follow-up; I verified the current PR head before filing.

kvnloo avatar Sep 23 '26 20:09 kvnloo

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

The gap you've described is real and the invariant is well-stated. Engineering will need to verify the current recovery boundary and decide on the right transport for durable gate state (thread inspection endpoint, connection handshake snapshot, or something else) — that call is theirs.

What the code already does, for context: the Angular implementation in packages/angular/src/lib/interrupt.ts does check agent.pendingInterrupts at connect time and replays any interrupts it finds there into pending state (lines 215–220). The React and Vue implementations in use-interrupt.tsx and use-interrupt.ts do not have an equivalent replay at subscription time — they only populate pending state from live onRunFinishedEvent / onRunFinalized callbacks. So the gap is narrower on Angular today, but the agent.pendingInterrupts population itself depends on having observed the relevant events, which is exactly the root problem you're pointing at.

The test shape in your "smallest proof" section is a clean way to make this deterministic and would be a useful addition to the test suite whenever engineering picks this up.


🤖 Generated by CopilotKit AI Support · Documentation


Was this helpful? React with 👍 or 👎

copilotkit-outpost-bot avatar Sep 23 '26 20:09 copilotkit-outpost-bot

I have encountered a similar issue.

hi-wendy avatar Sep 24 '26 07:09 hi-wendy

I have identified the issue with my code. TOOL_CALL_RESULT requires a messageId, which is mandatory. The absence of a messageId leads to an interruption

hi-wendy avatar Sep 24 '26 08:09 hi-wendy

One distinction that may help keep this issue narrow: a malformed TOOL_CALL_RESULT / missing messageId can certainly break an interrupt flow, but it is separate from the late-join case described here.

The late-join invariant is still:

if the backend is currently waiting on a human decision, a newly attached client can discover that unresolved obligation without having observed the event that originally announced it.

I'd test this by deliberately letting the interrupt happen before subscription, then attaching a fresh client with no replayed interrupt event. If the gate renders and resolves the originating run exactly once, the contract is satisfied.

That suggests a durable pending-gate snapshot at thread/run inspection or connection setup; the live event can remain the low-latency notification.

kvnloo avatar Sep 27 '26 18:09 kvnloo

It sounds like the client isn't able to detect when a thread is waiting for human input if the interrupt event happens before it joins. Is there a way for the client to access the current state of a thread to fix this?

modelpath-dev avatar Sep 28 '26 13:09 modelpath-dev