fix(agent): mark question tool messages sent#1302
Conversation
📝 WalkthroughWalkthroughThese 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
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.
Summary by CodeRabbit
Release Notes