fix(server): updateRow per-key merge + updateInstanceConfig transaction (CWD-3) - #322
Merged
Conversation
treat null property bags and undefined property values as no-ops, document the intentional null divergence, and cover store, local-client, http, pglite fifo, and optional postgres concurrency. this repairs a live data-loss bug: single-key writers previously wiped all other row cells: mcp set_db_cell (packages/mcp/src/server.ts:1718) and the ui ai bridge (packages/ui/src/lib/aiBridge.ts:410).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two server-side lost-update bugs, including a live data-loss path:
updateRowreplaced the wholepropertiesjsonb blob, so single-key writers — MCPset_db_cell(packages/mcp/src/server.ts:1718) and the AI bridge (aiBridge.ts:410) — wiped every other cell in the row on each write.updateInstanceConfigwas an untransacted read-modify-write that lost concurrent keys. Board: CWD-3 (epic OB-76).Solution
updateRownow locks the row (SELECT … FOR UPDATE, same predicate as the UPDATE, in-transaction) and merges per-key — null deletes, undefined skipped, absent preserved — matching what every existing caller already assumed.updateInstanceConfigmaterializes + locks the singleton settings row and merges inside one transaction (mirrors theclaimOwnershippattern). No API shape change. The known null-semantics divergence vssetPageProperties(stores null vs deletes) is documented at both sites; alignment lands with CWD-2's guarded rewrite.Key file:
packages/server/src/store.ts. New deps: none.Before / After
No visual change — server write semantics.
set_db_cell/ AI bridge single-cell writeFOR UPDATEtest, run green against postgres:16.9){properties: null}PATCH{properties: {}}PATCHTest procedure
Operational notes
None — no schema change, no config. The instance-config authorization TOCTOU at the route layer (pre-existing) is deliberately deferred to CWD-2's
expectedRevCAS and recorded as its acceptance criterion. When this merges after CWD-11, the two now-fixed harness races flip fromtest.failstotest(flip commit included at merge time).Verify: green (full
pnpm verify; real-Postgres lock test 10/10). Reviews cleared: code (Quinn — pre-endorsed conditional on the null-guard, applied in aa81ac9 with all touch-ups; lock/deadlock analysis clean on both backends).🤖 Generated with Claude Code
https://claude.ai/code/session_018RUicirLRuuZvjJN13N6yN