Skip to content

fix: prevent duplicate pending operations in mod queue - #359

Merged
cebarks merged 2 commits into
mainfrom
worktree-agent-aa8e5a93b3a24e779
Jul 29, 2026
Merged

fix: prevent duplicate pending operations in mod queue#359
cebarks merged 2 commits into
mainfrom
worktree-agent-aa8e5a93b3a24e779

Conversation

@cebarks

@cebarks cebarks commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds partial unique indexes to enforce one pending operation per (mod/addon, action)
  • Prevents duplicate queue entries from concurrent requests
  • Returns user-friendly error messages for duplicates

Changes

  1. Migration 019: Creates partial unique indexes on pending_operations:

    • idx_pending_ops_mod_action on (forge_mod_id, action) for mod operations
    • idx_pending_ops_addon_action on (forge_addon_id, action) for addon operations
  2. Database layer (src/db/users.rs):

    • insert_pending_op: Returns friendly error message for UNIQUE constraint violations
    • has_pending_url_op: New helper to check for duplicate URL-based operations
  3. Web handler (src/web/handlers/mods.rs):

    • URL install path checks for duplicates before downloading
    • Gracefully handles constraint violations with user-facing info messages

Test plan

  • Verified compilation with just check
  • Verified no clippy warnings with just clippy
  • Manual test: queue same mod install twice (should show "already queued" message)
  • Manual test: queue same URL install twice (should show "already queued" message)
  • Manual test: concurrent queue requests (database constraint should catch race)

Root Cause

The pending_operations table had no unique constraint on (forge_mod_id, action) or (forge_addon_id, action), allowing duplicate pending operations to be queued.

Implemented with the help of Claude Code

cebarks and others added 2 commits July 28, 2026 21:51
Adds partial unique indexes on `pending_operations` table to enforce
one pending operation per (mod/addon, action) pair. This prevents
duplicate queue entries when multiple users or requests attempt to
queue the same operation concurrently.

Changes:
- Migration 019: Add unique indexes for mod and addon operations
- insert_pending_op: Return friendly error message for duplicates
- has_pending_url_op: Add dedup check for URL-based installs
- URL install handler: Check for duplicates before download and
  handle constraint violations gracefully with user-facing messages

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Applies the same SQLITE_CONSTRAINT_UNIQUE handling pattern used in URL
installs to mod and addon removal queue operations. On the rare race
condition where has_pending_op() passes but the unique index catches a
duplicate, users now see a friendly "already queued" flash message
instead of a raw 500 error.

Additionally, add missing queueing support to remove_addon handler
(previously it would always perform immediate removal even when the
server was running and queue mode was enabled).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cebarks
cebarks enabled auto-merge (squash) July 29, 2026 04:31
@cebarks
cebarks merged commit 7a44b4b into main Jul 29, 2026
11 checks passed
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