Placeable capacity phase 4: shape holds, consumption, release and displacement¶
Prompt¶
Before responding to questions or discussion points in this document, explore the shakenfist codebase thoroughly and ground your answers in what the code actually does today. Do not speculate when you could read instead. Flag uncertainty explicitly.
This is phase 4 of PLAN-placeable-capacity.md. Read that master
plan's "Phase 4: shape holds — consumption, release and
displacement" section first, its G3, G5, G6, G7 and G8
requirements, its What a hold promises, and what it does not
section, and phase 0's D7, D9 and D15
(PLAN-placeable-capacity-phase-00-decisions.md). D7's
Consumption edges and Left to the implementing phases
paragraphs are the list of questions this plan answers; D9's
Left to phase 4 paragraph is the second list. Read phase 3's
plan (PLAN-placeable-capacity-phase-03-holds-schema.md) D1,
D4, D6, D10 and its Results: this phase writes to the schema
and the counters that phase built, and its arithmetic only closes
if phase 3's reconciler fold is understood.
Several plans number their decisions D-something, and the
numbers collide. In this file, a bare Dn is a decision of
this phase plan. A decision of
PLAN-placeable-capacity-phase-00-decisions.md is written
"phase 0's D7". A decision of
PLAN-placeable-capacity-phase-03-holds-schema.md is written
"phase 3's D10". A decision of shakenfist/private-ci's
PLAN-placeable-claims phase 0, which the master plan calls the
brief, is written "the brief's D3". A decision of
PLAN-scheduler-reservations.md is written "scheduler-reservations
D14".
Citations below are into develop at 7cb1f24ec4 unless stated
otherwise.
Planning effort¶
High, as the master plan specifies, and the review effort is high
too. This phase is where holds become reachable, and three of its
changes are on the path every instance create in the cluster
takes: the node guard's arithmetic for a consuming create, the
candidate list a create walks, and the transient classification a
refusal publishes. Each has a silent failure mode. Guard
arithmetic that moves the wrong amount between used_* and
held_* hands the same room out twice without any single
statement looking wrong. A candidate reorder applied when it
should not be defeats the deliberate spread (shakenfist#3937) for
every create in the cluster, and nothing fails. A refusal
classified transient when no retry can clear it makes callers
replay an impossible request until their deadline, which is the
exact regression TRANSIENT_CAPACITY_STAGES' own comment exists
to prevent. So the DoD items here are mostly arithmetic
identities and mutations rather than feature checks.
Scope¶
In:
- A REST surface for holds: booking a multiset of shapes onto a
claim, listing a claim's holds, releasing one (
D1). - Implicit best-fit consumption (
G3): the comparator (D3), the candidate resolution and reorder (D2), and the guarded statement that moves a hold's room fromheld_*toused_*and records the consuming instance (D6). - The optional explicit hold reference on
POST /instances, with phase 0D7's409reason tokens and its404for another namespace's hold (D5). - A held instance's delete returning its hold, booked where the
instance was, and a move carrying its booking (
D6). - Re-placement or displacement when a node loses its capacity row
(
D7), and the reporting that makes a displaced hold actionable (D8). - Ground-truth overbooking: reported by the reconciler, not
prevented (
D9). - One schema change, added mid-phase:
namespace_claim_holdsgainsdisplaced_fromand the table reaches version 2. Step 4h found thatD8asked for a field nothing recorded; see Execution notes for why it is a column rather than a dropped field, and why now was the last moment it was cheap. - One new refusal stage for a node refusal that held room alone
caused, classified as neither transient nor permanent (
D4). This is the master plan's open phase-4-or-phase-5 question, andD4answers it. - The capability token for
A, advertised once consumption and displacement both work (D10). - Operator and developer documentation of all of the above, and
the removal of
docs/operator_guide/scheduler.md:494-498's "there is currently no operator-facing way to create a hold".
Out:
- The held-create refusal fields — naming the hold and saying
it was retained (
G7). Phase 5. This phase ships the classification a capability cannot honestly ship without, and nothing more of the contract; seeD4. - The claim 507's
stage/transient/Retry-Aftercontract, and the issue that needs filing for it. Phase 5, andF4records that the gap is still real. sf_claim,sf-clientand the user-guide shape and affinity expression (G4, phase 0'sD11). Phase 6. A holder in this phase books holds withcurlor with a client written against the API, which is what the capability token is for.- Hard claim enforcement. It landed outside this plan while
phase 3 was in flight; see
F1. Nothing in this phase touchesCLAIM_ENFORCEMENT_HARDandG6's node-guard switch stays apart from it. - The admin-scoped hold for evacuate (phase 0's
D10, issue #1364), and gang create (B). - The disk ledger in the placement pre-filter. Phase 3's
D11declined it and the master plan's Future work carries it; this phase declines it again for the same reason and adds no ledger term to_has_sufficient_disk()(shakenfist/scheduler.py:1226). - Affinity re-evaluation for a hold.
F3is why this is not a gap: it is already done, by the filter that built the candidate list.
What the survey found¶
Citations are into develop at 7cb1f24ec4. Every line number
the master plan and phase 0 carry for this phase has moved —
mariadb.py alone gained about 1,900 lines in phase 3 and a
further 1,300 in scheduler-reservations phase 5b — so the
numbers below replace them rather than supplementing them.
F1. Hard claim enforcement has landed, and the master plan's
S1 is now wrong. S1 reads "Claim limits are advisory.
CLAIM_ENFORCEMENT_HARD is False". It is True
(shakenfist/mariadb.py:29312), flipped by
PLAN-scheduler-reservations-phase-05b-hard-ceiling.md in 31f3350c1c
(#5087) on 2026-11-26, three days after phase 3 landed. Two
consequences, both good for this phase and neither anticipated by
it. First, the master plan's Out of scope entry "Hard claim
enforcement (CLAIM_ENFORCEMENT_HARD). That is
scheduler-reservations phase 5" describes a future that has
happened; it is still out of scope for this phase, but as a fact
rather than as a pending change. Second, G6's insistence that
the node guard's switch and CLAIM_ENFORCEMENT_HARD "stay apart"
is now testable rather than hypothetical: both are on, and a test
can assert that a hold binds a namespace whose own claim has room
to spare. The planning commit corrects S1 and the Out of scope
entry at source.
F2. The claim-denial split phase 5 was to "state" has been
built, which narrows phase 5 and changes G5. The master plan
has phase 5 "state the split of claim denials out of the transient
stages that flipping CLAIM_ENFORCEMENT_HARD would require". 5b
did not state it, it shipped it: CAPACITY_CLAIM_STAGE =
'capacity_claim' exists (shakenfist/constants.py:335),
deliberately classified in neither TRANSIENT_CAPACITY_STAGES nor
PERMANENT_CAPACITY_STAGES so that
capacity_refusal_is_transient() answers False
(:356-406); a walk refused at the claim stage on every candidate
is answered 403 through _claim_only_denial()
(shakenfist/external_api/instance.py:726-757) and
claim_capacity_error() (shakenfist/external_api/base.py:295);
and docs/operator_guide/capacity_refusals.md:58-63, :139-147
and :158-220 document it. That is a precedent this phase follows
exactly (D4) and it is also why G5's "No new refusal stage
names" cannot be read literally any more — a stage was minted
after G5 was written, for the same structural reason this phase
needs one. The planning commit restates G5 at source as what it
was protecting: no stage renamed or repurposed, and a new stage
only where the transient classification requires one.
F3. A hold needs no affinity evaluation of its own, because
the candidate list has already done it. Phase 0's D7 says
"Affinity is tested at consumption instead: a hold whose node does
not satisfy the create's require_* constraints is not a match",
and leaves phase 4 to implement that test. There is nothing to
implement. _satisfies_hard_affinity()
(shakenfist/scheduler.py:986-1026) runs inside the filter
pipeline that produces the candidate list, so every node reaching
Instance.place_on_candidates()
(shakenfist/instance.py:1605) already satisfies the create's
hard affinity. Restricting hold matching to nodes in that list
therefore satisfies G3's "on a node satisfying any hard affinity
it has" by construction, and a second affinity evaluation against
a hold's node would be a second implementation of the rule — the
thing _satisfies_hard_affinity()'s own docstring says it exists
to prevent ("so a filter and a scorer cannot disagree about what
counts as a neighbour"). D2 takes this as its premise and the
plan asserts it with a test rather than assuming it.
F4. The claim 507 still carries no machine-readable contract,
and the issue still does not exist. The master plan's S1 and
phase 5 both rest on this. CLAIM_REFUSAL_STATUS and
CLAIM_REFUSAL_MESSAGE (shakenfist/external_api/auth.py:2144-2169)
map a refusal reason to a status and a prose message, and
_claim_dimension_detail() (:2184-2205) still "goes in the
message" because "sf_api.error() carries a message and nothing
else". No stage, no transient, no Retry-After. Unchanged and
still untracked; phase 5 owns filing it.
F5. Phase 3's hold API is reachable from the object layer and
from sf-database, and from nothing else. NamespaceClaim.book_holds()
(shakenfist/namespace_claim.py:383), .holds() (:457) and
.release_holds() (:461) exist, backed by book_claim_holds()
(shakenfist/mariadb.py:34052), get_namespace_claim_holds()
(:34084) and release_claim_holds() (:34097) with their
_direct_* implementations at :32931, :33149 and :33266.
No file under shakenfist/external_api/ mentions a hold, and the
claim's serialised view (claim_example,
shakenfist/external_api/auth.py:2096-2115) has no hold field.
API_CAPABILITIES (shakenfist/external_api/app.py:456) carries
placement-query for C (:605-615) and nothing for A.
Phase 3's D6 is intact: the premise of this phase holds.
F6. The node guard's comment names this phase's job
precisely, and the arithmetic it describes is the right one.
_claim_node() (shakenfist/mariadb.py:30736-30771) guards on
used_* + held_* + request <= limit_* and its comment says "a
create that is consuming a hold -- the one case where room moves
from one counter to the other -- does not exist yet. Until it
does, decrementing held_* here would hand the same room out
twice". Phase 3's reconciler fold (_reconcile_fetch_held(),
:28574) totals size - consumed_request per node, so an
unconsumed hold contributes its whole size and a consumed one its
residue. Those two facts together fix the consuming create's
arithmetic without a choice being left open, and D6 states it as
an invariant.
F7. The denial detail already distinguishes held room from
used room, so the stage D4 adds is derivable rather than
guessed. CapacityDimensionDetailDict.held
(shakenfist/mariadb.py:29349-29359) is present on the node
stage's allocation dimensions only, and its comment states the
relationship this phase relies on: "The node guard charges both,
so used is their sum and this says how much of it a holder has
reserved -- the distinction between a node which is full and a
node which is booked, which an operator acts on differently." A
dimension was refused by held room alone exactly when
used - held + requested <= limit < used + requested.
F8. A hold on a node that loses its capacity row is left
pointing at that node, contributing to nothing. The reconciler's
removals list (shakenfist/mariadb.py:28930-28935) deletes the
capacity rows of nodes that are no longer active hypervisors with
fresh metrics, and the held fold's comment says so in terms:
"Asking only about the nodes this loop writes is also what leaves
a hold booked on a node that has left service contributing to
nothing, without anything having to touch the hold row"
(:28938-28945). That is phase 3's deliberate deferral and it is
D7's starting point. Phase 0's D9 is confirmed: the trigger is
the loss of the row and not a state test, and the same pass
computes both.
F9. There is no overbooking concept anywhere. grep -ri
overbook over shakenfist/ and docs/ outside docs/plans/
finds nothing. The master plan's "ground truth wins and the node
is then overbooked, which the reconciler records" describes
reporting that does not exist; enforce=False already books past
holds, because it reduces each guard WHERE to its key equality
(shakenfist/mariadb.py:30505-30512). D9 builds the recording
half only.
F10. Candidate lists are node uuids, not names.
Instance.place_instance(location)
(shakenfist/instance.py:1427) passes location straight through
_admit_placement() (:1250) as node_uuid, and
_direct_admit_instance_placement() parses it with UUID()
(shakenfist/mariadb.py:30551). So a hold's node_uuid column
and a candidate are the same denomination and D2's match needs
no translation. Worth stating because the operator-facing
vocabulary is node names, and a reorder keyed on the wrong one
would silently match nothing.
Nothing else the master plan or phase 0 claims about this phase
was found to be wrong. Phase 0's D7 lifetime rules, its
consumption edges, its rejection of releasing a hold when its
instance is deleted, and its 409/404 statuses all still
describe code that behaves as they say. The master-plan
corrections F1 and F2 require are made in the planning commit,
in the master plan's S1, G5, phase 4 bullet, phase 5 bullet and
Out of scope section, and in the docs/plans/index.md row.
Decisions¶
D1. Holds are a sub-resource of a claim, not a key on it¶
POST /auth/namespaces/<namespace>/claims/<claim_ref>/holds books
a multiset of shapes; GET on the same path lists the claim's
holds; DELETE
/auth/namespaces/<namespace>/claims/<claim_ref>/holds/<hold_ref>
releases one. All three are admin-scoped and namespace-owned,
behind the same decorator stack the claim endpoints already carry
(shakenfist/external_api/auth.py:2301-2537).
The booking body is the shape vocabulary this API already
publishes — api_base.SHAPESPEC_SCHEMA, registered as the
arrayofshapespec argument type: cpus, memory in megabytes,
and disk as either disk already summed in gigabytes or
disk_spec in the form a create takes it, summed through
mariadb.disk_spec_virtual_gb() exactly as
PlacementShape.from_instance() does
(shakenfist/scheduler.py:149-156). count expands to that many
identical holds, bounded by MAX_PLACEMENT_SHAPES. The handler
converts to the {cpus, memory_mb, disk_gb} dict book_holds()
takes; hold responses keep publishing memory_mb and disk_gb,
which is what the hold row carries.
This decision originally named the object layer's dict as the
wire shape, and that was wrong. SHAPESPEC_SCHEMA's own comment
(shakenfist/external_api/base.py:1386-1391) says its keys are
POST /instances' words "because a shape has to mean one thing
across the API, the CLI and the Ansible collection, and the claim
verbs will publish the same vocabulary" — written by phase 2,
anticipating this route — and its additionalProperties: False
exists to buy "the human who typed memory_mb an error". Naming
memory_mb on the wire would have shipped that typo as the
contract and broken G1, which is the requirement this decision
cites. Step 4a's execution note records the correction.
affinity is a published key of that schema and is refused
with a 400, naming where affinity is actually evaluated. Phase 0's
D7 is explicit that a hold carries none: a booking made before
any instance exists has no neighbours to match, and the affinity a
create is filtered against is its own, applied when it consumes
the hold (F3). Accepting a document that then bound nothing
would promise a placement rule the booking cannot keep. The
refusal is documented in the parameter description and in the 400
of the published spec, so the OpenAPI contract does not claim to
take it.
Booking is all or nothing, as book_claim_holds() already is. The
two refusal reasons book_holds() raises -- a claim booking past
its own limits, and a node with no room left -- join
CLAIM_REFUSAL_STATUS as 507s, which that method's docstring
asks of "whatever adds that route". A set no node can host raises
the scheduling stage's own exception, which that docstring says is
"deliberately not translated here", so the handler translates it
with capacity_error() and the refused shape's index; without
that an unplaceable booking is a 500.
Rejected: a shapes key on claim create and update. It reads
like one round trip and is not one. _direct_book_claim_holds()
(shakenfist/mariadb.py:32931) is its own transaction, deliberately
— phase 3's D3 put the holds table last in the canonical write
order and gave booking its own guarded invariant — so a claim
create carrying shapes either leaves a claim with no holds when the
second transaction fails, or requires folding the booking into the
claim transaction, which is a schema-order change phase 3 declined
with reasons. Phase 0's D7's "a hold is created with its claim"
is a statement about a hold's lifetime, which the sub-resource
preserves exactly: the hold still ends with its claim.
Rejected: no release verb at all. Phase 0's D7 gives a hold
three endings — claim delete, expiry, shrink — and none of them
lets a holder give back one hold. release_claim_holds(hold_uuids=
...) is already built and unreachable, three G2 callers rebuild
their fleets on a schedule, and a holder forced to shrink its whole
claim to return one booking would have to re-grow it afterwards
against a cluster that may have taken the room. One DELETE is
cheaper than that and costs nothing new below the API.
Deferred to phase 6: the one-round-trip convenience. sf_claim
is declarative and composes create-then-book into one task, which
is where a holder actually wants it.
D2. Hold matching reorders the candidate list; it never bypasses a filter¶
Before the candidate walk, the create resolves the namespace's unconsumed holds against the candidate list it already has, and walks the candidates that carry a matching hold first, in their existing scheduler rank order, followed by the rest in theirs. The walk itself, the admission transaction and every live check are unchanged.
Three reasons this is the shape, rather than asking per candidate inside the walk as it stands:
- Asking per candidate without reordering makes a held create
unheld whenever the ranker put a hold-free node first — and the
ranker deliberately spreads allocation away from the most
committed nodes (shakenfist#3937), which is precisely the
behaviour phase 0's
D15identifies as what turns aggregate headroom into per-node fragments. A hold that the scheduler's own preference routes the create away from defends nothing, andD15says a hold must defend a slot for a shape on a node. - Reordering is a preference, and the candidate list is already
nothing but a preference:
find_candidates()filters against a metrics snapshot up to a minute stale andplace_on_candidates()'s docstring says so in terms (shakenfist/instance.py:1607-1615). The real decision is still the guardedUPDATE. A hold taken by another create in between loses the race there and the walk falls through to the next candidate, or the create becomes unheld — phase 0'sD7's "Two creates cannot take one hold", unchanged. - It satisfies
G3's affinity clause for free, byF3.
Rejected: force the hold's node to the head of the list,
skipping the filters. The live checks are the only guard against
the OOM kills that set RAM_OVERCOMMIT_RATIO to 1.0, and the
master plan's What a hold promises section rejects skipping them
for held creates outright.
Rejected: reorder unconditionally. A namespace with no
unconsumed holds must see a byte-identical candidate list, or this
phase has changed placement for every create in the cluster to
serve a feature nobody in that namespace is using. DoD item 2
asserts it.
Cost: one read of the namespace's unconsumed holds per create in
a namespace that holds an active claim, which is an indexed read on
idx_namespace_claim_holds_claim after the claim row the create
already reads. A namespace with no active claim does not read at
all. Measure it rather than assume it; if it is hot, the place to
cache is the claim probe the admission path already takes
(_probe_admission_rows(), shakenfist/mariadb.py:30224), not a
new cache.
D3. Best fit, and the tie-breaks phase 0 left open¶
Among the unconsumed holds of the namespace's active claim that
sit on one candidate node and that the create fits within on all
three dimensions, the chosen hold is the smallest by memory, then
by vCPUs, then by disk, then the oldest by created_at, then
by uuid.
G3 fixes the first three. The fourth is this plan's and
oldest-first is chosen because it is the mirror of the shrink
rule's newest-first (phase 3's D1 made created_at microsecond
precision specifically so that rule has a resolution), so one
ordering key governs both ends of a hold's life and a reader who
knows one knows the other. The uuid is the final tie-break for the
reason phase 3's column comment gives: stable, and only reached
when two bookings share a timestamp to the microsecond.
A create larger than every hold on the node is an unheld create
there, which is phase 0's D7, and it may still find a hold on a
later candidate — the reorder in D2 puts hold-bearing candidates
first but does not assert that every hold on them fits.
D4. A node refusal that held room alone caused gets its own stage, and this phase carries it¶
This answers the master plan's open question — "either phase 4 carries it, or phases 4 and 5 swap. That choice is this plan's and is not yet made." Phase 4 carries it. The phases do not swap.
CAPACITY_HELD_STAGE = 'capacity_held' is added to
shakenfist/constants.py beside CAPACITY_CLAIM_STAGE (:335),
classified in neither TRANSIENT_CAPACITY_STAGES nor
PERMANENT_CAPACITY_STAGES, so capacity_refusal_is_transient()
answers False by the absence rather than by an entry — exactly
as capacity_claim is, and documented in the same place and the
same words. It is published as a 507 with transient: false and
no Retry-After: the cluster genuinely has no room for this
caller, which is a 507 and not a 403, but no wait on the
caller's part can change it.
It is published only when every candidate's denial was a node
denial that held room alone caused, by the test F7 gives:
used - held + requested <= limit < used + requested on at least
one dimension of that candidate, and no dimension exceeded without
held room. A mixed walk — any candidate short on real use, on the
cluster guard, or on the claim — stays capacity_guard and stays
transient. That is _claim_only_denial()'s reasoning transplanted
(shakenfist/external_api/instance.py:726-757), and it is the
conservative direction: a cluster that is genuinely full must not
be reported as one that is merely booked.
Why it cannot wait for phase 5. The capability token ships in this
phase, so the first held refusal any caller meets ships in this
phase too. transient is derived from the stage alone and
deliberately so —
capacity_refusal_is_transient()'s docstring: "the alternative --
a transient= argument at each call site -- puts the
classification somewhere it can be got wrong once per caller" —
so there is no way to make a capacity_guard refusal
conditionally non-transient without undoing that design. The
alternative orderings are both worse: minting nothing tells every
caller to retry a refusal no retry clears, which is the regression
TRANSIENT_CAPACITY_STAGES' comment exists to prevent; swapping
phases 4 and 5 asks phase 5 to write the refusal fields of a held
create before a held create exists.
This is a departure from G5 as written ("No new refusal
stage names: a held create's refusal adds fields rather than
minting stages, so callers that switch on stage keep working"),
and the departure is deliberate. G5 was written on 2026-11-04
and overtaken on 2026-11-26, when 5b minted capacity_claim for
this same structural reason (F2). G5's substance — that a
caller switching on stage keeps working — is preserved: no stage
is renamed or repurposed, capacity_guard keeps meaning what it
means, and a caller that does not know capacity_held reads it
through the transient field it already reads, which is the field
the retry decision is actually made on. The planning commit
restates G5 in the master plan to say that.
Not in this phase: the held-create refusal fields of G7 —
naming the hold, saying it was retained. Those describe a create
that had a hold and was refused on a live check, which is a
different refusal from this one, and they are phase 5's.
D5. The explicit reference, its statuses and where the reason rides¶
One new optional body parameter on POST /instances, named
hold, carrying a hold uuid and nothing else (phase 0's D7).
It is answered by a handler guard block before Instance.new(),
which is where
docs/developer_guide/writing_an_endpoint.md says a guard for a
new body key belongs and where every other body parameter of that
handler is answered.
- A uuid that is not a hold of the request's namespace's active
claim is
404, with a body that names neither the hold's owner nor whether the uuid exists. That is phase 0'sD7andarg_is_claim_ref()'s reasoning (shakenfist/external_api/auth.py:2261). - A hold that exists but cannot be honoured is
409with a reason token in its ownreasonkey besideerror. The tokens areconsumed,displaced,too_smallandnode_not_a_candidate. Phase 0'sD7listedaffinityas the fifth;node_not_a_candidatereplaces it and is wider on purpose, because byF3andD2the one question that can be asked is whether the hold's node is in the candidate list this create built, and a node can be absent from it for affinity, for a live check, for queue depth or because it has left service. A token that saidaffinitywhen a node was dropped on idle memory would be a lie a caller would act on. - Phase 0's
D7also listedexpired. It is unreachable and is not minted: an expired claim's holds are released by the reconciler's sweep (phase 3 shipped it), so the row is gone and the answer is404.
A reason token in its own key rather than folded into the message,
because F4 is a live example of what folding costs: the claim
refusal's per-dimension detail has been prose since it was written
and phase 5 now has to unpick it.
D6. used + held is invariant across consumption and across a held instance's delete¶
This is the arithmetic the whole phase turns on, and it is stated as an invariant so that a test can assert it rather than a reader having to re-derive it.
A hold charges its node its full size for its whole life. Phase 3
built that: an unconsumed hold contributes size to held_* and
a consumed one contributes size - consumed_request, through
_reconcile_fetch_held() (shakenfist/mariadb.py:28574), while
used_* carries the instance. So:
- Consumption moves exactly the create's request:
held_* -= request,used_* += request,instance_uuid = <instance>, in the one statementG6requires, inside the admission transaction.used + helddoes not move. - The guard for a consuming create is therefore
used_* + held_* <= limit_*— the+ requestterm drops out, because the room is already booked. A consuming create cannot be refused by a node-guard allocation dimension on the node its hold is on, which is the whole point of a hold. It can still be refused on theD13demand clause and dropped by the live pre-filters, which is exactly what the master plan's What a hold promises says a hold does not cover. - A held instance's delete reverses it:
used_* -= request,held_* += request,instance_uuid = NULL, in_direct_release_instance_placement()'s existing transaction (shakenfist/mariadb.py:30934).used + helddoes not move, the hold returns to unconsumed booked on the node the instance was last on — phase 0'sD7— and keeps binding other namespaces without a gap. - A move carries the booking: the hold's
node_uuidfollows the instance, and theheld_*residue moves with it in the same transaction as theused_*transfer the move already does.
Every decrement is floored with the form _floored_node_decrement()
uses (:30037), for the same reason it is: a counter the
reconciler has not yet corrected must not go negative.
Note what moves, because an earlier draft of this paragraph got it
wrong and the wrong version is the plausible one. Both counters
move by the request, never by the hold's size. Consumption
takes the request out of held_* and puts it into used_*; a
delete puts the same amount back. The hold's size appears nowhere
in either statement -- what is left in held_* while the hold is
consumed is its residue, which phase 3's fold already computes as
size - consumed_request and which no statement here has to
restate. Worked, with step 4b's own live figures: a hold of
8/8192/80 consumed by a 2/2048/20 instance leaves held_* at
6/6144/60 and used_* at 2/2048/20, and the delete restores
held_* to 8/8192/80 by adding back the 2/2048/20 it lent. The
draft said the delete raises held_* by the hold's full size,
which would add the residue to the node's charge a second time on
every delete and break the identity this decision exists to state.
DoD item 1 asserts that identity at both transitions with a hold
strictly larger than its instance, which is the case the arithmetic
is easy to get wrong in -- as this paragraph demonstrates.
D7. Re-place inside the ledger, displace otherwise, and never retry¶
Phase 0's D9 fixes the trigger: a node losing its
scheduler_node_capacity row in the reconciler pass, which is the
removals list at shakenfist/mariadb.py:28930-28935. In that
same pass and transaction, for each unconsumed hold whose node
is in removals, largest first and oldest first among equals
(settled at the gate; see Execution notes, which records why the
original "most recently booked first" was wrong):
- Re-book it onto a node that still has a row and fits it on the
ledger —
used_* + held_* + size <= limit_*— updatingnode_uuidand the two nodes' counters. - Otherwise set
node_uuid = NULL: displaced. Inside its claim's aggregate limits, booked on no node, reported, never dropped and never re-tried by the server. The holder re-books.
Why largest first. Re-placement's job is to lose as few bookings as possible, and trying the hardest one to fit while the remaining room is least fragmented is the standard reason -- a first-fit-decreasing walk. Ties go to the booking held longest, which is the same reasoning the shrink's release order uses from the other end: the bookings a holder has had longest are the ones it is most likely to be relying on, so a shrink gives back the newest and a re-placement saves the oldest.
Re-placement is a ledger fit, not a scheduling decision. The
reconciler runs inside sf-database and must not call the
scheduler; it has capacity rows and nothing else. So re-placement
consults no live check, no affinity and no ranking. That is a
narrower test than find_candidates_for_shapes() would make, and
it is the honest one: a hold promises the ledger, so a hold
re-placed on the ledger promises exactly what it promised before.
Among nodes that fit, the one with the most free limit - used -
held is chosen, so a displaced batch spreads rather than piling
onto the first row the pass happens to read.
A consumed hold is never re-placed or displaced. Its room is
in used_* and its instance is on the departed node; the instance's
own fate (the cleaner, a restore, a delete) is what moves it, and
moving the hold out from under it would decouple the two. DoD
item 9 asserts it.
Each outcome is an event on the claim, with the node it left and
why, in the vocabulary phase 3's _event_released_holds() already
uses (shakenfist/namespace_claim.py:369-381). Events are emitted
by the caller from the reply fields, never from sf-database — the
convention _direct_admit_instance_placement()'s docstring states.
D8. A displaced hold is visible in three places¶
A hold booked on no node defends nothing, which is why phase 0's
D15 requires it reported rather than quietly retained as an
aggregate. It appears in:
- the claim's holds listing (
D1'sGET), withnodeempty, which is already how phase 3'sNamespaceClaimHoldRowspells it (shakenfist/mariadb.py:32554-32573); GET /admin/resources, as a cluster-level count and list of displaced holds with the node each left — not per node, because a displaced hold is on no node. That node had to be given a column. Displacement is the clearing ofnode_uuid, and no other column held it, so this bullet asked for something only the displacing pass knew;displaced_fromis what makes it readable afterwards, and step 4h added it;- the claim's event history, from
D7.
_summarize_resources()'s per-node fields are unchanged from phase
3, including phase 3's D4: disk_available is still not net of
held room. DoD item 11 keeps that regression out.
D9. Overbooking is recorded, not prevented¶
A ground-truth writer admits with enforce=False, which reduces
each guard WHERE to its key equality
(shakenfist/mariadb.py:30505-30512), so it already books past
holds. Ground truth wins: a guard cannot refuse a libvirt domain
that exists, and refusing to record it would leave the ledger
wrong, which is strictly worse. So this phase adds the recording
half only (F9): after the reconciler recomputes a node's
counters, a node with used_* + held_* > limit_* on any dimension
is reported — a counter, an event, and a field in GET
/admin/resources naming the node and the dimensions.
No hold is displaced for it. Displacing a holder's booking because a cleaner recorded reality would punish the holder for someone else's domain, and the overbooking resolves itself as the instances that caused it are deleted.
D10. One capability token, claim-shape-holds, advertised last¶
One token, in the auth family beside namespace-claims
(shakenfist/external_api/app.py:509-516), because a hold is a
property of a claim and D1's booking surface is the thing a
client cannot feature-detect any other way. It covers the create's
hold parameter too: a caller with no holds has no reason to send
one, so a client that checks the token before booking has checked
everything it needs.
Advertised in step 4i, after consumption and displacement both
work. G5 allows one string for A and A is not honestly
usable until a hold survives a node leaving service, so the token
is the last functional change in the phase rather than the first.
Rejected: two tokens, one for booking and one for the create's
reference. G5 says one.
Rejected: a ConditionalCapability (app.py:436). Holds need no
cluster configuration to work, so there is no predicate to make it
conditional on.
Step plan¶
Every step runs in this phase's worktree,
../shakenfist-wt-pc-p04, and they run strictly in sequence.
Two reasons, both learned in phase 3: pre-commit's stash is
repository-wide, so two agents in one worktree silently revert each
other, and a mutation run that overlaps a check leaves a killed
mutant in place with its own test gone quiet. One step at a time,
one tox/pre-commit at a time.
Steps 4b and 4c may not be reordered against each other or
against 4d: 4c calls what 4b builds and 4d reuses 4c's
resolution. Step 4e2 was inserted after 4e by the
management session, for a defect 4b introduced that the review of
4e found; it may not run before 4e, whose tests are what the
defect hid behind. 4i must be last of the functional steps, because it
is what makes everything before it reachable.
| Step | Effort | Model | Isolation | Brief for sub-agent |
|---|---|---|---|---|
| 4a | high | opus | none | The holds REST surface: book, list, release. Read D1 and F5, and phase 0's D7. Add three endpoints in shakenfist/external_api/auth.py, modelled on AuthNamespaceClaimsEndpoint (:2301) and AuthNamespaceClaimEndpoint (:2390) and carrying the same decorator stack those two do — @api_base.caller_is_admin, @requires_namespace_ownership, @arg_is_namespace, @arg_is_claim_ref (:2261), @api_base.log_token_use, and a @swag_from(api_base.swagger_helper(...)) block with a worked example beside claim_example (:2096). AuthNamespaceClaimHoldsEndpoint takes POST (a shapes body list, each {cpus, memory_mb, disk_gb} or {cpus, memory_mb, disk_spec}) and GET (the claim's holds). AuthNamespaceClaimHoldEndpoint takes DELETE of one hold. Routes go in shakenfist/external_api/app.py beside :753-758, as /auth/namespaces/<namespace>/claims/<claim_ref>/holds and .../holds/<hold_ref>. Do not add a capability token — that is step 4i. The handlers call NamespaceClaim.book_holds() (shakenfist/namespace_claim.py:383), .holds() (:457) and .release_holds() (:461) and must add no new database function: everything below the API exists. Sum a disk_spec with mariadb.disk_spec_virtual_gb(..., strict=True) and nothing else, mirroring PlacementShape.from_instance() (shakenfist/scheduler.py:149-156) — read that docstring's "two chances to disagree about how large a request is" paragraph first, because it is the reason. Validate the shapes through shakenfist/external_api/validation.py the way the create endpoint's body fields are, and refuse an empty list with a 400 rather than passing it to book_holds(), which raises ValueError (namespace_claim.py:421). A booking refused by the claim's own sum invariant is a 507 carrying the per-dimension detail the reply already returns; a DELETE of a hold that does not belong to this claim is a 404; a DELETE naming nothing is the exceptions.py:389 case and is a 400. Tests in shakenfist/tests/test_external_api.py (find the claim endpoint tests and mirror their fixture shape): booking writes holds and returns them; booking past the claim's limits is a 507 with the dimension named; listing a claim with no holds is [] and not a 404; releasing one hold leaves the others; a hold uuid from another claim is a 404; and the three routes are registered. Checks: tox -epy3, tox -eflake8, tox -emypy, then pre-commit run --all-files from the repository root. Commit subject: Book and release shape holds over the API. |
| 4b | xhigh | opus | none | The consuming admission: hold selection, the guard's exclusion, and the move in one statement. Read D3 and D6 in full, F6, F7, phase 3's D1 and D10, the block comment above _probe_admission_rows() (shakenfist/mariadb.py:30224) and the INVARIANT comment inside _direct_admit_instance_placement() before writing a line. D6 is the specification and its arithmetic is not negotiable: held_* -= request, used_* += request, instance_uuid set, one statement, used + held unchanged, and the guard for a consuming create loses its + request term because the room is already booked. Add an optional hold_uuid parameter to _direct_admit_instance_placement() (:30468) and through _grpc_* and the public admit_instance_placement() (:31342), plus the proto field on the admit request (protos/database.proto) and tox -e genprotos — a new field number, never reusing one. When it is set: inside the transaction and after the two scheduler_node_capacity updates, take the hold with a guarded UPDATE on namespace_claim_holds whose WHERE requires uuid = <hold>, claim_uuid = <the claim this create is charged to>, instance_uuid IS NULL, node_uuid = <node> and the three cpus/memory_mb/disk_gb >= request tests, setting instance_uuid and updated_at = NOW(6) (phase 3's D1 says why NOW(6)); a rowcount of zero is the lost race and must abort the transaction with a denial a caller can tell from a capacity denial, because the caller's next move is to fall through to an unheld create rather than to the next node. The claim_uuid term is defence in depth: the API layer resolves a reference namespace-scoped, and this tier must not depend on it having done so. Then _claim_node()'s guard drops + cpus/+ memory_mb/+ disk_gb from its three allocation clauses and its SET gains the matching held_* - request beside each used_* + request. The demand clause (_demand_guard_clause()) is unchanged — read D6's third bullet; a hold does not promise demand. Keep the canonical write order exactly as it is: the hold take goes last, after both node rows. An earlier draft of this row said the take must precede the node update because the node update's arithmetic depends on it. Both halves were wrong and the correction is load bearing. There is no data dependency -- the SET moves the request size, which the caller already knows, and never reads the hold row -- and inverting the order is a deadlock: the canonical order is cluster_capacity, namespace_claims, scheduler_node_capacity, then namespace_claim_holds (shakenfist/mariadb.py:32534-32540), _direct_book_claim_holds() follows it, and a consuming create that took hold rows first would invert the lock order against a concurrent booking on the same claim and node. Lost-race detection is unaffected, because a zero rowcount on a take that runs last still aborts the transaction and rolls the node charge back with it. Add no exception to that comment; the order needs no amendment. Do not touch _claim_capacity_guard() (:31711), the claim branch (:30660-30692) or the cluster branch (:30693-30719): a hold sits inside claimed, so the claim side is correctly blind to it. Also add a _direct_* selector for D3's best fit — unconsumed holds of a namespace's active claim, grouped by node, that a request fits within — as its own read function with its own gRPC and public wrappers, because step 4c needs it before it picks a node and the admission transaction is the wrong place to ask. Tests in shakenfist/tests/test_mariadb_capacity_holds.py and a live counterpart beside test_mariadb_capacity_claims_live.py: used + held is identical before and after a consumption, with a hold strictly larger than the instance on every dimension; a consuming create is admitted on a node whose used + held already equals its limit; the take's WHERE is asserted through _compiled() and the dispatching fake connection (shakenfist/tests/test_mariadb_capacity_admission.py:49 and :103), as that suite already asserts the claim UPDATE; two concurrent consumptions of one hold admit exactly one (the live test, the only place this is visible); a hold too small on one dimension is not taken; and an unheld create's guard is byte-identical to today's. Read docs/developer_guide/database_internals.md for running the live suite — it needs --serial. Checks as 4a. Commit subject: Consume a shape hold in the admission guard. |
| 4c | xhigh | opus | none | The create path: resolve holds, reorder candidates, thread the consumption. Read D2, D3, F3 and F10. In shakenfist/instance.py, place_on_candidates() (:1605) gains the hold resolution: with the candidate list in hand and before the walk, read the namespace's unconsumed holds grouped by node (4b's selector), pick each candidate's best-fit hold by D3's comparator, and build the reordered list — hold-bearing candidates first in their existing order, then the rest in theirs. Then place_instance() (:1427) and _admit_placement() (:1250) carry the chosen hold uuid for the candidate being tried. A lost-race denial appends that candidate to the end of the walk and carries on, so it still gets an unheld attempt but only after every node the ranker preferred. An earlier draft of this row said to re-try it immediately; that was wrong, because the reorder promoted the node above the ranker's preference on the strength of a hold that has now gone, and re-trying it first would defeat the deliberate spread (shakenfist#3937) for a booking that no longer exists. Re-trying it last keeps the node's ordinary room available without spending the spread on stale information. A lost-race denial must not enter the denials dict: that dict means "why this candidate refused the instance", _claim_only_denial() and 4f's _held_only_denial() both decide the published stage by inspecting every entry, and len(denials) is the refused count in the 507 message. A lost race is a retry signal, and 4b gave it a database-tier stage of its own ('hold') precisely so it can be told apart here. If the consumable read raises, let it propagate: silently turning a held create into an unheld one discards the guarantee the holder paid for, and this path already answers 503 for an unreachable database rather than claiming the cluster is full. Read place_on_candidates()'s docstring in full first: it documents the demand re-walk, and the note that "Only self.place_instance() is read from self here, which a preflight test double relies on" is a constraint this step must not break — the resolution must therefore take the namespace and the shape as arguments rather than reading more attributes off self. A namespace with no active claim does not read holds at all; a namespace with an active claim and no unconsumed holds gets the candidate list unchanged, and that is asserted rather than assumed. Record the consumed hold's uuid on the instance where the placement is recorded, in the placement attribute dict beside node (:1462-1479), so a reader of an instance can see which hold it took; it is written in the same _admit_placement() reply handling that already events the admission. Then the second placement walk: shakenfist/operations/node_inst_netdesc_op.py's preflight re-run (:302 is its refusal) goes through place_on_candidates() too, so it inherits the resolution for free — confirm that by reading it, and if it does not, say so rather than changing it. Tests in shakenfist/tests/test_instance.py and test_scheduler.py: a create in a namespace with a matching hold on the third-ranked candidate is placed there; the same create with no holds is placed on the first; a namespace with no holds gets an identical candidate list (assert the list, not the outcome); a create larger than every hold is placed as an unheld create and consumes nothing; a hold taken by a concurrent create makes this create retry the same node unheld; and the preflight walk honours a hold. Checks as 4a. Commit subject: Consume shape holds on the create path. |
| 4d | high | opus | none | The explicit hold reference on POST /instances. Read D5 and phase 0's D7's Consumption edges. Add one optional body parameter hold to the create handler in shakenfist/external_api/instance.py, as one more block in the chain of handler guards the handler already is (:745-757 region — read docs/developer_guide/writing_an_endpoint.md on where a body-key guard belongs), answered before Instance.new() so a refused reference creates nothing. Resolve it namespace-scoped against the namespace's active claim: not a hold of this namespace's claim is a 404 whose body names neither the owner nor whether the uuid exists, for arg_is_claim_ref()'s stated reason (shakenfist/external_api/auth.py:2261). A hold that exists but cannot be honoured is a 409 carrying D5's token in its own reason key: consumed (its instance_uuid is set), displaced (node_uuid is NULL), too_small (the request exceeds it on a dimension), node_not_a_candidate (its node is not in the candidate list this create built). Do not mint affinity or expired — D5 says why for each. A reference that resolves pins the walk to that hold's node and that hold alone: no implicit fallback, no other candidate, and a capacity refusal there is the ordinary refusal that node would give. Tests in test_external_api.py and test_instance.py: each of the four 409 tokens; the 404 for another namespace's hold, asserted on the body text as well as the status; a resolvable reference places on the hold's node and consumes it; a reference whose node the filters dropped is node_not_a_candidate and not a 507; and a create with no hold key behaves exactly as today. Checks as 4a. Commit subject: Take a named shape hold on instance create. |
| 4e | high | opus | none | The hold comes back when its instance goes, and travels when it moves. Read D6's third and fourth bullets and phase 0's D7's Rejected: release the hold when its instance is deleted — the hold row is not deleted here, it returns to unconsumed on the node the instance was last on. In _direct_release_instance_placement() (shakenfist/mariadb.py:30934), inside the existing transaction and after the node decrement, clear the consuming instance's hold: instance_uuid = NULL, updated_at = NOW(6), and held_* += request on that node to restore the hold's full contribution, floored with _floored_node_decrement()'s form (:30037) on the used_* side as it already is. Read that function's idempotency paragraph: the hold clear has to be idempotent in the same way, because the instance_location rows are the record of what is charged and a second release must touch no counter. For a move, _direct_admit_instance_placement() with old_node_uuid set carries the hold's node_uuid to the new node and moves its residue with the used_* transfer — one more statement in the pair of node updates that already run in uuid order (:30728-30735), under the same ordering discipline and for the same deadlock reason. Report what moved in the reply so the caller can event it, never eventing from sf-database. Tests in test_mariadb_capacity_holds.py and live: deleting a held instance leaves used + held unchanged on its node and the hold unconsumed and still booked there, with a hold strictly larger than the instance; a second release changes nothing; a delete-then-recreate in the same namespace takes the same hold back (this is the case three G2 callers depend on, so assert it end to end); a move carries the booking and leaves neither node double-charged; and a reconcile pass after each of those agrees with the counters. Checks as 4a. Commit subject: Return a shape hold when its instance is deleted. |
| 4e2 | xhigh | opus | none | A claim-level release of a consumed hold credits the residue, not the size. This step exists because the management session found and proved a defect step 4b introduced, and 4e did not reach: _release_hold_rows() (shakenfist/mariadb.py:33879) decrements a node's held_* by _hold_size() (:33368), the hold's full size, but once an instance consumes a hold only its residue is in held_* — the request is in used_*. Before this phase nothing could consume a hold, so size and residue were always equal and the function was correct; 4b made consumption real without revisiting it. Read D6, then _RECONCILE_HELD_SQL (:28544) end to end: GREATEST(0, h.cpus - COALESCE(i.cpus, 0)) and its JSON_TABLE disk subquery are the authoritative definition of a hold's contribution to held_*, and _hold_size() is a second, disagreeing one. The fix is to leave exactly one definition in the tree, not to add a third: give the residue its own helper next to _hold_size(), derive the decrement from it, and say in its docstring that the reconciler's SQL is the same expression in the other dialect so the next reader knows both must move together. Do not change _hold_size()'s own meaning — the claim-level arithmetic at :32763 and _holds_a_shrink_releases() (:32742) legitimately want the full size, because a hold's whole size is room inside its claim's limits whether or not an instance is drawing on it; confirm that by reading them rather than assuming it, and say either way. The residue needs the consuming instance's allocation, which the hold row does not carry. Read it on the probe connection where the caller already has one, or inside the transaction after its first write if the caller does not — a read there is allowed once the transaction has written (4e's own counter read-back does it, and the block comment at :30371 says why the first statement is the only one constrained) — and whichever you choose, say in a comment why that caller made that choice. Four callers pass hold rows without filtering out consumed ones and all four must end up correct: the claim expiry sweep (:28772), the shrink release (:33005), _direct_release_claim_holds() (:34026) and _direct_delete_namespace_claim() (:34186). Establish for _direct_release_claim_holds() whether the API already refuses to release a consumed hold; if it does, assert that rather than relying on it, and if it does not, it is in scope here like the others. The management session's proof, which the step must reproduce as a test before fixing anything: a claim with two bookings on one node, the older 4/4096/40 left unconsumed and the newer 8/8192/80 consumed by a 2/2048/20 instance, stands at used 2/2048/20, held 10/10240/100; shrinking the claim's limit_cpus to 4 releases the consumed booking alone and leaves held 2/2048/20, where the reconciler's own fold recomputes 4/4096/40 — short by exactly the instance's request, so the node under-reports its commitment and can over-admit by that much until the next pass. Single-claim cases are masked, because flooring at zero happens to give the right answer; the second claim's booking is the headroom that makes it visible, so every test here needs one. Tests in shakenfist/tests/test_mariadb_capacity_holds.py and test_mariadb_capacity_holds_live.py: that shrink case, asserting held_* against the reconciler's fold rather than against a literal; the same for expiry and for claim delete; a consumed hold whose instance has grown larger than the booking contributes zero rather than a negative (the GREATEST(0, ...) the fold already has); an unconsumed hold's release is byte-identical to today's, asserted on the compiled statements; and no clamp is reported where none is due, since the present over-decrement reports one and a reader could have learned to expect it. Checks as 4a, plus both live MariaDB versions. Commit subject: Credit a consumed hold's residue, not its size. |
| 4f | high | opus | none | The held-only refusal stage, and the classification that makes it honest. Read D4 in full, F2, F7, and shakenfist/constants.py:309-410 end to end — that passage is the design this step extends and its comments are the specification. Add CAPACITY_HELD_STAGE = 'capacity_held' beside CAPACITY_CLAIM_STAGE (:335), with a comment in the same register saying what it means, that it is a published API token, that it is a 507 rather than a 403, and that it is classified in neither set on purpose so capacity_refusal_is_transient() answers False by absence — the existing CAPACITY_CLAIM_STAGE comment is the model, down to the "the absence is the classification rather than an omission" sentence. Re-export it from shakenfist/external_api/base.py beside :230-231. Then add _held_only_denial(denials) to shakenfist/external_api/instance.py beside _claim_only_denial() (:727), which it mirrors in shape and in reasoning: it returns a denial only when every candidate's denial is failing_stage == 'node' and every such denial has at least one dimension for which used - held + requested <= limit < used + requested and no dimension exceeded without a held term — D4's test, written out of F7's identity. Publish it in the exhaustion branch (:1740-1767 on this branch, which 4c and 4d moved from where the row first cited it) after _claim_only_denial() and before the capacity_guard fallback, with the same shape: enqueue_delete_due_error(..., stage=...) so the refusal the instance carries and the refusal the client reads are the same fact (issue 4568), then capacity_error() (shakenfist/external_api/base.py:236), which already reads transient off the stage so no new argument is needed. The preflight abort in shakenfist/operations/node_inst_netdesc_op.py:297-308 records the same classification — check whether it can and say so either way. denials may contain a hold entry, and _held_only_denial() must tolerate it rather than assume every entry is a capacity stage. The implicit consumption 4c built never records one; the pinned reference 4d added does, at the database tier's own hold stage, because the handler reads it there to re-resolve the reference. That is safe today only because 4d's interception runs before the stage-publishing logic and returns in every branch -- so this step must not depend on that ordering for its own correctness. Decide deliberately whether a hold entry makes a walk not held-only, and say why in a comment. Rename and repurpose nothing: grep the diff for every existing stage string and confirm each is untouched, and confirm TRANSIENT_CAPACITY_STAGES and PERMANENT_CAPACITY_STAGES gained no member. Tests in test_external_api.py, test_instance.py and wherever capacity_refusal_is_transient() is tested: capacity_refusal_is_transient('capacity_held') is False; the stage is in neither frozenset; a walk whose every candidate was refused by held room alone publishes capacity_held with transient: false and no Retry-After; a walk mixing a held refusal with a genuine shortage publishes capacity_guard and is transient; a walk mixing held and claim denials publishes capacity_guard, not capacity_claim (the claim branch requires every denial, which this must not weaken); and the instance's recorded error_stage matches what the client was told. Checks as 4a. Commit subject: Publish a stage for a refusal held room caused. |
| 4g | xhigh | opus | none | Re-place or displace when a node loses its capacity row. Read D7, F8, phase 0's D9 in full, and the reconciler pass from shakenfist/mariadb.py:28698 onwards, in particular the removals list (:28930-28935), the held fold _reconcile_fetch_held() (:28574) and the comment at :28948-28955 that says a hold left booked on a departed node contributes to nothing, which is the deferral this step closes. Inside that same transaction and after removals is known but before the capacity rows are deleted (:29051-29054): read the unconsumed holds whose node_uuid is in removals and try them largest first, with created_at ascending among equals -- size descending over the three dimensions in the order disk_gb, memory_mb, cpus, which is the scarcest first on these nodes. For each, re-book it onto the node with the most free limit_* - used_* - held_* that fits it on all three dimensions, updating node_uuid, updated_at = NOW(6) and the destination's held_*; otherwise set node_uuid = NULL. Only unconsumed holds — a consumed hold is never touched here (D7, and DoD item 9 asserts it). Re-placement is a ledger fit only: no live check, no affinity, no ranking, and no call out of sf-database, which cannot reach the scheduler; say that in the code comment, because the next reader will ask. A hold re-booked onto a node changes what the next hold sees, so the free figures must advance with it: read each candidate node's counters once inside the transaction and carry a running tally in Python, decrementing as each booking lands, rather than re-reading the rows between bookings or deciding every booking from one initial snapshot. The transaction holds those rows' locks and the only writer is itself, so the tally cannot go stale; a re-read could only return what the tally already knows, at a round trip per booking inside a transaction holding capacity-row locks across the cluster. Deciding from one snapshot is the defect mutation 11 in step 4j exists to catch, so it must fail a named test. Return the two outcomes in the reconcile reply, per hold carrying its uuid, claim uuid, namespace, its three dimensions, the node it left and the node it landed on -- the last being empty for a displaced booking, which is deliberately the shape step 4h's displaced-holds report needs so the two agree without a translation in between. Do not add a per-dimension shortfall for a booking that fitted nowhere: the closest candidate's figure is near-meaningless when no node fits at all and an operator would read it as authoritative. The caller events them on the claim with _event_released_holds()'s vocabulary (shakenfist/namespace_claim.py:370); emit no event from sf-database. Add a Prometheus counter for each outcome beside the reconciler's existing ones. Tests in test_mariadb_capacity_reconcile.py and its live counterpart: a node going inactive re-places its holds onto a node that fits them and the destination's counters rise by exactly their sizes; a node going inactive with nowhere to fit displaces them and node_uuid is NULL with the claim's claimed_* unchanged; after any pass, no hold row names a node with no capacity row (assert it as a set difference over the two tables — that is the invariant this step exists to create); a consumed hold on a removed node is untouched; the largest hold is re-placed first and two of equal size go oldest first (assert the order, not just the outcome); a node that merely has stale metrics for one pass and returns is not treated as having left (RECONCILE_METRICS_MAX_AGE_SECONDS, :867); and the pass is idempotent. Checks as 4a. Commit subject: Re-place or displace holds when a node leaves. |
| 4h | high | opus | none | Report displaced holds and overbooked nodes. Read D8, D9, F9, and phase 3's D4 — which this step must not undo. In shakenfist/scheduler.py's _summarize_resources() (:676) add a cluster-level displaced_holds (a count and a list of {hold, claim, namespace, cpus, memory_mb, disk_gb, left_node}) and an overbooked_nodes list naming each node with used_* + held_* > limit_* and which dimensions. Cluster-level, not per node: a displaced hold is on no node. Do not change any per-node field phase 3 added, and in particular do not net held room out of disk_available (:894-900 records why) — DoD item 11 is a regression guard for exactly that. The reads go through the same accessors the summary already uses; add a _direct_* read with its gRPC and public wrappers for the displaced set if one does not exist, mirroring get_namespace_claim_holds() (shakenfist/mariadb.py:35237). Then the reconciler's overbooking detection: after the capacity-row upsert recomputes a node's counters (the loop ending at :29280, where step 4g built its free-room tally beside the same figures), flag a node whose used + held exceeds a limit, return it in the reply, and have the caller event it and bump a counter — one event per node per pass, not per dimension. No hold is displaced for an overbooking (D9). Update shakenfist/external_api/admin.py's example payload (:124-139 is where the held fields went) and every test that asserts over the summary payload's keys — find them with grep -rn "cpu_held" shakenfist/tests/ and extend rather than replace. Tests: the displaced list appears and is empty when nothing is displaced; an overbooked node is named with its dimensions; a node exactly at its limit is not overbooked; disk_available is unchanged by held disk (assert the negative case explicitly); and the cluster totals do not go negative. Checks as 4a. Commit subject: Report displaced holds and overbooked nodes. |
| 4i | medium | sonnet | none | Advertise A, and document all of it. Read D10, D4, D5 and F2. Add 'claim-shape-holds' to API_CAPABILITIES' auth family in shakenfist/external_api/app.py, beside 'namespace-claims' (:509-516), with a comment in that block's register saying what it covers — the holds sub-resource, the create's hold parameter, and the capacity_held stage — and that a client without it degrades to today's aggregate-claim behaviour. Change no other token and do not touch placement-query (:605-615). Then the documentation. docs/operator_guide/scheduler.md: replace :494-498's "There is currently no operator-facing way to create a hold" paragraph with how a holder books, lists and releases one, what a hold promises and what it does not (the master plan's What a hold promises section is the source, but write it in operator voice), best fit and its tie-breaks, and what displacement means for a holder — including that the server never re-books a displaced hold. docs/operator_guide/capacity_refusals.md: add capacity_held to the stage field list (:123-147), to the transient discussion (:10-63) and to the response-body section, following how capacity_claim is treated in each — it is the closest model and it is three weeks old. docs/developer_guide/subsystem_internals.md: extend the "Shape holds and the held counters" section (:442) with D6's invariant stated as an invariant, the consumption statement, the delete-return, and the re-place-or-displace rule; correct the sentence at :466 that says "Nothing sets the column yet". docs/operator_guide/database.md if it describes the holds table's columns. Both docs/developer_guide/database_internals.md:957 and docs/operator_guide/database.md:913 enumerate what one reconcile pass does and now omit the re-place-or-displace stage step 4g added; both lists need it, in each page's own voice. Step 4h added three more things no page yet describes: the displaced_from column and the holds table's version 2, and the two new cluster-level fields in GET /admin/resources, displaced_holds (with its degraded flag) and overbooked_nodes. docs/developer_guide/subsystem_internals.md:544 is the natural home for the last two; say for overbooked_nodes that the condition is recorded and never corrected, and that a node exactly at its limit is not overbooked. Do not name a plan or a phase number anywhere outside docs/plans/ — the Check documentation cites no plan phase numbers hook enforces it. Also extend the create handler's own published 507 description in shakenfist/external_api/instance.py so it names capacity_claim and capacity_held beside capacity_guard: it lists only the guard stage today, which was already incomplete before this phase, and adding one of the two without the other would invent a precedent. Leave AGENTS.md and ARCHITECTURE.md alone: no convention changed and no component was added. Tests: the capability test that enumerates advertised tokens. Checks: pre-commit run --all-files, with Check documentation links and anchors resolve passing. Commit subject: Advertise and document shape holds. |
| 4j | medium | sonnet | none | Prove the new assertions bite. Use the mutation-check skill's method over steps 4a-4h only. Each mutation is applied by replacement from a pristine copy held outside the worktree and restored in a finally — never with git checkout on a directory, which has discarded uncommitted work in this repository before — and each runs under timeout 900, one at a time, never beside a pre-commit run. Run the tests with python -B so a same-size mutant restored within a second cannot leave live bytecode behind. At least these sixteen. (1) The consuming guard keeps its + request term, so a consuming create is refused on a full node. (2) The consumption moves the hold's full size out of held_* instead of the request, so used + held falls. (3) The delete returns the hold's full size to held_* instead of the instance's request, so used + held rises on every delete and the node is charged the booking's residue twice. (The row previously had this the wrong way round -- it described the correct behaviour as the mutation, which would have changed nothing, failed no test, and been reported as a mutation no test caught. Crediting the request is right; mariadb.py's release is where to read it.) (4) The hold take drops instance_uuid IS NULL from its WHERE, so two creates take one hold. (5) The candidate reorder runs for a namespace with no holds. (6) The best-fit comparator orders by memory descending, so the largest hold is consumed. (7) The comparator's tie-break takes the newest hold, which should fail a named test. (8) _held_only_denial() returns a denial when any candidate was refused on real use, so a full cluster reports as merely booked. (9) capacity_held is added to TRANSIENT_CAPACITY_STAGES. (10) Re-placement considers consumed holds too. (11) Re-placement computes free room from one snapshot instead of recomputing, so two holds re-book onto room for one. (12) _summarize_resources() nets held room out of disk_available, which must fail phase 3's own negative test. Four more for work this phase added after the row was written. (13) _release_hold_rows() decrements a node by the hold's size instead of its residue -- the defect step 4e2 exists to fix, so it must fail a named test with a second claim's booking on the node, and the single-claim case must be shown not to catch it. (14) The re-placement leaves displaced_from set when it re-books a row, so a booking displaced, re-placed and displaced again carries a stale origin. (15) overbooked_dimensions() tests free <= 0 rather than free < 0, so a node exactly at its limit reports as overbooked. (16) The version 2 migration drops its AFTER node_uuid, so a migrated table's column order differs from a freshly created one -- which only the live test can see. Record which test failed and on which assertion for each, and compare the tree byte-for-byte against the pristine copy afterwards. Prefer the per-dimension variant of a guard mutation over the all-three variant, which phase 3's Results found cannot tell a per-dimension assertion from a whole-statement one. A mutation no test catches is a finding: report it with the test that should have caught it and do not write the test yourself. Change no file under shakenfist/. Commit subject: none — the management session records this in this plan's Results. |
Risks and mitigations¶
R1. The used + held arithmetic is wrong in a way no single
statement looks wrong for, and a node hands the same room out
twice. Consumption, delete and move each move room between two
counters, and each is correct only relative to what phase 3's
reconciler fold totals. A mistake does not fail: it shows up as a
node that over-admits, weeks later, as a capacity bug with no
obvious cause. Mitigation: D6 states the invariant rather than
the three statements, DoD item 1 asserts it at each transition
with a hold strictly larger than its instance (the case the
arithmetic is easy to get wrong in), every such test is followed by
a reconcile pass that must agree, and mutations 1, 2 and 3 in step
4j break each direction in turn. The management session re-runs
mutation 1 per dimension, not all three at once — phase 3's Results
record why.
R2. The candidate reorder changes placement for creates that
have nothing to do with holds. The ranker's spread is deliberate
(shakenfist#3937) and is load-bearing for the cluster's behaviour
under burst. A reorder applied too widely degrades every create in
the cluster, silently. Mitigation: D2 makes it conditional on
the namespace having unconsumed holds, DoD item 2 asserts the
candidate list itself — not the outcome — is identical for a
namespace with none, and mutation 5 removes the condition. The
reviewer checks that the resolution reads nothing when the
namespace has no active claim.
R3. A refusal is classified wrongly, in either direction.
Classifying a genuine shortage as capacity_held tells a caller
not to retry something a teardown would have cleared in seconds;
classifying a held refusal as transient makes it retry until its
deadline. Mitigation: D4's test is the conservative one — a
mixed walk stays capacity_guard — and it is derived from the
denial detail (F7) rather than from a heuristic. DoD items 3
and 4 assert both directions, including the mixed held-and-claim
case, and mutations 8 and 9 break each. The reviewer reads
shakenfist/constants.py:309-410 against the new comment and
confirms the register matches capacity_claim's.
R4. Re-placement inside the reconciler is a scheduling
decision in disguise. It picks nodes, and the reconciler cannot
reach the scheduler. A re-placement that silently promises more
than a ledger fit would make a hold mean different things depending
on how it got where it is. Mitigation: D7 states the narrow
contract and the code comment states it again; DoD item 8 asserts
the invariant the step exists to create (no hold names a node with
no capacity row) as a set difference over the two tables, which is
a property of the result rather than of the algorithm; mutation 11
breaks the accumulating recompute.
R5. The capability ships before the promise is whole. A's
token is what makes a caller build against holds, and a caller that
builds against a hold which silently stops binding when a node
drops out has been misled. Mitigation: D10 puts the token in
step 4i, after 4g. The reviewer checks the ordering held, and
DoD item 10 asserts the token is advertised and that nothing else
moved.
R6. Phase 5's scope is now ambiguous, because this phase
touches the refusal contract. D4 deliberately takes one piece
of it. Mitigation: D4's last paragraph and the Scope section's
Out list say exactly which piece, the planning commit narrows the
master plan's phase 5 bullet to match (and records in it that F2
has already done part of what it described), and DoD item 16
checks the master plan says so.
Definition of done¶
used + heldis invariant across consumption, delete and move. A test at each of the three transitions, each using a hold strictly larger than its instance on all three dimensions, asserts the node'sused_* + held_*is identical before and after, and a reconcile pass immediately afterwards reproduces the same counters. Mutations 2 and 3 in step4jfail these tests.- A namespace with no unconsumed holds sees an unchanged
candidate list. A test asserts the list
place_on_candidates()walks, element for element and in order, is whatfind_candidates()returned — not merely that the create landed on the same node. Mutation 5 fails it. capacity_heldis classified by absence.capacity_refusal_is_transient('capacity_held')isFalse, and'capacity_held'is in neitherTRANSIENT_CAPACITY_STAGESnorPERMANENT_CAPACITY_STAGES. A test asserts all three facts.- The classification is conservative in both directions. A
held-only walk publishes
capacity_heldwithtransient: falseand noRetry-After; a walk mixing a held refusal with a real shortage publishescapacity_guardand is transient; a walk mixing held and claim denials publishescapacity_guard. Three tests, and the instance's recordederror_stagematches the client's in each. - No stage was renamed or repurposed.
git diffovershakenfist/constants.pyaddsCAPACITY_HELD_STAGEand changes no existing stage string, and the two frozensets gained no member. Checked by reading the diff, not by a test alone. - A consuming create is refused by no node-guard allocation
dimension on its hold's node. A test admits a consuming create
onto a node whose
used + heldalready equals its limit on all three dimensions. Mutation 1 fails it. - Two concurrent creates cannot take one hold. A live test against a real MariaDB admits exactly one and leaves the other either on another candidate or unheld. Mutation 4 fails it.
- No hold row names a node with no capacity row, after any
reconcile pass. A test asserts it as a set difference over
namespace_claim_holds.node_uuid(non-NULL) andscheduler_node_capacity.node_uuid, after a pass that removed a node both with and without somewhere to re-place to. - A consumed hold is never re-placed or displaced. A test puts a consumed hold on a node that then leaves service and asserts the hold row is byte-identical afterwards.
claim-shape-holdsis advertised and nothing else moved.advertised_capabilities()['auth']contains it;advertised_capabilities()['instances']still containsplacement-query; a test diffs the whole advertised dict against its expected value so a token added elsewhere fails.- Phase 3's
D4still holds. A test assertsdisk_availableis not net of held room, in the negative form phase 3 wrote it. Mutation 12 fails it. - Each of the four
409reason tokens and the404is reachable and tested, and the404's body names neither the hold's owner nor whether the uuid exists — asserted on the body text, not only the status. - A delete-then-recreate takes the same hold back. One
end-to-end test, because this is the case three
G2callers depend on and it spans4b,4cand4e. - Step
4jreports at least twelve mutations, every one caught, with the failing test and assertion named for each, and the worktree byte-identical to its pristine copy afterwards. - Proto stubs were regenerated with
tox -e genprotosand committed, with no field number reused, and a secondgenprotosrun leaves no diff. (Was untrue when first claimed: a round-one comment edit was never regenerated. Re-checked in review round three by md5, andProtoCommentDriftTestCasenow fails rather than leaving it to be noticed.) toxandpre-commit run --all-filespass from the repository root, andtools/check-plan-status.pyagrees with the index after the close-out commit.- The live MariaDB suite passes against a real server for the
steps that carry one (
4b,4e,4e2,4g), run with--serial. A step whose live test could not be run says so rather than being reported as passing. - No fact about a hold is stated differently on two pages.
docs/operator_guide/scheduler.md,docs/operator_guide/capacity_refusals.mdanddocs/developer_guide/subsystem_internals.mdagree on what a hold promises, when it ends, and what displacement means; andscheduler.md:494-498's "no operator-facing way to create a hold" andsubsystem_internals.md:466's "Nothing sets the column yet" are both gone. -
The master plan corrections this phase's planning commit made are in place and are not re-litigated by a later step:
S1says claim limits are binding (F1),G5is restated asD4describes (F2), the phase 4 bullet records that the split lands here and the phases do not swap, the phase 5 bullet is narrowed, and the Out of scope entry for hard claim enforcement says it has landed. -
A hold's contribution to
held_*is defined once, and every writer agrees with the reconciler. For a consumed hold released by its claim -- expiry, shrink or delete -- the decrement a node'sheld_*takes equals what_reconcile_fetch_held()recomputes for the surviving rows, and the test asserts it against that fold rather than against a literal. Each such test leaves a surviving booking on the node, because with nothing left there an over-credit floors at zero and the error is invisible. For claim delete, the expiry sweep and a named release that survivor has to belong to a second claim, since those paths end every hold of the claim they act on; for a shrink it does not, because a shrink releases only what no longer fits and an older booking of the same claim survives it. -
The schema change is proved against a real server. A version 1
namespace_claim_holdswith rows in it migrates to version 2 with those rows intact anddisplaced_fromNULL; a fresh create lands at version 2 directly; running the migration twice is a no-op; and a migrated table matches a freshly created one column for column. Asserted live on both MariaDB versions, because phase 3 found that a column change can be a silent no-op that only a real server reveals.
Back brief¶
Before executing any step of this plan, please back brief the operator as to your understanding of the plan and how the work you intend to do aligns with that plan.
Three gates in particular, because each is cheap to propose and expensive to redo:
- Before step
4bwrites any SQL, state the consuming transaction's statement order, the exactWHEREof the hold take, the exactSETandWHEREof the modified_claim_node(), and the arithmetic identity you intend to assert — and wait.D6decides all of it, and getting it wrong is a capacity defect that only a live test and a mutation can see. - Before step
4cchangesplace_on_candidates(), state where the hold resolution sits relative to the demand re-walk, what happens to the reordered list on the second pass, and how the lost-race retry of the same candidate interacts with the denials dict the caller reads — and wait. That method is on every create path in the cluster and its contract is documented in its own docstring. - Before step
4gwrites the re-placement, state the order the re-bookings are applied in, how the free figures are recomputed between them, and what the reply carries per hold — and wait.
Execution notes¶
2026-11-28 (AEDT). The back brief was answered before step 4a ran, and all three answers are recorded here because later steps depend on them.
- The live MariaDB suite runs against both servers, as phase 3
did: 11.8.9 with
innodb_snapshot_isolationON and 10.11.19 with it OFF. Both were started as throwaway containers (sf-mariadb-118on port 13318,sf-mariadb-1011on 13311) andmysqlclient2.3.2 was installed into the worktree's.tox/py3. Baseline taken before any step ran, which is what lets a later failure be attributed to this phase rather than inherited: 260 live tests passed with zero skips on each server. The selector isshakenfist\.tests\.test_mariadb_.*_live\., quoted with the count because phase 3's notes record that the number alone does not say what was counted -- dropping the trailing dot picks up five tests in other modules. - All three back-brief gates are honoured. The management session states the design and waits before 4b, 4c and 4g.
- This session has permission to push and open the pull request when the definition of done has been run, so it does not ask again at the end.
Steps run strictly in sequence, as the step plan requires. No two steps were run in parallel at any point.
Step 4a: the wire vocabulary in D1 was wrong, and the step was
right to depart from it. D1 named {cpus, memory_mb, disk_gb}
as the booking body. That is the dict book_holds() takes, not a
wire shape: SHAPESPEC_SCHEMA already publishes cpus, memory
and disk/disk_spec for the placement query, its comment says
those keys were chosen because "the claim verbs will publish the
same vocabulary", and its additionalProperties: False exists
specifically to answer "the human who typed memory_mb" with an
error. Following D1 literally would have published that typo as
the contract and broken G1, the requirement D1 cites. D1 is
corrected at its own site rather than only noted here. Two
consequences of sharing the schema were accepted with it: count
is honoured, and affinity is refused with a 400 rather than
ignored, which phase 0's D7 requires and which the published
spec documents in both the parameter and the 400 so the contract
does not overstate what it takes.
Step 4a: three refusal paths were added that the row did not
name, all three on phase 3's own instruction.
NamespaceClaim.book_holds()'s docstring says its two refusal
reasons are absent from the API's claim refusal table "because
nothing a REST caller can reach books a hold yet; whatever adds
that route adds them there too", and that a scheduling refusal is
"deliberately not translated here" because a caller needs the
stage and the refused shape's index. So claim_capacity and
node_capacity joined CLAIM_REFUSAL_STATUS as 507s, and the
scheduler's exception is translated with capacity_error().
Without the third an unplaceable booking would have been a 500.
One wart is created and belongs to phase 5: this endpoint now has
two shapes of 507, one carrying stage/transient and one not,
which is F4's gap seen from a new angle.
Step 4a also joined three censuses, which are guards rather
than incidental test edits: test_openapi_spec.py's
STRUCTURED_PARAMETERS, test_parameter_declarations.py's pinned
count of handlers behind caller_is_admin (29 to 32, three new
handlers), and test_required_sweep.py's census (76 to 77, the
one new required body parameter) with a seed_namespace_claim()
fixture. The management session checked the arithmetic of each
rather than taking the new numbers on trust.
The 4b row carried a deadlock, found at its gate and fixed
before the step ran. The row said the hold take must precede the
node update "because the node update's arithmetic depends on it".
It does not -- the SET moves the request size, which the caller
already has -- and taking hold rows before scheduler_node_capacity
inverts the canonical lock order against a concurrent booking,
which takes the capacity row first and the hold row last. Two such
transactions on the same claim and node could then deadlock. The
row now says the take goes last, which costs nothing: a zero
rowcount still aborts the transaction and rolls back the node
charge. This is the gate earning its place in the plan.
Step 4b went in as gated, with four calls the gate did not
cover. The denial for a lost take is failing_stage == 'hold' in
the database tier's vocabulary (cluster/claim/node), which
mints no API stage and leaves capacity_held free for 4f; it is
what lets 4c tell a lost race from a capacity refusal.
enforce=False does not relax the take's predicate, because every
term in it is an identity or ownership test rather than a capacity
guard, so a ground-truth writer cannot take a hold that moved,
shrank or belongs to another claim. A consuming create in a
namespace with no active claim is denied without touching the holds
table. And the consumable read raises on a failed read rather than
answering [], which hands 4c a decision rather than making one.
The unheld path was proven unchanged rather than asserted to
be. The compiled node UPDATE for an unheld admission was dumped
before and after the edit and diffed empty, and that string is now
pinned as a module constant with a test over it, plus a companion
test that an unheld create issues no statement naming the holds
table. This matters because the step rewrote the SET as a dict: the
rendering is identical because values() orders the SET by table
column regardless, which is a fact worth having a test behind
rather than a comment.
A test-harness ordering trap, found in review.
_PlacementRouter told the admission's node UPDATE from the
release's floored decrement by looking for GREATEST, and a
consuming drawdown now carries GREATEST on its held decrement
too. Left alone, every consuming test would have been handed the
release path's rowcount. The dispatch now tests expected_demand=
first, which only the drawdown carries. Checked and commented in
place.
pip install mysqlclient into .tox/py3 broke the tox
environment, and the live suite should not use that environment at
all. The driver the DSN names is not in the tox test extras, so
it has to come from somewhere; installing it into the tox env makes
tox consider that env dirty, and the pre-commit unit-test hook's
own tox run then tried to recreate it, raced its teardown and
deleted .tox/py3 outright. The symptom is a ModuleNotFoundError
from inside tox's own machinery (cachetools._cached) that looks
nothing like an environment problem. Recovered with tox -epy3 -r,
and pre-commit then passed. Later live steps (4e, 4g) use a
throwaway venv built outside the worktree -- python3 -m venv plus
pip install -e '.[test]' mysqlclient -- which leaves the worktree
clean, because .tox/ and *.egg-info/ are both gitignored. The
live counts below were taken before the breakage and are unaffected
by it; the suite was re-run from the isolated venv afterwards to
confirm it works.
Verification of step 4b, re-run by the management session rather
than taken from the step's report. Unit: 9102 ran, 8821 passed,
281 skipped, 0 failed, against a pre-phase baseline of 9048 / 8786
/ 262 -- which reconciles exactly, 35 new unit tests plus 19 new
live tests that the unit run skips. Live, selector
shakenfist\.tests\.test_mariadb_.*_live\., --serial: 279
passed with 0 skips on 11.8.9 with snapshot isolation ON, and 279
on 10.11.19 with it OFF, both against the 260 baseline. tox -e
genprotos is idempotent (stub md5s unchanged by a second run),
and no proto field number was reused -- the one removed line is
failing_stage = 6, which keeps its number while its comment moved
above it to document the new hold value.
Step 4c required a signature change to place_on_candidates(),
and that was the right answer rather than a convenience. The
method's docstring records that only self.place_instance() may be
read from self, because a preflight test double relies on it, so
the resolution could not reach for the namespace and the shape
through self. They became required keyword-only arguments, which
also means a caller that forgets them fails loudly instead of
silently resolving no holds -- the quiet failure being the one that
would have shipped. The preflight redirect needed one line to
forward them and inherits the whole resolution; the step made that
one change rather than reporting it, which was correct, because the
"preflight honours a hold" test cannot pass otherwise.
A defect in step 4b, found reviewing step 4c, fixed at its root
in 3f3256e450. 4b stopped the node guard charging a consuming
create's own request -- correctly, because the room is already
booked in held_* on that row -- but left _admission_denial_dimensions()
charging it, so exceeded recomputed a comparison the guard had
not made. That is the exact failure that function's own comment
exists to warn about, and it is not cosmetic: on a node whose
used + held equals its limit, a consuming create that passed the
allocation clauses and was refused on demand reported all three
allocation dimensions as exceeded,
CapacityAdmissionDenied.demand_only is derived from that set and
so read False, and place_on_candidates() skipped the pass that
waives the demand clause. A create whose booking was waiting for it
on that node was refused rather than placed -- the single-node
lockout of 2026-08-14 reintroduced, in the one case where a hold is
worth most. The fix is the charged flag that already existed for
the demand dimension, whose docstring already warned that getting
it wrong changes whether the waiver fires. No test in the phase
would have caught it: 4c's own demand-waiver test gives its node
generous limits, so the trigger -- a node booked exactly to its
limit -- never arose. The missing coverage is now four tests, two
of them regression guards in the other direction (an unheld create
on the same row still reports its allocations exceeded; a row left
over its limit by a ground-truth write still refuses), so the flag
cannot hide a refusal that is real.
Two of the management session's own briefs carried confident,
wrong premises, which is worth recording because both were the
kind an implementing agent follows without question. The 4b brief
asserted a data dependency that did not exist and would have
inverted the canonical lock order (caught at the gate, before the
step ran). The fix brief asserted consuming was already at
function scope; it was a closure local inside _admit(), so the
fix as specified would have raised NameError in the except
handler. The step checked, hoisted it, and said so. The pattern in
both is that the instruction sounded plausible because it came
with a reason -- which is exactly what makes a brief's premises
worth verifying before sending it, and what the gates are for.
A subagent killed another session's pre-commit run --all-files,
believing it a stray duplicate of its own. Nothing was lost:
--all-files does not stash, so no tree was left half-restored,
and the two stale ~/.cache/pre-commit/patch* files both predate
the kill and belong to other work. The cost was that session's run.
The brief had forbidden touching the checkout but said nothing
about processes. The distinction worth carrying, which that session
supplied: a concurrent --all-files in a different worktree is
legitimate and several run on this machine at once, so a second one
is never evidence of a stray. What is unsafe is two in the same
worktree, because pre-commit's stash is repository-wide. Both the
reasoning and a blanket "do not kill what you did not start" are in
the remaining step briefs.
Step 4d deviates from phase 0's D7 on one refusal, deliberately
and with the deviation found before the step ran rather than
after. D7 says an explicit reference "answers before
Instance.new() so a refused reference creates nothing". Four of
the five refusals honour that, because they need only the hold row
and the requested shape: the 404, and consumed, displaced and
too_small. The fifth cannot. node_not_a_candidate is a question
about the candidate list, and find_candidates(inst) reads the
instance's own placement and affinity attributes and addresses its
audit events to the instance, so candidacy is unknowable until the
instance exists. That one is answered after the candidate list is
built, with the enqueue_delete_due_error() cleanup every capacity
refusal on that path already does. Restructuring the create path to
compute candidates from a bare shape would avoid it and is a much
larger change than this phase justifies.
D5's widening of that token is worth restating because it is what
makes the deviation acceptable: node_not_a_candidate covers more
than affinity on purpose, since a node can be missing from the
candidate list for affinity, a live measurement, queue depth or
having left service, and a token saying affinity when the cause
was idle memory would be a lie a caller acts on.
Step 4d closed a hole the row left open, which the management
session's brief had not seen. The row said a resolved reference
pins the walk to one hold on one node, and said nothing about a
lost take on such a walk. Left alone that would have published
the ordinary exhaustion refusal -- a 507 reading "no node had
capacity for this instance, 0 candidates refused it", which is
technically true and actively misleading, because one node was
asked and it said nothing about its room. The handler now
intercepts that denial before the stage-publishing logic,
re-resolves the reference, and answers with whichever token is now
true of the row, or the 404 if the expiry sweep has taken it.
Every branch returns, so a hold-stage denial cannot reach
_claim_only_denial() or the capacity_guard fallback.
A divergence between the two consumption modes, carried into step
4f. In the implicit mode 4c built, a lost take never enters the
denials dict. In 4d's pinned mode it does, at the database tier's
hold stage, because the handler reads it there to re-resolve. That
is safe today only because the interception above runs first, so
4f's _held_only_denial() must tolerate a hold entry rather than
assume every entry is a capacity stage.
What the management session checked rather than accepted, since
nothing in 4d turned out to be wrong. The claim-selection rule the
step invented -- active coverage, unexpired, lowest uuid -- was
verified identical to the admission path's order_by(uuid).limit(1),
including that COVERAGE_ACTIVE and the admission's state ==
'active' are the same column rather than this schema's other
coverage_state concept; a mismatch there would have let a
reference resolve against a claim the take would then refuse. The
extraction of requested_capacity() was verified to return exactly
the tuple _capacity_claim built inline, and to sit after both
declared_integer() conversions so a numeric-string cpus cannot
reach its arithmetic. And the 404's secrecy is asserted on the
response body, not only its status, so a later change cannot quietly
turn it into a disclosure.
Step 4e needed no correction, and its one departure from the row is an improvement. The row said the residue should move "one more statement in the pair of node updates"; the step instead issues the hold statement first and the two counter statements after it, so a booking that ended between the probe and the lock credits nothing rather than forcing either a denial or a stale-retry loop. Both node rows are already locked by the pair, so the later statements take no new lock and cannot reorder anything; they are still issued in node-uuid order, which asserts the intra-table rule rather than depending on it.
The step also declined half of a decision, correctly. The gate
answer was to floor the held_* move to match phase 3. The step
floored the decrement and argued that an increment needs no floor:
an increment cannot drive a counter negative, which is the only thing
the floored form exists to stop, and there is no ceiling to clamp
against either, because held_* may legitimately stand above
limit_* on a row the reconciler has recomputed into an overbooked
state -- clamping there would hide the overbooking that D9 exists to
record. What does need asserting is that there is a booking to credit
at all, and that is the guarded hold statement's rowcount. Kept as the
step wrote it.
Kept from the step beyond its row. The consumed-hold read moved onto the probe connection and is gated on the namespace having an active claim, so an ordinary create and an unclaimed delete issue no extra statement; the mock double mirrors both transactions; and both public wrappers' docstrings describe the new reply keys. All three were kept.
What the management session verified rather than accepted. Unit
9192 ran / 8898 passed / 294 skipped / 0 failed, and the live suite 292
of 292 on both 11.8.9 with innodb_snapshot_isolation ON and 10.11.19
with it off, each re-run here rather than read from the step's report.
The arithmetic was read against D6 statement by statement: both
counters move by the instance's request, the live cases book 8/8192/80
against a 2/2048/20 instance so the booking is strictly larger on every
dimension, used and held are asserted separately rather than only
their sum, and a reconcile pass afterwards agrees. The claim that the
guarded hold statement's rowcount is sufficient protection was checked
at its root: _release_hold_rows() does decrement the node before it
touches the row, so no concurrent writer can end a booking between this
transaction taking the node lock and reaching its hold statement.
A defect step 4b introduced, found reviewing 4e, fixed in step 4e2.
_release_hold_rows() decrements a node's held_* by the hold's full
size, but only a consumed hold's residue is in held_*. Nothing could
consume a hold before this phase, so the two were always equal; 4b made
consumption real and left this site alone. Proved against live MariaDB
rather than argued: a shrink releasing a consumed 8/8192/80 booking
beside an unconsumed 4/4096/40 one on the same node leaves held
at 2/2048/20 where the reconciler's fold recomputes 4/4096/40, short by
exactly the consuming instance's request. The node therefore
under-reports its own commitment and can over-admit by that much until
the next reconcile pass, which is the unsafe direction. Three paths
reach it with a consumed hold -- claim expiry, claim shrink and claim
delete -- and none filters consumed rows out of the set it hands over.
Single-claim cases are masked because flooring at zero happens to give
the right answer, which is why no test in 4b, 4c, 4d or 4e caught it.
Step 4e2 is inserted after 4e to fix it; the underlying cause is that
a hold's contribution to held_* is expressed twice in the tree, in
_hold_size() and in _RECONCILE_HELD_SQL, so the step's brief
requires the two be reduced to one definition rather than corrected
separately.
Step 4e2 needed no correction, and it improved on its row in three
places. The row asked that the duplicated definition be reduced to
one; the step found a third rendering the management session had
missed -- the move path's own max(0, hold - request) triple, added by
4e the day before -- and folded that into the helper too. It found that
the mock double carried the same defect for the same reason, mirroring
the arithmetic instead of sharing it, and made it call the real helper.
And it worked out a test requirement the row had not: for the paths
that end every hold of a claim, the surviving booking has to belong
to a different, still-active claim, because the reconciler's fold
counts only active claims' holds and a sibling booking on the same
lapsing claim would be invisible to it as well. The row's instruction
to carry a second booking was necessary but not sufficient, and the
step is what noticed.
What the management session verified rather than accepted. The
step's load-bearing claim is that disk_spec_virtual_gb() is the
oracle for the held fold's disk term. Its docstring only claims to
specify _RECONCILE_USAGE_SQL, which is a different statement, so the
claim was checked rather than read: the two JSON_TABLE subqueries are
identical character for character -- same projection, same DEFAULT '0'
ON EMPTY/ON ERROR, same JSON_TYPE(...) = 'ARRAY' guard, same
grouping -- so the oracle covers both. Also checked: that a node whose
bookings are all fully consumed is still issued its zero decrement, so
4e's argument that a release takes the node's capacity row lock before
the hold row moves still holds; that the consumption map's keys and the
hold rows' instance_uuid are the same spelling, since a mismatch
would silently restore the defect while every test still passed; and
that a hold whose instance has vanished is credited its whole size,
which is what the fold's COALESCE(i.cpus, 0) gives it.
The defect's own probe, re-run. The management session's original
proof read held 2/2048/20 where the fold recomputed 4/4096/40. On
this tree it reads 4/4096/40 immediately after the shrink, with no
reconcile pass run.
Two things the step declined, both correctly. The expiry sweep's
credit has no live statement proof: the same pass restates held_*
from the fold a few statements later, so no credit it makes is
observable live. Its outcome is asserted live and its amount in the
mocked reconciler suite, and the test says which. And the release
DELETE gained no instance term to make a stale probe re-probe,
because that would change the compiled statement for every release,
which the row required stay byte-identical; the staleness is floored,
the next pass restates it, and the claim delete's own used_* guard
catches it outright.
Counts. Unit 9221 ran / 8919 passed / 302 skipped / 0 failed, and
the live suite 300 of 300 on both 11.8.9 with
innodb_snapshot_isolation ON and 10.11.19 with it off, each re-run in
the management session.
Step 4f needed no correction, and the review kept a predicate
stricter than the row asked for. The row's test was that some
dimension satisfy used - held + requested <= limit < used +
requested. The step requires the left-hand inequality of every
dimension carrying a booked figure, and the right-hand one of at least
one, which implies the row's reading and refuses one case the row's
reading would have allowed: a node that would have been short anyway
on another dimension is never published as merely booked. The step
argues the asymmetry explicitly -- reporting a genuinely full cluster
as booked sends an operator hunting a holder who is not the problem
while telling the client not to retry something a teardown would fix
in seconds, so a mixture stays at the guard stage -- and that is the
right direction to be wrong in. Kept as written.
The hold entry divergence is answered structurally, which is
better than the row required. The row said the held-only test must
tolerate a hold entry rather than assume every entry names a
capacity stage. It is rejected by the same failing_stage != 'node'
test that rejects a claim or cluster entry, before any dimension is
read, so the tolerance does not depend on 4d's interception running
first -- which the row asked for and the step delivered. The reasoning
is that a lost take measured nothing and a retry genuinely can clear
one, so a non-transient stage would tell the caller not to try the only
thing that works.
What the management session verified rather than accepted. The
step's predicate rests on three properties of the denial detail, all
checked at their source in _capacity_dimension(): that the node stage
passes the sum of occupied and booked room as used and the booked
part again as held; that held is absent rather than zero wherever
there is no held account -- the claim and cluster stages and the demand
dimension -- so reading an absent field as zero would turn every
ordinary full node into a booked one; and that _dimension_from_proto()
uses HasField('held'), so a reply from an sf-database predating the
field reads as "not reported" rather than as a node which has booked
nothing. Unit 9248 ran / 8946 passed / 302 skipped / 0 failed, and all
17 pre-commit hooks pass, re-run in the management session. The step
judged that it needs no live-MariaDB component, which is right: it is
the refusal contract above the database tier and the tier's own
arithmetic is already covered.
Two things carried forward rather than done here. The preflight
redirect in operations/node_inst_netdesc_op.py walks the same
candidates and could ask the same question of its own denials, but
publishes the guard stage for a booked-only walk exactly as it already
does for a claim-only one. The classifier lives in the API layer, which
nothing below it imports -- which is why the stage sets themselves live
in shakenfist/constants.py -- so closing it means deciding where the
classifier belongs rather than copying it, and a second copy is how two
publishers come to disagree about one refusal. It is a real gap and it
predates this phase for the claim stage, so it is recorded in the
master plan's Future work rather than fixed on the way past. And the
create handler's published 507 description still lists only
capacity_guard; capacity_claim is absent from it too, so adding
capacity_held alone would invent a precedent. Step 4i's row now
carries both tokens.
The 4g gate, answered 2026-11-29 (AEDT), and a planning error it
exposed. All three answers are as recommended, and D7 and the 4g
row are corrected at source rather than carrying the answers only
here.
Re-booking order: largest first, oldest first among equals. The plan
said "most recently booked first", and that was wrong rather than
merely arguable. It contradicted the reasoning this plan already uses
at the other end of the same question: _holds_a_shrink_releases()
gives back the newest bookings precisely because the ones a holder
has had longest are the ones it is most likely relying on. Newest-first
re-placement hands the best remaining room to the bookings that matter
least and displaces the ones that matter most. No argument for it
survived being written down. Largest first is the standard answer to
the question re-placement actually asks -- lose as few bookings as
possible -- because trying the hardest one to fit while the remaining
room is least fragmented is a first-fit-decreasing walk; size descends
over disk_gb, memory_mb, cpus, scarcest first on these nodes.
Ties go to the oldest, which makes the two orders consistent: a shrink
releases the newest, a re-placement saves the oldest.
Free figures: a running tally in Python. Each candidate node's
counters are read once inside the transaction and decremented as each
booking lands. The transaction holds those rows' locks and is their
only writer, so the tally cannot go stale, and a re-read between
bookings could only return what the tally already knows -- at a round
trip per booking inside a transaction holding capacity-row locks across
the cluster. Deciding every booking from one initial snapshot is the
separate defect 4j's mutation 11 exists to catch.
Reply detail: identity, size, the node left and the node landed on.
Per booking: uuid, claim uuid, namespace, its three dimensions, the
node it left, and the node it landed on -- empty for a displaced one.
That is deliberately the shape step 4h's displaced-holds report
needs, so the two agree without a translation between them. A
per-dimension shortfall for a booking that fitted nowhere was declined:
the closest candidate's figure is near-meaningless when no node fits at
all, and an operator would read it as authoritative.
Step 4g needed no correction, and its one deviation is an improvement. The row said to read each candidate node's counters once inside the transaction; the step builds the tally from the limits, usage and booked figures this pass has just recomputed in the loop above it, rather than from the pre-pass row read. That is strictly better and the step said why: a booking placed against limits the pass has already superseded would be placed against a node that no longer has that much. Kept.
The trigger's scope, which the management session checked rather than
accepted. The step keys re-placement on the pass's removals list
alone, so a hold naming a node whose capacity row went in some
earlier pass would never be repaired -- and the expiry sweep a few
statements above deliberately takes the opposite approach, sweeping
every expired claim "however it arose". Two facts make the narrow
trigger airtight rather than merely adequate, and both were verified:
removals is the only place in mariadb.py where a
scheduler_node_capacity row is ever deleted, and the booking guard
refuses to book onto a node that has no capacity row. So the only route
by which a hold can come to name a node without a capacity row is that
node appearing in removals, which this step handles. On top of that,
nothing on the default branch calls NamespaceClaim.book_holds()
outside tests -- the stack exists down to that method and no caller
above it does -- so no hold row exists in any real database and there
is no legacy state to repair on upgrade. If a future change adds
another hold-creating path or another deleter of capacity rows, that
reasoning lapses and the trigger has to widen with it.
What else was verified rather than read. That the credit is proved
against the next pass's own fold and not only against a literal: the
pass states each surviving node's held_* from the fold, which still
groups a departing node's booking under the node it is leaving, and
then credits the destination on top, so a wrong credit would be
silently corrected one pass later -- which is how a wrong credit hides.
The step's own test runs the pass after and asserts agreement, which is
the right instrument. Also that the move is guarded on the row still
being unconsumed and still on the node it was read from, which is what
makes "a consumed booking is never moved" true against a create that
consumed it mid-pass rather than only against the read; that a
destination's free figure can be negative on an already-overbooked row
and such a node then fits nothing; and that the node-side size comes
from _hold_residue(row, None) rather than a fourth expression of the
same quantity.
Counts, and one failure that did not reproduce. Unit 9291 ran /
8979 passed / 312 skipped / 0 failed. The live suite passes 310 of 310
on both 11.8.9 with innodb_snapshot_isolation ON and 10.11.19 with it
off, each re-run in full in the management session. The step reported
one failure on 11.8 in
HoldConcurrencyLiveTestCase.test_concurrent_bookings_of_separate_claims_all_land,
a booking-path test this change does not touch; it passed on the step's
own module re-run and in both of the management session's full runs, so
it is recorded here as an observed intermittent rather than filed. A
second occurrence is a flake worth an issue; it is not evidence of a
regression in this phase, and a future failure there should not be read
as one.
Three pieces of stale prose it found, two of them from this
session's own correction of the re-booking order a few hours earlier,
which had reached D7 and the 4g row but not the master plan's phase
4 description or phase 0's deferral. Fixed in their own commit, along
with _hold_summary()'s explanation that hold events omit the
consuming instance "because nothing consumes a hold yet" -- false since
4b, and replaced with the reason the omission is still right rather
than removed. The step left that one alone as someone else's
rationale, which was the cautious call and the wrong one: a docstring
whose stated reason has become false is worse than one with no reason.
Two documentation sites it identified for step 4i, now in that
row: docs/developer_guide/database_internals.md:957 and
docs/operator_guide/database.md:913 both enumerate the reconcile
pass's stages and now omit this one.
Step 4h found that D8 specified a field the schema cannot
supply, which is the first wrong premise this phase has found in a
decision rather than in a brief. D8's second bullet asks for each
displaced booking to be reported "with the node each left". Clearing
node_uuid is exactly what displaces a booking, and no other column
ever held that node, so a read of namespace_claim_holds could name
nothing: only the pass that did the displacing knew. The step published
the key empty, said why in the docstrings and the proto comment, and
named the two options rather than inventing a source for it -- a join,
a guess or a quiet drop would all have looked like compliance.
Resolved at a gate, 2026-11-30 (AEDT): add the column. The decisive
fact is one the management session had established a few hours earlier
for an unrelated reason -- nothing on the default branch calls
NamespaceClaim.book_holds() outside tests -- so the table has shipped
and is provably empty in production, and the migration is an
ALTER on no rows. Once this phase merges and the G2 holders adopt
bookings, that stops being true, so this was the last moment it was
free. The alternative, dropping the field, was rejected because the
holder is the party that has to re-book a displaced hold and
/admin/resources is admin-scoped: without the column a holder reading
its own claim sees a booking it is owed, unplaced, and nothing saying
what unplaced it. Shipping it permanently empty was rejected outright:
a published field that is always empty cannot be told from one that is
merely unset, and a client eventually depends on it.
What the step did with that, and what it decided for itself. The
column is written by the same statement that clears node_uuid, and
cleared again when a later pass re-books the row, so a booking
displaced, re-placed onto a returning node and displaced again never
carries a stale origin. It chose to carry the field in the claim's
holds listing as well, reasoning from who needs the fact rather than
from symmetry, which is the argument recorded above. The migration
takes its column type from the table definition so the DDL cannot
drift, and adds the column AFTER node_uuid so a migrated table
matches a fresh one column for column -- asserted by a test against a
real server, because phase 3 found that a column change can be a
silent no-op that only a live check reveals.
Two extras kept deliberately. The degraded flag on the displaced
report: a failed read would otherwise either raise from an endpoint
that already tolerates a degraded capacity read, or publish a zero
count that cannot be told from "nothing is displaced". It matches this
module's existing convention -- capacity_degraded and the per-node
degraded both predate the step -- rather than inventing one. And the
widened _relocated_hold_reply(), which takes the node from the mover
while the pass is moving and from the row's own column when a caller is
reading, so the standing report names the node the pass named at the
time without a second shape or a translation between them. That
sharing was the row's own instruction and the step met it in the one
way that does not duplicate the shape.
What the management session verified rather than accepted. That
overbooked_dimensions() tests strictly on a negative free figure, so
a node exactly at its limit is not overbooked -- correct, because the
node guard admits used + held + request <= limit -- and that the one
definition is shared by the pass that records the condition and the
summary that publishes it. That phase 3's D4 is intact: no per-node
field moved and its own negative test over disk_available still
passes unmodified. And that a booking on no node cannot be consumed, so
the displaced read needs no consumption filter: the take's WHERE
names node_uuid, which a NULL never matches. Unit 9336 ran / 9012
passed / 324 skipped / 0 failed; live 322 of 322 on both 11.8.9 with
innodb_snapshot_isolation ON and 10.11.19 with it off, each re-run
here.
The test MariaDB containers were removed mid-phase by something
outside this session, and the step built its own, sf-p04-11.8 on
13318 and sf-p04-10.11 on 13311, bound to localhost rather than to
every interface as the earlier pair were. They are deliberately left
running for step 4j and are dropped in the close-out. Two
sf-live-* containers from another session, exited for a week, were
correctly left alone.
Step 4i needed no correction, and all four of its out-of-brief finds
are kept. Three were documentation this phase had already falsified
and which would otherwise have shipped stating the opposite of the
code: subsystem_internals.md said a hold on a node with no capacity
row is "left alone, neither deleted nor given a null node" (false
since 4g), and said "nothing a caller can reach creates a hold yet"
and "admission never touches held_*" (false since 4a and 4b);
database_internals.md still said the holds table was at schema
version 1 (false since 4h, the same day). Each reads as
authoritative to an operator.
The fourth is one the management session should have caught.
scheduler.py's _displaced_holds() docstring said both node fields
of a displaced booking are empty "because a displaced row records
neither" -- written honestly by step 4h before the displaced_from
column existed, and left behind when that step was sent back to add
it. The management session reviewed that follow-on diff and did not
notice the stale prose in a file the step had already touched. The
lesson is narrow and worth keeping: when a step is sent back to extend
its own work, the reasoning it wrote the first time is part of what has
to be re-read, not only the code it adds.
One claim it declined to assert. It could not find the move's hold
carry in the code and said so rather than writing the sentence on the
plan's authority. The carry is real -- _carry_holds(), nested inside
_direct_admit_instance_placement(), which is why a search for a
top-level name missed it -- and the management session confirmed it
before keeping the sentence. Flagging an unverifiable claim is the
behaviour these briefs ask for, and it cost one grep to settle.
What the management session verified rather than accepted, since a
wrong sentence in an operator guide outlives a wrong line reference:
both 507 refusal messages quoted in the new operator section appear
verbatim in auth.py; the 409 for a lapsed claim exists; the "at
most 64 holds" bound is MAX_PLACEMENT_SHAPES and the handler's own
message uses the constant; and the claim that each shape is booked on
the node the scheduler would have chosen with the earlier shapes
already charged matches _hold_shapes()'s own docstring. Unit 9337
ran / 9013 passed / 324 skipped / 0 failed, and all 17 hooks pass
including the documentation link-and-anchor check.
4i's row was the first in this phase whose references all held,
because nothing in the phase touched the files it points at. Worth one
sentence as a real result.
4j ran at opus/high, not the row's sonnet/medium, and the
departure is the management session's. A row's model is a judgement
about the work's difficulty, and the management session had changed
the work after the row was written: twelve unit-level mutations became
sixteen, one of them (16) observable only against a live server. The
decisive reason is what the step is for. 4j is the step that
certifies the other ten, so a sweep which reports "all sixteen caught"
without having checked is not a neutral failure -- it is false
assurance about the whole phase, and it is close to undetectable from
the report alone. The brief therefore also told the agent that a
mutation no test catches is a finding to report rather than to fix,
that the test for such a finding is the management session's to write,
and that mutation 3 had described correct behaviour until shortly
before dispatch. That last warning earned its place: see mutation 5
below.
The management session reproduced two of the sixteen itself rather
than reading the table. Mutation 13, because it is the one that
certifies 4e2's fix of the only real defect this phase found:
applied by hand, test_a_consumed_bookings_credit_is_its_residue
fails [6, 6144, 60] != [8, 8192, 80], which is the residue-versus-size
confusion in its own numbers. Mutation 5, because a "this mutation
is a no-op" verdict is exactly the shape a sweep uses to excuse a
survivor, and it needed checking at the source rather than in prose.
It is a genuine no-op, and {} being the only empty value a caller
passes is what makes it one -- hold_ordered_candidates()'s two
callers at instance.py:1852 and :1854 both produce a dict, so the
early return's removal cannot reach a candidate in None. Both files
were restored from the pristine copies and compared byte for byte.
Running the definition of done found four more stale facts, three
of them in the master plan and all three the same failure as the
ordering sweep earlier in this phase: a correction landed in one place
and not in its sibling prose. G5's restatement and the phase 5
bullet's narrowing both went into the Execution-table bullets, while
the detailed phase 5 section three hundred lines further down kept
"No new stage names (G5)" and kept instructing phase 5 to state a
split that scheduler-reservations 5b had already shipped -- and that
section, not the bullet, is what a phase 5 implementer reads as its
brief. The brief-citation paragraph still asserted
CLAIM_ENFORCEMENT_HARD = False as a structural fact that holds,
which F1 corrected everywhere except there; the value is dropped,
since that sentence is about the identifiers being present. And one
success criterion claimed summarize_resources() "nets them out",
which is true of cpu_available and ram_available and deliberately
false of disk_available -- phase 3's D4 declined exactly that
netting and this phase's own definition of done asserts the negative,
so the plan's criterion contradicted two of its own phases. The
fourth is in this file: item 20 required "a second claim's booking on
the same node" for all four release paths, which is right for the
three that end every hold of a claim and wrong for a shrink, where an
older booking of the same claim survives. What all four have in
common is that nothing would have caught them except reading the
item and checking it, which is the argument for running a definition
of done rather than ticking it.
Item 4 is recorded as partially met rather than ticked. Its three
classification tests all exist and assert the published stage,
transient and the Retry-After header, and a fourth test proves a
booking does not by itself make a node refuse. But the item also asks
that the instance's recorded error_stage match the client's "in
each", and only the capacity_held case asserts that
(test_the_instance_records_the_stage_the_client_was_told); the two
guard-stage mixtures assert the body and not the recorded stage. The
publish branch sets the stage once and hands it to both, and the
guard-stage recording is pre-existing behaviour this phase did not
touch, so the risk is low -- but it is not what the item says, and
the item is not ticked. Left for Mikal to decide whether to extend
the tests or the item, deliberately not resolved by quietly editing
the wording of a check this phase failed.
Resolved in review round one by extending the tests, not the
item. The two mixture tests now assert
enqueue_delete_due_error(stage=...) beside the body, as the
capacity_held case already did, so all three classification cases
assert the recorded stage and item 4 is met as written. The guard is
worth its two lines: mutation 22 -- the guard branch recording
capacity_held while publishing capacity_guard, which is issue
4568's own failure mode -- is killed by them and by nothing else.
Results¶
4j: the mutation sweep¶
Sixteen mutations, each applied by replacement from a pristine copy
held outside the worktree, one at a time, never beside a pre-commit
run, each under timeout 900, with the suite run under
PYTHONDONTWRITEBYTECODE=1 so a same-size mutant could not be served
from stale bytecode. Every mutant ran the whole unit suite, so a
collateral kill is visible rather than hidden by a narrow selector.
Baselines: unit 9337 ran / 9013 passed / 324 skipped / 0 failed; live
322 passed / 0 failed on each of 11.8.9 and 10.11.19.
Fifteen of sixteen killed; the sixteenth is not a mutation. No
coverage gap, and so no test was owed -- but one was written anyway,
for the reason under mutation 8.
| # | File | Outcome | Killed by |
|---|---|---|---|
| 1 | mariadb.py |
killed | test_the_consuming_guard_drops_the_requests_own_term |
| 2 | mariadb.py |
killed | test_the_amounts_moved_are_the_requests_and_not_the_holds; live, 17 tests |
| 3 | mariadb.py |
killed | test_the_credit_is_the_request_and_not_the_booking (sole unit killer) |
| 4 | mariadb.py |
killed | test_the_take_names_the_hold_the_claim_the_node_and_the_sizes |
| 5 | instance.py |
no-op | nothing, and correctly so -- see below |
| 6 | mariadb.py |
killed | test_the_order_is_best_fit_then_oldest_then_uuid |
| 7 | mariadb.py |
killed | test_the_order_is_best_fit_then_oldest_then_uuid |
| 8 | external_api/instance.py |
killed | an end-to-end test, not the named one -- see below |
| 9 | constants.py |
killed | test_the_held_stage_is_classified_as_neither_kind, +3 |
| 10a | mariadb.py |
killed (unit) | test_the_read_asks_only_for_unconsumed_bookings, +12 |
| 10b | mariadb.py |
killed (unit) | test_the_move_is_guarded_on_the_node_and_on_being_unconsumed |
| 11 | mariadb.py |
killed | test_the_free_figures_advance_as_each_booking_lands; live |
| 12 | scheduler.py |
killed | test_summarize_resources_does_not_net_held_out_of_disk |
| 13 | mariadb.py |
killed | test_a_consumed_bookings_credit_is_its_residue, +5; live ×6 |
| 14 | mariadb.py |
killed | test_a_re_placement_clears_the_node_it_had_left |
| 15 | mariadb.py |
killed | test_a_node_exactly_at_its_limit_is_not_overbooked, +1 |
| 16 | mariadb.py |
killed live only | test_a_migrated_table_matches_a_fresh_one, on both versions |
Mutation 5 describes correct behaviour, which makes it the
second row of the sixteen to do so -- mutation 3 was the first, and
it was corrected before dispatch. Deleting
hold_ordered_candidates()'s if not holds: return list(candidates)
changes nothing: with holds == {} the two-group comprehension is
[] + [every candidate], the identical order. The early return is
readability and an explicit statement of the no-booking contract, not
behaviour. A variant that does reorder the no-hold path is killed by
test_the_reorder_preserves_the_list_when_nothing_is_booked and nine
others, so the contract itself is guarded. Two non-mutations in
sixteen is worth carrying forward: writing a mutation list is as
error-prone as writing the code, and a mutation that cannot fail is
indistinguishable in a report from a test that cannot fail.
Mutation 8 was killed by a test that was not aiming at it, and
that is a test-quality finding even though the mutation died. Turning
_held_only_denial()'s all into any accepts a mixed walk as
booked-only, publishing a 507 that tells a client not to retry
something a delete elsewhere would clear -- the exact error direction
D4's "every candidate, or none" exists to prevent. Every direct unit
test in HeldOnlyDenialTestCase that reaches the mutated line passes
a one-candidate walk, where all and any are the same function;
the two multi-entry tests (test_a_lost_booking_entry_is_not_held_only,
test_a_cluster_entry_is_not_held_only) return at the earlier
failing_stage test and never reach it. So the class whose docstring
promises "the shapes the guard cannot produce" was missing the one
mixture that distinguishes the quantifier, and the mutation died only
to an end-to-end test named for stage classification. The management
session added test_a_booked_node_beside_a_short_one_is_not_held_only
-- two node-stage denials, one booked-only and one genuinely short --
and verified it passes clean and is the sole failure under the
mutation.
Mutation 10 is defended twice over. Each of the read filter and
the write guard is caught at statement level by its own unit test, yet
each survives the live suite alone, because either one alone makes the
other unobservable. That is defence in depth rather than weak testing,
and it is the answer to a reviewer who asks why both exist.
Mutation 13's masking was demonstrated, not asserted. It dies to
the two-claim cases, and survives a live run of the pre-4e2
single-booking classes (HoldReleaseLiveTestCase,
HoldLifecycleLiveTestCase). That is the masking which let the
over-decrement live from 4b to 4e in plain sight: the old tests
booked one hold per node, and one hold's residue and its size differ
only when a second hold shares the fold.
Driver and logs:
<scratchpad>/p04/step-4j/ (run-mutants.sh, gen_mutants.py,
unit-cmd.sh, live-cmd.sh, verify-restore.sh, unit-run.log,
live-*.log).
Review round one¶
The automated review of the pull request raised 3 fix, 1 document
and 6 consider items. All four of the first two were taken; three of
the six optional ones were, and three were declined with a reason
recorded on the pull request. Two of the three fix items are real
defects this phase shipped and neither was reachable by the tests it
wrote, which is the part worth keeping.
A placement which is both a move and a consumption consumed two
bookings. _take_hold() and _carry_holds() were both called
unconditionally, so a held create whose node fails preflight -- the
redirect in operations/node_inst_netdesc_op.py, which resolves this
namespace's bookings against its own candidate list exactly as a create
does -- took a booking on the node it arrived at and carried the one
it had consumed on the node it left. Two hold rows then named one
instance and the pair of nodes stood one request under-charged for the
life of the instance.
The reason the phase's own agreement tests could not see it is the
interesting part: the reconciler's fold computes size - request for
each consumed row, and so agrees with the counters in exactly this
state. used + held over the pair is what moves, and nothing
asserted that over two nodes at once. The two statements are now
mutually exclusive -- the take wins, and the booking on the node being
left goes back to unconsumed where it stands, reported in the
admission reply's new unconsumed_holds field (proto 18, the same
shape and name the release reply already used). Returning it rather
than carrying it is the better of the two correct answers: a booking
stays on the node its holder booked it on, where the next create in
that namespace can draw on it, and the placement attribute still names
the booking that was actually consumed.
A re-placement that lost its race stranded its booking for good.
_reconcile_replace_holds() logs and continues when its guarded move
matches no row, and the same transaction then deletes that node's
capacity row -- after which the node can never appear in a removal set
computed from existing rows, so no later pass would look at that
booking again. It would contribute to no counter, bind nothing, and
stay invisible to the displaced read, which asks for bookings on no
node. The plan's argument that the narrow trigger was airtight
("removals is the only deleter") assumed the move always succeeds.
The trigger is now the standing condition: every pass asks for the
unconsumed bookings whose node has no capacity row, unioned with the
rows this pass is about to delete. That makes the invariant true by
construction rather than by an argument about deleters, and repairs
anything an earlier pass stranded. Two deliberate limits: a pass which
sized no node and has no removals skips the question, because it
could only answer "displace every booking in the cluster" from a
capacity view that found nothing; and a consumed booking on an
unsized node is still left alone, because its instance's fate is what
moves it. The suite's
test_a_hold_on_a_node_without_a_capacity_row_is_left_alone encoded
the old narrow rule and is rewritten as the consumed case, which is
what it was really about -- the fold crediting nothing.
The third fix was a 500 for a caller's mistake.
_hold_shape_disk_gb() returned a summed disk_spec unbounded while
the disk branch two lines below routed its value through
_claim_limit(), so a negative size was refused by the published
declaration at enforce and answered 500 at warn or off -- the
operator's rollback, which AGENTS.md is explicit a handler must not
rest on. Both denominations now end at the same bound.
Of the three optional items taken, one closed definition-of-done
item 4 (above), one rewrapped two overlong documentation lines, and one
recorded in a comment that the consuming admission's floored held_*
decrement deliberately reports no clamp: detecting one needs the row's
value before a write that rides inside the guarded UPDATE, and reading
it there would read a row this transaction has not locked yet.
Of the three declined, two are performance work with no present
defect -- the consumable-hold read ships every fitting booking on the
shortlist rather than one per node, and the re-placement issues one
UPDATE per booking inside the pass's transaction -- and one asked for a
create-path latency measurement the plan's D2 promised. The first
item's comment did overclaim, saying the design "keeps a fleet's
bookings off the wire", and that claim is now stated accurately with
the window function that would fix it named; the second's suggested
per-pass bound is only safe with this round's widened trigger, which
is now in place for whoever takes it.
Review round one: mutations 17 to 24¶
Eight more mutations, carrying the sweep to 24, applied the same way
(replacement from a pristine copy outside the worktree, restored in a
finally, one at a time, each run under timeout, never beside a
pre-commit run) with the driver in <scratchpad>/mutants/
(mutations.py, run.py, sweep-*.log). Seven killed; the eighth is
not a mutation.
| # | What is broken | Result | Killed by |
|---|---|---|---|
| 17 | _carry_holds() carries as well as taking (the defect) |
killed (unit) | test_a_consuming_move_returns_the_old_booking_and_takes_the_new, ..._carries_nothing, test_the_returned_booking_is_credited_the_request_not_its_size, test_a_return_that_matches_nothing_credits_nothing |
| 18 | The returned booking is credited its size, not the request | killed (unit) | test_the_returned_booking_is_credited_the_request_not_its_size |
| 19 | The departing read loses its standing condition | killed (live only) | test_a_booking_stranded_on_an_unsized_node_is_re_placed, test_a_stranded_booking_that_fits_nowhere_is_displaced |
| 20 | The pass skips the question when a pass has no removals | killed (live only) | the same two |
| 21 | The booked disk_spec sum is returned unbounded |
killed (unit) | test_a_negative_disk_spec_size_is_refused_by_the_handler |
| 22 | The guard branch records a stage it does not publish | killed (unit) | test_a_booked_node_beside_a_full_one_is_still_the_guard_stage, ..._beside_a_claim_refusal_... -- the two the definition of done asked for |
| 23 | The widened read drops its explicit NULL exclusion | not a mutation | -- |
| 24 | The mock double carries as well as taking | killed (unit) | test_a_consuming_move_leaves_exactly_one_booking_consumed |
Mutations 19 and 20 are killed by the live suite and by nothing else. The mocked reconcile tests answer the read with whatever rows the fixture handed them, whatever the predicate says, so a widened predicate is invisible to them by construction -- which is the same reason that suite's own header gives for having a live counterpart at all. Worth stating because a sweep run unit-only would have reported both as surviving.
Mutations 17 and 24 are the same defect in two places, and each is
killed only by tests of its own tier. The caller-level test added for
this round reaches the double in mock_mariadb.py, not the statement
in mariadb.py, so it survives 17 and dies to 24; the four
statement-level tests do the reverse. That is the division of labour
the double's docstring asks for and the parity suite exists to police,
and it is only visible because the first run of this sweep was
misread: a bug in the new caller-level test (it ignored that
place_on_candidates() returns a tuple) failed it under every mutant,
which looked like 19 and 20 being killed at unit level. The test was
fixed and the three re-run. A mutation sweep is also a test of the
tests, and a test that fails for its own reasons reports every mutation
as caught.
Mutation 23 is the third non-mutation in the sweep, and it is
recorded as one rather than as a surviving finding. A NULL node_uuid
satisfies neither IN (departing) nor NOT IN (sized) under
three-valued logic, so a displaced booking is excluded by the OR
whether the term is there or not -- confirmed by a clean unit and
live run under the mutation. The term is a statement of intent for the
next reader, not behaviour, which is the same conclusion mutations 3
and 5 reached about two other lines and the same reason to keep them.
Review round two¶
Ten items: 2 fix, 2 document, 4 consider, 2 informational, against round one's 3 fix / 1 document / 6 consider. Both fixes and both document items were taken, two of the four considers were taken and two declined. The diff this round is about a third of round one's and adds no proto field and no RPC, which is the shape a converging round should have.
Item 1 (fix) was a real defect, and it had a second instance the
review did not find. The hold body parameter is declared with the
uuid format, which accepts every spelling uuid.UUID() accepts and
hands the handler the caller's own, because that layer is check-only
(D14). active_claim_hold() then compared that string against a row
spelled str(uuid4()), so POST /instances answered 404 for a booking
which exists and is consumable, while DELETE .../holds/<ref> took the
same reference happily -- it checks with valid_uuid4() and the
database layer normalises below it. Two surfaces disagreeing about one
reference.
Sweeping the class rather than the instance is what found the rest of
it. Every uuid comparison this phase added was checked: the SQL
predicates all wrap in UUID(), the object layer normalises through
_as_uuid() (so claim_ref on all seven claim routes is fine, via
NamespaceClaim._db_get()'s str(_as_uuid(...))), and
active_claim_hold() was the single Python-side string comparison. But
the sweep had to go further than the real code, because the mock
double keyed its hold dictionaries on the caller's spelling in two
places where the real layer parses -- the guarded take
(UUID(hold_uuid)) and the per-claim read a release filters through
([UUID(u) for u in hold_uuids]). With only active_claim_hold()
fixed, the new handler test still failed: the reference resolved and
the double then refused the take, which the handler read as a lost race
and answered 409 consumed. The double now normalises through one
_hold_key() helper that says why, which is the derivable fix rather
than two more ad-hoc str(UUID(...)) calls.
Item 4 (consider) was taken because checking its premise made it
worse than the review said. The review's case was that eventing after
the commit can leave SCHEDULER_CAPACITY_LAST_SUCCESS stale and emit
no completion line, which alerting reads as a broken reconciler. True,
and _event_relocated_holds()'s own docstring already said failing the
task "would cost the pass's metrics and log line as well" -- it guarded
the claim-has-gone case and not DatabaseUnavailable, so it was an
incomplete implementation of its own stated intent. What the review did
not say is what reading _run_due_scheduled_jobs() shows: an exception
out of a scheduled job ends the whole maintenance batch, skipping
every job sorted after it and leaving the raising job due for the next
60-second cycle. So an unwritten event would have cost the reaper and
every other maintenance job its turn. Both halves are addressed -- the
success signal moved to sit with the commit, and the eventing guarded
in its own right -- and the mutation record below says which of the two
is load-bearing today.
Item 8 (consider) was taken with a better answer than the one
suggested. The review proposed documenting that finding a hold's
holder means enumerating every namespace, then its claims, then their
holds. GET /admin/claims already lists every claim in the cluster, so
the walk is two steps rather than three; the guide now names that walk
and says plainly that no node-scoped hold read exists, rather than
leaving advice that reads as a one-step lookup.
Items 5 and 6 were declined, both for the same underlying reason:
each is an additive change through the proto, the servicer and the
double, and round one is the evidence for what that costs. Item 5
would cap displaced_holds in the resources summary; it changes a
published field's contract, and bounding list-shaped
DatabaseService replies is the entire subject of a registered master
plan (PLAN-grpc-bounded-replies.md), where the cap should be designed
once rather than invented for one field in a review round. Item 6 would
push active_claim_hold()'s lookup into SQL; GetNamespaceClaimHoldsRequest
carries only claim_uuid, so it needs a new proto field plus both tier
implementations, the servicer and the double -- the same shape of
change that took round one to ~900 insertions -- for a cost that falls
only on namespaces which name a hold, and for correctness that is
already delivered by item 1's fix at the layer where the comparison
actually was. The review itself notes correctness is unaffected.
Items 9 and 10 are informational and need nothing: both record that phase 5 owns the refusal contract which would settle them.
Review round two: mutations 25 to 32¶
Eight more, carrying the sweep to 32, applied the same way as before
with the same driver in <scratchpad>/mutants/. Seven killed; the
eighth is not a mutation. One of the eight survived its first run and
is the reason this round has a test the review did not ask for.
| # | What is broken | Result | Killed by |
|---|---|---|---|
| 25 | active_claim_hold() compares spellings, not uuids (the defect) |
killed (unit) | test_a_booking_named_in_another_spelling_is_still_found |
| 26 | A reference which is not a uuid is left to raise | killed (unit) | test_a_reference_which_is_not_a_uuid_at_all_is_not_found |
| 27 | The double's guarded take keys on the caller's spelling | killed (unit) | test_a_booking_named_in_another_spelling_is_still_found |
| 28 | The double's per-claim read does the same, which a release filters through | killed (unit) | test_a_hold_is_released_however_its_reference_is_spelled |
| 29 | The post-commit eventing is left unguarded | killed (unit) | test_a_committed_pass_survives_eventing_it_cannot_write |
| 30 | The success gauge moved back below the eventing | not a mutation | -- |
| 31 | The double skips the claim guard for a consuming create | killed (unit) | test_a_booking_cannot_be_spent_past_its_claims_own_ceiling |
| 32 | The real transaction skips the claim guard for a consuming create | killed (live only) | test_a_booking_cannot_be_spent_past_its_claims_own_ceiling (live) |
Mutation 32 survived both tiers on its first run, and that was a real
finding. Item 2 asked for the aggregate-ceiling non-promise to be
documented, and suggested an end-to-end test for the 403; the review
also stated that the database tier's half is covered by
ConsumingDenialDetailTestCase's
test_a_claim_denial_is_unaffected_by_the_hold. It does not, and the
mutation is what showed it: that test forces the claim update's
rowcount to 0 in order to exercise what a refusal publishes, so
dropping the guard's WHERE
terms for a consuming create changes nothing it can observe. Writing
the promise into the operator guide without pinning it at the tier that
keeps it would have been documenting an assumption. The live test added
for it is killed by nothing else, because whether a guarded UPDATE's
WHERE binds is a property only a real server has.
Mutation 30 is the fourth non-mutation in the sweep, and it is recorded as one rather than as a finding. Item 4 was addressed two ways: the success gauge and completion line moved above the eventing, and the eventing guarded in its own right. With the guard in place (mutation 29) the exception is swallowed, so moving the gauge back below the eventing leaves the gauge set and the line emitted either way, and nothing observable depends on the order -- confirmed by a clean unit and live run under the mutation. The guard is what the test pins; the ordering is kept because it says where a pass's success signal belongs and is what stops a future unguarded write in that block costing the signal. Stating which of the two is load-bearing is the point of recording it.
The driver itself had to be fixed mid-sweep, which is worth
recording. Mutation 25's first run reported unit exit 1 with no
failing test named, because run.py scraped FAIL: lines out of the
log and stestr prints no FAIL: detail block for a failure raised
inside subTest() -- which every new spelling test uses. An empty
attribution reads exactly like a surviving mutation to anyone skimming
the sweep log. failures() now asks stestr failing --list, which
reports the last run's failures from the repository rather than from
the text, and falls back to the scrape only if stestr cannot answer.
Round one's lesson was that a mutation sweep is also a test of the
tests; this one is that it is a test of the sweep.
Review round three¶
Eight items: 1 fix, 1 document, 4 consider, 2 informational -- down from 2 fix in round two. Every item is about code earlier rounds added rather than about the original change, which is the generator loop's leading indicator, so this is the last round: nothing here is a defect in the feature.
| Item | Action | Taken | What |
|---|---|---|---|
| 1 | fix | yes | The .pyi stub was stale against a round-one .proto comment edit |
| 2 | document | yes | database.md's scheduler_capacity_* metric list did not name the three new counters |
| 3 | consider | yes | An overbooked node was evented every pass, for ever |
| 4 | consider | yes | A move's two clamps carried the same counter label |
| 5 | consider | yes | active_claim_hold()'s read cost is now recorded in its docstring |
| 6 | consider | yes | The three unbounded hold replies are now in PLAN-grpc-bounded-replies.md's audit scope |
| 7 | none | no | The preflight redirect's stage asymmetry; already in Future work |
| 8 | none | yes | One test case pinning the charged flag against the held-only classifier |
Item 1 was a stale stub, and the interesting part is that nothing
could see it. Comments are not in the serialized descriptor, so
database_pb2.py was unaffected and the generator-stamp and enum
checks in test_generated_proto_stubs.py are both blind to a comment.
The instance is a one-line regeneration; the class is that a
hand-edited .proto comment can sit in the tree indefinitely, which is
what happened here for two rounds, and what made item 15 of the
definition of done untrue while it was claimed. So the round added
ProtoCommentDriftTestCase, which compares every documented
declaration in protos/*.proto against the docstring protoc wrote for
it. Item 15 was then re-checked rather than re-asserted: a second
genprotos run leaves every stub's md5 unchanged.
The first cut of that check was itself caught by the sweep, which is
worth recording. It compared message comments only, and mutation 39
-- a hand-edited comment with no regeneration, the exact defect -- walked
straight through it, because the comment the mutation touched was on a
field. Of the documented declarations in protos/database.proto, 403
of 436 are on fields, so the first cut covered under a tenth of the
surface while reading as a guard. The rewritten version reads both the
annotated-attribute and the @property renderings and pairs 441
declarations, and carries a floor on that count so a future parse
change cannot quietly stop pairing them: a comparison that pairs
nothing passes for every tree. The lesson is round one's again, one
level up -- a test written to close a coverage gap needs its own
mutation before it is believed.
Item 3 was taken because the project's own convention decides it.
An event is a durable, queryable record and a log line is the right
channel for a repeated finding, so a standing condition which nothing
corrects was writing roughly 288 identical rows a day onto one node's
history until somebody deleted an instance -- burying the history an
operator reads it for. _event_overbooked_nodes() now events on
transition: the first pass which finds a node over, and again when the
set of dimensions over it changes. The warning log and the counter stay
per-pass, because they are how "how often" is read, and
GET /admin/resources already answers "is it true now". The memory is
the same once-per-distinct-condition shape
_force_capacity_reconcile() keeps, and is process-local for the same
stated reason: a new process has no cause to trust the previous elected
node's observations, and saying it once more is cheap.
The call site became unconditional as part of that, which is the half
easy to miss: the memory is pruned by the pass that finds nothing, so a
condition which clears and returns is a transition rather than being
swallowed as already said. Mutations 36 and 37 are both that line.
Item 4 is small but it is a correctness claim about a reply. Issue
4050 exists because clamped alone could not say what drifted, and
this phase added a second clamp site on the same row -- so a move which
clamped both the node's used_* and a carried booking's held_*
residue emitted two entries with an identical counter. The label is
now derived from the column family being moved rather than passed in
(_node_clamp_counter()), so it cannot drift from the ledger it names,
and a third counter triple added to that row raises here instead of
silently reusing the node uuid. The proto says the same on both
CapacityClampDetail.counter and AdmitInstancePlacementReply.clamps,
including that the order of the two is not part of the contract.
Items 5 and 6 are recorded rather than fixed, which is what they
asked for. Round two declined pushing active_claim_hold()'s
predicate into SQL and declined capping the three list-shaped hold
replies, both with reasons that still hold; what was missing was the
record. The read bound is now in the docstring with the shape the fix
would take if taken up -- a hold_uuid filter on
GetNamespaceClaimHoldsRequest, not a new RPC -- and the three fields
are in the bounded-replies plan's audit scope with the property that
makes a per-pass bound safe for two of them: the trigger is the
standing condition and not the removal set, so a bounded pass leaves
the remainder for the next one to find.
Review round three: mutations 33 to 42¶
Ten more, carrying the sweep to 42, applied the same way: by
replacement from a pristine copy held outside the worktree, one at a
time, each under timeout, with the suite run under
PYTHONDONTWRITEBYTECODE=1, and the four mutated files compared
byte-for-byte against the pristine copy afterwards. Every mutant ran
the whole unit suite. Baselines: unit 9160 passed / 337 skipped / 0
failed; live 251 passed / 0 failed on MariaDB 11.4.
All ten killed -- but one only after the test it was aimed at was
rewritten. See mutation 39.
| # | What is broken | Result | Killed by |
|---|---|---|---|
| 33 | _node_clamp_counter() labels held_* with the bare node uuid |
killed (unit) | test_the_held_ledger_is_suffixed, test_the_two_labels_differ, +2 |
| 34 | Overbooking is evented every pass again -- the defect | killed (unit) | test_a_standing_condition_is_evented_once_and_logged_every_pass, +2 |
| 35 | A node whose object had gone is remembered as evented | killed (unit) | test_an_event_that_could_not_be_written_is_not_remembered |
| 36 | The memory is updated rather than replaced, so nothing is forgotten | killed (unit) | test_a_condition_which_clears_and_returns_events_again |
| 37 | The eventing call is conditional again, so a clean pass prunes nothing | killed (unit) | test_a_condition_which_clears_and_returns_events_again |
| 38 | The memory keys on the reply's list rather than a set | killed (unit) | test_the_order_of_the_dimensions_is_not_a_transition |
| 39 | A .proto comment edited by hand with no regeneration |
survived, then killed | test_every_comment_reached_its_generated_stub, after the rewrite |
| 40 | _held_only_dimensions() stops answering no for a dimension with no held |
killed (unit) | test_a_consuming_denial_refused_on_demand_is_not_held_only, +1 |
| 41 | A consuming create's denial detail is charged | killed (unit) | ConsumingDenialDetailTestCase, 3 tests |
| 42 | The warning log is suppressed along with the event | killed (unit) | test_a_standing_condition_is_evented_once_and_logged_every_pass |
Mutation 39 is the finding of this round, and it is a finding
against a test written in this round rather than against the feature:
the first ProtoCommentDriftTestCase compared message comments only
and did not notice a hand-edited field comment at all. It is recorded
here as survived-then-killed rather than as a kill, because reporting
it as a kill would hide the only thing it taught.
Mutations 40 and 41 were both killed by tests that already existed,
which is worth saying plainly: item 8's suggested case is a second
witness rather than a closed gap. 40 is killed by the new consuming
case and by test_a_demand_refusal_on_a_booked_node_is_not_held_only;
41 is killed by three ConsumingDenialDetailTestCase tests and by
none of the new ones, since the new cases call _capacity_dimension()
directly. The review said as much -- it could construct no
misclassification and asked for the case as a guard against a future
change to the charged handling, which is what it is.