@bli-cockpit/telemetry-core 0.1.60 → 0.1.64

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.
@@ -17,6 +17,11 @@ export interface TablePattern {
17
17
  note: string;
18
18
  /** Where the verdict came from: a ticket, a commit, a measured window. */
19
19
  basis: string;
20
+ /**
21
+ * Judge a matching line even when it carries no trouble word (BLI-12870: `[SMS Pull] Skipped … no_extension=[…]`
22
+ * names users who need a person, in words the important-line filter does not know). Off by default.
23
+ */
24
+ watch?: boolean;
20
25
  }
21
26
  export interface ClassTableData {
22
27
  version: number;
@@ -38,6 +43,8 @@ export declare class ClassTable {
38
43
  private readonly patterns;
39
44
  private readonly cache;
40
45
  constructor(data: ClassTableData);
46
+ /** True when a `watch` pattern matches this masked line: the digest judges it instead of counting it as routine. */
47
+ watches(unit: string, template: string, source: string): boolean;
41
48
  /** A table read from its JSON text (the `--table` file a person writes to try a pattern). */
42
49
  static fromJson(text: string): ClassTable;
43
50
  classify: Classify;
@@ -35,6 +35,20 @@ export class ClassTable {
35
35
  };
36
36
  });
37
37
  }
38
+ /** True when a `watch` pattern matches this masked line: the digest judges it instead of counting it as routine. */
39
+ watches(unit, template, source) {
40
+ for (const pattern of this.patterns) {
41
+ if (!pattern.spec.watch)
42
+ continue;
43
+ if (pattern.unit && !pattern.unit.test(unit))
44
+ continue;
45
+ if (pattern.source && !pattern.source.test(source))
46
+ continue;
47
+ if (pattern.match.test(template))
48
+ return true;
49
+ }
50
+ return false;
51
+ }
38
52
  /** A table read from its JSON text (the `--table` file a person writes to try a pattern). */
39
53
  static fromJson(text) {
40
54
  return new ClassTable(JSON.parse(text));
@@ -45,6 +45,11 @@ export interface DigestOptions {
45
45
  * Off by default so Kaiben's journals digest exactly as the Python does.
46
46
  */
47
47
  taggedLines?: boolean;
48
+ /**
49
+ * A class table's say on a line that carries no trouble word (BLI-12870): true judges it anyway. Only patterns marked
50
+ * `watch` answer true, so Kaiben's journals and every unmarked table digest exactly as before.
51
+ */
52
+ watch?: (group: string, template: string) => boolean;
48
53
  }
49
54
  export interface LineFacts {
50
55
  /** systemd's own words about a unit rather than the unit's output. */
@@ -65,6 +70,7 @@ export declare class Digest {
65
70
  private readonly quiet;
66
71
  private readonly routineUnits;
67
72
  private readonly taggedLines;
73
+ private readonly watch;
68
74
  private readonly openTracebacks;
69
75
  constructor(options?: DigestOptions);
70
76
  isNoise(unit: string | undefined, identifier: string | undefined): boolean;
@@ -72,6 +78,8 @@ export declare class Digest {
72
78
  addEntry(entry: JournalEntry): void;
73
79
  /** One log line from any source. `ts` is epoch seconds (0 when the source has none). */
74
80
  addLine(unit: string, message: string, ts: number, facts?: LineFacts): void;
81
+ /** A line the class table asked to see even without a trouble word (a `watch` pattern matches its masked text). */
82
+ private watched;
75
83
  private routineCount;
76
84
  private addGroup;
77
85
  /** Python tracebacks span many lines: fold each into one group named by its exception and last frame. */
@@ -53,9 +53,11 @@ export class Digest {
53
53
  quiet;
54
54
  routineUnits;
55
55
  taggedLines;
56
+ watch;
56
57
  openTracebacks = new Map();
57
58
  constructor(options = {}) {
58
59
  this.taggedLines = options.taggedLines ?? false;
60
+ this.watch = options.watch ?? null;
59
61
  this.noise = compileAll(options.noise ?? DEFAULT_NOISE);
60
62
  this.quiet = compileAll(options.quietUnits ?? []);
61
63
  this.routineUnits = new Set(options.routineUnits ?? []);
@@ -141,7 +143,10 @@ export class Digest {
141
143
  const parsed = parseTagged(message);
142
144
  if (parsed) {
143
145
  const judged = judgeTagged(parsed, facts.level);
144
- if (!judged.important) {
146
+ if (!judged.important && this.watched(group, message)) {
147
+ this.addGroup(group, instance, "tagged", mask(message), ts, message);
148
+ }
149
+ else if (!judged.important) {
145
150
  this.routineCount(group, judged.template, null);
146
151
  }
147
152
  else {
@@ -155,7 +160,7 @@ export class Digest {
155
160
  // The source's own level is NOT a verdict on a plain line: Tower writes ordinary output to stderr, which Vercel
156
161
  // and Railway both mark "error" (measured 2026-10-07). Words and fields decide; see tagged.ts.
157
162
  const judgedText = this.taggedLines ? withoutZeroCounters(message) : message;
158
- if ((looksImportant(judgedText) || (this.taggedLines && JS_EXCEPTION.test(judgedText))) && !(manager && SYSTEMD_ROUTINE.test(message))) {
163
+ if ((looksImportant(judgedText) || (this.taggedLines && JS_EXCEPTION.test(judgedText)) || this.watched(group, message)) && !(manager && SYSTEMD_ROUTINE.test(message))) {
159
164
  this.addGroup(group, instance, event, mask(message), ts, message);
160
165
  return;
161
166
  }
@@ -166,6 +171,10 @@ export class Digest {
166
171
  this.routineCount(group, routineEvent, null);
167
172
  }
168
173
  // -- internals
174
+ /** A line the class table asked to see even without a trouble word (a `watch` pattern matches its masked text). */
175
+ watched(group, message) {
176
+ return this.watch !== null && this.watch(group, mask(message));
177
+ }
169
178
  routineCount(group, event, subject) {
170
179
  let events = this.routine.get(group);
171
180
  if (!events)
@@ -13,7 +13,7 @@ export { readCollector, receiptLine, streamLines, windowShare } from "./sources/
13
13
  export { RAILWAY_ENVIRONMENT, RAILWAY_PROJECT_ID, railwayRefusal, readRailway } from "./sources/railway.js";
14
14
  export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecordLines, vercelRefusal, type VercelClasses, type VercelRecord } from "./sources/vercel.js";
15
15
  export { readStdin } from "./sources/stdin.js";
16
- export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, scrubRow, storedRowBytes, toStoredRows, type DigestedLines, type StoredMerge, type StoredRow, type StoredWindow, } from "./stored.js";
16
+ export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, type DigestedLines, type StillRefusing, type StoredMerge, type StoredRow, type StoredWindow, type UnreadableSource, } from "./stored.js";
17
17
  export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
18
- export { LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, findLogProject, type LogProject, type LogSource, type NotWiredSource, type RailwaySource, type SupabaseSource, type SupabaseStream, type VercelSource, } from "./log-projects.js";
18
+ export { LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, findLogProject, type GcpSource, type LogProject, type LogSource, type NotWiredSource, type RailwaySource, type SupabaseSource, type SupabaseStream, type VercelSource, } from "./log-projects.js";
19
19
  export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
@@ -13,7 +13,7 @@ export { readCollector, receiptLine, streamLines, windowShare } from "./sources/
13
13
  export { RAILWAY_ENVIRONMENT, RAILWAY_PROJECT_ID, railwayRefusal, readRailway } from "./sources/railway.js";
14
14
  export { VERCEL_PROJECT, VERCEL_SCOPE, readDashboard, routeTemplate, vercelRecordLines, vercelRefusal } from "./sources/vercel.js";
15
15
  export { readStdin } from "./sources/stdin.js";
16
- export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, scrubRow, storedRowBytes, toStoredRows, } from "./stored.js";
16
+ export { LOCAL_ACCESS_REFUSALS, STORED_MAX_TEMPLATES_PER_WINDOW, digestLines, mergeStored, notReadLines, scrubRow, storedRowBytes, toStoredRows, } from "./stored.js";
17
17
  export { PROJECT_TABLES, projectClassTable } from "./project-classes.js";
18
18
  export { LOG_EXCLUDED, LOG_EXCLUDED_SUPABASE_REFS, LOG_PROJECTS, LOG_PROJECT_IDS, LOG_PROJECT_PATTERN, TOWER_RAILWAY, VERCEL_TEAM_ID, findLogProject, } from "./log-projects.js";
19
19
  export { STORED_EXAMPLE_CHARS, STORED_TEMPLATE_CHARS, scrubForStorage, scrubLine, scrubUnit } from "./scrub.js";
@@ -49,6 +49,20 @@ export interface SupabaseSource extends SourceBase {
49
49
  name: string;
50
50
  streams: readonly SupabaseStream[];
51
51
  }
52
+ /**
53
+ * Google Cloud Logging, one Cloud Run service (BLI-12855). Read with a read-only service account
54
+ * (`roles/logging.viewer`) whose JSON key is `LOGS_GCP_SA_KEY_B64` on the `logs-digest` service; the registry holds
55
+ * the project and service names only, never the key.
56
+ */
57
+ export interface GcpSource extends SourceBase {
58
+ kind: "gcp";
59
+ /** The GCP project id that holds the logs (`resourceNames: ["projects/<id>"]`). */
60
+ gcp_project: string;
61
+ /** The Cloud Run service name (`resource.labels.service_name`). */
62
+ service: string;
63
+ /** The unit prefix of every line. */
64
+ unit_prefix: string;
65
+ }
52
66
  export interface NotWiredSource extends SourceBase {
53
67
  kind: "not_wired";
54
68
  /** The platform it would be read from. */
@@ -56,7 +70,7 @@ export interface NotWiredSource extends SourceBase {
56
70
  /** Plain words: why nothing reads it, and what would. */
57
71
  reason: string;
58
72
  }
59
- export type LogSource = VercelSource | RailwaySource | SupabaseSource | NotWiredSource;
73
+ export type LogSource = VercelSource | RailwaySource | SupabaseSource | GcpSource | NotWiredSource;
60
74
  export interface LogProject {
61
75
  /** What `cockpit logs <project>` takes. */
62
76
  id: string;
@@ -38,6 +38,14 @@ const supabase = (name, ref, streams = ["postgres", "api", "auth"]) => ({
38
38
  name,
39
39
  streams,
40
40
  });
41
+ const gcpCloudRun = (gcp_project, service) => ({
42
+ kind: "gcp",
43
+ source: `gcp:${service}`,
44
+ family: "gcp",
45
+ gcp_project,
46
+ service,
47
+ unit_prefix: service,
48
+ });
41
49
  const notWired = (source, platform, reason) => ({ kind: "not_wired", source, family: platform, platform, reason });
42
50
  export const LOG_PROJECTS = [
43
51
  {
@@ -73,8 +81,10 @@ export const LOG_PROJECTS = [
73
81
  sources: [
74
82
  vercel("bluepearl-frontend", "prj_cnvD5OppdZqyc8NjlfELlJlChkWf"),
75
83
  supabase("BluePearl", "cfznyqwbdjlyvmfhvfuo"),
76
- // From the Pearl Portal session (ticket 12860's comment), not re-verified live from here.
77
- notWired("gcp:blue-pearl-mortgage", "gcp", "gcloud_not_authenticated: Pearl's mortgage backend runs on Google Cloud Run (service blue-pearl-mortgage, GCP project buildlaunchiterate, region northamerica-northeast2), read through Cloud Logging; this machine's gcloud login (edward@buildlaunchiterate.ca) needs a fresh `gcloud auth login` before a read-only service account (roles/logging.viewer) can be minted, and the cron holds no Google credential yet"),
84
+ // Pearl's mortgage backend on Cloud Run, named by the Pearl Portal session (ticket 12860's comment). Read with the
85
+ // read-only service account tower-logs-reader@buildlaunchiterate (roles/logging.viewer). Its staging service,
86
+ // staging-bluepearlmortgage, exists but is unused: never registered.
87
+ gcpCloudRun("buildlaunchiterate", "blue-pearl-mortgage"),
78
88
  notWired("sentry:build-launch-iterate/javascript-nextjs", "sentry", "sentry_token_not_mintable: the Pearl frontend also reports to Sentry (org build-launch-iterate, project javascript-nextjs); a read-only internal-integration token (event:read, project:read, org:read) needs org-level write that the existing Sentry login lacks (creating the integration answered 403), so no token was minted and Edward's broader personal token was not copied; create the integration in Sentry settings, then register the source"),
79
89
  ],
80
90
  },
@@ -14,9 +14,85 @@ import { ClassTable } from "./classify.js";
14
14
  import { LOG_PROJECT_IDS } from "./log-projects.js";
15
15
  import { TOWER_CLASSES, TOWER_PATTERNS } from "./tower-classes.js";
16
16
  const SHARED = TOWER_PATTERNS.filter((pattern) => pattern.id.startsWith("any-"));
17
+ const raw = String.raw;
18
+ /**
19
+ * Pearl Portal's backend (Cloud Run `blue-pearl-mortgage`, source family `gcp`), seeded from `gcloud logging read` over
20
+ * 2026-10-06 08:00Z onward. Masking turns every counter into `#`, so a pattern can tell a line's SHAPE, never its values.
21
+ */
22
+ const PEARL_PORTAL = [
23
+ {
24
+ id: "pearl-sms-optout-sweep-done",
25
+ class: "benign",
26
+ source: "^gcp$",
27
+ unit: "^blue-pearl-mortgage",
28
+ // Only the `done mode=` summary that says `complete=true`: any other OptOut line, or a sweep that did not complete, still alerts.
29
+ match: raw `^\[SMS OptOut Sweep\] done mode=\w+ swept=# .*\bcomplete=true ms=#$`,
30
+ note: "the SMS opt-out sweep's end-of-run summary, one line per run; masking hides the counters, and every run read had refused=0 deferred=0 unfinished=0",
31
+ basis: "pearl-portal gcp:blue-pearl-mortgage via gcloud logging read, 2026-10-06 08:00Z onward: 6 runs, all refused=0 deferred=0 unfinished=0 complete=true",
32
+ },
33
+ // BLI-12870 (revision blue-pearl-mortgage-00682-csz, live 2026-10-07 09:19Z) gave the SMS pull one line per failed user and
34
+ // one skipped line per run, so the summary no longer has to carry the failures. Shapes from BLI-12870 comment d699a863.
35
+ {
36
+ id: "pearl-sms-pull-user-failed-reconnect",
37
+ class: "config_drift",
38
+ source: "^gcp$",
39
+ unit: "^blue-pearl-mortgage",
40
+ match: raw `^\[SMS Pull\] User # failed: reason=(token_refresh_failed|no_token_for_extension|token_unavailable)\b`,
41
+ note: "an ACTIVE user's RingCentral login is dead or missing (deactivated users are skipped before any token call), so their texts are not pulled; a person must reconnect that user's RingCentral (BLI-12871, Ian)",
42
+ basis: "BLI-12870 comment d699a863: the failure line's reason labels; 291 and 297 were failing token refresh every cycle before the fix",
43
+ },
44
+ {
45
+ id: "pearl-sms-pull-user-failed-code",
46
+ class: "our_bug",
47
+ source: "^gcp$",
48
+ unit: "^blue-pearl-mortgage",
49
+ match: raw `^\[SMS Pull\] User # failed: reason=(message_store_refused|upsert_failed|unexpected_error)\b`,
50
+ note: "the pull reached RingCentral but storing or reading the messages failed: our code or our database, not a login",
51
+ basis: "BLI-12870 comment d699a863: the failure line's reason labels",
52
+ },
53
+ {
54
+ id: "pearl-sms-pull-skipped-needs-setup",
55
+ class: "config_drift",
56
+ watch: true, // the line has no trouble word, so without this the digest would count it as routine and never alert
57
+ source: "^gcp$",
58
+ unit: "^blue-pearl-mortgage",
59
+ match: raw `^\[SMS Pull\] Skipped # user\(s\):.*\b(no_extension|empty_jwt)=\[`,
60
+ note: "active users with no RingCentral extension or no RingCentral login, so their texts never reach Pearl; Edward 2026-10-07: a gap, not expected. A person sets them up (BLI-12871, Ian)",
61
+ basis: "BLI-12870 comment d699a863: no_extension was 7 users in production (179, 192, 194, 274, 286, 291, 297)",
62
+ },
63
+ {
64
+ id: "pearl-sms-pull-skipped-inactive",
65
+ class: "benign",
66
+ source: "^gcp$",
67
+ unit: "^blue-pearl-mortgage",
68
+ // Only reached when the line names no no_extension or empty_jwt list (the pattern above wins first).
69
+ match: raw `^\[SMS Pull\] Skipped # user\(s\): inactive_user=\[[#, ]*\]$`,
70
+ note: "deactivated users skipped before any token call, by design since BLI-12870",
71
+ basis: "BLI-12870 comment d699a863",
72
+ },
73
+ {
74
+ id: "pearl-sms-pull-done",
75
+ class: "benign",
76
+ source: "^gcp$",
77
+ unit: "^blue-pearl-mortgage",
78
+ match: raw `^\[SMS Pull\] Done\. Users: #, Fetched: #, Upserted: #, Skipped: #, Errors: #$`,
79
+ note: "the SMS pull's end-of-run summary; every failure now has its own `User # failed` line, which carries the alert, so the counters here are information",
80
+ basis: "BLI-12870 comment d699a863; first run after the fix (09:34Z) said Errors: 0",
81
+ },
82
+ {
83
+ id: "pearl-rc-token-pool-refresh-failed",
84
+ class: "config_drift",
85
+ source: "^gcp$",
86
+ unit: "^blue-pearl-mortgage",
87
+ match: raw `^Failed to refresh token for user #: `,
88
+ note: "the RingCentral token pool cannot refresh a user's login (OAU-222 account gone, OAU-331). It fires for active users who need reconnecting AND for deactivated users whose rc_jwt offboarding never cleared; either way a person acts (reconnect, or clear the deactivated user's RingCentral login)",
89
+ basis: "BLI-12870 comment d699a863: about 96 lines a day each for 221, 247 (deactivated) and 291, 297 (active)",
90
+ },
91
+ ];
17
92
  /** Patterns seeded from each project's first real day. Specific patterns first; first match wins. */
18
93
  const SEEDED = {
19
94
  tower: TOWER_PATTERNS,
95
+ "pearl-portal": [...PEARL_PORTAL, ...SHARED],
20
96
  };
21
97
  export const PROJECT_TABLES = Object.fromEntries(LOG_PROJECT_IDS.map((id) => [id, { version: 1, classes: TOWER_CLASSES, patterns: SEEDED[id] ?? SHARED, noiseUnits: [] }]));
22
98
  const compiled = new Map();
@@ -49,6 +49,25 @@ export interface StoredWindow {
49
49
  noise: number;
50
50
  raw_chars: number;
51
51
  }
52
+ /**
53
+ * A source whose NEWEST row on record is a refusal: blind right now, however old the refusal is. The cron writes an
54
+ * unchanged refusal about every six hours, not every pass, so a read that only looks inside the asked window loses an
55
+ * ongoing outage the moment the window starts after the last refusal row (BLI-12855, the `--since 1h` that read as all clear).
56
+ */
57
+ export interface StillRefusing {
58
+ source: string;
59
+ /** The named reason of the newest row (`vercel_token_missing`). */
60
+ reason: string;
61
+ /** When the first refusal after this source's last good window was written: how long it has been blind. */
62
+ since: string;
63
+ /** When the newest refusal row was written. */
64
+ last_seen: string;
65
+ }
66
+ /** A registered source nothing reads, with the reason the registry gives. */
67
+ export interface UnreadableSource {
68
+ source: string;
69
+ reason: string;
70
+ }
52
71
  export interface DigestedLines {
53
72
  lines: number;
54
73
  noise: number;
@@ -89,10 +108,24 @@ export interface StoredMerge {
89
108
  /** `source: reason` for every distinct refusal inside the span, so a blind spot is named. */
90
109
  refusals: string[];
91
110
  }
111
+ /**
112
+ * The verdict lines that sit right under the header: `NOT READ: 5 sources refusing since ...: reason xN, ...` and one
113
+ * line per source. Empty only when every registered source is wired and its newest row is a good window, which is the
114
+ * one state that may read as clear. The counts of ERROR templates stay in the header, apart from this.
115
+ */
116
+ export declare function notReadLines(stillRefusing: readonly StillRefusing[], notWired: readonly UnreadableSource[]): string[];
92
117
  /** Many windows of stored rows merged by template id into one capped digest (about 2 KB, real bugs first). */
93
118
  export declare function mergeStored(storedRows: readonly StoredRow[], windows: readonly StoredWindow[], options: {
94
119
  project: string;
95
120
  label: string;
96
121
  maxBytes?: number;
97
122
  extraNotes?: readonly string[];
123
+ /** Sources whose newest row is a refusal, whatever the asked window: the answer is NOT clear while any exists. */
124
+ stillRefusing?: readonly StillRefusing[];
125
+ /** Registered sources nothing reads: also NOT clear. */
126
+ notWired?: readonly UnreadableSource[];
127
+ /** True when the project has no window row at all (the cron has never written one for it). */
128
+ neverRan?: boolean;
129
+ /** When the newest row of the project was written, said when the span holds no window. */
130
+ lastRowAt?: string | null;
98
131
  }): StoredMerge;
@@ -29,7 +29,11 @@ export const STORED_MAX_TEMPLATES_PER_WINDOW = 200;
29
29
  const iso = (epoch) => (epoch ? new Date(epoch * 1000).toISOString() : null);
30
30
  /** Digests one window's lines and classifies every template with the project's table. */
31
31
  export function digestLines(lines, options) {
32
- const digest = new Digest({ noise: options.table.noiseUnits, taggedLines: true });
32
+ const digest = new Digest({
33
+ noise: options.table.noiseUnits,
34
+ taggedLines: true,
35
+ watch: (group, template) => options.table.watches(group, template, options.family),
36
+ });
33
37
  let rawChars = 0;
34
38
  for (const line of lines) {
35
39
  rawChars += line.message.length + 1;
@@ -72,6 +76,40 @@ export function storedRowBytes(row) {
72
76
  return Buffer.byteLength(JSON.stringify(row), "utf8");
73
77
  }
74
78
  const MAX_REFUSALS_NOTED = 4;
79
+ const MAX_STILL_REFUSING_LINES = 6;
80
+ /** `2026-10-07T06:47Z` from any ISO-ish time, the form the other notes use. */
81
+ function minuteOf(time) {
82
+ const parsed = Date.parse(time);
83
+ return Number.isNaN(parsed) ? time.slice(0, 16) : `${new Date(parsed).toISOString().slice(0, 16)}Z`;
84
+ }
85
+ /**
86
+ * The verdict lines that sit right under the header: `NOT READ: 5 sources refusing since ...: reason xN, ...` and one
87
+ * line per source. Empty only when every registered source is wired and its newest row is a good window, which is the
88
+ * one state that may read as clear. The counts of ERROR templates stay in the header, apart from this.
89
+ */
90
+ export function notReadLines(stillRefusing, notWired) {
91
+ if (stillRefusing.length === 0 && notWired.length === 0)
92
+ return [];
93
+ const ordered = [...stillRefusing].sort((a, b) => Date.parse(a.since) - Date.parse(b.since) || (a.source < b.source ? -1 : a.source > b.source ? 1 : 0));
94
+ const parts = [];
95
+ if (ordered.length > 0) {
96
+ const reasons = new Map();
97
+ for (const entry of ordered)
98
+ reasons.set(entry.reason, (reasons.get(entry.reason) ?? 0) + 1);
99
+ const earliest = minuteOf(ordered[0].since);
100
+ const together = ordered.every((entry) => minuteOf(entry.since) === earliest);
101
+ const when = together ? ` since ${earliest}` : `, oldest since ${earliest}`;
102
+ parts.push(`${ordered.length} source${ordered.length === 1 ? "" : "s"} refusing${when}: ${[...reasons].map(([reason, count]) => `${reason} x${count}`).join(", ")}`);
103
+ }
104
+ if (notWired.length > 0)
105
+ parts.push(`not wired: ${notWired.map((entry) => entry.source).join(", ")}`);
106
+ const lines = [`NOT READ: ${parts.join("; ")}`];
107
+ for (const entry of ordered.slice(0, MAX_STILL_REFUSING_LINES))
108
+ lines.push(` ${entry.source}: ${entry.reason} (since ${minuteOf(entry.since)}, still refusing)`);
109
+ if (ordered.length > MAX_STILL_REFUSING_LINES)
110
+ lines.push(` +${ordered.length - MAX_STILL_REFUSING_LINES} more still refusing (--json lists all)`);
111
+ return lines;
112
+ }
75
113
  /** Many windows of stored rows merged by template id into one capped digest (about 2 KB, real bugs first). */
76
114
  export function mergeStored(storedRows, windows, options) {
77
115
  // Defence in depth: whatever wrote the rows, what leaves the table is scrubbed again (the scrub is idempotent).
@@ -110,7 +148,10 @@ export function mergeStored(storedRows, windows, options) {
110
148
  const noise = okWindows.reduce((sum, window) => sum + window.noise, 0);
111
149
  const merged = mergeResults([{ lines, noise, groups, span: [null, null] }]);
112
150
  const refusals = [...new Set(windows.filter((window) => window.status !== "ok").map((window) => `${window.source}: ${window.status}`))];
113
- const notes = [];
151
+ const stillRefusing = options.stillRefusing ?? [];
152
+ const stillBlind = new Set(stillRefusing.map((entry) => entry.source));
153
+ // The verdict first, right under the header: a source that is blind or unwired means the counts below are not the whole story.
154
+ const notes = notReadLines(stillRefusing, options.notWired ?? []);
114
155
  const spans = okWindows.map((window) => [Date.parse(window.window_start), Date.parse(window.window_end)]);
115
156
  if (spans.length > 0) {
116
157
  const from = new Date(Math.min(...spans.map((span) => span[0]))).toISOString().slice(0, 16);
@@ -118,11 +159,19 @@ export function mergeStored(storedRows, windows, options) {
118
159
  const names = new Set(okWindows.map((window) => window.source));
119
160
  notes.push(`stored digests: ${okWindows.length} window${okWindows.length === 1 ? "" : "s"} of ${names.size} source${names.size === 1 ? "" : "s"}, ${from}Z to ${to}Z`);
120
161
  }
162
+ else if (options.neverRan) {
163
+ // The ONLY case that says "not run yet": the project has no window row at all, a good one or a refusal.
164
+ notes.push("stored digests: the cron has not run for this project yet (it has written no window row for it)");
165
+ }
121
166
  else {
122
- notes.push("stored digests: no window was read in this span (the cron has not run for this project yet, or every read was refused)");
167
+ // The cron has run. A refusal is named above; with none, say how old the newest row is instead of guessing why.
168
+ const newest = stillRefusing.length === 0 && options.lastRowAt ? `; the newest row Tower has for this project was written ${minuteOf(options.lastRowAt)}` : "";
169
+ notes.push(`stored digests: no window was read in this span${newest}`);
123
170
  }
124
- if (refusals.length > 0) {
125
- notes.push(`unread: ${refusals.slice(0, MAX_REFUSALS_NOTED).join("; ")}${refusals.length > MAX_REFUSALS_NOTED ? ` +${refusals.length - MAX_REFUSALS_NOTED}` : ""}`);
171
+ // A refusal inside the span from a source that is still refusing is already in the NOT READ block; this lists the gaps that closed.
172
+ const gaps = [...new Set(windows.filter((window) => window.status !== "ok" && !stillBlind.has(window.source)).map((window) => `${window.source}: ${window.status}`))];
173
+ if (gaps.length > 0) {
174
+ notes.push(`unread: ${gaps.slice(0, MAX_REFUSALS_NOTED).join("; ")}${gaps.length > MAX_REFUSALS_NOTED ? ` +${gaps.length - MAX_REFUSALS_NOTED}` : ""}`);
126
175
  }
127
176
  notes.push(...(options.extraNotes ?? []));
128
177
  const text = renderCapped(merged, {
@@ -243,6 +243,24 @@ export const TOWER_PATTERNS = [
243
243
  basis: "dashboard 1 h: 1 line",
244
244
  },
245
245
  // ------------------------------------------------------------------ railway cron services
246
+ {
247
+ id: "railway-logs-digest-repeat-refusal",
248
+ class: "benign",
249
+ source: "^railway$",
250
+ unit: "^logs-digest$",
251
+ match: raw `^\[project-logs unit\] (not asked, platform refused earlier in this firing|refusal unchanged, not written again) reason=`,
252
+ note: "the digest cron restating a refusal it already reported (the platform refused once this firing, or the stored refusal is unchanged); the first refusal is its own line and stays an alert",
253
+ basis: "Edward's QA of `cockpit logs railway --since 1h`, 2026-10-07: 272 such lines filled 6 of the 9 ERROR rows while three tokens were missing",
254
+ },
255
+ {
256
+ id: "railway-logs-digest-token-missing",
257
+ class: "config_drift",
258
+ source: "^railway$",
259
+ unit: "^logs-digest$",
260
+ match: raw `^\[project-logs unit\] refused reason=[a-z]+_token_missing`,
261
+ note: "a platform token is not set on the logs-digest service, so that platform's sources wait (BLI-12855); setting the variable is the fix",
262
+ basis: "Edward's QA, 2026-10-07: LOGS_VERCEL_TOKEN, LOGS_RAILWAY_TOKEN, LOGS_SUPABASE_TOKEN unset on the first live firing",
263
+ },
246
264
  {
247
265
  id: "railway-cal-sync-token-expired",
248
266
  class: "hiccup",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bli-cockpit/telemetry-core",
3
- "version": "0.1.60",
3
+ "version": "0.1.64",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",