Refill composer when cancelling before the agent starts#2880
Conversation
Restore the just-sent message into the composer when a turn is cancelled before the agent has produced any output, so a quick "oops" doesn't lose the text. The message stays in history (it's already in the agent's context). Core owns the "did the agent start?" decision so the optimistic window is handled correctly for both local and cloud. Generated-By: PostHog Code Task-Id: 88f22fa1-dfa2-4fae-905f-26d327c1a133
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
|
Reviews (1): Last reviewed commit: "feat(sessions): refill composer when can..." | Re-trigger Greptile |
| markActivity(taskId); | ||
| await sessionService.sendPrompt(taskId, text, { | ||
| steer: messagingMode === "steer", | ||
| }); | ||
|
|
||
| const view = getAppViewSnapshot(); | ||
| const isViewingTask = | ||
| view?.type === "task-detail" && view?.taskId === taskId; | ||
| if (isViewingTask) { | ||
| const steer = messagingMode === "steer"; | ||
| // A steer folds into the running turn rather than starting its own, so it |
There was a problem hiding this comment.
lastSentTextRef populated before sendPrompt resolves
lastSentTextRef.current is assigned before the await, so it is set even when sendPrompt ultimately rejects (e.g., network error). On a brand-new task with no previous events, hasAgentStartedCurrentTurn returns false, so a subsequent cancel would refill the failed-send's text. For existing sessions the refill is suppressed because the backwards-scan sees a prior agent event and returns true, which limits the blast radius. The current behaviour is arguably fine (user gets back what they tried to send), but it is worth confirming this is intentional rather than accidental — moving the assignment to after the await and inside the try block would make the intent explicit.
What
xmlToContent).How
SessionService.hasAgentStartedCurrentTurn(taskId)owns the decision:falsewhile the prompt is still optimistic (echo not landed → no output possible → refill safe),session/prompt, reusing the existingclassifyTurnEventKind.liveTurnContent).useSessionCallbacksjust captures the serialized text and applies the queued-wins / focus gating.Test plan
Created with PostHog Code