@catalyst-cloud/schema 0.1.28 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@catalyst-cloud/schema",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "type": "module",
5
5
  "description": "Typed Drizzle schema = single source of truth for the per-tenant Mirror DO SQLite store (CTC-13 / ADR-0002). Shared by the mirror Worker, the host-sync replica, and the browser OPFS replica.",
6
6
  "license": "MIT",
@@ -1030,6 +1030,13 @@ export const durableEventTypes = {
1030
1030
  wakes: false,
1031
1031
  entity: "ticket",
1032
1032
  },
1033
+ "phase.pr.park": {
1034
+ rationale:
1035
+ "ADR-0039 durable-fact example ('a phase started, completed, failed, or was preempted'): the pr phase was PARKED — a terminal-until-released outcome, distinct from `phase.pr.failed`, which a reader must be able to tell apart (CTC-1322). Paired with the already-registered `phase.pr.revive`.",
1036
+ ingestVerb: "coordination.publish",
1037
+ wakes: false,
1038
+ entity: "ticket",
1039
+ },
1033
1040
  "phase.pr.preempted": {
1034
1041
  rationale:
1035
1042
  "ADR-0039 durable-fact example ('a phase started, completed, failed, or was preempted'): a higher-priority worker preempted this phase.",
@@ -1843,6 +1850,11 @@ export const telemetryEventTypes = {
1843
1850
  "A replica read falling back to a secondary path — an internal routing diagnostic, not a ticket/phase coordination fact.",
1844
1851
  },
1845
1852
  "catalyst.service.health": { reason: "A periodic service health-check gauge." },
1853
+ "ci.run.completed": {
1854
+ reason:
1855
+ "CTC-1261 M4 — a completed check_suite webhook joined to its ticket at ingest time (head_branch == CTC-NNN by convention), zero extra API calls. Gauge/counter-shaped (catalyst_ci_runs_total{conclusion}): the collapsed count per (ticket, conclusion) is the signal, not any one occurrence's identity.",
1856
+ sampling: { kind: "counted" },
1857
+ },
1846
1858
  "cloud-feed.would-dispatch": {
1847
1859
  reason:
1848
1860
  "A 'would-*' counterfactual dispatch evaluation — the dry-run analogue of phase.dispatch.requested, never an actual dispatch.",
@@ -1945,6 +1957,11 @@ export const telemetryEventTypes = {
1945
1957
  reason:
1946
1958
  "Phase-agent worker-directory garbage collection. phase.terminal.reap-requested alone is 10,015 lines/mo — a periodic sweep re-requesting cleanup of already-terminal workers, not a discrete coordination fact worth replay.",
1947
1959
  },
1960
+ "phase.lifecycle": {
1961
+ reason:
1962
+ "CTC-1261 — one closed vocabulary for every phase-transition observation across the relay ladder (claim, refuse, publish-success, release/setup-failure/reclaim), so a 20-30-runner fleet's phase health is queryable from one AE table by ticket. Each occurrence is individually meaningful (a specific ticket/phase/nonce transition), not a rollup-only gauge — always, never sampled away.",
1963
+ sampling: { kind: "always" },
1964
+ },
1948
1965
  "phase.predecessor.reap-complete": {
1949
1966
  reason:
1950
1967
  "Phase-agent worker-directory garbage collection. phase.terminal.reap-requested alone is 10,015 lines/mo — a periodic sweep re-requesting cleanup of already-terminal workers, not a discrete coordination fact worth replay.",
@@ -2095,6 +2112,16 @@ export const telemetryEventTypes = {
2095
2112
  reason:
2096
2113
  "A periodic context-usage/size sample logged during an agent session — a gauge, not a discrete session-lifecycle fact (contrast session.started/session.ended, which ARE durable).",
2097
2114
  },
2115
+ "work.backlog.sampled": {
2116
+ reason:
2117
+ "CTC-1261 M3 — a per-(team,bucket) count from the 5-minute eligibility sweep (explainEligibleWork), the missing starvation time series (catalyst_work_backlog{team,bucket}). Gauge-shaped: only the collapsed count matters, not any one sweep's identity.",
2118
+ sampling: { kind: "counted" },
2119
+ },
2120
+ "work.oldest-eligible-age.sampled": {
2121
+ reason:
2122
+ "CTC-1261 M3 — a per-team age gauge (catalyst_oldest_eligible_age_seconds) from the same sweep as work.backlog.sampled. Documented approximation: time since the team's dispatch queue was last (re)published (dispatch_queue_meta.published_at), not a true per-ticket time-became-eligible (no such timestamp exists in the schema) — a floor bound, not an exact dwell time.",
2123
+ sampling: { kind: "counted" },
2124
+ },
2098
2125
  "worker.memory.sampled": {
2099
2126
  reason:
2100
2127
  "ADR-0039's own telemetry example ('process samples') applied to a phase worker's own process.",
package/src/index.ts CHANGED
@@ -86,6 +86,8 @@ export * from "./events/index.js";
86
86
  // admission gate over the events registry above, and the pure AE/Iceberg record builders both the
87
87
  // mirror Worker and any future out-of-Worker emitter import.
88
88
  export * from "./telemetry/point.js";
89
+ // CTC-1261 — the phase.lifecycle family's closed status vocabulary and shared point builder.
90
+ export * from "./telemetry/phase-lifecycle-point.js";
89
91
 
90
92
  /** Every table in the Mirror DO store — pass as `drizzle(storage, { schema: mirrorSchema })`. */
91
93
  export const mirrorSchema = {
@@ -0,0 +1,79 @@
1
+ // phase-lifecycle-point.ts — CTC-1261. The closed `status` vocabulary for the `phase.lifecycle`
2
+ // telemetry family and the shared TelemetryPoint builder every mirror-side emit site (E1/E2/E4)
3
+ // uses, so the four call sites don't hand-build the object literal four different ways.
4
+ //
5
+ // The registry (../events/registry.ts) only runtime-validates the event NAME (assertEmittable) —
6
+ // there is no per-payload-field runtime enum validator anywhere in this package. `status` is a
7
+ // second, independent closed vocabulary layered on top of one registry name, so it needs its own
8
+ // guard here, in the same throw-not-a-falsy-sentinel posture as assertEmittable.
9
+
10
+ import type { TelemetryPoint } from "./point.js";
11
+
12
+ export const PHASE_LIFECYCLE_STATUSES = [
13
+ "claimed",
14
+ "started",
15
+ "succeeded",
16
+ "failed",
17
+ "refused",
18
+ "released",
19
+ "setup_failed",
20
+ "reclaimed",
21
+ ] as const;
22
+
23
+ export type PhaseLifecycleStatus = (typeof PHASE_LIFECYCLE_STATUSES)[number];
24
+
25
+ function assertKnownStatus(status: string): asserts status is PhaseLifecycleStatus {
26
+ if (!(PHASE_LIFECYCLE_STATUSES as readonly string[]).includes(status)) {
27
+ throw new Error(
28
+ `phase.lifecycle refuses status "${status}": not one of ${PHASE_LIFECYCLE_STATUSES.join("|")} ` +
29
+ `(packages/schema/src/telemetry/phase-lifecycle-point.ts is the one closed vocabulary)`,
30
+ );
31
+ }
32
+ }
33
+
34
+ export interface PhaseLifecycleFields {
35
+ status: PhaseLifecycleStatus;
36
+ ticket: string;
37
+ phase: string;
38
+ nonce: number;
39
+ executor: string;
40
+ substrate?: string;
41
+ provider?: string;
42
+ branch?: string;
43
+ baseSha?: string;
44
+ prNumber?: number;
45
+ artifactKey?: string;
46
+ durationMs?: number;
47
+ reason?: string;
48
+ }
49
+
50
+ /**
51
+ * Build one `phase.lifecycle` TelemetryPoint. Throws (never a falsy sentinel) on an unrecognized
52
+ * `status` — the same posture as `assertEmittable` for the event name.
53
+ */
54
+ export function buildPhaseLifecyclePoint(fields: PhaseLifecycleFields): TelemetryPoint {
55
+ assertKnownStatus(fields.status);
56
+ const detailParts = [
57
+ `status=${fields.status}`,
58
+ `ticket=${fields.ticket}`,
59
+ `phase=${fields.phase}`,
60
+ `nonce=${fields.nonce}`,
61
+ `executor=${fields.executor}`,
62
+ ...(fields.substrate !== undefined ? [`substrate=${fields.substrate}`] : []),
63
+ ...(fields.provider !== undefined ? [`provider=${fields.provider}`] : []),
64
+ ...(fields.branch !== undefined ? [`branch=${fields.branch}`] : []),
65
+ ...(fields.baseSha !== undefined ? [`base_sha=${fields.baseSha}`] : []),
66
+ ...(fields.prNumber !== undefined ? [`pr_number=${fields.prNumber}`] : []),
67
+ ...(fields.artifactKey !== undefined ? [`artifact_key=${fields.artifactKey}`] : []),
68
+ ...(fields.reason !== undefined ? [`reason=${fields.reason}`] : []),
69
+ ];
70
+ return {
71
+ name: "phase.lifecycle",
72
+ service: "catalyst-cloud.mirror",
73
+ outcome: fields.status === "failed" || fields.status === "setup_failed" ? "error" : "ok",
74
+ detail: detailParts.join(" "),
75
+ traceId: `${fields.ticket}:${fields.phase}:${fields.nonce}`,
76
+ durationMs: fields.durationMs ?? null,
77
+ count: 1,
78
+ };
79
+ }