Skip to content

[Bug] Concurrent publishes race on skill coordinate and return 500 #617

Description

@XiaoSeS

Summary

Skill lifecycle mutations are not serialized by the final (namespace_id, slug) coordinate.

In the publish flow, the service performs a check-then-create sequence:

  1. query skills by namespace/slug;
  2. query the current owner's skill;
  3. insert the skill if absent;
  4. query/replace/create a version.

Two concurrent publishes for the same owner, namespace, slug, and version can both observe “not found” and race on the database uniqueness constraints. One request then returns an unhandled DataIntegrityViolationException as HTTP 500. Concurrent publish/review mutations can also interleave pending-review withdrawal and latest_version_id updates.

Current code:

Steps To Reproduce

  1. Prepare a valid publish package for a new skill/version.
  2. Use the same user and namespace in two concurrent publish requests.
  3. Add a barrier after both transactions finish the “find existing skill/version” reads and before either insert, to make the race deterministic.
  4. Release both requests.
  5. Observe one request succeed and the other fail with a unique-constraint exception / HTTP 500.

A second regression test should run publish and review approval concurrently on the same skill coordinate and assert deterministic lifecycle state.

Expected Behavior

Mutations for the same final skill coordinate should be serialized or otherwise use an atomic upsert/conflict protocol.

Concurrent identical requests should result in either:

  • one success and one deterministic business conflict/idempotent response; or
  • two serialized, valid outcomes.

They should not produce an internal server error or leave ambiguous lifecycle pointers.

Environment

  • Branch: main
  • Commit: 9f602f8184f23347124b3606ffce1a6ac5f19c0a
  • Database: PostgreSQL

API Contract Impact

No response-shape change is required. Contention should stop surfacing as HTTP 500.

Logs Or Screenshots

Representative database symptoms:

duplicate key value violates unique constraint "skill_namespace_id_slug_owner_id_key"
duplicate key value violates unique constraint on skill_version(skill_id, version)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingeffort/l大改动或高风险改动,需要 maintainer 负责 / Large or risky change requiring maintainer ownership.priority/p1高优先级 / High priority triage bucket.risk/high涉及安全、鉴权、迁移或公共契约 / Touches security, auth, migrations, or public contracts.triage/core交由 core maintainer 结合 AI 协同处理 / Issue should be handled by a core maintainer with AI support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions