forge
Explore
Log in

Don't you dare go Hollow

🗑️ drop the whole-row-save gate — it banned a spelling, not a bug

Browse files at this commit

523a565be7b8015d92f0f7bba6aad6a1da0c2b44Ahmet Kaan GümüşParent: 25747d8
  • chore
    • 🗑️ drop the whole-row-save gate — it banned a spelling, not a bug
Show full message
chore: 🗑️ drop the whole-row-save gate — it banned a spelling, not a bug

`scripts/check-whole-row-saves.sh` matched only `.content(&?self[).]`.
Six evasions of the very thing it forbade passed it: an alias variable,
`*self`, a raw `"UPDATE $id CONTENT $row"`, `.merge(self)`, a multi-line
`.content(\n self)`, and `.content(clone)`. Its one caller was an
untracked `.git/hooks/pre-commit`, so it guarded a single working copy
and died on clone, and its own comment still claimed 22 pre-existing hits
against a tree that was already at zero.

It was also aimed at the wrong invariant. `.content(self)` is a spelling;
the bug is any value bound from a read taken before the write. That is
what `field_update.rs` fixes, and every PATCH path now routes through it.

The in-code `// whole-row-save-ok:` annotations stay — they explain why
each remaining save is safe, which outlives any grep. The pre-commit hook
was nothing but the one invocation, so it is gone too.
scripts/check-whole-row-saves.shdeleted+0 -59
@@ -1,59 +0,0 @@
1-#!/bin/sh
2-# Ban whole-row saves: `db.update(...).content(self)` and friends.
3-#
4-# WHY: `.content(self)` REPLACES the entire stored row with the in-memory
5-# struct. If `self` was loaded before an `.await` (a permission check, another
6-# query, an HTTP/QUIC call), any concurrent PATCH that landed in between is
7-# silently reverted — the write succeeds, the other user's change is gone, no
8-# error anywhere. A grep cannot see "read before an await", so the shape itself
9-# is banned and the exceptions are made explicit and reviewable.
10-#
11-# FIX: write only the fields the request actually changed, e.g.
12-# db.query("UPDATE $id SET text = $text, points = $points")
13-# or hold a lock across the whole read-modify-write and opt out below.
14-#
15-# OPT OUT: put this on the line IMMEDIATELY above the call:
16-# // whole-row-save-ok: <why this row cannot be raced>
17-#
18-# Usage:
19-# scripts/check-whole-row-saves.sh # whole tree (gate mode)
20-# scripts/check-whole-row-saves.sh a.rs b.rs # only these files (hook mode)
21-# Exit 1 if any unannotated whole-row save is found.
22-
23-cd "$(dirname "$0")/.." || exit 1
24-
25-if [ "$#" -gt 0 ]; then
26- set -- "$@"
27-else
28- # shellcheck disable=SC2046 # paths in this repo have no spaces
29- set -- $(find src -name '*.rs' | sort)
30-fi
31-[ "$#" -eq 0 ] && exit 0
32-
33-awk '
34-FNR == 1 { prev = "" }
35-/\.content\(&?self[).]/ {
36- if (prev !~ /\/\/[ \t]*whole-row-save-ok:[ \t]*[^ \t]/) {
37- sub(/^[ \t]+/, "", $0)
38- printf "%s:%d: %s\n", FILENAME, FNR, $0
39- bad++
40- }
41-}
42-{ prev = $0 }
43-END {
44- if (bad) {
45- print ""
46- print "whole-row save: .content(self) replaces the ENTIRE row, so any"
47- print "concurrent PATCH that landed after this struct was read (i.e."
48- print "across any .await above) is silently reverted — no error, data"
49- print "just disappears. Write only the changed fields instead:"
50- print " db.query(\"UPDATE $id SET field = $field\")"
51- print "If the row genuinely cannot be raced (e.g. a write lock is held"
52- print "across the read and the write), opt out on the line directly above:"
53- print " // whole-row-save-ok: <why this row cannot be raced>"
54- print ""
55- printf "%d unannotated whole-row save(s).\n", bad
56- exit 1
57- }
58-}
59-' "$@"