Skip to content

Prevent concurrent draft agent creation - #3272

Closed
boudra wants to merge 1 commit into
mainfrom
fix/draft-create-idempotency
Closed

Prevent concurrent draft agent creation#3272
boudra wants to merge 1 commit into
mainfrom
fix/draft-create-idempotency

Conversation

@boudra

@boudra boudra commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Linked issue

Refs #3217

Type of change

  • Bug fix
  • New feature
  • Enhancement
  • Refactor
  • Docs

Reasoning

Draft creation used React render state as its only in-flight guard. Multiple submit callbacks entering before React committed the first state transition each started a separate agent creation request. The shared create-flow store is updated synchronously before the request, so it is the operation owner that can reject later callbacks in the same render.

This fixes the demonstrated client-side duplicate-submit producer. It does not claim to explain the paired six outline requests in #3217; the hosted relay path does not fan out client frames, so that part remains under investigation.

Goals

  • Permit at most one active create request for a draft.
  • Reject a concurrent callback before it sends another daemon RPC.
  • Preserve retries after a failed attempt clears the shared state.

Non-goals

Supersedes

QA

  • Before the fix: npx vitest run packages/app/src/composer/draft/create-flow.test.ts --bail=1 timed out because both same-render submissions entered the unresolved create request.
  • After the fix: the same focused test file passes, including the new assertion that only one request starts.
  • npm run typecheck passes.
  • npm run lint passes.
  • npm run format:files -- packages/app/src/composer/draft/create-flow.ts packages/app/src/composer/draft/create-flow.test.ts passes.

Checklist

  • One focused change
  • npm run typecheck passes
  • npm run lint passes
  • npm run format passes
  • QA evidence
  • Tests added or updated where it made sense

React submit state is render-lagged, so callbacks entering in the same render can all start create requests. Claim the draft synchronously in the shared create-flow store before the first request begins.
@greptile-apps

greptile-apps Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR synchronously consults the shared create-flow store before starting draft agent creation, preventing multiple same-render callbacks from issuing duplicate requests.

  • Adds a per-draft guard that rejects submissions while an active create attempt exists.
  • Adds regression coverage proving two immediate submissions start only one request.
  • Preserves the existing failure cleanup and retry path.

Confidence Score: 5/5

The PR appears safe to merge, with the new shared-store guard preventing the demonstrated duplicate request path.

The first callback synchronously marks the draft’s create attempt active, allowing the second callback to be rejected before it reaches the daemon while existing error handling clears the pending attempt for retry.

Important Files Changed

Filename Overview
packages/app/src/composer/draft/create-flow.ts Adds a synchronous shared-store availability check before draft agent creation; no actionable defect was established in the reachable production flow.
packages/app/src/composer/draft/create-flow.test.ts Adds focused regression coverage showing concurrent same-render submissions issue only one create request.

Sequence Diagram

sequenceDiagram
  participant U as Submit callbacks
  participant H as Draft create flow
  participant S as Create-flow store
  participant D as Daemon

  U->>H: First submission
  H->>S: Check draft availability
  S-->>H: Available
  H->>S: Set lifecycle active
  H->>D: Create agent request

  U->>H: Concurrent submission
  H->>S: Check draft availability
  S-->>H: Active
  H-->>U: Reject without daemon request
Loading

Reviews (1): Last reviewed commit: "fix(app): prevent concurrent draft agent..." | Re-trigger Greptile

@boudra

boudra commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this because the Playwright user-action check did not reproduce duplicate creation with or without the change. The unit test manufactured concurrent callbacks without establishing that users can reach that state, so this is not a supported fix for issue 3217.\n\n_Posted by an agent, not the maintainer; reviewed by the maintainer._

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.

bug: one send creates six agents when the draft's list_prompts request fails

1 participant