Skip to content

fix: make task identifiers unique in the database #248

Closed

Description

@uniqueg

Why?

The only unique index of the tasks collection (db.dbs.taskStore.collections.tasks.indexes in pro_tes/config.yaml) is on task_id and worker_id, sparse. Task documents store their identifier as task.id, not task_id, and worker_id is a new UUID for each task, so the index never rejects a task identifier that is already used: the DuplicateKeyError retry in TaskRuns._write_doc_to_db() is dead code.

Since #215, tasks are owned per user, and a repeated identifier would give access to the task of someone else. The PR for #215 makes the controller skip identifiers of stored tasks and identifiers with owner roles, and grants the owner before the task is stored, so only two concurrent requests drawing the same identifier at the same moment could still collide (about 1 in 2.2e9 per pair). A unique index closes that gap and makes the check atomic.

How?

  1. Replace the index with a unique index on task.id (not sparse), and, if useful, one on worker_id.
  2. Upgrading notes: index creation fails if stored tasks share an identifier; how to find and resolve duplicates (db.tasks.aggregate([{ $group: { _id: "$task.id", n: { $sum: 1 } } }, { $match: { n: { $gt: 1 } } }])).
  3. Test with the real MongoDB job that a duplicate task.id is rejected and retried.

Acceptance criteria

  • Two tasks can't be stored with the same task.id.
  • Upgrading notes cover existing duplicates.

Activity

  1. added
    priority: medium
    status: triage
    type: bug
    type: security
    workload: hours
    status: in progress
    and removed
    status: triage
    on Oct 23, 2026
  2. removed
    status: in progress
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: bugtype: securityworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions