fix(web): preserve failed inactive send prompts#657
Open
oodavy41 wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Findings
- [Major] Retried preserved prompts drop attachments — resolve failure now creates a failed bubble with
attachments, but the new retry path callsmutation.mutatewithout carrying those attachments forward.api.sendMessagetherefore receivesundefinedfor attachments, so a preserved image/file prompt retries as text-only; attachment-only preserved prompts also remain non-retryable because the retry guard rejects emptyoriginalText. Evidenceweb/src/hooks/mutations/useSendMessage.ts:226.
Suggested fix:const message = findMessageByLocalId(sessionId, localId) if (!message) return false const content = message.content const userContent = content && typeof content === 'object' && 'role' in content && (content as { role?: unknown }).role === 'user' && 'content' in content ? (content as { content?: unknown }).content : undefined const attachments = userContent && typeof userContent === 'object' && 'attachments' in userContent ? (userContent as { attachments?: AttachmentMetadata[] }).attachments : undefined const originalText = message.originalText ?? '' if (!originalText && !attachments?.length) return false mutation.mutate({ sessionId: targetSessionId, text: originalText, localId, createdAt: message.createdAt, attachments, scheduledAt: message.scheduledAt ?? null, })
Questions
- None.
Summary
- Review mode: initial
- One regression found in the new preserved-prompt retry path. Add coverage for text+attachment and attachment-only preserved resolve failures so retry behavior matches the bubble the user sees.
Testing
- Not run (automation):
bun --cwd web test src/hooks/mutations/useSendMessage.test.tsxfailed here becausebunis not on PATH (/bin/bash: bun: command not found).
HAPI Bot
| } | ||
| } | ||
|
|
||
| mutation.mutate({ |
There was a problem hiding this comment.
[MAJOR] Retrying a prompt preserved by the new resolve-failure path drops its attachments. createOptimisticMessage now stores attachments in the failed bubble, but this retry mutation does not pass them back to api.sendMessage, so image/file prompts get retried as text-only; attachment-only prompts are still rejected by the originalText guard.
Suggested fix:
const message = findMessageByLocalId(sessionId, localId)
if (!message) return false
const content = message.content
const userContent = content
&& typeof content === 'object'
&& 'role' in content
&& (content as { role?: unknown }).role === 'user'
&& 'content' in content
? (content as { content?: unknown }).content
: undefined
const attachments = userContent
&& typeof userContent === 'object'
&& 'attachments' in userContent
? (userContent as { attachments?: AttachmentMetadata[] }).attachments
: undefined
const originalText = message.originalText ?? ''
if (!originalText && !attachments?.length) return false
mutation.mutate({
sessionId: targetSessionId,
text: originalText,
localId,
createdAt: message.createdAt,
attachments,
scheduledAt: message.scheduledAt ?? null,
})
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Preserve the user’s prompt when sending to an inactive/invalid session fails during session resolution/resume.
Previously, if
resolveSessionIdfailed before the send mutation started, the composer had already cleared the input, so a 500/502 resume/send failure could make the user’s prompt disappear with no visible recovery path.Changes
resolveSessionIdfailure before send, append a failed optimistic user bubble containing the original prompt.scheduledAtand attachments in the failed bubble metadata/content.resolveSessionIdbefore sending.scheduledAt.Notes
Known pre-existing limitation: retrying a failed bubble does not currently re-send attachments. This PR preserves attachments visually in the failed bubble but does not change the broader retry attachment behavior.
Validation
git diff --check origin/main..HEADbun typecheckbun --cwd web test src/hooks/mutations/useSendMessage.test.tsxenv -u HAPI_CLI_EXECUTABLE bun run testFull suite passed.