Skip to content

core/charts/repairs.ts ​

Generated from the exports of core/charts/repairs.ts · npm run docs:gen

Repairs of alta.chart/0.1 (docs/standards/alta-chart-0.1.md §13): the closed list of repair kinds a chart may declare, and which of them the owner may allow to run without being asked each time (a standing grant). Pure.

Standards that cite this file: alta.chart/0.1: the Agent Chart

Exports ​

RepairKind type ​

ts
type RepairKind =
  | "service.restart" | "model.pull" | "signin.refresh" | "gateway.recover" | "automation.rerun" | "channel.reconnect"
  | "part.reapply" | "signin.again" | "channel.pair";

RepairKindInfo interface ​

ts
interface RepairKindInfo {
  kind: RepairKind;
  /**
   * The executor that does it; "part" and "signin": the executor of the part or the sign-in the repair names.
   */
  executor: string | "part" | "signin";
  /**
   * "yes": the owner may tick its box. "not-yet": in the closed list, but no box is offered until the real command of
   * each tool was verified on a machine. "never": always a plan card or an answer of the owner.
   */
  grant: "yes" | "not-yet" | "never";
  /** The arguments the declaration gives (literals only), each one naming something the chart declares. */
  args: readonly string[];
  /** Seconds to wait after a run before the proof is read again (model.pull: until its job ends). */
  settleS: number;
  /** Runs allowed per repair id and per 24 h. */
  dailyCap: number;
}

REPAIR_KINDS const ​

The closed list. Owner's decision (5 December): at launch only service.restart, model.pull and gateway.recover can be granted. signin.refresh and channel.reconnect stay "not-yet" until a real command of each tool was verified; automation.rerun is always asked (a run may cost a model call).

ts
const REPAIR_KINDS: readonly RepairKindInfo[]

REPAIR_KIND_IDS const ​

ts
const REPAIR_KIND_IDS: readonly string[]

repairKind const ​

ts
const repairKind = (k: unknown) => …

grantable const ​

ts
const grantable = (k: unknown) => …

Repair interface ​

A repair a chart declares.

ts
interface Repair { id: string; kind: RepairKind; args?: Record<string, string | number | boolean>; title?: { en?: string; fr?: string }; suggest?: boolean }

GRANTS_SCHEMA const ​

ts
const GRANTS_SCHEMA = "alta.grants/0.1"

Grant interface ​

One standing yes: one repair id of one chart, for the declaration it had when the owner ticked the box.

ts
interface Grant {
  id: string;
  chart: string;
  repair: string;
  kind: RepairKind;
  /** sha256 of grantSubject(chart, repair): a new version that changes the repair or its target voids it. */
  digest: string;
  grantedAt: string;
  /** Always null: a grant lasts until the owner revokes it (owner's decision, 5 December). */
  expiresAt?: null;
}

GrantsFile interface ​

ts
interface GrantsFile { schema: typeof GRANTS_SCHEMA; paused: boolean; grants: Grant[] }

emptyGrants const ​

ts
const emptyGrants = (): GrantsFile => …

checkGrants function ​

Problems of a grants file (grants.*): the server refuses to use a file that has one.

ts
function checkGrants(g: unknown): string[]

AliveLike interface ​

ts
interface AliveLike { id: string; grace?: number; repair?: string[] }

grantSubject function ​

What a grant's digest is the sha256 of (the caller hashes it): null when the chart has no such repair.

ts
function grantSubject(chart: ChartLike, repairId: string): string | null

grantFor function ​

The owner's grant for this repair of this chart, if it still holds (same kind, same digest, grantable).

ts
function grantFor(grants: Pick<GrantsFile, "grants">, chartId: string, repair: Repair, digest: string | undefined): Grant | undefined

REPAIR_RULES const ​

The decision table (docs/standards/alta-chart-0.1.md §13), in one place.

ts
const REPAIR_RULES = { /** Failures in a row before an incident opens, when the proof gives no `grace`. */ grace: 2, /** The delay before …

Incident interface ​

An open incident: an alive proof failed grace times in a row. It closes only when the proof passes again.

ts
interface Incident {
  chart: string;
  proof: string;
  openedAt: number;
  /** Failures in a row. */
  failures: number;
  /** Per repair id: the attempts of this incident and when the last one ran. */
  attempts: Record<string, { count: number; last: number }>;
  /** The last run, for the settle time. */
  lastRun?: { repair: string; kind: RepairKind; at: number };
}

RepairHistory interface ​

What happened before, read from the ledger and the guard's state.

ts
interface RepairHistory {
  /** Automatic runs: one per run, on this machine. */
  runs: { at: number; chart: string; repair: string; kind: RepairKind }[];
  /** Incidents opened (this one included), per proof. */
  incidents: { at: number; chart: string; proof: string }[];
}

RepairState interface ​

ts
interface RepairState {
  /** The machine switch `--allow-repair`. */
  capOn: boolean;
  /** The owner paused every automatic repair (grants.json `paused`). */
  paused: boolean;
  /** Why the machine is busy, or null: an apply holds the engine's lock, a job of the chart runs, the owner has a run open on the same target. */
  busy: null | "apply" | "job" | "owner-run";
  /** sha256 of grantSubject(chart, repair id), per repair id of the chart. */
  digests: Record<string, string>;
}

RepairDecision type ​

ts
type RepairDecision =
  | { do: "run"; repair: Repair; grant: Grant; attempt: number }
  | { do: "wait"; until: number; reason: "grace" | "settle" | "backoff" | "busy" }
  | { do: "ask"; repairs: string[]; reason: "not-granted" | "nothing-declared" | "switch-off" | "paused" | "flapping" | "daily-cap" | "circuit-breaker"; pause?: true }
  | { do: "give-up"; reason: "RepairGaveUp"; condition: "Drifted" };

nextIncident function ​

The incident after one reading of the proof: null when it passes (the only success), else one more failure.

ts
function nextIncident(prev: Incident | null, chart: string, proof: string, passed: boolean, now: number): Incident | null

decideRepair function ​

What the guard loop does for one failing alive proof, now. Pure: every rule of the table, in this order: grace, the proof's repairs, the machine switch and the pause, flapping, the circuit breaker, busy, settle, then each repair of the proof's list in order (granted, under its daily cap and its three attempts, after its backoff).

ts
function decideRepair(incident: Incident, chart: ChartLike, grants: Pick<GrantsFile, "grants">, history: RepairHistory, state: RepairState, now: number): RepairDecision

The standard, the SDK and the CLI are Apache-2.0; Alta System OS and Alta World are FSL-1.1-ALv2.