March Docs

Control

Control: the pure core of the in-cluster control plane (distributed-deploys build step 12a). Design: specs/plans/2026-09-28-dd-step12-control-plane-design.md, sections 3, 4, 7 and 8, decisions D37-D41.

The control plane holds no root keys (D37). forge writes and signs a RELEASE: a sequence number, the digest of its parent, the environment, the topology digest, the builds it ships, and an ordered list of steps with host selectors and gates. The leader only executes it:

  • parse / serialize read and write the release's text form (section 4);
  `check` validates it, `digest` / `verify` / `sign` cover its identity and
  its operator signature, and `accept` is the leader's compare-and-set on
  `parent`.
* `pass` is the executor, level-triggered and pure: its inputs are the
  newest release held, the membership (which node is in which pool), what
  each Agent last reported, the nodes with an order outstanding, and the
  time. It finds the first step whose selected nodes do not yet report the
  step's end state and orders the next nodes the step allows. Nothing else
  is carried between passes, so a new leader resumes a half-finished
  rollout from observation alone. A failed step or gate HALTS the release;
  the executor never rolls back (a rollback is a new release).
* `Leader` wraps `pass` in the few facts a leader keeps in memory: the
  reports (`Obs`, with the leader-clock time each node became healthy, so a
  gate window restarts on a new leader, section 4), orders in flight, and a
  sticky halt.
* `agent_apply` is the Agent's side of one `StepOrder`, over an `AgentOps`
  dictionary: the node's reload server and CAS are reached through it. Until
  the `reload_request` builtin exists (design section 6) the dictionary is
  the seam tests and the real Agent plug into.
* The payloads of the control protocols (section 7): `AgentReport`,
  `StepOrder`, `StepResult`, `CtlChunk`, and the `ControlOps` dictionary a
  leader's `Ctl` session is driven by. The `Ctl` and `CtlFetch`
  declarations themselves live in test/session/control_peers.march for
  now. A protocol may live in a stdlib module since 2026-10-03
  (specs/progress/2026-10-03-endpoints-protocol-in-nested-module.md); the
  move is specs/todos/2026-09-28-dd-step12a-control-wiring.md.

The leader itself is count = 1 placement over SWIM with no strict lease (D40): two leaders during a partition each drive their side toward the newest release they hold, and nodes refuse anything older (12-pre).

Everything but the Agent's real ops, signing and verifying is pure, so the examples build one small release (rel, in parse) and a simulated node and follow it through the executor; later examples reuse earlier bindings.

doc: try

Types

typeCtlHostsCtlHosts = HostsCanary(Int) | HostsRest | HostsAll#
typeCtlActionCtlAction = DoActivate(String) | DoTopology | DoDrain | DoCerts#
typeCtlGateCtlGate = GateNone | GateHealthy(Int)#
typeCtlStepCtlStep = { id : Int, pools : List(String), hosts : CtlHosts, action : CtlAction, gate : CtlGate, batch : Int }#
typeCtlBuildCtlBuild = { name : String, base : String, manifest : String }#
typeCtlDrainCtlDrain = { epoch : Int, soft_ms : Int, hard_ms : Int }#
typeCtlLineCtlLine = { step : Int, text : String }#
typeCtlCertCtlCert = { node : String, cert : String }#
typeCtlReleaseCtlRelease = {#
typeCtlMemberCtlMember = { node : String, pools : List(String) }#
typeCtlVersionCtlVersion = { build : String, manifest : String }#
typeCtlFailureCtlFailure = { seq : Int, step : Int, why : String }#
typeAgentReportAgentReport = {#
typeStepOrderStepOrder = {#
typeStepResultStepResult = { seq : Int, step : Int, node : String, ok : Bool, detail : String }#
typeCtlObsCtlObs = { report : AgentReport, healthy_since : Option(Int) }#
typeCtlDecisionCtlDecision = RolloutApply(Int, List(StepOrder)) | RolloutWait(Int, String) | RolloutHalted(Int, String, String) | RolloutComplete | RolloutBehind(Int)#
typeCtlLeaderCtlLeader = { release : Option(CtlRelease), obs : List(CtlObs), inflight : List(String), halted : Option(CtlDecision) }#
typeAgentOpsAgentOps = { report : () -> AgentReport, has : String -> Bool, request : String -> String }#
typeCertOpsCertOps = {#
typeCtlChunkCtlChunk = { offset : Int, data : String, last : Bool }#
typeCtlNextCtlNext = NextOrder(StepOrder) | NextPoll | NextBye(String)#
typeControlOpsControlOps = { report : AgentReport -> (), stepped : StepResult -> (), next : String -> CtlNext, head : () -> Int }#

Functions

fnacceptaccept(head : Option(CtlRelease), r : CtlRelease) : Result((), String)#

The leader's compare-and-set (design section 9): may [r] replace [head], the newest release held? The first release is accepted whatever its parent. The held release itself is accepted again (a retry). Otherwise r.seq must be higher and r.parent must be digest(head): the parent chain is enforced by the one writer that sees every release (section 5).

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.accept(None, rel)
    Ok(())
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.accept(Some(rel), rel)
    Ok(())
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.accept(Some(rel), { rel with seq: 2, parent: Control.digest(rel) })
    Ok(())
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.accept(Some(rel), { rel with seq: 2, parent: "x" })
    Err("parent mismatch: release 2 does not follow the head 1")
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.accept(Some({ rel with seq: 5 }), rel)
    Err("stale: release 1 is older than the head 5")
fnagent_applyagent_apply(ops : AgentOps, o : StepOrder) : StepResult do agent_apply_ticked(ops, o, 200) end#

Apply one order on this node. Idempotent: a node that already reports the order's end state answers ok without touching the reload server, so an order a new leader sends again is harmless. Missing artifacts or a refused line answer not-ok with the reason, which halts the release. A topology step the reload server took is given a few placement ticks for the node to report it (agent_apply_within).

Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> let res = Control.agent_apply(ops, ord)
    march> res.detail
    "already applied"
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> let res = Control.agent_apply({ ops with has: fn h -> false }, { ord with want: "m2" })
    march> res.detail
    "missing artifacts: m1"
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> let res = Control.agent_apply({ ops with request: fn l -> "ERR bad signature" }, { ord with want: "m2", lines: "SEQ 1 x" })
    march> res.detail
    "ERR bad signature"
fnagent_apply_certsagent_apply_certs(c : CertOps, o : StepOrder) : StepResult#

Apply a do:certs order on this node (step 12b): check the release it carries (the deploy key's signature, that it is the release the order names, not older than one this node took from), then take the certificate item for THIS node, if there is one (apply_cert; items for other nodes are not this node's to apply), then every revocation (ClusterNode.revoke keeps a known one once, so a revocation already gossiped here is a no-op). Idempotent: a certificate already in use and a revocation already known change nothing. Any refusal answers not-ok with the reason, which halts the release.

    match Control.agent_apply_certs(cert_ops, order) do
      r -> if r.ok do () else println("refused: " ++ r.detail) end
    end
fnagent_apply_certs_recordingagent_apply_certs_recording(c : CertOps, memory : Vault(String), o : StepOrder) : StepResult#

agent_apply_certs, remembering a failure in [memory] like agent_apply_recording, and the release's seq once it succeeds: the floor below which this node refuses certificate releases (CertOps.floor should read it back with cert_floor).

    let res = Control.agent_apply_certs_recording(cert_ops, mem, order)
    Control.cert_floor(mem)    -- order.seq once res.ok
fnagent_apply_recordingagent_apply_recording(ops : AgentOps, memory : Vault(String), o : StepOrder, tick_ms : Int) : StepResult#

agent_apply_ticked (on a node whose placement loop ticks every [tick_ms]), remembering a failure in [memory] so the node's next report carries it (a new leader re-derives the halt from it) and forgetting it once a later order succeeds. A batch left half-staged by an earlier failed step is rolled back first.

Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> let mem = Authority.must(Vault.new("doc_control_memory"))
    march> let res = Control.agent_apply_recording({ ops with has: fn h -> false }, mem, { ord with want: "m2" }, 200)
    march> res.ok
    false
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> let mem = Authority.must(Vault.new("doc_control_memory"))
    march> let res = Control.agent_apply_recording(ops, mem, ord, 200)
    march> res.ok
    true

After the failure `mem` holds `"failure"` = `"1 1 missing artifacts: m1"` (`seq step
why`); the success that follows removes it.
fnagent_apply_tickedagent_apply_ticked(ops : AgentOps, o : StepOrder, tick_ms : Int) : StepResult#

agent_apply on a node whose placement loop ticks every [tick_ms] (MARCH_PLACEMENT_TICK_MS; agent_apply assumes its default, 200): a topology step waits topology_wait_ms(tick_ms) for the node to report it.

A [tick_ms] below 1 is taken as 1.

## Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> let res = Control.agent_apply_ticked(ops, ord, 50)
    march> res.ok
    true
fnagent_apply_withinagent_apply_within(ops : AgentOps, o : StepOrder, wait_ms : Int, poll_ms : Int) : StepResult#

agent_apply, waiting at most [wait_ms] (polling every [poll_ms]) for a topology step's end state. The reload server takes a TOPOLOGY line at once, but the node reports the digest only once its placement loop has re-read the file, on its next tick (MARCH_PLACEMENT_TICK_MS): until then the step is pending, not failed. Every other step is checked once.

Examples

Every line accepted, but the node never reports the new manifest:

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> let res = Control.agent_apply_within(ops, { ord with want: "m2" }, 0, 10)
    march> res.detail
    "the node accepted every line but does not report activate(web) at m2"
fnanswer_linesanswer_lines(resp : String) : List(String)#

The non-empty lines of a reload-server answer.

Examples

    march> Control.answer_lines("OK\n\nSTATE head:3\n")
    ["OK", "STATE head:3"]
fnaudit_decisionaudit_decision(ts : Int, leader : String, seq : Int, d : CtlDecision) : Option(String)#

The audit line for a release's end: a halt (with its step, node and reason) or completion; None for any other decision.

Examples

    march> Control.audit_decision(1000, "n1", 1, Control.RolloutComplete)
    Some("{\"ts\":1000,\"type\":\"complete\",\"leader\":\"n1\",\"seq\":1}\n")
    march> Control.audit_decision(1000, "n1", 1, Control.RolloutWait(1, "gate"))
    None
fnaudit_orderaudit_order(ts : Int, leader : String, o : StepOrder) : String#

The audit line for an order sent to a node (its signed lines are not logged).

Examples

    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> Control.audit_order(1000, "n1", ord)
    "{\"ts\":1000,\"type\":\"order\",\"leader\":\"n1\",\"seq\":1,\"release\":\"abc\",\"step\":1,\"node\":\"a\",\"action\":\"activate(web)\",\"artifacts\":\"m1\"}\n"
fnaudit_refusalaudit_refusal(why : String) : String#

The result of a release the leader refused, from its reason: err_stale, err_fork, err_parent (the compare-and-set on parent), or err_invalid (the release does not check).

Examples

    march> Control.audit_refusal("stale: release 1 is older than the head 2")
    "err_stale"
    march> Control.audit_refusal("missing env")
    "err_invalid"
fnaudit_releaseaudit_release(ts : Int, leader : String, seq : Int, digest : String, result : String, why : String) : String#

The audit line for a release offered to the leader: [result] is "ok" or an err_... word, [why] the reason ("" when accepted). One JSON object and a newline.

Examples

    march> Control.audit_release(1000, "n1", 2, "abc", "ok", "")
    "{\"ts\":1000,\"type\":\"release\",\"leader\":\"n1\",\"seq\":2,\"release\":\"abc\",\"result\":\"ok\",\"why\":\"\"}\n"
fnaudit_stepaudit_step(ts : Int, leader : String, res : StepResult) : String#

The audit line for a node's answer to an order.

Examples

    march> Control.audit_step(1000, "n1", { seq: 1, step: 1, node: "a", ok: true, detail: "applied" })
    "{\"ts\":1000,\"type\":\"step\",\"leader\":\"n1\",\"seq\":1,\"step\":1,\"node\":\"a\",\"result\":\"ok\",\"why\":\"applied\"}\n"
fncert_floorcert_floor(memory : Vault(String)) : Int#

The newest release seq this agent has taken certificates or revocations from (0: none), as agent_apply_certs_recording keeps it. An unreadable entry also reads 0.

Examples

    march> Control.cert_floor(Authority.must(Vault.new("doc_control_cert_floor")))
    0
fncerts_textcerts_text(own : Option(NodeCert.Cert), revs : List(NodeCert.Revocation)) : String#

A node's certificate state as it reports it (AgentReport.certs): cert:<serial> for the certificate it presents (absent on a shared-secret node), then rev:<id> for every revocation it knows (NodeCert.revocation_id).

    Control.certs_text(Some(my_cert), revs)   -- "cert:<serial> rev:<id> ..."

## Examples

    march> Control.certs_text(None, [])
    ""
fncheckcheck(r : CtlRelease) : Result((), String)#

Is the release well formed? A positive seq, a parent, env and topology, distinct builds, steps numbered 1..n in order, every activate(b) naming a shipped build, a drain line for a drain step, every signed line naming a step that exists, and certificate and revocation items that decode, one certificate per node, with a do:certs step to deliver them.

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.check(rel)
    Ok(())
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.check({ rel with seq: 0 })
    Err("seq must be positive")
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.check({ rel with builds: [] })
    Err("step 1: activates build `web`, which the release does not ship")
fnchunkschunks(hex : String, size : {Int | _ > 0}) : List(CtlChunk)#

Split [hex] (an artifact as hex) into chunks of [size] hex characters, offsets counted in characters; an artifact of at most [size] characters (including an empty one) is one last chunk. Panics if [size] is not positive (also a refinement precondition).

Examples

    march> List.map(Control.chunks("abcdef", 4), fn c -> c.data)
    ["abcd", "ef"]
    march> List.map(Control.chunks("abcdef", 4), fn c -> c.offset)
    [0, 4]
    march> List.map(Control.chunks("", 4), fn c -> c.last)
    [true]
fndigestdigest(r : CtlRelease) : String do sha256(Bytes.from_string(signed_text(r))) end#

The release's content address: sha256 (hex, 64 characters) of signed_text. A child names it as its parent. The sig line is not covered, so signing a release does not change its digest.

    let child = { next with seq: rel.seq + 1, parent: Control.digest(rel) }
fnleader_newleader_new() : CtlLeader do { release: None, obs: Nil, inflight: Nil, halted: None } end#

A leader holding nothing yet.

Examples

    march> let ldr0 = Control.leader_new()
    march> Option.is_none(ldr0.release)
    true
fnleader_passleader_pass(l : CtlLeader, members : List(CtlMember), now : Int) : (CtlLeader, Option(CtlDecision))#

Run a pass. The orders it returns are now in flight. A RolloutHalted verdict sticks until a new release; RolloutComplete and RolloutWait hold no state.

A leader with no release returns `None`.

## Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> let ldr0 = Control.leader_new()
    march> let ldr1 = Result.unwrap(Control.leader_release(ldr0, rel))
    march> Option.map(Tuple.second(Control.leader_pass(ldr1, members, 0)), Control.show_decision)
    Some("step 1: apply to [a]")
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> let ldr0 = Control.leader_new()
    march> Tuple.second(Control.leader_pass(ldr0, members, 0))
    None
fnleader_releaseleader_release(l : CtlLeader, r : CtlRelease) : Result(CtlLeader, String)#

Offer a release to the leader (check, then accept's compare-and-set). A new release clears the halt and the orders in flight; offering the held release again changes nothing.

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let ldr0 = Control.leader_new()
    march> let ldr1 = Result.unwrap(Control.leader_release(ldr0, rel))
    march> Control.leader_release(ldr1, { rel with seq: 0 })
    Err("seq must be positive")
fnleader_reportleader_report(l : CtlLeader, rep : AgentReport, now : Int) : CtlLeader#

An agent reported: record it; the node's order (if any) is no longer in flight. A failure this leader already knows of for the node is kept even if the report omits it, so a halt cannot be lost to a report sent before the failure; so is the node's detail when the report has none (a poll's).

Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ldr2 = Control.leader_report(Control.leader_new(), rep, 1000)
    march> List.length(ldr2.obs)
    1
fnleader_resultleader_result(l : CtlLeader, res : StepResult, now : Int) : CtlLeader#

An agent answered an order. A failure is recorded as the node's failed step (so the next pass halts; a new leader re-derives the halt from the agent's own report). The order stays in flight until the node's next report, so it is not sent again on the strength of a stale report.

A result from a node the leader has no report of changes nothing.

## Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> let ldr2 = Control.leader_report(Control.leader_new(), rep, 1000)
    march> let ldr3 = Control.leader_result(Result.unwrap(Control.leader_release(ldr2, rel)), { seq: 1, step: 1, node: "a", ok: false, detail: "ERR refused" }, 1500)
    march> Option.map(Tuple.second(Control.leader_pass(ldr3, members, 2000)), Control.show_decision)
    Some("step 1: HALTED on a: ERR refused")
fnmissingmissing(ops : AgentOps, o : StepOrder) : List(String)#

The artifacts of [o] the node does not hold yet (to fetch over CtlFetch before applying).

Examples

`ops` simulates a node: it reports `rep`, holds artifact `m1`, and accepts every line.
It is reused by the examples further down:

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> Control.missing(ops, ord)
    []
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> let ops = { report: fn -> rep, has: fn h -> h == "m1", request: fn l -> "OK" }
    march> Control.missing({ ops with has: fn h -> false }, ord)
    ["m1"]
fnno_parentno_parent() : String do "none" end#

The parent of the first release of an environment.

Examples

    march> Control.no_parent()
    "none"
fnobserveobserve(obs : List(CtlObs), rep : AgentReport, now : Int) : List(CtlObs)#

Record [rep] at leader time [now]. A node's healthy window starts when the leader first sees it healthy in its current state, and restarts when the state changes or the node reports unhealthy. The window is the leader's own, so a new leader restarts every window: conservative (design section 4).

Examples

`obs0` (node "a" healthy since t=1000) is reused by the examples further down:

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let obs0 = Control.observe([], rep, 1000)
    march> List.map(Control.observe(obs0, rep, 5000), fn o -> o.healthy_since)
    [Some(1000)]
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let obs0 = Control.observe([], rep, 1000)
    march> List.map(Control.observe(obs0, { rep with versions: "web=m2" }, 5000), fn o -> o.healthy_since)
    [Some(5000)]
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let obs0 = Control.observe([], rep, 1000)
    march> List.map(Control.observe(obs0, { rep with healthy: false }, 5000), fn o -> o.healthy_since)
    [None]
fnorderorder(r : CtlRelease, step : CtlStep, node : String) : StepOrder#

The order that takes [step] of [r] on [node]: release is digest(r), want is want_for, the artifacts are the build's manifest (activate) or the topology digest (topology), and the lines are the release's signed lines for the step (a certs step carries the whole serialized release instead).

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let step1 = List.head(rel.steps)
    march> let o1 = Control.order(rel, step1, "a")
    march> Control.order_artifacts(o1)
    ["m1"]
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let step1 = List.head(rel.steps)
    march> let o1 = Control.order(rel, step1, "a")
    march> o1.want
    "m1"
fnorder_artifactsorder_artifacts(o : StepOrder) : List(String) do words(o.artifacts) end#

The artifact hashes [o] needs.

Examples

`ord` is reused by the examples further down:

    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> Control.order_artifacts(ord)
    ["m1"]
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> Control.order_artifacts({ ord with artifacts: "" })
    []
fnorder_linesorder_lines(o : StepOrder) : List(String)#

The signed lines [o] relays, in order; blank lines are dropped.

Examples

    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> Control.order_lines({ ord with lines: "L1\n\nL2" })
    ["L1", "L2"]
    march> let ord = { seq: 1, release: "abc", step: 1, node: "a", action: "activate(web)", want: "m1", artifacts: "m1", lines: "" }
    march> Control.order_lines(ord)
    []
fnparseparse(text : String) : Result(CtlRelease, String)#

Parse a release document (design section 4). The first non-blank line must be release v1; words may be separated by any run of spaces, and sig - stands for an unsigned release. The result is checked, so an Ok release is well formed (not yet verified: see verify).

`Err` names the line: an unknown entry, a malformed step, anything after `sig`, or a
failed `check`.

## Examples

`rel` is a two-step release (a canary, then the rest) used by the examples further
down; it round-trips through its text form:

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Result.map(Control.parse(Control.serialize(rel)), fn r -> List.length(r.steps))
    Ok(2)
    march> Control.parse("release v1\nseq x")
    Err("line 2: seq: not a number: x")
    march> Control.parse("release v2")
    Err("expected `release v1` first, got `release v2`")
    march> Control.parse("")
    Err("empty release")
fnparse_durationparse_duration(s : String) : Result(Int, String)#

A duration: 250ms, 60s, 2m, or a bare number of milliseconds. Err when the number part is not an integer.

Examples

    march> Control.parse_duration("250ms")
    Ok(250)
    march> Control.parse_duration("2m")
    Ok(120000)
    march> Control.parse_duration("1500")
    Ok(1500)
    march> Control.parse_duration("soon")
    Err("duration: not a number: soon")
fnpasspass(r : CtlRelease, members : List(CtlMember), obs : List(CtlObs), inflight : List(String), now : Int) : CtlDecision#

The executor's pass (design section 4), a pure function of the release, the membership, the observations, the nodes with an order in flight, and the leader's clock. Steps run strictly in order: a step's orders go out only once every earlier step is done on its nodes and its gate has passed, and a node is ordered only while it does not report the step's end state and has no order in flight. So no step is skipped and none is applied twice.

Examples

Node "a" is the canary; once it reports `m1` the 30 s gate holds step 2 back:

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> Control.show_decision(Control.pass(rel, members, [], [], 0))
    "step 1: apply to [a]"
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> Control.show_decision(Control.pass(rel, members, [], ["a"], 0))
    "step 1: apply to []"
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let obs0 = Control.observe([], rep, 1000)
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> Control.show_decision(Control.pass(rel, members, obs0, [], 2000))
    "step 1: waiting, gate healthy(30s): a healthy for 1000ms of 30000ms"
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let obs0 = Control.observe([], rep, 1000)
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> Control.show_decision(Control.pass(rel, members, obs0, [], 31000))
    "step 2: apply to [b, c]"
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> Control.show_decision(Control.pass(rel, members, Control.observe([], { rep with seq: 4 }, 0), [], 0))
    "behind: a node holds release 4"
fnreal_opsreal_ops(name : String, pools : String, status : () -> (String, Bool), certs : () -> String, memory : Vault(String)) : AgentOps#

The Agent's ops over this node's reload server. [status] is called for each report: the topology status text (Topology.status_text), and whether the verified topology is the one the node applied. [memory] keeps the last failed step (see agent_apply_recording). [certs] is the node's certificate state (certs_text). has is the artifact's presence in the CAS (a base: in the release is informational: the base image is not an artifact).

    let mem = Authority.must(Vault.new("agent"))
    let ops = Control.real_ops("node-a", "web", status, certs, mem)
    Control.agent_apply_recording(ops, mem, order, 200)
fnrelay_linerelay_line(line : String) : String do reload_request(line) end#

The reload server's answer to [line] (or lines: the request is a stream, a body verb's bytes follow the first newline). Goes through the stdlib-only reload_request builtin.

    Control.relay_line("NODE_STATE")
fnreload_reportreload_report(name : String, pools : String, status : String, applied : Bool, failure : String, certs : String) : AgentReport#

What the node reports without the status file: the reload server's NODE_STATE and PINS, and [failure] (the last step this agent failed, seq step why, or \"\"). Not VERSIONS_DETAIL: one line per function (about 14,000 in a small app), on every poll, cost a node gigabytes within a minute. The patch artifacts in effect (NODE_STATE) are what the executor needs, and an operator reads the per-function view through the control API (VERSIONS_DETAIL passes through).

    let rep = Control.reload_report("node-a", "web", status_text, true, "", certs)
fnreport_failurereport_failure(rep : AgentReport) : Option(CtlFailure)#

The last step [rep]'s node failed, if any (failed_seq 0 means none).

Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.report_failure(rep)
    None
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Option.map(Control.report_failure({ rep with failed_seq: 1, failed_step: 2, failed_why: "refused" }), fn f -> f.why)
    Some("refused")
fnreport_serialreport_serial(rep : AgentReport) : String#

The serial of the certificate [rep]'s node presents ("" when it reports none).

Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.report_serial(rep)
    "42"
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.report_serial({ rep with certs: "" })
    ""
fnreport_versionsreport_versions(rep : AgentReport) : List(CtlVersion)#

The builds [rep] runs, read back from its versions text; a word with no = is skipped.

Examples

`rep` is reused by the examples further down:

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> List.map(Control.report_versions({ rep with versions: "api=m2 web=m1" }), fn v -> v.build)
    ["api", "web"]
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.report_versions({ rep with versions: "" })
    []
fnreports_statereports_state(rep : AgentReport, action : String, w : String) : Bool#

Does [rep] show the end state [w] of an order with action [action] (show_action form)? activate: a version of that build (or *) with manifest [w]; topology: the digest; drain: drained at least to epoch [w]; certs: every word of [w] among the reported ones. An unknown action is never done.

Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.reports_state(rep, "activate(web)", "m1")
    true
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.reports_state(rep, "activate(web)", "m2")
    false
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.reports_state(rep, "drain", "1")
    false
    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> Control.reports_state(rep, "certs", "cert:42")
    true
fnselectselect(step : CtlStep, members : List(CtlMember), prior : List((CtlStep, List(String)))) : List(String)#

The nodes [step] applies to, given the selections of the steps before it ((step, nodes) pairs): canary(n) the first n targets, all every target, rest the targets no earlier step with the same action selected. Selection depends only on the release and the membership, never on progress, so every leader selects the same canary.

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> let step1 = List.head(rel.steps)
    march> Control.select(step1, members, [])
    ["a"]
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> let step1 = List.head(rel.steps)
    march> let step2 = List.nth(rel.steps, 1)
    march> Control.select(step2, members, [(step1, ["a"])])
    ["b", "c"]
fnserializeserialize(r : CtlRelease) : String#

The release document: signed_text, then its sig line (sig - when unsigned). parse(serialize(r)) == Ok(r) for a well-formed r.

Examples

Using `rel` from `parse`:

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.serialize(rel)
    "release v1\nseq 1\nparent none\nenv prod\ntopology t1\nbuild web base:b1 manifest:m1\nstep 1 pools:web hosts:canary(1) do:activate(web) gate:healthy(30s)\nstep 2 pools:web hosts:rest do:activate(web) gate:none\nsig -\n"
fnshow_actionshow_action(a : CtlAction) : String#

The action as the release and the wire write it: activate(web), topology, drain, certs.

Examples

    march> Control.show_action(Control.DoActivate("web"))
    "activate(web)"
    march> Control.show_action(Control.DoDrain)
    "drain"
fnshow_decisionshow_decision(d : CtlDecision) : String#

The decision as one line, for status output and logs.

Examples

    march> Control.show_decision(Control.RolloutComplete)
    "complete"
    march> Control.show_decision(Control.RolloutHalted(2, "a", "ERR refused"))
    "step 2: HALTED on a: ERR refused"
fnshow_durationshow_duration(ms : Int) : String#

A duration written the way parse_duration reads it back: whole seconds as Ns, else Nms (so 0 and negative durations are written in ms).

Examples

    march> Control.show_duration(60000)
    "60s"
    march> Control.show_duration(1500)
    "1500ms"
    march> Control.show_duration(0)
    "0ms"
fnsignsign(r : CtlRelease, sk : Bytes) : CtlRelease#

Sign [r] with an ed25519 secret key (ed25519_seed_keypair form). What forge does; here for tests and tooling. Returns [r] with signature set to the signature's hex.

    let kp = ed25519_seed_keypair(seed)
    let signed = Control.sign(rel, kp)
fnsigned_textsigned_text(r : CtlRelease) : String#

The canonical text the signature covers: the release without its sig line, one entry per line, single spaces, a newline after every line. forge signs exactly this, so a document may be laid out any way parse accepts and still verify.

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> Control.signed_text(rel)
    "release v1\nseq 1\nparent none\nenv prod\ntopology t1\nbuild web base:b1 manifest:m1\nstep 1 pools:web hosts:canary(1) do:activate(web) gate:healthy(30s)\nstep 2 pools:web hosts:rest do:activate(web) gate:none\n"
fnstate_fieldstate_field(line : String, key : String) : String#

The value of key:value among the words of [line] ("" when absent).

Examples

    march> Control.state_field("STATE head:3 drained:1 topology:t1", "head")
    "3"
    march> Control.state_field("STATE head:3", "topology")
    ""
fnstate_linestate_line(lines : List(String)) : String#

The STATE line of a NODE_STATE answer ("" when absent).

Examples

    march> Control.state_line(["PIN 1", "STATE head:3 drained:1"])
    "STATE head:3 drained:1"
    march> Control.state_line([])
    ""
fntargetstargets(step : CtlStep, members : List(CtlMember)) : List(String)#

A step's target nodes: the members in any of its pools (every member for ["*"]), sorted by node name (the canary is the first).

Examples

`members`, `step1` and `step2` are reused by the examples further down:

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> let step1 = List.head(rel.steps)
    march> let step2 = List.nth(rel.steps, 1)
    march> Control.targets(step1, members)
    ["a", "b", "c"]
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let members = [{ node: "b", pools: ["web"] }, { node: "a", pools: ["web"] }, { node: "c", pools: ["web"] }, { node: "db1", pools: ["db"] }]
    march> let step1 = List.head(rel.steps)
    march> Control.targets({ step1 with pools: ["*"] }, members)
    ["a", "b", "c", "db1"]
fntopology_wait_mstopology_wait_ms(tick_ms : Int) : Int#

How long a topology step waits for the node's placement loop to apply a digest the reload server already took, given the loop's tick [tick_ms]: ten ticks, at least two seconds (a loaded host delays a tick), at most a minute.

Examples

    march> Control.topology_wait_ms(200)
    2000
    march> Control.topology_wait_ms(500)
    5000
    march> Control.topology_wait_ms(10000)
    60000
fnverifyverify(r : CtlRelease, pubkey : Bytes) : Bool#

Does [r] carry a valid operator signature for [pubkey]? The leader checks this before storing a release so it never relays junk; the nodes check the signed lines themselves either way (the control plane is not trusted, D37).

`false` too when the signature is not hex.

    Control.verify(Control.sign(rel, secret), public)   -- true
    Control.verify(rel, public)                         -- false: unsigned
fnversions_textversions_text(vs : List(CtlVersion)) : String#

The canonical text of what a node runs: build=manifest words, sorted by build. An empty list gives "".

Examples

    march> Control.versions_text([{ build: "web", manifest: "m1" }, { build: "api", manifest: "m2" }])
    "api=m2 web=m1"
    march> Control.versions_text([])
    ""
fnwantwant(r : CtlRelease, step : CtlStep) : String#

The end state a node reports once [step] of [r] is done on it (StepOrder.want): the build's manifest for activate, the topology digest, or the drain epoch. "" for a certs step (per node: see want_for) and for a build or drain the release lacks.

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let step1 = List.head(rel.steps)
    march> Control.want(rel, step1)
    "m1"
    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let step1 = List.head(rel.steps)
    march> Control.want(rel, { step1 with action: Control.DoTopology })
    "t1"
fnwant_forwant_for(r : CtlRelease, step : CtlStep, node : String) : String#

The end state [node] reports once [step] of [r] is done on it: want, except for a do:certs step, whose end state is per node: cert:<serial> when the release carries a certificate for [node], and rev:<id> for each of its revocations (the words of certs_text the node must report).

Examples

    march> let rel = { seq: 1, parent: "none", env: "prod", topology: "t1", builds: [{ name: "web", base: "b1", manifest: "m1" }], steps: [{ id: 1, pools: ["web"], hosts: Control.HostsCanary(1), action: Control.DoActivate("web"), gate: Control.GateHealthy(30000), batch: 0 }, { id: 2, pools: ["web"], hosts: Control.HostsRest, action: Control.DoActivate("web"), gate: Control.GateNone, batch: 0 }], lines: [], certs: [], revokes: [], drain: None, signature: "" }
    march> let step1 = List.head(rel.steps)
    march> Control.want_for(rel, step1, "a")
    "m1"
fnwith_failurewith_failure(rep : AgentReport, f : CtlFailure) : AgentReport#

[rep] with its failure set to [f].

Examples

    march> let rep = { node: "a", seq: 1, versions: "web=m1", topology: "t1", drained: 0, healthy: true, failed_seq: 0, failed_step: 0, failed_why: "", detail: "", pools: "web", certs: "cert:42 rev:r7" }
    march> let res = Control.with_failure(rep, { seq: 1, step: 2, why: "refused" })
    march> res.failed_step
    2