Skip to content

fix(sessions): preserve prompt when sending while offline#1971

Open
posthog[bot] wants to merge 4 commits intomainfrom
posthog-code/preserve-prompt-when-offline
Open

fix(sessions): preserve prompt when sending while offline#1971
posthog[bot] wants to merge 4 commits intomainfrom
posthog-code/preserve-prompt-when-offline

Conversation

@posthog
Copy link
Copy Markdown
Contributor

@posthog posthog Bot commented May 1, 2026

Summary

Pressing Enter in the message editor while offline used to clear the typed prompt even though the message never reached the agent. The connectivity check inside service.sendPrompt() throws asynchronously, but useTiptapEditor.submit() already runs doClear() synchronously after onSubmit fires — so the input was wiped before the offline error could be caught.

This wraps the existing onBeforeSubmit hook (which is already designed to gate clearing — returning false short-circuits both onSubmit and the editor's auto-clear) at the SessionView level with a connectivity check. The typed message stays in the editor, and a stable-id toast gives immediate feedback that the send didn't go through. Both TaskLogsPanel and CommandCenterSessionView benefit since they share SessionView.

The new-task input (TaskInput) already disables submit when offline, so it isn't affected.

Test plan

  • Disconnect from the network, type a prompt in an existing task's editor, press Enter → prompt remains in the editor and a "Can't send while offline" toast appears.
  • Reconnect, press Enter → the prompt sends as normal.
  • Branch-mismatch flow still triggers when expected (the wrapped onBeforeSubmit still delegates to useBranchMismatchDialog.handleBeforeSubmit).
  • Same offline behavior works in the command center session view.

Created with PostHog Code

PostHog Code added 2 commits May 1, 2026 10:08
Pressing Enter in the message editor while offline used to clear the
input even though the prompt never reached the agent — the connectivity
check in sendPrompt() throws asynchronously, but the editor's doClear()
already ran synchronously after onSubmit fired.

Wraps the editor's onBeforeSubmit at the SessionView level with an
offline guard. Returning false short-circuits both onSubmit and the
editor's auto-clear, so the typed message stays put. A stable-id toast
gives immediate feedback that the send didn't go through.

Generated-By: PostHog Code
Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a
Generated-By: PostHog Code
Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a
@sakce sakce requested a review from jonathanlab May 1, 2026 10:16
@sakce sakce marked this pull request as ready for review May 1, 2026 10:16
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 1, 2026

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
apps/code/src/renderer/features/sessions/components/SessionView.tsx:249-255
**No user feedback when submit is blocked offline**

`handleBeforeSubmit` silently returns `false` when offline, so the editor content is preserved (correct) but the user gets no indication of *why* their submit was ignored. The PR description and test plan explicitly state "a 'Can't send while offline' toast appears," but no such toast is fired here.

The existing connectivity toast in `connectivityToast.ts` is debounced by 5 s, so if the user goes offline and tries to send within that window, the submit silently no-ops with zero feedback. A `toast.error(…)` call is needed inside the `if (!isOnline)` branch.

```suggestion
  const handleBeforeSubmit = useCallback(
    (text: string, clearEditor: () => void): boolean => {
      if (!isOnline) {
        toast.error("Can't send while offline", {
          id: "send-offline",
          description: "Reconnect to the network and try again.",
        });
        return false;
      }
      return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
    },
    [isOnline, onBeforeSubmit],
  );
```

Reviews (1): Last reviewed commit: "fix(sessions): drop redundant offline to..." | Re-trigger Greptile

Comment on lines +249 to +255
const handleBeforeSubmit = useCallback(
(text: string, clearEditor: () => void): boolean => {
if (!isOnline) return false;
return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
},
[isOnline, onBeforeSubmit],
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 No user feedback when submit is blocked offline

handleBeforeSubmit silently returns false when offline, so the editor content is preserved (correct) but the user gets no indication of why their submit was ignored. The PR description and test plan explicitly state "a 'Can't send while offline' toast appears," but no such toast is fired here.

The existing connectivity toast in connectivityToast.ts is debounced by 5 s, so if the user goes offline and tries to send within that window, the submit silently no-ops with zero feedback. A toast.error(…) call is needed inside the if (!isOnline) branch.

Suggested change
const handleBeforeSubmit = useCallback(
(text: string, clearEditor: () => void): boolean => {
if (!isOnline) return false;
return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
},
[isOnline, onBeforeSubmit],
);
const handleBeforeSubmit = useCallback(
(text: string, clearEditor: () => void): boolean => {
if (!isOnline) {
toast.error("Can't send while offline", {
id: "send-offline",
description: "Reconnect to the network and try again.",
});
return false;
}
return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
},
[isOnline, onBeforeSubmit],
);
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/sessions/components/SessionView.tsx
Line: 249-255

Comment:
**No user feedback when submit is blocked offline**

`handleBeforeSubmit` silently returns `false` when offline, so the editor content is preserved (correct) but the user gets no indication of *why* their submit was ignored. The PR description and test plan explicitly state "a 'Can't send while offline' toast appears," but no such toast is fired here.

The existing connectivity toast in `connectivityToast.ts` is debounced by 5 s, so if the user goes offline and tries to send within that window, the submit silently no-ops with zero feedback. A `toast.error(…)` call is needed inside the `if (!isOnline)` branch.

```suggestion
  const handleBeforeSubmit = useCallback(
    (text: string, clearEditor: () => void): boolean => {
      if (!isOnline) {
        toast.error("Can't send while offline", {
          id: "send-offline",
          description: "Reconnect to the network and try again.",
        });
        return false;
      }
      return onBeforeSubmit ? onBeforeSubmit(text, clearEditor) : true;
    },
    [isOnline, onBeforeSubmit],
  );
```

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

originally, is the general toast for connectivity shown after this prompt is submitted? so if this stays as is, we would not be showing anything?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, that's correct. The general connectivity toast from connectivityToast.ts fires on the isOnline state transition (after a 5-second debounce), not in response to a submit attempt. So it would show up regardless of whether the user tried to submit or not.

In the original (pre-PR) flow:

  1. onBeforeSubmit passed (no connectivity check), onSubmit fired, editor cleared
  2. sendPrompt threw asynchronously
  3. The general offline toast appeared only after the 5s debounce (unrelated to the submit)

With this PR, if the user goes offline and submits within that 5-second window, handleBeforeSubmit returns false silently — the debounced toast hasn't appeared yet and there's no submit-specific toast either, so they get zero feedback. After the 5s window the general toast is already visible, so the silent no-op is more tolerable, but it's still not great UX.

Adding a toast.error(...) in the !isOnline branch (as I originally suggested) would handle the window case and give immediate, action-specific feedback regardless of when the user goes offline.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

PostHog Code added 2 commits May 1, 2026 10:32
Within the 5s offline-debounce window, blocking submit silently was
indistinguishable from a no-op. Reuse the same global connectivity toast
(same id, same message) instead of inventing a new one.

Generated-By: PostHog Code
Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a
Generated-By: PostHog Code
Task-Id: ba36fa8e-ca18-4fd5-9d57-9bca8825814a
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