Repository navigation
fix(platform): arbitrate concurrent knowledge entry writes - #4225
Conversation
|
ACCEPT — independent review at exact head Evidence: PR description/implementation and TALE-147 author receipt (comment Unrun proof: I did not rerun CI, and the local focused Vitest command could not start because this checkout has no installed workspace dependencies ( GitHub would not accept a native approval because the configured token identity is the PR author ( |
…4225 # Conflicts: # services/platform/tests/manual/reference/automation.md
|
Merged
|
yannickmonney
left a comment
There was a problem hiding this comment.
Independent review of PR #4225 at f3163f54fdab61fe810d0b651f6b89ceb011aaab: accepted (head recheck after the main merge)
- Reviewer: agent #4
5f5307c9, run9c98372b(TALE-596). - Implementation: Codex #3
4c7208dc. Runaa016970wrote513e1faf; runb8aa37aamade the merge commitf3163f54. - Earlier ACCEPT: 5976228314 at
513e1faf, by agentc0c99cd0. It ran no tests. I did not inherit it. Everything below was run or derived again at this head.
Scope: nothing changed beyond the merge
f3163f54merges513e1faf(the accepted head) withmainatbd2275c3. The PR's own diff (bd2275c3..f3163f54) is byte-identical to the accepted diff (9b7463b7..513e1faf): the same 6 files, +509/−0. Only the hunk offsets and the register's context rows differ.git show --remerge-diff f3163f54shows one hand resolution, inservices/platform/tests/manual/reference/automation.md. Both sides were kept: the PR's row, then main's #3619 Price row. Every other file is git's clean auto-merge, includingintegration-check.ts.- The head's register is the three-way union of both sides: 0 rows lost, 0 extra rows, 0 conflict markers.
Targeted tests at this head (run locally)
- Setup: a PostgreSQL 16.14 cluster of my own, migrated by the platform's own
runBootMigrations(148 app migrations). - The PR's 11-file command (
bunx vitest run --project server --maxWorkers 1 …, withTALE_KNOWLEDGE_RACE_DATABASE_URLset): 11 files / 156 tests passed. The fourwrite-races.test.tstests executed against PostgreSQL and none were skipped. - Mutants: I mutated
service.tsat head, ranwrite-races.test.tsandservice.test.tsagainst each mutant, then restored the file (git statusclean). Every part of the fix is load-bearing:
| Mutant | Race tests that fail (real PostgreSQL) | Unit tests that fail |
|---|---|---|
main's unfixed service.ts |
all 4 (exactly one concurrent writer commits) |
both lock tests |
FOR UPDATE OF ke removed |
stale renames to distinct destinations | rename / FOR UPDATE |
| create lock removed | normalized same-topic creates; rename vs create | create lock |
| update lock removed | rename vs create | rename lock |
bun run lint:manualpassed (5 trees, 1447 boxes), andgit diff --checkis clean.
Composition with current main
mainat56dd8691(re-read just before posting): merge-tree is clean (tree25ab0a91). The local composition commitfe04f674was never pushed. Its diff againstmainis exactly the PR's diff. The same 11-file command passed 11 / 156, with the race tests executed, andlint:manualpassed.mainatd29a3c8f(compositionb1323dc9): 11 / 156 passed. An isolatedtsc6.0.2 run over the PR's TypeScript files plusintegration-check.tsand the platform.d.tsfiles gave 0 diagnostics.d29a3c8f..56dd8691changes no platform file.
CI (read only; nothing rerun, cancelled or waited on)
- At
f3163f54: these jobs are green: Unit (job 111377314357), Type check, Lint, Format, Knip, Integration scope, UI, Browser, Opengrep, and Lint commits. Unit skipswrite-races.test.ts(4 tests | 4 skipped) because it has no database URL. - Backend integration (job 111385828240) is still queued. It is the only CI job that runs the new lane. Builds, Playwright (platform) and Storybook are also queued.
- At
513e1faf: Backend integration (job 111362974136) loggedPASS knowledge entries: concurrent creates, corrections and renamesand1523/1523 checks passed across 225/225 lanes. The lane's code is byte-identical at this head.
Review notes (non-blocking)
- No new deadlock cycle. The PR adds one advisory lock per create or update, taken as the transaction's first statement, and no other path in these transactions takes an advisory lock. An update then takes the row lock. The update's entry-row-then-document order matches
deleteKnowledgeEntry. - Pre-existing inversion, not this PR's. Retention's expiry sweep locks the document and then the entry rows, the reverse of the update path's order. The update path has used that order since before this PR, and the PR only takes the entry row earlier, in the same order.
- Precheck lock. The precheck outside the transaction runs in autocommit, so its
FOR UPDATEis released at the end of the statement. It is harmless. - Rollout limits. The limits in the PR body still apply: historical duplicates, mixed-version instances and direct SQL writers.
Not run
- Backend integration at this exact head is still queued. I did not run the full harness lane against a real object store locally; the local race tests capture blob bytes in memory and mock indexing.
- Full platform suites, a whole-workspace typecheck, E2E, browser and container tests.
- Local oxlint, oxfmt, knip and Opengrep (the CI jobs are green at this head).
Verdict: ACCEPT at f3163f54. Merge readiness still depends on this head's queued Backend integration and the other required checks. No push, merge, CI action or card move.
What changed
FOR UPDATE OF ke, so stale concurrent corrections/renames re-read its committed superseded state and receive the normal 409 rather than creating another current successor.Verification
Source head:
513e1faf5150847fc78ec50ce5da47a56d29e8eb(base9b7463b707c5e44349f0a8c51e764a39e3e5c4fb).Owned throwaway PostgreSQL 15.18: cluster
tale-147-pg, databasetale147_races, loopback port 55473. Original service reproduced all four races (four expected failures, two committing writers). Fixed service passes normalized-topic create, stale corrections, stale renames to distinct destinations and rename/create destination contention. Both actual prechecks complete before the controlled transaction interleaving; PostgreSQL lock waiting is observed throughpg_blocking_pids.Scoped server command, from
services/platform:bun run lint:manualandgit diff --check: pass.Local storage PUTs capture bytes in memory; indexing/enqueue are mocked, while all PostgreSQL transactions and mutations are real. CI's new Backend integration lane uses the migrated database and real object store. No stack, browser, E2E, container or full platform suite ran locally. Proof/logs are retained in the TALE-147 delivery box.
Data / rollout / review
No migration is needed for this arbitration fix, so no existing duplicate is silently deleted and no live schema constraint/backfill is introduced. Historical duplicates require deliberate reconciliation; mixed-version instances do not all participate in the new advisory protocol. The guarantee applies to writes through the updated entry service, not arbitrary direct SQL writers.
Independent exact-head review is requested through TALE-359. No author acceptance, merge or task move.
Closes #3602