Files
seaweedfs/seaweed-block/docs/spec/cuttime/CutTime.tla
T
Ping QiuandClaude Opus 5.5 a5686e7fa7 Sync seaweed-block v1.1.1 into seaweed-block/ (#13411)
Brings seaweed-block main (v1.1.1 plus the docs and a test fix after it)
into seaweed-block/ as one commit. Only files under seaweed-block/ change,
and the subtree equals seaweed-block main exactly. The module's full
history stays in the seaweed-block repository.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 19:04:53 -08:00

485 lines
40 KiB
Plaintext

------------------------------ MODULE CutTime ------------------------------
(***************************************************************************)
(* CutTime r8c: (1) a *)
(* settlement read that sees a FOREIGN HEAD (owner changed) is terminal *)
(* and not progress: landed -> published, else typed fenced (a definite *)
(* failure); never renew and retry (NoRetryAfterFence). (2) an INHERITED *)
(* pending proposal is settled before this call's own work and is never *)
(* this call's result (OwnResult). Mutants "fence_renews", *)
(* "inherited_as_own". *)
(* CutTime r8: the publish (HEAD write) *)
(* answer can be lost; it may or may not have landed. The worker settles *)
(* it itself (read-back) inside the window: landed -> published; not *)
(* landed -> the publish is retried, the uploads kept. Only a settlement *)
(* with no progress for W ends typed unknown. Never a failure once a *)
(* publish may have landed (NoFalseFailure). Mutants "settle_as_failed", *)
(* "settle_skip". *)
(* CutTime r7: Kind = "detach", a *)
(* plain detach waiting on its final cut. It is never refused cut_busy. *)
(* - A running SCHEDULED cut is PREEMPTED: cancelled, its completed *)
(* uploads stay staged and the detach's final cut reuses them. *)
(* - Behind a running MANUAL cut it WAITS; its sequence rises with each *)
(* completed step of that cut AND at that cut's end (either outcome), *)
(* then with its own final cut's steps, so the stop CLI keeps renewing. *)
(* The blocking cut has its own window W. *)
(* - Its own window starts when its own final cut is admitted. *)
(* A reserved detach slot (N = 4 cuts + 1 detach) is projection, not *)
(* state. Mutants: "queued_no_renew" (no rise while waiting), *)
(* "preempt_manual", "preempt_loses_uploads". *)
(* CutTime r6: the poll's *)
(* cut handle. A manual cut's handle is kept by cut id from admission; *)
(* once the cut ended it is retired ONLY when it has aged Wc (the *)
(* request's own CLI window), never on sending the terminal answer (a *)
(* reply can be lost and the CLI polls again) and never by a later cut. *)
(* At a per-volume cap a new manual cut is refused, retryable; nothing is *)
(* evicted (cap not modelled: refusals touch no state here). *)
(* CutTime r5: read-only polling replaces resubmission. *)
(* After CutWindow r1, cuts have no request id or *)
(* receipt, so the CLI POLLS a read-only status by the cut's in-memory id *)
(* (never re-POSTs: a re-POST would meet its own cut's lock as cut_busy). *)
(* A holder restart loses the id: the poll answers "unknown cut id" and *)
(* the CLI exits unknown (the steps stay in the store and are adopted by *)
(* a later cut). The V3 time contract for a cut and for the CLI *)
(* that waits on it. A cut works through U per-object steps of its own *)
(* set, fixed at the barrier (a payload upload, or a verification lookup *)
(* or adoption of one object), one request at a time, then *)
(* publishes. *)
(* - A MANUAL cut that finds another cut holding the volume's capture *)
(* lock does not queue: it is refused at once, typed cut_busy {running *)
(* cut id}, retryable. Otherwise it is admitted, and its *)
(* window starts at admission. Internal scheduled cuts keep their *)
(* queue (not modelled). *)
(* - Each request has its own per-call deadline P: a request that does *)
(* not answer is cancelled and retried later, never left running. *)
(* - The cut's no-progress window W_cut (W) is renewed ONLY by a *)
(* completed per-object step of this cut, once per object per attempt. *)
(* W steps with none fail the attempt, typed cut_stalled. NO total *)
(* bound. *)
(* - The cut call, then each CLI poll by cut id, is answered with the *)
(* terminal result (published, cut_stalled, cut_busy, unknown cut id) *)
(* or in_progress {cut id, sequence}. Only a rise of the *)
(* sequence renews the CLI's window Wc; no rise or no answer for Wc *)
(* gives exit unknown. --deadline DL (0 = none) is absolute. *)
(* - Prompt: TRUE, the server answers as soon as the sequence rises (or *)
(* the cut ended), else at the latest W after the request: then *)
(* Wc = W + slack suffices. FALSE needs Wc = 2W + slack. *)
(* - After the CLI answered, the background schedule retries a failed or *)
(* cancelled cut with the steps already done kept. *)
(* - P is the bound VolDelSweep's resweep window derives from. *)
(* *)
(* Break = "none", or ONE of: *)
(* "total_cap" a total bound around the cut (today's 5 min) *)
(* "attempt_renews" sending a request renews the window *)
(* "timeout_renews" a cancelled request renews the window *)
(* "window_not_reset" a completed step does not renew the window *)
(* "no_call_deadline" a request that does not answer stays in *)
(* flight *)
(* "retry_loses_progress" a retry starts the steps over *)
(* "cli_total_timeout" the CLI's --timeout is a total bound *)
(* "cli_no_window" only the server times out *)
(* "global_renews" a process-global counter renews the CLI *)
(* "cli_no_slack" the CLI's window equals W_cut *)
(* "queued_stalls" a manual cut queues behind the lock holder *)
(* with its window running, and answers *)
(* cut_stalled *)
(* "busy_when_free" cut_busy answered while no cut holds the lock *)
(* "repost" the CLI re-POSTs instead of polling: its own *)
(* running cut answers it cut_busy *)
(* "restart_as_failed" a holder restart answers cut_stalled (a *)
(* failure) instead of unknown *)
(* "forget_on_send" the handle is dropped when the terminal *)
(* answer is sent *)
(* "overwrite_next" a later manual cut overwrites the handle *)
(* "retire_early" the handle is retired before it aged Wc (a *)
(* guessed TTL) *)
(* and the cfg row mut_answer_late: Prompt = FALSE with Wc = W + 1. *)
(* *)
(* Bounded by construction: done and ever subsets of 1..U, inflight 0..U, *)
(* age 0..P+1, since 0..W, real 0..W+1, pollAge 0..W, lastSeq 0..U, *)
(* cliSince and realCli 0..Wc+1, total 0..TCap, attempts 1..MaxAtt; the *)
(* rest phases and Booleans. *)
(***************************************************************************)
EXTENDS Integers, FiniteSets
CONSTANTS U, W, Wc, P, CapT, TCap, MaxAtt, DL, Prompt, Break, Kind, K
Ups == 1..U
VARIABLES phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
cli, link, pollOut, pollAge, lastSeq, cliSince, realCli,
early, cliEarly, linkLost, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail,
settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished
vars == <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
cli, link, pollOut, pollAge, lastSeq, cliSince, realCli,
early, cliEarly, linkLost, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
\* restarted ... queuedOnce sit in both groups: every action that does not name them keeps them
cliVars == <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn, handle, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
restVars == <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, handle, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
Ended == phase \in {"published", "failed", "unknownOutcome", "fenced"}
Min2(a, b) == IF a < b THEN a ELSE b
Waiting == cli = "waiting"
\* the request's sequence: its own cut's completed steps; for a queued detach also the blocking cut's (r7)
Seq == Cardinality(done) + (IF Break = "queued_no_renew" THEN 0 ELSE otherSteps)
+ (IF Break = "settle_no_rise" THEN 0 ELSE settleSteps) \* (r8 BFS) a completed read-back renews AND rises
+ (IF inhSettled THEN 1 ELSE 0) \* (r8c) settling an inherited proposal is a step too
DetachQ == Kind = "detach" /\ phase = "admitting" /\ other = "manual" \* a detach waiting behind a running MANUAL cut
OtherDue == DetachQ /\ osince >= W \* the blocking cut's own window ran out
CliWin == IF Break = "cli_no_slack" THEN W ELSE Wc
Terminal == phase \in {"published", "failed", "busy", "lost", "unknownOutcome", "fenced"}
Queued == phase = "admitting" /\ Break = "queued_stalls"
Init == /\ phase = "admitting" /\ done = {} /\ ever = {} /\ inflight = 0 /\ hung = FALSE /\ age = 0
/\ since = 0 /\ real = 0 /\ total = 0 /\ attempts = 1 /\ other \in {"none", "scheduled", "manual"}
\* a running scheduled cut may already have completed some uploads (staged, reusable)
/\ otherDone \in (IF Kind = "detach" /\ other = "scheduled" THEN SUBSET Ups ELSE {{}}) /\ manualPreempted = FALSE
/\ landed = FALSE /\ landedEver = FALSE /\ settleStalled = FALSE /\ falseFail = FALSE /\ settleSteps = 0
\* (r8c) an earlier cut may have left an uncertain proposal pending; whether it landed is unknown to this call
/\ foreign = FALSE /\ fencedSeen = FALSE /\ inherited \in {"none", "pending"} /\ inheritedLanded \in BOOLEAN
/\ inhSettled = FALSE /\ ownPublished = FALSE
/\ cli = "waiting" /\ link = "up" /\ pollOut = TRUE /\ pollAge = 0 /\ lastSeq = 0 /\ cliSince = 0 /\ realCli = 0
/\ early = FALSE /\ cliEarly = FALSE /\ linkLost = FALSE /\ timedOutOnce = FALSE /\ failedOnce = FALSE
/\ stallQueued = FALSE /\ busyFalse = FALSE /\ restarted = FALSE /\ busyOwn = FALSE
/\ handle = "none" /\ hAge = 0 /\ lostOnce = FALSE /\ otherSteps = 0 /\ osince = 0 /\ queuedOnce = FALSE
\* ---- admission of the manual cut, or of a detach's final cut ----
\* no other cut holds the capture lock: admitted; the window starts here
Admit == /\ phase = "admitting" /\ other = "none" /\ phase' = "uploading" /\ handle' = "held"
/\ since' = 0 /\ real' = 0
/\ UNCHANGED <<done, ever, inflight, hung, age, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
\* (r7) the cut a queued detach waits on completes a step: its own window renews, and the detach's sequence rises
OtherStep == /\ DetachQ /\ otherSteps < K
/\ otherSteps' = otherSteps + 1 /\ osince' = 0
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, handle, hAge, lostOnce, queuedOnce,
otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* another cut holds it: a manual cut is refused at once, typed cut_busy {running cut id}, retryable (a detach queues)
Busy == /\ phase = "admitting" /\ Break # "queued_stalls" /\ Kind = "cut"
/\ other # "none" \/ Break = "busy_when_free"
/\ phase' = "busy" /\ busyFalse' = (busyFalse \/ other = "none")
/\ UNCHANGED <<done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued>> /\ UNCHANGED cliVars
\* (r7) a detach admission cancels a running SCHEDULED cut; its completed uploads stay staged and are reused
\* (mutants: the preempted cut's uploads are lost; a running MANUAL cut is preempted)
Preempt == /\ Kind = "detach" /\ phase = "admitting"
/\ other = "scheduled" \/ (Break = "preempt_manual" /\ other = "manual")
/\ other' = "none" /\ manualPreempted' = (manualPreempted \/ other = "manual")
/\ done' = (IF Break = "preempt_loses_uploads" THEN done ELSE done \cup otherDone)
/\ ever' = ever \cup otherDone
/\ UNCHANGED <<phase, inflight, hung, age, since, real, total, attempts,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone>>
\* the other cut ends (published or failed) and releases the lock; for a detach waiting on it, that end is
\* progress of the work it waits on, so its sequence rises (else the CLI sees no rise for the blocker's last W
\* plus its own first step: up to 2W)
OtherEnd == /\ other # "none" /\ other' = "none"
/\ otherSteps' = (IF DetachQ THEN otherSteps + 1 ELSE otherSteps)
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn,
handle, hAge, lostOnce, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
\* ---- the cut ----
\* a request for step u is sent; it may hang (no answer)
Start(u) == /\ phase = "uploading" /\ inflight = 0 /\ u \notin done
/\ inflight' = u /\ age' = 0 /\ hung' \in BOOLEAN
/\ since' = (IF Break = "attempt_renews" THEN 0 ELSE since)
/\ UNCHANGED <<phase, done, ever, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>> /\ UNCHANGED cliVars
\* the step completes: done and kept, the cut's window renewed
Complete == /\ phase = "uploading" /\ inflight # 0 /\ ~hung
/\ done' = done \cup {inflight} /\ ever' = ever \cup {inflight} /\ inflight' = 0 /\ age' = 0
/\ since' = (IF Break = "window_not_reset" THEN since ELSE 0)
/\ real' = 0
/\ UNCHANGED <<phase, hung, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>> /\ UNCHANGED cliVars
\* the per-call deadline cancels a request that has not answered; it is retried later
CallTimeout == /\ phase = "uploading" /\ inflight # 0 /\ age >= P /\ Break # "no_call_deadline"
/\ inflight' = 0 /\ age' = 0 /\ hung' = FALSE /\ timedOutOnce' = TRUE
/\ since' = (IF Break = "timeout_renews" THEN 0 ELSE since)
/\ UNCHANGED <<phase, done, ever, real, total, attempts, other,
early, failedOnce, stallQueued, busyFalse>> /\ UNCHANGED cliVars
\* (r8c) an inherited pending proposal is settled BEFORE this call's own work; its outcome is never this call's result
\* (mutant inherited_as_own: a landed inherited proposal is returned as this call's published cut)
SettleInherited == /\ phase = "uploading" /\ inherited = "pending" /\ inflight = 0
/\ inherited' = "none" /\ inhSettled' = TRUE /\ since' = 0 /\ real' = 0
/\ phase' = (IF Break = "inherited_as_own" /\ inheritedLanded THEN "published" ELSE "uploading")
/\ UNCHANGED <<done, ever, inflight, hung, age, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted,
landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inheritedLanded, ownPublished>>
\* every step done: the HEAD write publishes the cut, and its answer arrives (only after any inherited proposal is settled)
Publish == /\ phase = "uploading" /\ inflight = 0 /\ done = Ups /\ inherited = "none" /\ phase' = "published"
/\ ownPublished' = TRUE
/\ UNCHANGED <<done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted,
landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled>>
\* (r8) the HEAD write's answer is lost: it may or may not have landed. The worker settles it itself
\* (mutants: report it failed at once; report unknown without settling)
PublishLost == /\ phase = "uploading" /\ inflight = 0 /\ done = Ups /\ settleSteps < 2 \* bounded: at most 2 lost answers
/\ inherited = "none"
/\ landed' \in BOOLEAN /\ landedEver' = (landedEver \/ landed')
/\ foreign' \in BOOLEAN \* (r8c) the owner may have changed meanwhile (a fencing takeover)
/\ phase' = (IF Break = "settle_as_failed" THEN "failed"
ELSE IF Break = "settle_skip" THEN "unknownOutcome" ELSE "settling")
/\ UNCHANGED <<done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted, settleStalled, falseFail, settleSteps, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
\* the settlement's read-back answers (a completed step: the window renews): landed -> published; not landed ->
\* the publish is retried, the uploads kept. (r8c) A FOREIGN HEAD (the owner changed) is terminal and no progress:
\* landed -> published; not landed -> typed fenced, a definite failure (it can never land). Mutant fence_renews:
\* a foreign not-landed read renews and retries.
Settle == /\ phase = "settling"
/\ phase' = (IF landed THEN "published"
ELSE IF foreign /\ Break # "fence_renews" THEN "fenced" ELSE "uploading")
/\ fencedSeen' = (fencedSeen \/ foreign)
/\ ownPublished' = (ownPublished \/ landed)
/\ IF foreign /\ Break # "fence_renews"
THEN UNCHANGED <<since, real, settleSteps>>
ELSE since' = 0 /\ real' = 0 /\ settleSteps' = settleSteps + 1 \* the same step report renews and rises
/\ UNCHANGED <<done, ever, inflight, hung, age, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted,
landed, landedEver, settleStalled, falseFail, foreign, inherited, inheritedLanded, inhSettled>>
\* the settlement makes no progress for W (the store does not answer): the outcome stays typed unknown
SettleStall == /\ phase = "settling" /\ since >= W
/\ phase' = "unknownOutcome" /\ settleStalled' = TRUE
/\ UNCHANGED <<done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, falseFail,
settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
\* W steps with no completed step (or, in the mutant, the total bound): cut_stalled
CapDue == Break = "total_cap" /\ total >= CapT
Fail == /\ phase = "uploading" \/ Queued
/\ since >= W \/ CapDue
/\ phase' = "failed" /\ inflight' = 0 /\ age' = 0 /\ hung' = FALSE /\ failedOnce' = TRUE
/\ early' = (early \/ real < W)
/\ stallQueued' = (stallQueued \/ phase = "admitting")
/\ UNCHANGED <<done, ever, since, real, total, attempts, other, timedOutOnce, busyFalse>> /\ UNCHANGED cliVars
\* the holder process restarts: the running cut dies and its in-memory id is gone; the steps already in the store stay
HolderRestart == /\ phase \in {"uploading", "settling"} /\ ~restarted
/\ phase' = (IF Break = "restart_as_failed" THEN "failed" ELSE "lost")
/\ inflight' = 0 /\ age' = 0 /\ hung' = FALSE /\ restarted' = TRUE
/\ UNCHANGED <<done, ever, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, busyOwn, handle, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* after the CLI answered, the background schedule retries with the steps already done (adopted from the store)
Retry == /\ phase \in {"failed", "cancelled", "lost", "unknownOutcome"} /\ ~Waiting /\ attempts < MaxAtt
/\ attempts' = attempts + 1 /\ phase' = "uploading" /\ since' = 0 /\ real' = 0
/\ done' = (IF Break = "retry_loses_progress" THEN {} ELSE done)
/\ UNCHANGED <<ever, inflight, hung, age, total, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse>> /\ UNCHANGED cliVars
\* ---- the CLI: polls a read-only status by cut id; in_progress {cut id, sequence} or the terminal result ----
Poll == /\ Waiting /\ ~pollOut /\ pollOut' = TRUE /\ pollAge' = 0
/\ UNCHANGED restVars /\ UNCHANGED <<cli, link, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* the server answers in_progress with this cut's sequence; only a rise renews the CLI's window
InProgress == /\ Waiting /\ pollOut /\ link = "up" /\ phase \in {"uploading", "admitting", "settling"}
/\ pollOut' = FALSE
/\ IF Seq > lastSeq
THEN lastSeq' = Seq /\ cliSince' = 0 /\ realCli' = 0
ELSE UNCHANGED <<lastSeq, cliSince, realCli>>
/\ UNCHANGED restVars /\ UNCHANGED <<cli, link, pollAge, cliEarly, linkLost>>
\* the CLI's requests stop getting answers (transport or server process gone), and stay so
LinkDrop == /\ Waiting /\ link = "up" /\ link' = "silent" /\ linkLost' = TRUE
/\ UNCHANGED restVars /\ UNCHANGED <<cli, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly>>
\* (mutant) another cut's completed step moves a process-global counter the CLI watches
OtherUpload == /\ Break = "global_renews" /\ Waiting /\ cliSince' = 0
/\ UNCHANGED restVars /\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, realCli, cliEarly, linkLost>>
\* the terminal answers over a live link: exit 0 published; exit 1 cut_stalled; a distinct retryable exit on cut_busy
Justified == real >= W \/ (DL > 0 /\ total >= DL)
CliOk == /\ Waiting /\ pollOut /\ link = "up" /\ phase = "published" /\ handle = "held" /\ cli' = "ok"
/\ UNCHANGED restVars /\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
CliBusy == /\ Waiting /\ pollOut /\ link = "up" /\ phase = "busy" /\ cli' = "busy"
/\ UNCHANGED restVars /\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* the holder restarted: the poll answers "unknown cut id"; the CLI exits unknown (the outcome is unknown)
CliUnknownId == /\ Waiting /\ pollOut /\ link = "up" /\ phase = "lost" /\ cli' = "unknown"
/\ UNCHANGED restVars /\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* (mutant) the CLI re-POSTs the cut instead of polling: the request meets its own running cut's lock
RepostBusy == /\ Break = "repost" /\ Waiting /\ pollOut /\ link = "up" /\ phase = "uploading"
/\ cli' = "busy" /\ busyOwn' = TRUE
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, handle, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* ---- the handle a poll reads (r6) ----
\* a terminal answer is sent but lost on the way (the link stays up); the CLI polls again
ReplyLost == /\ Waiting /\ pollOut /\ link = "up" /\ Ended /\ handle = "held"
/\ pollOut' = FALSE /\ lostOnce' = TRUE
/\ handle' = (IF Break = "forget_on_send" THEN "gone" ELSE "held")
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, hAge,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<cli, link, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* the ended cut's handle is retired once it aged Wc, the request's own CLI window (mutant: any time)
Retire == /\ handle = "held" /\ Ended /\ (hAge >= Wc \/ Break = "retire_early") /\ handle' = "gone"
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* (mutant) a later manual cut takes the slot and overwrites the ended cut's handle
OtherManual == /\ Break = "overwrite_next" /\ handle = "held" /\ Ended /\ handle' = "gone"
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<cli, link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* the poll finds no handle for the id: "unknown cut id"; the CLI exits unknown
CliGone == /\ Waiting /\ pollOut /\ link = "up" /\ Ended /\ handle = "gone" /\ cli' = "unknown"
/\ UNCHANGED restVars /\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* (r8) the settlement stalled: the server's typed outcome-unknown answer; the CLI exits unknown
CliServerUnknown == /\ Waiting /\ pollOut /\ link = "up" /\ phase = "unknownOutcome" /\ handle = "held" /\ cli' = "unknown"
/\ UNCHANGED restVars /\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* (r8c) the typed fenced answer: a definite failure (the proposal can never land); judged like cut_stalled
CliFenced == /\ Waiting /\ pollOut /\ link = "up" /\ phase = "fenced" /\ handle = "held" /\ cli' = "fenced"
/\ falseFail' = (falseFail \/ landedEver)
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, handle, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, settleSteps,
foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
CliStalled == /\ Waiting /\ pollOut /\ link = "up" /\ phase = "failed" /\ handle = "held" /\ cli' = "stalled"
/\ cliEarly' = (cliEarly \/ ~Justified)
/\ falseFail' = (falseFail \/ landedEver) \* judged when the CLI answers: its own attempt (Retry needs ~Waiting)
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, handle, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, linkLost>>
\* no rise of this cut's sequence (or no answer) for the CLI's window: exit typed unknown; the cut is not touched
CliSilentDue == Waiting /\ cliSince >= CliWin /\ Break # "cli_no_window"
CliSilent == /\ CliSilentDue /\ cli' = "unknown"
/\ UNCHANGED restVars /\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, cliEarly, linkLost>>
\* the user's deadline, or (mutant) the --timeout as a total bound: the CLI exits; a live connection cancels the cut
CliDue == /\ Waiting
/\ (DL > 0 /\ total >= DL) \/ (Break = "cli_total_timeout" /\ total >= CapT)
CliGiveUp == /\ CliDue
/\ cli' = (IF DL > 0 /\ total >= DL THEN "deadline" ELSE "timeout")
/\ cliEarly' = (cliEarly \/ ~Justified)
/\ IF phase = "uploading" /\ link = "up"
THEN phase' = "cancelled" /\ inflight' = 0 /\ age' = 0 /\ hung' = FALSE
ELSE UNCHANGED <<phase, inflight, age, hung>>
/\ UNCHANGED <<done, ever, since, real, total, attempts, other,
early, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn, handle, hAge, lostOnce,
otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
/\ UNCHANGED <<link, pollOut, pollAge, lastSeq, cliSince, realCli, linkLost>>
\* ---- time ----
\* an answer the server owes now: a terminal result; at the latest W after the request; with Prompt, a rise
AnswerDue == /\ Waiting /\ pollOut /\ link = "up"
/\ Terminal \/ pollAge >= W \/ (Prompt /\ Seq > lastSeq)
CliClocks == /\ cliSince' = (IF Waiting THEN Min2(cliSince + 1, Wc + 1) ELSE cliSince)
/\ realCli' = (IF Waiting THEN Min2(realCli + 1, Wc + 1) ELSE realCli)
/\ pollAge' = (IF Waiting /\ pollOut THEN Min2(pollAge + 1, W) ELSE pollAge)
/\ total' = Min2(total + 1, TCap)
\* every party answers its deadlines first; the admission answers at once (no waiting state)
TimeOK == /\ ~CapDue /\ ~CliDue /\ ~CliSilentDue /\ ~AnswerDue /\ ~(Waiting /\ ~pollOut) /\ ~OtherDue
/\ ~(phase = "admitting" /\ Break # "queued_stalls" /\ ~DetachQ)
\* time passes while the cut works (in the mutant, also while it queues); a queued detach's own window has not started
Tick == /\ phase \in {"uploading", "settling"} \/ Queued \/ DetachQ
/\ since < W /\ TimeOK
/\ inflight = 0 \/ age < P \/ Break = "no_call_deadline"
/\ since' = (IF DetachQ THEN since ELSE since + 1)
/\ real' = (IF DetachQ THEN real ELSE Min2(real + 1, W + 1))
/\ age' = (IF inflight # 0 THEN Min2(age + 1, P + 1) ELSE age)
/\ osince' = (IF DetachQ THEN Min2(osince + 1, W) ELSE osince)
/\ queuedOnce' = (queuedOnce \/ DetachQ)
/\ CliClocks
/\ UNCHANGED <<phase, done, ever, inflight, hung, attempts, other, cli, link, pollOut, lastSeq,
early, cliEarly, linkLost, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn,
handle, hAge, lostOnce, otherSteps, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
\* time passes for a CLI whose answer is lost after the cut ended (over a live link the answer comes first)
CliTick == /\ phase \notin {"uploading", "admitting", "settling"} /\ Waiting /\ TimeOK
/\ CliClocks
/\ hAge' = (IF handle = "held" /\ Ended THEN Min2(hAge + 1, Wc) ELSE hAge)
/\ UNCHANGED <<phase, done, ever, inflight, hung, age, since, real, attempts, other, cli, link, pollOut, lastSeq,
early, cliEarly, linkLost, timedOutOnce, failedOnce, stallQueued, busyFalse, restarted, busyOwn,
handle, lostOnce, otherSteps, osince, queuedOnce, otherDone, manualPreempted, landed, landedEver, settleStalled, falseFail, settleSteps, foreign, fencedSeen, inherited, inheritedLanded, inhSettled, ownPublished>>
Next == \/ Admit \/ Busy \/ OtherEnd \/ OtherStep \/ Preempt
\/ \E u \in Ups : Start(u)
\/ Complete \/ CallTimeout \/ Publish \/ PublishLost \/ Settle \/ SettleStall \/ Fail \/ HolderRestart \/ Retry
\/ Poll \/ InProgress \/ LinkDrop \/ OtherUpload
\/ CliOk \/ CliBusy \/ CliUnknownId \/ RepostBusy \/ CliStalled \/ CliServerUnknown \/ CliSilent \/ CliGiveUp
\/ SettleInherited \/ CliFenced
\/ ReplyLost \/ Retire \/ OtherManual \/ CliGone
\/ Tick \/ CliTick
Spec == Init /\ [][Next]_vars
\* ---- rules ----
\* the cut answers cut_stalled only after W steps with no completed step, never on a total bound
NoEarlyFail == ~early
\* no attempt runs past W steps without a completed step (sending or cancelling a request is not progress)
NoSilentStall == phase = "uploading" => real <= W
\* no request outlives its per-call deadline: the bound VolDelSweep's resweep window derives from
NoLongCall == inflight # 0 => age <= P
\* steps done are never lost to a retry
ProgressKept == ever \subseteq done
\* the CLI fails only on cut_stalled after W, or at the deadline the user chose
CliNoEarlyExit == ~cliEarly
\* the CLI never waits past its window without a seen rise of THIS cut's sequence
CliNoSilentWait == Waiting => realCli <= Wc
\* the CLI answers unknown only when its requests really went unanswered, or the holder restarted (the id is gone)
CliUnknownOnlySilent == cli = "unknown" => (linkLost \/ restarted \/ settleStalled)
\* (r8) the CLI never reports a failure once a publish may have landed
NoFalseFailure == ~falseFail
\* (r8c) the CLI's success answer is this call's OWN proposal published, never an inherited one
OwnResult == cli = "ok" => ownPublished
\* (r8c) a settlement that saw a foreign HEAD never retries the publish (fence is terminal, not progress)
NoRetryAfterFence == fencedSeen => phase # "uploading"
\* the CLI never answers cut_busy because of its own running cut (it polls, never re-POSTs)
CliBusyNotOwn == ~busyOwn
\* (r7) a detach never preempts a running MANUAL cut (it waits behind it)
NoManualPreempt == ~manualPreempted
\* a cut that was never admitted never answers cut_stalled (waiting for the lock is not this cut's silence)
NoQueuedStall == ~stallQueued
\* cut_busy only while another cut holds the capture lock
BusyOnlyWhenHeld == ~busyFalse
\* ---- witnesses ----
WitSlowNoFail == ~(cli = "ok" /\ total >= TCap /\ ~failedOnce) \* a cut longer than any total bound, progressing: CLI exit 0
WitTimedOutThenPub == ~(cli = "ok" /\ timedOutOnce) \* a hung request cancelled at P and retried: CLI exit 0
WitCliStalled == ~(cli = "stalled") \* no progress for W: cut_stalled, CLI exit 1
WitStalledRetryPub == ~(phase = "published" /\ cli = "stalled") \* the background retry keeps the steps and publishes
WitCliDeadline == ~(cli = "deadline" /\ phase = "cancelled") \* the user's deadline passes: CLI exits, cut cancelled
WitUnknownThenPub == ~(cli = "unknown" /\ phase = "published") \* requests unanswered: CLI unknown, the cut still publishes
WitBusy == ~(cli = "busy") \* another cut holds the lock: cut_busy at once, retryable exit
WitRestartUnknown == ~(cli = "unknown" /\ restarted /\ ~linkLost) \* the holder restarted: unknown cut id, CLI unknown over a live link
WitLostReplyThenOk == ~(cli = "ok" /\ lostOnce) \* the terminal reply was lost; the next poll still finds the handle
WitDetachAfterQueue == ~(cli = "ok" /\ queuedOnce /\ otherSteps >= 2) \* a detach waited behind a manual cut through its steps and end, then done
WitPreemptReuse == ~(cli = "ok" /\ otherDone # {} /\ Kind = "detach") \* a detach preempted a scheduled cut and reused its staged uploads
WitSettleThenOk == ~(cli = "ok" /\ landedEver) \* a lost publish answer that landed, settled by read-back: CLI exit 0
WitSettleUnknown == ~(cli = "unknown" /\ settleStalled /\ ~linkLost /\ ~restarted) \* the settlement stalled for W: typed unknown over a live link
WitFenced == ~(cli = "fenced") \* a lost answer, a foreign HEAD, not landed: typed fenced
WitInheritedThenOwn == ~(cli = "ok" /\ inhSettled /\ inheritedLanded) \* an inherited proposal had landed; this call still published its own
=============================================================================