Skip to content

fix(desktop): block a second submit while a task is being created - #80137

Merged
trunk-io[bot] merged 2 commits into
masterfrom
posthog-code/fix-duplicate-task-on-double-submit
Aug 8, 2026
Merged

fix(desktop): block a second submit while a task is being created#80137
trunk-io[bot] merged 2 commits into
masterfrom
posthog-code/fix-duplicate-task-on-double-submit

Conversation

@pauldambra

@pauldambra pauldambra commented Aug 8, 2026

Copy link
Copy Markdown
Member

Problem

Pressing Cmd+Enter twice in the desktop task composer starts two identical tasks. isCreatingTask — the flag that disables the send button and the editor's Enter shortcut — is only raised after the cloud-usage and worktree-branch pre-flight checks have awaited. A second Enter that lands during those round trips passes every guard and creates a duplicate.

That pre-flight window is also where the composer shows no pending state at all, which is what invites the second press.

Changes

setIsCreatingTask(true) moves above the pre-flight awaits, and the rest of the submit is wrapped in the try that its existing finally already resets. No new guard: a keydown is a discrete event, so React commits the re-render before the next keypress is handled, and canSubmitBase (which already carries !isCreatingTask) blocks the repeat submit on its own.

The composer also shows its pending state for the whole create rather than only after the pre-flight.

Both callers of the hook — TaskInput and ChannelHomeComposer — get this for free; they already route every submit path through handleSubmit.

Most of the diff is the re-indent from the new try. Review with ?w=1 — the real change is five lines.

How did you test this code?

Not manually tested — I could not run the Electron app in this environment.

Automated checks I ran: pnpm --filter @posthog/ui typecheck and biome check on the changed file, both clean.

No test added. useTaskCreation pulls in roughly thirty injected hooks, stores, and services, so a unit test around it would be mostly mocking and would break on any unrelated import change. Worth revisiting if this hook gets a test harness.

Automatic notifications

  • Publish to changelog?

Docs update

None.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Reported from Slack: a user pressed Cmd+Enter, found the loading state too subtle, pressed again, and ended up with two identical tasks.

I first checked the web /tasks composer (products/posthog_ai/frontend), where every submit path funnels through one sendDisabledReason check and is already safe. The desktop hook is the one with the gap.

The first version of this PR added a useRef re-entrancy guard on top of the state flag. On review that was unnecessary: React flushes discrete-event state updates synchronously, so the existing flag is sufficient once it is raised early enough. The ref only covered two submits dispatched inside a single tick, which no user input path produces. Dropping it left the smaller change.

Skills invoked: none.


Created with PostHog from a Slack thread

The `isCreatingTask` state flag only blocks a repeat submit once React has
re-rendered, and the cloud-usage / worktree-branch pre-flight awaits run inside
that window. Two quick Enters both cleared the guard and created two tasks.

Add a synchronous ref guard around the submit, and raise the in-flight state at
the keystroke so the send button and editor show the pending state during the
pre-flight instead of only after it.

Generated-By: PostHog Code
Task-Id: ede35980-160f-474e-8b38-243396877386
@trunk-io

trunk-io Bot commented Aug 8, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Hey @pauldambra! 👋

It looks like your git author email on this PR isn't your @posthog.com address (paul.dambra@gmail.com). Since you're on the PostHog team, it's worth pointing your local git author email at your @posthog.com address. Why it matters:

  • Consistent work identity in git history — internal tooling that attributes commits to team members keys off your @posthog.com address.
  • Keeps team contributions easy to tell apart from external community ones when scanning history.

You can fix it for this repo with:

git config user.email "you@posthog.com"

Or set it globally with git config --global user.email "you@posthog.com". No need to redo this PR — just a nudge for next time. 🙂

@github-actions github-actions Bot added the feature/desktop Feature Tag: Desktop label Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit e43cac1.

@trunk-io

trunk-io Bot commented Aug 8, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

… flag

Drop the ref. A keydown is a discrete event, so React commits the
`setIsCreatingTask(true)` re-render before the next keypress is handled — once
the flag is raised above the pre-flight awaits, `canSubmitBase` blocks the
repeat submit on its own.

Generated-By: PostHog Code
Task-Id: ede35980-160f-474e-8b38-243396877386
@pauldambra
pauldambra marked this pull request as ready for review August 8, 2026 17:37

@pauldambra pauldambra left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note

🤖 Automated comment by QA Swarm — not written by a human

QA Swarm review complete. See inline comments.

Copy link
Copy Markdown
Member Author

Note

🤖 Automated comment by QA Swarm — not written by a human

Multi-perspective review: router (cheap-first pass) + delegated reviewers (qa-team, paul-reviewer, xp-reviewer, security-audit as warranted)

Verdict: ✅ APPROVE (round 1 @ e43cac1)

The fix is correct for the bug it targets, and the two findings are a UX trade-off and a durability nit — neither blocks merge.

Key findings

  • 🟢 LOW — the editor is now disabled and the send button shows loading for the whole cancelable worktree/remote-branch confirm window, which it wasn't before. Minor UX shift, worth a conscious sign-off.
  • NIT — the guard rests on React batching a discrete-keydown setState rather than an explicit lock. Correct for every call path in the repo today; a future non-discrete caller would silently reopen the race.

Convergence

None — a single router pass covered the change; danger was assessed LOW with HIGH confidence, so no delegation was warranted.

Reviewer summaries

Reviewer Assessment
🧭 router Traced both submit paths (ProseMirror handleKeyDown gated by submitDisabledRef/view.editable, and the send button's native disabled attribute) and found no path that invokes handleSubmit twice in one tick; all early returns inside the new try pass through exactly one finally, and the useCallback deps are unchanged and still correct. Danger LOW, confidence HIGH, delegated nothing.

Automated by QA Swarm — not a human review

@pauldambra pauldambra added the stamphog Request AI approval (no full review) label Aug 8, 2026 — with PostHog

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Frontend-only race-condition fix reordering an existing flag/try-finally in the desktop task composer; diff matches the description, no risky-territory surface touched, and an automated review plus bot reactions are net positive with no unresolved concerns.

  • 👍 on the PR from chatgpt-codex-connector[bot], hex-security-app[bot].
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 508L, 1F substantive — within ceiling
tier T1-agent / T1d-complex (508L, 1F, single-area, fix)
stamphog 2.0.0b4 .stamphog/policy.yml @ 85af931 · reviewed head e43cac1

@trunk-io
trunk-io Bot merged commit d9ca594 into master Aug 8, 2026
314 checks passed
@trunk-io
trunk-io Bot deleted the posthog-code/fix-duplicate-task-on-double-submit branch August 8, 2026 18:31
@deployment-status-posthog

deployment-status-posthog Bot commented Aug 8, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-08-08 18:56 UTC Run
prod-us ✅ Deployed 2026-08-08 19:10 UTC Run
prod-eu ✅ Deployed 2026-08-08 19:09 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature/desktop Feature Tag: Desktop stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant