Skip to content

fix(platform): serialize concurrent alias registrations - #4220

Merged
yannickmonney merged 4 commits into
mainfrom
fix/concurrent-website-alias-registration
Oct 13, 2026
Merged

yannickmonney merged 4 commits into
mainfrom
fix/concurrent-website-alias-registration

Conversation

@yannickmonney

Copy link
Copy Markdown
Contributor

What changed

  • Serialize website registration by organization and canonical apex host with a transaction-scoped advisory lock.
  • Add regression coverage that verifies the lock is acquired before alias duplicate lookup and preserves the normal 409 path.

Verification

  • bunx oxlint --type-aware services/platform/backend/domains/websites/service.ts services/platform/backend/domains/websites/service.contract.test.ts
  • bunx oxfmt --check services/platform/backend/domains/websites/service.ts services/platform/backend/domains/websites/service.contract.test.ts
  • git diff --check
  • Focused Vitest was attempted but the checkout is missing eventsource-parser and has a Storybook file: preset resolution failure. No local PostgreSQL client/server is available for the controlled interleaving reproduction.

Closes #3593

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review — REQUEST CHANGES

PR #4220 / TALE-139 / #3593; exact head: eb3b62ebaafbb2c5201af5274c46f289224b60c9 (confirmed before review and posting).
Reviewer: agent 8c78cac9-4b65-4630-b901-0a52f2317ff3, run 12c69551-8638-4628-b65c-6ca16826d4a0; distinct from implementation agent dce9fe1e-9749-4181-8df8-464a4176ed56, run 57ce143a-cd57-443b-bb11-8054f8966895.

Findings

  1. P2 — The newly added contract test fails at this exact head. service.contract.test.ts:274 expects captured values ["website-registration:org-1:docs.example", 0], but service.ts:961 interpolates only the key: the seed 0 is SQL text, not a template argument. Actual values are ["website-registration:org-1:docs.example"]. Fix the assertion to match the statement and retain the lock-before-lookup assertion. Observed twice: standalone contract suite 10 passed / 1 failed, and six-file targeted server/importer run 181 passed / 1 failed. This is an assertion failure, not a dependency/startup failure.

  2. P2 — The lock key does not cover every accepted sibling rejected by the duplicate predicate. service.ts:285 strips exactly one www.. Accepted hosts www.fixture.example and www.www.fixture.example therefore take different keys (…:fixture.example versus …:www.fixture.example), although siteHosts('www.www.fixture.example') includes www.fixture.example. On owned PostgreSQL, synchronizing both DNS seams after both real duplicate SELECTs makes both service calls commit: two app.websites rows and two real pgboss.job rows, not spies. Sequential single-www then double-www correctly returns WEBSITE_DUPLICATE_DOMAIN/409, proving this is a collision already recognized by the existing predicate. Make locking/duplicate coverage consistent for accepted spellings and add a permanent controlled-concurrency regression. The repeated-prefix lookup also has directional semantics; merely stripping more prefixes from the lock key is not by itself proof for every arrival order.

Positive evidence

Owned, loopback-only PostgreSQL 15.18, review cluster/role/application tale543_review, database postgres, port 55443, READ COMMITTED; no shared service, container or production DB used. Real service, postgres.js transactions, pg-boss 12.28.0 enqueue, website rows and outbox writes execute. DNS returns only a synthetic documentation-range address; external fetch throws; no crawl worker runs.

Reviewer harness: 7 passed / 1 failed (8 checks). Ordinary fixture.example/www.fixture.example, both winner directions, produces one row + one real job, the loser receives WEBSITE_DUPLICATE_DOMAIN/409, and pg_stat_activity confirms the loser waits on the advisory lock. Sequential 409 holds in both ordinary directions. Same pair in different tenants proceeds independently. A controlled rollback after real enqueue removes both row and job and releases the lock. The failed check is finding 2; the repeated-www sequential control passes.

For the ordinary pair, the organization + normalized host namespace is tenant-scoped. The parameterized 64-bit hash can theoretically collide, but that adds serialization, not a duplicate bypass; it is not mathematically collision-free. One advisory lock is acquired before row/job writes, so this path introduces no multi-advisory-lock ordering cycle. There is no schema/migration diff. Existing duplicate cleanup and mixed old/new writers are not solved by a cooperative application lock.

Other local checks: scoped type-aware Oxlint, Oxfmt check and git diff HEAD^ HEAD --check pass. Only six selected server test files plus the eight-check PostgreSQL harness were run, one worker, Node heap capped at 2048–2304 MiB. The normal Vitest config initially failed on the Storybook file: preset. A server-only review config avoids loading browser/Storybook projects; missing checkout dependencies [email protected] and [email protected] were provisioned only for this isolated review at the exact manifest versions.

Unrun / not claimed: full platform/workspace suite, standalone compiler gate, browser/E2E, crawler/knowledge effects, full migration chain and mixed-version rollout. CI remains queued/nonterminal at observation; no CI rerun or cancellation. No merge, push, source repair or card movement. GitHub author and credential share a principal, so this independent agent verdict is a PR comment, not a self-review or native human approval.

Evidence delivery: /agent/output/d8abbf5b-fc21-407a-8f33-d5e368e91018/ — review report, exact diff, targeted logs, reviewer PostgreSQL harness/configs and CI observation. Next owner: implementation author for repair through existing review/admission controls; TALE-359 for re-review and reconciliation after a new head. This receipt does not move or override the pending native review.

yannickmonney and others added 4 commits October 13, 2026 12:53
The 0 of hashtextextended(key, 0) is part of the statement, so the query
carries one parameter. The assertion expected two and failed once the
test ran.
… pair

The lock key repeated the www rule that the duplicate lookup already
reads from siteHosts, so the two could drift apart. Both now take the
pair's first spelling as the key. Tests hold that the apex and the www
spelling share a lock and that the lock stays within one organization.
The one-source-per-website rule now holds when the two spellings are
added at the same moment, and its tests say so.
@yannickmonney
yannickmonney force-pushed the fix/concurrent-website-alias-registration branch from eb3b62e to 7109b7c Compare October 13, 2026 10:58
@yannickmonney yannickmonney changed the title fix(websites): serialize concurrent alias registrations fix(platform): serialize concurrent alias registrations Oct 13, 2026
@yannickmonney
yannickmonney merged commit 9ea948c into main Oct 13, 2026
@yannickmonney
yannickmonney deleted the fix/concurrent-website-alias-registration branch October 13, 2026 12:21
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.

Bug: Concurrent www/apex registrations create duplicate websites and enqueue both crawls

1 participant