Skip to content

Add duplicate detection for plan_create#242

Merged
neoneye merged 6 commits intomainfrom
feature/plan-create-dedup
Mar 11, 2026
Merged

Add duplicate detection for plan_create#242
neoneye merged 6 commits intomainfrom
feature/plan-create-dedup

Conversation

@neoneye
Copy link
Member

@neoneye neoneye commented Mar 11, 2026

Summary

  • Adds server-side dedup for plan_create: if the same (user_id, prompt, model_profile) is submitted within a configurable time window (default 60s), returns the existing pending/processing plan with deduplicated: true instead of creating a new one
  • Configurable via PLANEXE_DEDUP_WINDOW_SECONDS env var (set to 0 to disable)
  • No schema migration needed — uses existing columns

Changes

  • mcp_cloud/db_queries.py: Added DEDUP_WINDOW_SECONDS constant and _find_recent_duplicate_plan() helper; modified _create_plan_sync to call it before INSERT
  • mcp_cloud/tool_models.py: Added deduplicated field to PlanCreateOutput
  • mcp_cloud/schemas.py: Updated plan_create description and set idempotentHint: true
  • mcp_cloud/app.py: Added _find_recent_duplicate_plan to re-exports
  • mcp_cloud/tests/test_plan_create_tool.py: Added dedup and window=0 opt-out tests; updated existing test to patch dedup helper

Test plan

  • python -m pytest mcp_cloud/tests/test_plan_create_tool.py -v (requires Docker)
  • python -m pytest mcp_cloud/tests/ -v
  • python -m pyright mcp_cloud/
  • Manual: submit same prompt twice quickly → second call returns same plan_id with deduplicated: true
  • Manual: set PLANEXE_DEDUP_WINDOW_SECONDS=0 → dedup disabled, both calls create new plans

🤖 Generated with Claude Code

neoneye and others added 6 commits March 11, 2026 13:19
When the same user submits the same prompt + model_profile within a
configurable time window (default 60s, env PLANEXE_DEDUP_WINDOW_SECONDS),
return the existing pending/processing plan instead of creating a new one.
This prevents double-submissions from double-clicks, network retries, or
agent re-attempts from consuming duplicate pipeline resources.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…lumns

The query now fetches only (id, timestamp_created, parameters) instead of
full PlanItem objects. This avoids loading the prompt column (up to 4 GB)
and any eagerly-loaded fields.  Returns a lightweight dict instead of a
PlanItem instance.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Document why the request_id approach was not adopted (LLMs cannot
generate UUIDs natively) and describe the implemented server-side
auto-dedup approach from PR #242.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Protects against runaway agents hammering plan_create with the same
prompt overnight and draining credits.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@neoneye neoneye merged commit 432b125 into main Mar 11, 2026
3 checks passed
@neoneye neoneye deleted the feature/plan-create-dedup branch March 11, 2026 14:09
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