Skip to content

fix(projects): enforce unique task ID prefixes - #780

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
sinbumu:fix/779-unique-task-prefix
Nov 21, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
sinbumu:fix/779-unique-task-prefix

Conversation

@sinbumu

@sinbumu sinbumu commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #779. Short task keys now identify a single active project: non-empty prefixes are unique case-insensitively, while soft-deleted projects and empty prefixes are excluded.

  • Migration 000093 keeps the oldest project (created_at, then UUID), assigns available numeric suffixes within 10 characters, records old/new values in project_prefix_changes_000093, and creates the partial unique index. Project writes are locked until deduplication, audit records and index creation commit together. Crash-window replay preserves the audit history.
  • Create/update map the named index violation to ErrPrefixTaken / HTTP 409 PROJECT_PREFIX_TAKEN, distinct from the existing name error. Automatic creation retries conflicting candidates through the database constraint, including concurrent requests; failed attempts roll back their setup.
  • Create/edit forms show translated inline conflicts in all nine locales. Untouched suggestions are allocated by the server; explicitly edited prefixes remain explicit. ASCII suggestion rules match the form, including a valid fallback for non-ASCII names.
  • Prefix lookups include the partial-index predicate, and short-key lookup no longer falls through duplicate projects.

Data and link impact

Task/project UUIDs and task numbers are preserved; UUID URLs remain stable. Renamed projects get new display keys, CSV labels and short links. Historical short links and textual git references are not rewritten or aliased: an old duplicate key addresses the project that retained the prefix, or returns not found if it lacks that task number. Future prefix changes or reuse after soft deletion can also change an old short link's target. Authorization on the resolved task remains in place.

The migration blocks project writes during deduplication/index construction. There is no automatic down migration: dropping the index does not restore old prefixes. Keep backups and the audit history; blindly restoring old values after subsequent edits would be unsafe. An application-only rollback retains the new values, but old binaries lack conflict handling. Details are in the development and API documentation.

Validation

Passed locally on macOS:

  • go test -race -timeout 300s ./... with DB/E2E opt-ins unset (Docker E2E and optional PostgreSQL tests skip in this mode).
  • go vet ./... and go build ./....
  • PostgreSQL 14.17 in a newly initialized, isolated cluster with TCP disabled and synthetic fixtures only: all 93 migrations, deterministic deduplication/ties, suffix collisions/truncation, audit/transaction rollback/replay, UUID and short-key resolution, create/update conflicts, case-insensitivity, empty prefixes, reuse after deletion, and concurrent generated/explicit creation and updates. Four new PostgreSQL tests passed with the race detector.
  • Project service and HTTP integration regressions, including 409 error codes distinct from name conflicts.
  • Web: 166 test files / 1,728 tests; inline create/edit and all-locale checks also re-run after the test fixture type correction (100 passed). bun run lint and bun run build passed. Lint reports four existing unused-suppression warnings in untouched files; build reports large chunks. Node 25 needed NODE_OPTIONS=--no-experimental-webstorage for the existing jsdom setup.

The wider optional PostgreSQL suite is not green: eight existing top-level tests fail, reproduced unchanged at base 4a5e5da: document row-lock timing, git upsert previous-state reporting, IAM key mapping, plugin-manifest migration, project-role-resource migration, roles API, roles-assign migration, and service-account API. These are outside this change.

Not run locally: PostgreSQL 16, Docker full-stack E2E, Playwright browsers, and golangci-lint. The new PostgreSQL tests use the repository's existing PACA_TEST_PG_DSN opt-in. No existing/production database was contacted, and no deployment was performed.

Type of Change

Other: project key integrity and conflict handling.

Checklist

AI-assisted implementation and automated review/testing with OpenAI Codex. Human review is still pending; this PR is intentionally a draft.

Separate third-party imports from local packages and use the test context for the migration audit query.

Validated with golangci-lint 2.15.0 (Go 1.26.11): 0 issues; all four TestProjectPrefix PostgreSQL tests passed with -race against the isolated task cluster.
@pikann

pikann commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Hi @sinbumu ,
It’s been 2 days since your last commit, and this PR is still marked as a draft. Could you please mark it as "Ready for review" once you're done?
Thank you so much for your contribution!

@sinbumu
sinbumu marked this pull request as ready for review November 21, 2026 10:29

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Approach: sound — the database index is the single arbiter for prefix uniqueness, the migration dedupes, audits and builds that index in one transaction, and the service treats the constraint violation as the retry signal, so concurrent creates cannot bypass it.

Reviewed changes — read the full diff (35 files, both commits) and ran the new Postgres tests plus the affected Go packages locally.

  • Migration 000093: dedupes active non-empty prefixes (oldest kept by created_at, id, first free numeric suffix within 10 chars), records old/new in project_prefix_changes_000093, and adds the partial unique index on upper(task_id_prefix) WHERE task_id_prefix <> '' AND deleted_at IS NULL, all inside the runner's per-file transaction.
  • Repository and service: Create/Update map the named index violation to ErrPrefixTaken ahead of the generic name fallback; auto-generated prefixes retry through the constraint while explicit prefixes fail fast.
  • Lookups: FindByTaskIDPrefix, FindTaskByKey and git FindTaskByRef carry the non-empty/soft-delete predicates and drop the oldest-project fallback.
  • API and web: 409 PROJECT_PREFIX_TAKEN is mapped and documented; both project forms surface it inline in all nine locales, and untouched suggestions are server-allocated.
  • Tests: Postgres migration/dedupe/replay/concurrency coverage, service retry tests, an integration 409 test and a web component test.

Verification: the four TestProjectPrefix* tests pass against a local PostgreSQL 18 cluster, and go test passes for internal/service/project, internal/transport/http/handler, internal/transport/http/presenter, internal/repository/postgres and test/integration.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 1ed4379 into Paca-AI:master Nov 21, 2026
7 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.

[Feature] Enforce unique project task ID prefixes and index them

2 participants