Skip to content

Commit 7d587ac

Browse files
os-zhuangclaude
andauthored
fix(pm): stop --report labelling the arrival depth as "waiters already ahead" (#12782) (#12822)
The depth is read AFTER take_ticket has minted this call's own ticket, so the recorded value is the arriving run PLUS the waiters ahead of it and its floor is 1. --report printed it under "queue depth on arrival (waiters already ahead)", so a completely uncontended fleet read as one waiter deep on every row, and a reader had no way to tell whether the label or the record was the wrong one. The record was never wrong -- announce_arrival already derives `ahead = depth - 1` from the same number and says "0 ahead of you" on a free lock -- so this repairs the heading and leaves the recording path byte-for-byte untouched. Rewriting the field instead would put a meaning boundary through the middle of a ledger nothing can re-date, which is the mixed-population hazard --report already has to warn about for `command-exit`. Measured on a private lock and ledger, one holder plus two waiters: the holder and the first waiter both record depth=1 (a holder deletes its ticket when it acquires, so it is not in the queue either), and the second waiter records depth=2 while its arrival line says "1 ahead of you". That second reading is why the heading gained a second note: depth=1 is evidence about the QUEUE and says nothing about whether the lock was held. Self-test pins the record at its floor (an uncontended acquire records depth=1) so a later "fix" that subtracts one in the recording path goes red, and pins that the off-by-one heading is gone rather than merely annotated. Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3f42920 commit 7d587ac

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

scripts/pm/os-verify-lock.sh

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,10 +1769,31 @@ mode_report() {
17691769
printf ' n=%s p50=%s p90=%s max=%s\n' \
17701770
"$(wc -l < "${tmp}/held" | tr -d ' ')" "$(pct_of "${tmp}/held" 50)" \
17711771
"$(pct_of "${tmp}/held" 90)" "$(pct_of "${tmp}/held" 100)"
1772-
printf 'queue depth on arrival (waiters already ahead):\n'
1772+
# ⚠ THE LABEL, NOT THE RECORD. The field counts the arriving run itself: the
1773+
# depth is read AFTER `take_ticket` has minted this call's own ticket, so its
1774+
# floor is 1 and a completely uncontended fleet printed "1 waiter already
1775+
# ahead" on every row it had. The record was never wrong -- `announce_arrival`
1776+
# derives `ahead = depth - 1` from the same number and has always said "0
1777+
# ahead of you" on a free lock -- so the repair is this heading, and ⛔ NOT the
1778+
# recorded value: rewriting the field would put a meaning boundary through the
1779+
# middle of the ledger, which is the mixed-population hazard the outcomes
1780+
# block above already has to warn about for `command-exit`.
1781+
#
1782+
# The second ⇒ is the misreading the first one leaves behind. A run that
1783+
# queued behind a busy holder with nobody in front of it records exactly what
1784+
# a run that walked up to a free lock records, because a holder deletes its
1785+
# ticket at the moment it acquires; measured on both paths, both 1. So this
1786+
# column is evidence about the QUEUE and about nothing else -- `held` and the
1787+
# outcomes block are where "was the lock busy" is answered.
1788+
printf 'queue depth on arrival (the arriving run INCLUDED — 1 means nobody was ahead):\n'
17731789
printf ' n=%s p50=%s p90=%s max=%s\n' \
17741790
"$(wc -l < "${tmp}/depth" | tr -d ' ')" "$(pct_of "${tmp}/depth" 50)" \
17751791
"$(pct_of "${tmp}/depth" 90)" "$(pct_of "${tmp}/depth" 100)"
1792+
printf ' ⇒ waiters already ahead = this minus 1. The depth is read after this call mints\n'
1793+
printf ' its own ticket, so 1 is the floor, not a waiter.\n'
1794+
printf ' ⇒ it does not count the HOLDER either — queueing behind a busy lock with nobody\n'
1795+
printf ' in front of you records 1, exactly as walking up to a free lock does. This\n'
1796+
printf ' column measures the queue, never whether the lock was held.\n'
17761797

17771798
# ⭐ The table this whole mechanism exists for. Ranked by TOTAL seconds held,
17781799
# not by the worst single run: the command that decides how much the fleet
@@ -2545,6 +2566,14 @@ mode_self_test() {
25452566
"$(grep -c 'outcome=command-exit' "$realled" 2> /dev/null || true)" 1
25462567
st_case 'and the record carries the wait, the hold and the queue depth' \
25472568
"$(grep -c 'waited=[0-9]* held=[0-9]* depth=' "$realled" 2> /dev/null || true)" 1
2569+
# ⛔ THE RECORDED FIELD IS PINNED AT ITS FLOOR, on purpose. The run above was
2570+
# uncontended, and it still records 1, because the depth is read after this
2571+
# call has minted its own ticket. That is the value `--report`'s heading now
2572+
# describes, and the repair for the heading being wrong was the heading --
2573+
# subtracting one HERE instead would read better for a day and then put a
2574+
# meaning boundary through the middle of a ledger nothing can re-date.
2575+
st_case 'and the depth it records counts the arriving run itself — floor 1, never 0' \
2576+
"$(grep -c ' depth=1 ' "$realled" 2> /dev/null || true)" 1
25482577
st_case 'and exactly one record per run, not one per verdict line' \
25492578
"$(wc -l < "$realled" | tr -d ' ')" 1
25502579

@@ -2578,6 +2607,22 @@ mode_self_test() {
25782607
"$(bash "$SELF" --report 2>&1 | grep -c 'LOWER-BOUNDS that mixture')" 1
25792608
st_case 'and names the newline flattening, which no label length can recover' \
25802609
"$(bash "$SELF" --report 2>&1 | grep -c 'flattened to a space BEFORE the cut')" 1
2610+
# The arrival-depth heading, which said "waiters already ahead" over a number
2611+
# whose floor is 1 -- so an idle fleet read as one-deep on every row and a
2612+
# reader had no way to tell whether the label or the record was the wrong one.
2613+
# The last case is the one that would have caught it: asserting only that the
2614+
# true wording is PRESENT would also pass on a report that kept the old
2615+
# heading beside it, and the defect was a heading, not a missing sentence.
2616+
local rpt
2617+
rpt="$(bash "$SELF" --report 2>&1)"
2618+
st_case 'and --report says the arrival depth counts the arriving run itself' \
2619+
"$(printf '%s\n' "$rpt" | grep -c 'the arriving run INCLUDED')" 1
2620+
st_case 'and hands over the conversion rather than leaving it as arithmetic' \
2621+
"$(printf '%s\n' "$rpt" | grep -c 'waiters already ahead = this minus 1')" 1
2622+
st_case 'and blocks the next misreading: 1 is not evidence the lock was free' \
2623+
"$(printf '%s\n' "$rpt" | grep -c 'it does not count the HOLDER either')" 1
2624+
st_case 'and the off-by-one heading itself is gone, not merely annotated' \
2625+
"$(printf '%s\n' "$rpt" | grep -c 'waiters already ahead):')" 0
25812626
# A measurement apparatus that can redden a gate has become part of the thing
25822627
# it measures. This is the case that keeps it out of the way.
25832628
st_case 'an unwritable ledger loses records, never runs' \

0 commit comments

Comments
 (0)