Skip to content

CopilotChat: message sent while a confirmation card is pending vanishes until the card is answered #8263

Open

Description

@HoussemDjeghri

♻️ Reproduction Steps

  1. In CopilotChat (v2), trigger a useHumanInTheLoop tool so a confirmation card waits for the user.
  2. Without answering the card, type a follow-up and press Enter.

✅ Expected Behavior

The input clears and the message is visible in the conversation as accepted. It is sent once the card resolves.

❌ Actual Behavior

The input clears, but the message appears nowhere. It shows up, and is actually sent, only after the card is answered. Until then it looks as though the message was thrown away.

Screenshots

No response

𝌚 CopilotKit Version

main @ c7815d9a

📄 Logs (Optional)

Activity

  1. added
    bug
    on Nov 8, 2026
  2. copilotkit-outpost-bot commented on Nov 8, 2026

    @copilotkit-outpost-bot

    The v2 send flow clears the composer immediately, but adds the queued user message only after the active HITL run settles. That explains why the text is eventually sent yet invisible while the confirmation card waits. The fix should stage the accepted user message in visible chat state immediately, then dispatch that same message after the interrupt resolves without duplicating it.

    Technical details and sources

    The current React v2 implementation confirms the sequencing:

    • The composer clears before the deferred submission runs.
    • Submission waits for waitForActiveRunToSettle().
    • agent.addMessage(...) occurs only after that wait.

    Therefore, the existing submission queue serializes dispatch but does not provide a visible pending-message entry. The message has not been rejected; it is held inside the queued callback, which explains the delayed appearance.

    A suitable fix is:

    1. Create/render a pending user-message entry as soon as Enter is accepted.
    2. Keep the actual agent dispatch queued behind the active HITL run.
    3. Reuse the staged message when calling agent.addMessage or the corresponding agent update, so it is sent exactly once.
    4. Handle thread changes or failed runs by restoring or marking the staged entry instead of silently dropping it.

    A regression test should pause a useHumanInTheLoop run, submit a second prompt, assert that the second user message is visible before resolving the card, resolve the card, and assert that the prompt is dispatched exactly once with no duplicate rendered message. No retrieved evidence establishes that this behavior is fixed or shipped in a released package version.

    Applies to: React `CopilotChat` v2; the reporter supplied main commit c7815d9, and current main contains the same clear-then-await-then-add ordering. No released package version was supplied.

    API version: v2

    Sources


    🤖 Generated by CopilotKit AI Support · Documentation


    Was this helpful? React with 👍 or 👎

  3. HoussemDjeghri commented on Nov 8, 2026

    @HoussemDjeghri
    ContributorAuthor

    Thanks for the analysis! The PR follows it closely: the message shows as soon as Enter is accepted, the send stays queued behind the confirmation card, and the shown message keeps its id when it is sent, so it is sent exactly once and never duplicated. The regression test is the one suggested here: pause on the card, send, check the message is visible, answer the card, and check it was sent once.

    One point I intentionally handled differently: restoring a queued message after a thread switch. A queued send is never dispatched once the thread changes, and that is already the behaviour on main. Putting its text back into the new thread's input could send it to the wrong conversation, and keeping it for the original thread needs per-thread draft state that this fix doesn't otherwise touch. So the PR removes the queued bubble on a thread switch, as before, and leaves that as a possible follow-up. A failed connection does restore the text to the input, as it already did.

    Happy to revisit this if maintainers would prefer it handled here.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions