Skip to content

Fix race between auto-save and publish on Cmd+Enter#2895

Closed
vitaly-andr wants to merge 1 commit into
basecamp:mainfrom
vitaly-andr:fix/cmd-enter-publish-race
Closed

Fix race between auto-save and publish on Cmd+Enter#2895
vitaly-andr wants to merge 1 commit into
basecamp:mainfrom
vitaly-andr:fix/cmd-enter-publish-race

Conversation

@vitaly-andr
Copy link
Copy Markdown

Summary

When the user types a title and immediately presses Cmd+Enter on a new draft, the publish request can reach the server before the auto-save PATCH commits the title. The before_save callback in Card then writes "Untitled" (since card.title is still nil in memory), and the late PATCH overwrites it with the typed value. The intermediate state has several visible side effects:

  • Phantom card_title_changed event is recorded.
  • System comment "changed the title from 'Untitled' to ''" is created on the brand-new card.
  • Webhook subscribers receive a fake card_title_changed delivery.
  • The board view shows "Untitled" until the Turbo Stream broadcast from the late PATCH replaces it — which is why the bug is hard to notice on fast setups but stuck-visible on slow self-hosted instances (Incomplete card title when a new card is saved with Cmd+Enter keyboard shortcut #2778).

Fix

Add an optional auto-save outlet to clicker_controller. When wired up via clicker_auto_save_outlet="#card_form" on the Create card / Create and add another buttons, clicker awaits the auto-save submit before triggering the publish click. Backwards-compatible: clicker without the outlet behaves exactly as before.

Reproduction

Adding sleep 0.6 to CardsController#update widens the race window and reliably reproduces the bug. The included system test uses the same technique.

Test plan

  • System test in test/system/card_creation_race_test.rb — TDD-validated (fails on main, passes with this commit).
  • Asserts: typed title preserved on the board view, no phantom card_title_changed event, no "changed the title from..." system comment.
  • All existing tests remain green (bin/ci).

Prior art

@LuisMSAmorim outlined the same root cause and proposed a similar outlet-based approach in #2362; this PR extends that analysis with a reliable repro and documents the data-pollution side effects.

Closes #2778

When the user types a title and immediately presses Cmd+Enter on a new
draft, the publish request can reach the server before the auto-save
PATCH commits the title. The before_save callback in Card sets the
title to "Untitled" (since title was still nil in memory), and the
late PATCH rewrites it to the typed value — but the intermediate state
generates a phantom card_title_changed event, a system comment
"changed the title from Untitled to ...", and a webhook delivery as
side effects.

Fix by adding an optional auto-save outlet to clicker_controller.
When wired up via clicker_auto_save_outlet="#card_form", clicker awaits
the auto-save submit before triggering the publish click. The change
is backwards-compatible: clicker without the outlet behaves as before.

Closes basecamp#2778
Copilot AI review requested due to automatic review settings May 10, 2026 06:45
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a race condition where publishing a brand-new draft via Cmd/Ctrl+Enter could reach the server before the draft’s auto-save PATCH, causing a transient "Untitled" title and related phantom side effects (events, system comments, webhook deliveries). The fix makes the publish hotkey wait for the draft auto-save to complete before triggering the publish action.

Changes:

  • Add an optional auto-save Stimulus outlet to clicker_controller and await the outlet’s submit() before clicking.
  • Wire clicker_auto_save_outlet="#card_form" on the “Create card” and “Create and add another” buttons so hotkey-triggered publish waits for auto-save.
  • Add a system test that reproduces the race (via an artificial delay) and asserts no phantom title-change artifacts are created.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
app/javascript/controllers/clicker_controller.js Await auto-save (via optional outlet) before triggering the click action used by hotkeys.
app/views/cards/container/footer/_create.html.erb Provide the auto-save outlet hookup for the create/publish buttons on draft creation.
test/system/card_creation_race_test.rb System-level regression test for the Cmd/Ctrl+Enter publish race and its side effects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


async click() {
if (this.hasAutoSaveOutlet) {
await this.autoSaveOutlet.submit()
@vitaly-andr
Copy link
Copy Markdown
Author

Closing as duplicate of #2812 (which was opened first). See my comment there.

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.

Incomplete card title when a new card is saved with Cmd+Enter keyboard shortcut

2 participants