Repository navigation
Description
Concurrent www/apex registrations create duplicate websites and enqueue both crawls
Severity: P2. Reproduced locally at 44e0dcf254975286c0e9dea443b5cd1ca6b23347.
Two tabs/integrations can create contradictory tracking rows and duplicate crawl jobs for one canonical site, undermining duplicate prevention and potentially duplicated processing/citations.
Expected: The documented www/non-www one-site rule must hold under concurrent registration; one row/job wins and the other request gets the normal duplicate response.
Actual: READ COMMITTED check-then-insert spans both aliases but UNIQUE(org_id,domain) guards only exact spelling. Two alias transactions commit independently.
Reproduction:
- Use two concurrent authorized website registration requests in the same org, one domain=concurrent.fixture.example and one domain=www.concurrent.fixture.example.
- Interleave so both ordinary transactions complete getWebsiteCoveringDomain before either inserts; the local test synchronizes the stubbed DNS seam reached after that SELECT.
- Both calls succeed with distinct IDs, both database rows persist and websites.register is enqueued twice. Sequential registration of the same alias pair correctly refuses the second with WEBSITE_DUPLICATE_DOMAIN/409.
Source:
- services/platform/backend/domains/websites/service.ts:857-862,893-905
- services/platform/backend/db/migrations/0045_websites.sql:9-29
- docs/en/platform/knowledge/crawling.md:17
Local proof:
PASS: fresh real PostgreSQL controlled-interleaving test confirms two committed rows and two addJobInTx calls, with sequential 409 control. No network; resolver returns a local synthetic address, global fetch throws.
it('simultaneous www/apex registrations both commit and enqueue; sequential aliases refuse', async () => {
let arrived = 0;
let release!: () => void;
const barrier = new Promise<void>((resolve) => { release = resolve; });
setSafeFetchResolverForTests(async () => {
// Each transaction has already completed its real alias SELECT when it resolves DNS.
arrived += 1;
if (arrived === 2) release();
await barrier;
return publicAddress;
});
const args = { organizationId: org, scanInterval: '1d' };
const results = await Promise.all([
registerWebsite(sql, { ...args, domain: 'concurrent.fixture.example' }),
registerWebsite(sql, { ...args, domain: 'www.concurrent.fixture.example' }),
]);
expect(results).toHaveLength(2);
expect(new Set(results.map((item) => item.id)).size).toBe(2);
const rows = await sql`SELECT domain FROM app.websites WHERE org_id=${org} ORDER BY domain`;
expect(rows.map((row) => row.domain)).toEqual(['concurrent.fixture.example', 'www.concurrent.fixture.example']);
expect(addJobInTx).toHaveBeenCalledTimes(2);
setSafeFetchResolverForTests(async () => publicAddress);
await registerWebsite(sql, { ...args, domain: 'sequential.fixture.example' });
await expect(registerWebsite(sql, { ...args, domain: 'www.sequential.fixture.example' })).rejects.toMatchObject({ code: 'WEBSITE_DUPLICATE_DOMAIN', status: 409 });
console.log('WEBSITE_ALIAS_RACE', { registrations: results.map((item) => ({ domain: item.domain, id: item.id })), duplicateJobs: 2, sequentialAlias: 409 });
});Run only the frozen proof file:
PATH=/Users/yannick/.npm/_npx/22f2fe8d8bc13000/node_modules/.bin:$PATH bunx vitest run --config /Users/yannick/.codex/notes/tale-100-findings/knowledge-proof/vitest.config.ts authorization-concurrency.test.tsLimits: Service choreography and database transactions execute. Job enqueue is spied rather than real pg-boss; crawler effects beyond two jobs are source-inferred, not executed. A single URL-list paste already canonicalizes and registers sequentially, so that is not the claimed trigger.
Dedup: Searched existing-issues.json website/duplicate terms and GitHub all-state searches; no equivalent www/apex current-platform concurrency issue. Related exclusions: #1755 closed legacy Python register_website prefetch bookkeeping TOCTOU; inspected full body, different layer/root; #1993/#2003 closed raw duplicate error reporting.
Activity