Skip to content

fix(agent): mark question tool messages sent#1302

Merged
zerob13 merged 1 commit intodevfrom
bugfix/question-end-error
Feb 5, 2026
Merged

fix(agent): mark question tool messages sent#1302
zerob13 merged 1 commit intodevfrom
bugfix/question-end-error

Conversation

@zerob13
Copy link
Collaborator

@zerob13 zerob13 commented Feb 5, 2026

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Edited assistant messages are now properly marked as sent instead of remaining in a pending state
    • Fixed message delivery status handling when assistant responses contain pending actions requiring user input
    • Enhanced recovery of incomplete assistant messages during session restart to ensure proper message states

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

These changes modify message status handling across three presenter layers to mark assistant messages as 'sent' when they contain pending question requests or while waiting for user input, rather than leaving them in pending state or treating them as errors.

Changes

Cohort / File(s) Summary
Agent Presenter Message Status
src/main/presenter/agentPresenter/index.ts, src/main/presenter/agentPresenter/streaming/llmEventHandler.ts
Updates message status to 'sent' after editing or when enqueuing final delta with pending questions, ensuring generated messages are properly marked even while awaiting user input.
Session Message Manager Initialization
src/main/presenter/sessionPresenter/managers/messageManager.ts
Detects question_request action blocks in pending assistant messages and marks them as 'sent' instead of invoking error handling, allowing graceful recovery of messages with pending questions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A hop, a question, a message in flight,
Now marked 'sent' when pending questions align right,
Three handlers unite in graceful accord,
Where pending means sent, no error abhorred!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: marking question tool messages as sent across multiple handlers to prevent error states.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/question-end-error

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/main/presenter/sessionPresenter/managers/messageManager.ts`:
- Around line 387-394: When restoring messages that contain a question_request
action in MessageManager (messageManager.ts), finalize any non-action "loading"
blocks in message.content before calling updateMessageStatus(message.id, 'sent')
so spinners don't remain stuck; specifically, iterate the blocks array (the same
one used for the hasQuestionRequest check), convert any loading-type blocks that
are not action blocks into their final form (e.g., replace or mutate their
type/content to a completed/text block or set a completed flag), persist those
changes to the message object, then call this.updateMessageStatus(message.id,
'sent') and continue. Ensure you touch the same message.content structure and
keep the existing hasQuestionRequest logic.

Comment on lines +387 to +394
const blocks = Array.isArray(message.content) ? message.content : []
const hasQuestionRequest = blocks.some(
(block) => block.type === 'action' && block.action_type === 'question_request'
)
if (hasQuestionRequest) {
await this.updateMessageStatus(message.id, 'sent')
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Finalize non-action loading blocks when restoring question messages.

Marking the message as sent without normalizing loading blocks can leave spinners stuck after a restart. Consider finalizing non-action loading blocks before persisting status.

💡 Suggested fix
           if (hasQuestionRequest) {
+            let didNormalize = false
+            const normalizedBlocks = blocks.map((block) => {
+              if (block.type !== 'action' && block.status === 'loading') {
+                didNormalize = true
+                return { ...block, status: 'success' }
+              }
+              return block
+            })
+            if (didNormalize) {
+              await this.editMessage(message.id, JSON.stringify(normalizedBlocks))
+            }
             await this.updateMessageStatus(message.id, 'sent')
             continue
           }
🤖 Prompt for AI Agents
In `@src/main/presenter/sessionPresenter/managers/messageManager.ts` around lines
387 - 394, When restoring messages that contain a question_request action in
MessageManager (messageManager.ts), finalize any non-action "loading" blocks in
message.content before calling updateMessageStatus(message.id, 'sent') so
spinners don't remain stuck; specifically, iterate the blocks array (the same
one used for the hasQuestionRequest check), convert any loading-type blocks that
are not action blocks into their final form (e.g., replace or mutate their
type/content to a completed/text block or set a completed flag), persist those
changes to the message object, then call this.updateMessageStatus(message.id,
'sent') and continue. Ensure you touch the same message.content structure and
keep the existing hasQuestionRequest logic.

@zerob13 zerob13 merged commit 56a6c35 into dev Feb 5, 2026
2 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.

1 participant