Skip to content

fix(app): prevent duplicate draft agent creation - #2614

Closed
lincolnaleixo wants to merge 5 commits into
getpaseo:mainfrom
lincolnaleixo:agent/prevent-duplicate-agent-create
Closed

fix(app): prevent duplicate draft agent creation#2614
lincolnaleixo wants to merge 5 commits into
getpaseo:mainfrom
lincolnaleixo:agent/prevent-duplicate-agent-create

Conversation

@lincolnaleixo

Copy link
Copy Markdown

What changed

  • Treat an already-active create attempt in the shared create-flow store as an in-flight submission.
  • Reject a concurrent submit even before React has rendered the reducer's creating state.
  • Add a regression test that invokes the submit handler twice in the same render cycle and verifies that only one create request starts.

Root cause

handleCreateFromInput guarded on isSubmitting, which is derived from the reducer state captured by the current render. Multiple submit callbacks in the same event loop all observed isSubmitting === false, generated independent message IDs, and started independent createAgent requests before React could render the first SUBMIT transition.

The create-flow Zustand store is updated synchronously before the request starts, so checking its active attempt closes that render gap while preserving retries after failed attempts are cleared.

Observed impact

In a real Paseo 0.2.3 desktop session, one new-workspace prompt produced seven create_agent_request messages from the same client, session, and connection within one millisecond. All seven became real Codex agents.

This may be related to #94, although that issue describes duplicate draft tabs rather than confirmed duplicate provider agents.

Validation

  • npm run build:app-deps
  • npm run test --workspace=@getpaseo/app -- src/composer/draft/create-flow.test.ts
  • npm run typecheck --workspace=@getpaseo/app

All passed locally.

@lincolnaleixo
lincolnaleixo marked this pull request as ready for review July 29, 2026 16:49
@greptile-apps

greptile-apps Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Prevents duplicate draft-agent creation by:

  • synchronously checking the shared create-flow store for an active draft attempt before submission
  • rejecting same-render concurrent submissions before React exposes the reducer’s creating state
  • adding regression coverage that verifies only one create request starts

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
packages/app/src/composer/draft/create-flow.ts Adds a synchronous draft-scoped active-attempt check that closes the same-render duplicate-submission window.
packages/app/src/composer/draft/create-flow.test.ts Adds regression coverage for two submissions invoked before React rerenders, asserting only one creation request starts.

Sequence Diagram

sequenceDiagram
  participant U as Submit callbacks
  participant H as Draft create hook
  participant S as Create-flow store
  participant A as Agent creation request
  U->>H: First submit
  H->>S: Check active attempt
  S-->>H: None
  H->>S: Store active attempt
  H->>A: Start create request
  U->>H: Concurrent submit
  H->>S: Check active attempt
  S-->>H: Active
  H-->>U: Reject duplicate submission
  A-->>H: Creation completes
  H->>S: Mark sent or clear on failure
Loading

Reviews (3): Last reviewed commit: "Merge branch 'main' into agent/prevent-d..." | Re-trigger Greptile

@boudra

boudra commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Superseded by #4442, which takes over the duplicate draft-agent workflow with the shared active-attempt check, stable per-draft creation/message identities, and durable daemon receipts. The canonical PR includes failing-first browser coverage for rapid submissions and replayed requests.

@boudra boudra closed this Sep 7, 2026
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.

2 participants