feat(web): composer stays usable during approvals, and sending declines and redirects #21503
Mergedmaria-rcksmerged 27 commits into
main fromrefs/pull/21503/headmerged by maria-rcks View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
juliusmarminge added labelsmacroscope-review
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/chat/ChatComposer.tsx lines 4005 to 4005OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3983,0 +3985,21 @@3985+ if (activePendingApproval !== null && activePendingProgress === null) {3986+ event?.preventDefault();3987+ if (3988+ approvalSubmissionInFlightRef.current ||3989+ respondingRequestIds.includes(activePendingApproval.requestId) ||3990+ !composerSendState.hasSendableContent3991+ )3992+ return;3993+ const validationMessage = getComposerSubmissionValidationMessage({3994+ prompt: promptRef.current,3995+ submissionTarget: "provider-turn",3996+ });3997+ setComposerSubmissionError(validationMessage);3998+ if (validationMessage) return;3999+ approvalSubmissionInFlightRef.current = true;4000+ try {4001+ if (4002+ !(await declinePendingApproval(activePendingApproval, onRespondToApproval)) ||4003+ composerDraftTargetKey !== composerDraftTargetKeyRef.current4004+ )4005+ return;apps/mobile/src/features/threads/ThreadDetailScreen.tsx line 906OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -903,3 +903,4 @@903903 const hasUserMessage = selectedThreadFeed.some(904904 (entry) => entry.type === "message" && entry.message.role === "user",905905 );906+ if (props.activePendingApproval !== null && props.activePendingUserInput === null) {
- apps/web/src/components/chat/ChatComposer.tsx line 4000OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3981,3 +3982,19 @@39813982 });39823983 return;39833984 }3985+ if (activePendingApproval !== null && activePendingProgress === null) {3986+ event?.preventDefault();3987+ if (3988+ approvalSubmissionInFlightRef.current ||3989+ respondingRequestIds.includes(activePendingApproval.requestId) ||3990+ !composerSendState.hasSendableContent3991+ )3992+ return;3993+ const validationMessage = getComposerSubmissionValidationMessage({3994+ prompt: promptRef.current,3995+ submissionTarget: "provider-turn",3996+ });3997+ setComposerSubmissionError(validationMessage);3998+ if (validationMessage) return;3999+ approvalSubmissionInFlightRef.current = true;4000+ try {
- apps/web/src/components/chat/ChatComposer.tsx line 4003OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3982,2 +3983,21 @@39823983 return;39833984 }3985+ // Saving a queued-message edit sends nothing, so it leaves the approval alone. Approvals3986+ // the typing guard still hides count too: the redirect replaces them all.3987+ if (pendingApprovals.length > 0 && activePendingProgress === null && !isEditingQueuedMessage) {3988+ event?.preventDefault();3989+ if (3990+ approvalSubmissionInFlightRef.current ||3991+ pendingApprovals.some((approval) => respondingRequestIds.includes(approval.requestId)) ||3992+ !composerSendState.hasSendableContent3993+ )3994+ return;3995+ const validationMessage = getComposerSubmissionValidationMessage({3996+ prompt: promptRef.current,3997+ submissionTarget: "provider-turn",3998+ });3999+ setComposerSubmissionError(validationMessage);4000+ if (validationMessage) return;4001+ const submittedPrompt = promptRef.current;4002+ approvalSubmissionInFlightRef.current = true;4003+ const declined = await declinePendingApprovals(pendingApprovals, onRespondToApproval).catch(
- apps/mobile/src/features/threads/ThreadDetailScreen.tsx line 918OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -898,8 +900,19 @@898900 selectedThreadKey,899901 ]);900902901- const handleSendMessage = async (followUp?: ActiveTurnComposerAction) => {903+ const handleSendMessage = async (904+ followUp?: ActiveTurnComposerAction,905+ stillSendable?: () => boolean,906+ ) => {902907 const targetThreadKey = selectedThreadKey;903908 const hasUserMessage = selectedThreadFeed.some(904909 (entry) => entry.type === "message" && entry.message.role === "user",905910 );911+ // Saving a queued-message edit or submitting `/feedback` sends nothing to the agent, so it912+ // leaves approvals alone.913+ if (914+ props.activePendingApprovals.length > 0 &&915+ props.activePendingUserInput === null &&916+ props.queuedRunEdit === null &&917+ (props.composerDraftKey === null ||918+ parseCodexFeedbackCommand(getComposerDraftSnapshot(props.composerDraftKey).text) === null)apps/mobile/src/features/threads/ThreadDetailScreen.tsx line 922OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -901,5 +903,20 @@901- const handleSendMessage = async (followUp?: ActiveTurnComposerAction) => {903+ const handleSendMessage = async (904+ followUp?: ActiveTurnComposerAction,905+ stillSendable?: () => boolean,906+ ) => {902907 const targetThreadKey = selectedThreadKey;903908 const hasUserMessage = selectedThreadFeed.some(904909 (entry) => entry.type === "message" && entry.message.role === "user",905910 );911+ // Saving a queued-message edit or submitting `/feedback` sends nothing to the agent, so it912+ // leaves approvals alone.913+ if (914+ props.activePendingApprovals.length > 0 &&915+ props.activePendingUserInput === null &&916+ props.queuedRunEdit === null &&917+ (props.composerDraftKey === null ||918+ parseCodexFeedbackCommand(getComposerDraftSnapshot(props.composerDraftKey).text) === null)919+ ) {920+ if (921+ props.respondingApprovalId !== null ||922+ !(await declinePendingApprovals(props.activePendingApprovals, props.onRespondToApproval)) ||
- apps/mobile/src/features/threads/ThreadComposer.tsx lines 620 to 633Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -544,4 +549,14 @@544549 const threadKey = scopedThreadKey(props.environmentId, props.selectedThread.id);545550 if (inFlightThreadIdsRef.current.has(threadKey)) return;546551 inFlightThreadIdsRef.current.add(threadKey);547- const sent = await settlePromise(() => onSendMessage(followUp));552+ const draftAtSend = getComposerDraftSnapshot(composerDraftKey);553+ const stillSendable = () => {554+ const draft = getComposerDraftSnapshot(composerDraftKey);555+ return (556+ pendingPastedTextAttachmentCountRef.current === 0 &&557+ pendingNativeImagePasteCountRef.current === 0 &&558+ draft.text === draftAtSend.text &&559+ draft.attachments.length === draftAtSend.attachments.length560+ );561+ };562+ const sent = await settlePromise(() => onSendMessage(followUp, stillSendable));apps/web/src/components/chat/ChatComposer.tsx lines 4002 to 4011OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3983,0 +3991,21 @@3991+ draftBeforeDecline === null ||3992+ !composerDraftHasUserContent({ ...draftBeforeDecline, prompt: "" });3993+ // Mirrors the send handler: these commands run locally only when the draft is just the prompt.3994+ const runsLocalCommand =3995+ promptOnly &&3996+ ((onUsageLimitsCommand !== undefined && isUsageLimitsCommand(promptRef.current)) ||3997+ (planModeUiEnabled && parseStandaloneComposerSlashCommand(promptRef.current) !== null) ||3998+ (selectedProvider === "codex" && parseCodexFeedbackCommand(promptRef.current) !== null));3999+ // Saving a queued-message edit or running a local command sends nothing to the agent, so it4000+ // leaves approvals alone. Approvals the typing guard still hides count too: the redirect4001+ // replaces them all.4002+ if (4003+ pendingApprovals.length > 0 &&4004+ activePendingProgress === null &&4005+ !isEditingQueuedMessage &&4006+ !runsLocalCommand4007+ ) {4008+ event?.preventDefault();4009+ if (4010+ approvalSubmissionInFlightRef.current ||4011+ pendingApprovals.some((approval) => respondingRequestIds.includes(approval.requestId)) ||
- apps/web/src/components/ChatView.tsx line 6526OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6512,3 +6513,14 @@65126513 );65136514 return;65146515 }6516+ // A message sent while approvals are pending redirects the agent. They are declined only6517+ // here, after everything above has accepted the send, so local commands and rejected6518+ // drafts leave them alone.6519+ if (pendingApprovals.length > 0) {6520+ const draftBeforeDecline = useComposerDraftStore6521+ .getState()6522+ .getComposerDraft(composerDraftTarget);6523+ const promptBeforeDecline = promptRef.current;6524+ const declined =6525+ !pendingApprovals.some((approval) => respondingRequestIds.includes(approval.requestId)) &&6526+ (await declinePendingApprovals(pendingApprovals, onRespondToApprovalStable).catch(
- apps/web/src/components/ChatView.tsx line 6524OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6512,3 +6518,7 @@65126518 );65136519 return;65146520 }6521+ // A message sent while approvals are pending redirects the agent. They are declined only6522+ // here, after everything above has accepted the send, so local commands and rejected6523+ // drafts leave them alone.6524+ const approvalsToDecline = pendingApprovalsRef.current;
- apps/mobile/src/state/use-thread-composer-state.ts lines 651 to 667Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -618,3 +621,8 @@618621 return null;619622 }620623624+ if (beforeDispatch !== undefined) {625+ if (!(await beforeDispatch())) return null;626+ // A context paste that started while approvals were declined isn't in this draft yet.627+ if (appAtomRegistry.get(composerContextImportsAtom)[threadKey]) return null;628+ }
- apps/web/src/components/ChatView.tsx line 6552OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6523,3 +6532,21 @@65236532 );65246533 return;65256534 }6535+ // A message sent while approvals are pending redirects the agent. They are declined only6536+ // here, after everything above has accepted the send, so local commands and rejected6537+ // drafts leave them alone. After navigating away during an upload, the shown approvals6538+ // are another thread's, so this send leaves them alone too.6539+ const approvalsToDecline =6540+ currentRouteThreadKeyRef.current === routeThreadKey ? pendingApprovalsRef.current : [];6541+ if (approvalsToDecline.length > 0) {6542+ // A draft edited since send, or a paste still landing in it, is no longer the message6543+ // the user sent.6544+ const attachmentIdsAtSend = composerAttachmentsSnapshot.map((attachment) => attachment.id);6545+ const draftChangedSinceSend = () => {6546+ const sendContext = composerRef.current?.getSendContext();6547+ const attachmentIds = sendContext6548+ ? [...sendContext.images, ...sendContext.files].map((attachment) => attachment.id)6549+ : attachmentIdsAtSend;6550+ return (6551+ promptRef.current !== promptAtSend ||6552+ attachmentIds.length !== attachmentIdsAtSend.length ||
- apps/web/src/components/ChatView.tsx lines 6847 to 6852Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -6525,0 +6556,21 @@6556+ const attachmentIds = sendContext6557+ ? [...sendContext.images, ...sendContext.files].map((attachment) => attachment.id)6558+ : attachmentIdsAtSend;6559+ const promptUnchanged =6560+ promptRef.current === promptAtSend || promptRef.current === promptForSend;6561+ const attachmentsUnchanged =6562+ sameIds(attachmentIds, attachmentIdsAtSend) ||6563+ (annotationImageId !== undefined &&6564+ sameIds(attachmentIds, attachmentIdsBeforeAnnotation));6565+ return !promptUnchanged || !attachmentsUnchanged;6566+ };6567+ const draftBeforeDecline = useComposerDraftStore6568+ .getState()6569+ .getComposerDraft(composerDraftTarget);6570+ const changedBeforeDecline = draftChangedSinceSend();6571+ const declined =6572+ !changedBeforeDecline &&6573+ !approvalsToDecline.some((approval) => respondingRequestIds.includes(approval.requestId)) &&6574+ (await declinePendingApprovals(approvalsToDecline, onRespondToApprovalStable).catch(6575+ () => false,6576+ ));
- apps/mobile/src/state/use-thread-composer-state.ts line 657Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -637,3 +640,10 @@637640 return null;638641 }639642643+ if (beforeDispatch !== undefined) {644+ if (!(await beforeDispatch())) return null;645+ // A context paste still landing, or any draft change while approvals were declined,646+ // means this snapshot is no longer what the user sent.647+ if (appAtomRegistry.get(composerContextImportsAtom)[threadKey]) return null;648+ const current = getComposerDraftSnapshot(threadKey);649+ if (
- apps/web/src/components/chat/ChatComposer.tsx line 2833OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2828,4 +2828,6 @@28282828 const nonPersistedComposerImageIdSet = new Set(nonPersistedComposerImageIds);2829282928302830 const isComposerApprovalState = activePendingApproval !== null;2831- const composerSuggestionsVisible = composerMenuOpen && !isComposerApprovalState;2831+ // A send during an approval declines it to redirect the agent, so it steers the waiting2832+ // turn instead of queueing behind it.2833+ const followUpBehavior = isComposerApprovalState ? "steer" : settings.followUpBehavior;
- apps/web/src/components/ChatView.tsx lines 6805 to 6806OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -6787,3 +6798,9 @@67876798 );67886799 return;67896800 }6801+ // A message sent while approvals are pending redirects the agent. They are declined only6802+ // here, after everything above has accepted the send, so local commands and rejected6803+ // drafts leave them alone. After navigating away during an upload, the shown approvals6804+ // are another thread's, so this send leaves them alone too.6805+ const approvalsToDecline =6806+ currentRouteThreadKeyRef.current === routeThreadKey ? pendingApprovalsRef.current : [];
- apps/web/src/components/ChatView.tsx line 6847Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -6789,0 +6824,21 @@6824+ if (composerRef.current?.hasPendingAttachments() === true) return true;6825+ const sendContext = composerRef.current?.getSendContext();6826+ const attachmentIds = sendContext6827+ ? [...sendContext.images, ...sendContext.files].map((attachment) => attachment.id)6828+ : attachmentIdsAtSend;6829+ const promptUnchanged =6830+ promptRef.current === promptAtSend || promptRef.current === promptForSend;6831+ const attachmentsUnchanged =6832+ sameIds(attachmentIds, attachmentIdsAtSend) ||6833+ (annotationImageId !== undefined &&6834+ sameIds(attachmentIds, attachmentIdsBeforeAnnotation));6835+ return !promptUnchanged || !attachmentsUnchanged;6836+ };6837+ const draftBeforeDecline = useComposerDraftStore6838+ .getState()6839+ .getComposerDraft(composerDraftTarget);6840+ const changedBeforeDecline = draftChangedSinceSend();6841+ const approvalResponding = approvalsToDecline.some((approval) =>6842+ respondingRequestIdsRef.current.includes(approval.requestId),6843+ );6844+ const declined =
maria-rcks merged thisa93b03c
maria-rcks closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed