Skip to content

fix(ui): prevent duplicate ask_user card on session load#1446

Merged
EItanya merged 1 commit intokagent-dev:mainfrom
Matcham89:fix/ask-user-duplicate-card
Mar 5, 2026
Merged

fix(ui): prevent duplicate ask_user card on session load#1446
EItanya merged 1 commit intokagent-dev:mainfrom
Matcham89:fix/ask-user-duplicate-card

Conversation

@Matcham89
Copy link
Contributor

@Matcham89 Matcham89 commented Mar 5, 2026

Summary

  • When loading a session with a pending ask_user request, the "Questions for you" card was rendered twice
  • Two code paths both generated an AskUserRequest message for the same pending confirmation:
    1. extractMessagesFromTasks() found it in task history (no decision yet → pending card)
    2. extractApprovalMessagesFromTasks() found the same confirmation in task.status.message
  • Both were concatenated into storedMessages, causing the duplicate

Fix: extractMessagesFromTasks() now skips unresolved confirmations (where no subsequent user decision exists in history). Pending confirmations are exclusively owned by extractApprovalMessagesFromTasks() via task.status.message; resolved ones continue to render inline from history as before.

Test plan

  • Start a session with an agent that uses ask_user (e.g. an agent configured to ask before merging a PR)
  • Trigger the ask_user prompt, then reload/revisit the session
  • Change/Swap to another conversation - then return
  • Verify only one "Questions for you" card is shown (previously two appeared)
  • Verify that answering the question still works correctly
  • Verify resolved ask_user sessions show the answered card correctly (read-only)

@Matcham89 Matcham89 requested a review from peterj as a code owner March 5, 2026 18:20
Copilot AI review requested due to automatic review settings March 5, 2026 18:20
When loading a session with a pending ask_user request,
the confirmation appeared twice because two code paths both
created an AskUserRequest card:

1. extractMessagesFromTasks() found the unresolved confirmation
   in task history and created a pending card.
2. extractApprovalMessagesFromTasks() found the same confirmation
   in task.status.message and created another pending card.

Both were then concatenated into storedMessages, resulting in
the duplicate "Questions for you" UI shown to the user.

Fix: skip unresolved confirmations in extractMessagesFromTasks().
Pending confirmations are now exclusively owned by
extractApprovalMessagesFromTasks() via task.status.message, while
resolved ones continue to be rendered inline from history.

Signed-off-by: Matcham89 <cjmatcham@hotmail.co.uk>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@EItanya EItanya merged commit d257bcf into kagent-dev:main Mar 5, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants