@bli-cockpit/telemetry-core 0.1.103 → 0.1.105
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/dist/collector-heartbeat.d.ts +1 -0
- package/dist/log-digest/stored.d.ts +4 -3
- package/dist/log-digest/tower-classes.js +2 -2
- package/dist/memory-hook-performance.d.ts +13 -0
- package/dist/memory-hook-performance.js +44 -0
- package/dist/memory-hook-stats.d.ts +4 -0
- package/dist/memory-hook-stats.js +17 -0
- package/dist/memory-install-receipt.d.ts +1 -0
- package/dist/node-read-cache.d.ts +20 -0
- package/dist/node-read-cache.js +40 -1
- package/package.json +1 -1
|
@@ -267,6 +267,7 @@ export declare const CollectorHeartbeatSchema: z.ZodObject<{
|
|
|
267
267
|
unreadable_samples: "unreadable_samples";
|
|
268
268
|
cleanup_failed: "cleanup_failed";
|
|
269
269
|
}>>;
|
|
270
|
+
failure_reasons: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
270
271
|
}, z.core.$strict>>;
|
|
271
272
|
}, z.core.$strict>>;
|
|
272
273
|
setup_receipt: z.ZodOptional<z.ZodObject<{
|
|
@@ -55,9 +55,10 @@ export interface StoredWindow {
|
|
|
55
55
|
raw_chars: number;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
|
-
* A source whose NEWEST row on record is a refusal: blind right now, however old the refusal is. The cron
|
|
59
|
-
* unchanged refusal about every six hours
|
|
60
|
-
* ongoing outage the moment the window
|
|
58
|
+
* A source whose NEWEST row on record is a refusal: blind right now, however old the refusal is. The cron wrote an
|
|
59
|
+
* unchanged refusal about every six hours until BLI-25225 (every pass since), so a read that only looked inside the asked
|
|
60
|
+
* window lost an ongoing outage the moment the window started after the last refusal row (BLI-12855, the `--since 1h`
|
|
61
|
+
* that read as all clear). Reading the newest row keeps that true whatever the cron's cadence.
|
|
61
62
|
*/
|
|
62
63
|
export interface StillRefusing {
|
|
63
64
|
source: string;
|
|
@@ -263,8 +263,8 @@ export const TOWER_PATTERNS = [
|
|
|
263
263
|
class: "benign",
|
|
264
264
|
source: "^railway$",
|
|
265
265
|
unit: "^logs-digest$",
|
|
266
|
-
match: raw `^\[project-logs unit\] (not asked, platform refused earlier in this firing|refusal unchanged, not written again) reason=`,
|
|
267
|
-
note: "the digest cron restating a refusal it already reported (the platform refused once this firing
|
|
266
|
+
match: raw `^\[project-logs unit\] (not asked, (platform|project) refused earlier in this firing|refusal row written|refusal unchanged, not written again) reason=`,
|
|
267
|
+
note: "the digest cron restating a refusal it already reported (the platform or, for Supabase, the project refused once this firing; the refusal's row was stored; or, before BLI-25225, the stored refusal was unchanged); the first refusal is its own line and stays an alert",
|
|
268
268
|
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",
|
|
269
269
|
},
|
|
270
270
|
{
|
|
@@ -51,8 +51,20 @@ export declare const MemoryHookSampleSchema: z.ZodObject<{
|
|
|
51
51
|
person_ms: z.ZodOptional<z.ZodNumber>;
|
|
52
52
|
total_ms: z.ZodOptional<z.ZodNumber>;
|
|
53
53
|
}, z.core.$strict>>;
|
|
54
|
+
failure_reason: z.ZodOptional<z.ZodString>;
|
|
54
55
|
}, z.core.$strict>;
|
|
55
56
|
export type MemoryHookSample = z.infer<typeof MemoryHookSampleSchema>;
|
|
57
|
+
/** At most this many distinct failure reasons are kept per window; the rest are summed under the overflow label. */
|
|
58
|
+
export declare const MEMORY_HOOK_FAILURE_REASONS_MAX = 8;
|
|
59
|
+
/** A failed or timed-out sample written by a client older than the reason field (memory-mcp 0.1.99 and before). */
|
|
60
|
+
export declare const MEMORY_HOOK_FAILURE_REASON_NOT_RECORDED = "not_recorded";
|
|
61
|
+
/** Distinct reasons past `MEMORY_HOOK_FAILURE_REASONS_MAX`, summed so the counts still add up. */
|
|
62
|
+
export declare const MEMORY_HOOK_FAILURE_REASON_OTHER = "other_reasons";
|
|
63
|
+
/**
|
|
64
|
+
* BLI-26024: one hook reason, made safe for the sample's `failure_reason`. A reason the schema would refuse must never
|
|
65
|
+
* cost the whole sample, so characters outside the label set become `_` and the label is cut to 60 characters.
|
|
66
|
+
*/
|
|
67
|
+
export declare function memoryHookFailureLabel(reason: string): string;
|
|
56
68
|
export declare const MemoryHookSamplingLeaseSchema: z.ZodObject<{
|
|
57
69
|
schema_version: z.ZodLiteral<"memory-hook-sampling-lease.v1">;
|
|
58
70
|
continuous_since: z.ZodString;
|
|
@@ -117,5 +129,6 @@ export declare const MemoryHookPerformanceSchema: z.ZodObject<{
|
|
|
117
129
|
unreadable_samples: "unreadable_samples";
|
|
118
130
|
cleanup_failed: "cleanup_failed";
|
|
119
131
|
}>>;
|
|
132
|
+
failure_reasons: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
120
133
|
}, z.core.$strict>;
|
|
121
134
|
export type MemoryHookPerformance = z.infer<typeof MemoryHookPerformanceSchema>;
|
|
@@ -61,8 +61,29 @@ export const MemoryHookSampleSchema = z
|
|
|
61
61
|
producer_version: SemverSchema,
|
|
62
62
|
/** Optional so samples written before BLI-23554 still parse. */
|
|
63
63
|
server_timings: MemoryHookServerTimingsSchema.optional(),
|
|
64
|
+
/**
|
|
65
|
+
* BLI-26024: WHY a `failed` or `timeouts` run lost its recall, as the hook's own closed log label
|
|
66
|
+
* (`dashboard_unreachable`, `http_401`, `timeout`, `unknown_internal:hook_threw:TypeError`, ...). Never text from a
|
|
67
|
+
* response, a prompt or a memory. Optional so samples written before it still parse; the reader counts a
|
|
68
|
+
* failed sample without one as `not_recorded`.
|
|
69
|
+
*/
|
|
70
|
+
failure_reason: z.string().min(1).max(60).regex(/^[a-z0-9_:.-]+$/iu).optional(),
|
|
64
71
|
})
|
|
65
72
|
.strict();
|
|
73
|
+
/** At most this many distinct failure reasons are kept per window; the rest are summed under the overflow label. */
|
|
74
|
+
export const MEMORY_HOOK_FAILURE_REASONS_MAX = 8;
|
|
75
|
+
/** A failed or timed-out sample written by a client older than the reason field (memory-mcp 0.1.99 and before). */
|
|
76
|
+
export const MEMORY_HOOK_FAILURE_REASON_NOT_RECORDED = "not_recorded";
|
|
77
|
+
/** Distinct reasons past `MEMORY_HOOK_FAILURE_REASONS_MAX`, summed so the counts still add up. */
|
|
78
|
+
export const MEMORY_HOOK_FAILURE_REASON_OTHER = "other_reasons";
|
|
79
|
+
/**
|
|
80
|
+
* BLI-26024: one hook reason, made safe for the sample's `failure_reason`. A reason the schema would refuse must never
|
|
81
|
+
* cost the whole sample, so characters outside the label set become `_` and the label is cut to 60 characters.
|
|
82
|
+
*/
|
|
83
|
+
export function memoryHookFailureLabel(reason) {
|
|
84
|
+
const cleaned = reason.trim().replace(/[^a-z0-9_:.-]/giu, "_").slice(0, 60);
|
|
85
|
+
return cleaned.length > 0 ? cleaned : "unnamed";
|
|
86
|
+
}
|
|
66
87
|
export const MemoryHookSamplingLeaseSchema = z
|
|
67
88
|
.object({
|
|
68
89
|
schema_version: z.literal(MEMORY_HOOK_SAMPLING_LEASE_SCHEMA_VERSION),
|
|
@@ -188,9 +209,32 @@ export const MemoryHookPerformanceSchema = z
|
|
|
188
209
|
unreadable_samples: CountSchema,
|
|
189
210
|
capped: z.boolean(),
|
|
190
211
|
reasons: z.array(PerformanceReasonSchema).max(MEMORY_HOOK_PERFORMANCE_REASONS.length),
|
|
212
|
+
/**
|
|
213
|
+
* BLI-26024: the failed and timed-out samples split by their reason label. Present only when the window has at
|
|
214
|
+
* least one; sums to `outcomes.failed + outcomes.timeouts`. Absent on a collector older than the field, which reads
|
|
215
|
+
* as "reasons not reported", never as "nothing failed".
|
|
216
|
+
*/
|
|
217
|
+
failure_reasons: z
|
|
218
|
+
.record(z.string().min(1).max(60).regex(/^[a-z0-9_:.-]+$/iu), CountSchema)
|
|
219
|
+
.optional(),
|
|
191
220
|
})
|
|
192
221
|
.strict()
|
|
193
222
|
.superRefine((value, context) => {
|
|
223
|
+
if (value.failure_reasons) {
|
|
224
|
+
const keys = Object.keys(value.failure_reasons);
|
|
225
|
+
// The kept reasons, plus `not_recorded` and the overflow label.
|
|
226
|
+
if (keys.length > MEMORY_HOOK_FAILURE_REASONS_MAX + 2) {
|
|
227
|
+
context.addIssue({ code: "custom", path: ["failure_reasons"], message: "too many failure reasons" });
|
|
228
|
+
}
|
|
229
|
+
const reasonTotal = Object.values(value.failure_reasons).reduce((sum, count) => sum + count, 0);
|
|
230
|
+
if (reasonTotal !== value.outcomes.failed + value.outcomes.timeouts) {
|
|
231
|
+
context.addIssue({
|
|
232
|
+
code: "custom",
|
|
233
|
+
path: ["failure_reasons"],
|
|
234
|
+
message: "failure reason counts must sum to failed plus timeouts",
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
194
238
|
const outcomeTotal = Object.values(value.outcomes).reduce((sum, count) => sum + count, 0);
|
|
195
239
|
if (outcomeTotal !== value.samples) {
|
|
196
240
|
context.addIssue({
|
|
@@ -84,6 +84,7 @@ export declare const MemoryHookCountsSchema: z.ZodObject<{
|
|
|
84
84
|
via_daemon: z.ZodOptional<z.ZodNumber>;
|
|
85
85
|
via_direct: z.ZodOptional<z.ZodNumber>;
|
|
86
86
|
skipped_trivial: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
skipped_automated: z.ZodOptional<z.ZodNumber>;
|
|
87
88
|
billing_exhausted: z.ZodOptional<z.ZodNumber>;
|
|
88
89
|
chars: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
89
90
|
}, z.core.$strict>;
|
|
@@ -106,6 +107,7 @@ export declare const MemoryHookStatsFileSchema: z.ZodObject<{
|
|
|
106
107
|
via_daemon: z.ZodOptional<z.ZodNumber>;
|
|
107
108
|
via_direct: z.ZodOptional<z.ZodNumber>;
|
|
108
109
|
skipped_trivial: z.ZodOptional<z.ZodNumber>;
|
|
110
|
+
skipped_automated: z.ZodOptional<z.ZodNumber>;
|
|
109
111
|
billing_exhausted: z.ZodOptional<z.ZodNumber>;
|
|
110
112
|
chars: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
111
113
|
}, z.core.$strict>>>;
|
|
@@ -132,6 +134,8 @@ export interface MemoryHookWindow {
|
|
|
132
134
|
viaMeasured: boolean;
|
|
133
135
|
/** Trivial prompts the hook declined to search for (BLI-3881). A subset of skips. */
|
|
134
136
|
skippedTrivial: number;
|
|
137
|
+
/** Background-task notifications the hook declined to search for (BLI-25241). A subset of skips. */
|
|
138
|
+
skippedAutomated: number;
|
|
135
139
|
/**
|
|
136
140
|
* BLI-3891: runs the provider refused because the account has no credit. A
|
|
137
141
|
* subset of `failed`, summed only over buckets that carry the field, so a
|
|
@@ -141,6 +141,19 @@ export const MemoryHookCountsSchema = z
|
|
|
141
141
|
* failed + skipped` still holds.
|
|
142
142
|
*/
|
|
143
143
|
skipped_trivial: z.number().int().min(0).optional(),
|
|
144
|
+
/**
|
|
145
|
+
* BLI-25241 — the SUBSET of `skipped` that was a background task reporting
|
|
146
|
+
* back, not a person's prompt (`<task-notification>`). The hook runs on
|
|
147
|
+
* those too, and a review of 321 recall blocks on one laptop found 49% were
|
|
148
|
+
* attached to them. They are skipped, and counted here so a falling recall
|
|
149
|
+
* rate reads as "the host sent notifications", never as "the shelf was empty".
|
|
150
|
+
*
|
|
151
|
+
* OPTIONAL for the same reason `skipped_trivial` is: this schema is strict
|
|
152
|
+
* and a required field would turn every existing machine's history into
|
|
153
|
+
* `hook_stats_unrecognised_shape` overnight. Counted BESIDE `skipped`, so
|
|
154
|
+
* `runs = printed + empty + timeouts + failed + skipped` still holds.
|
|
155
|
+
*/
|
|
156
|
+
skipped_automated: z.number().int().min(0).optional(),
|
|
144
157
|
/**
|
|
145
158
|
* BLI-3891 — the SUBSET of `failed` that was the ACCOUNT, not the code.
|
|
146
159
|
*
|
|
@@ -211,6 +224,7 @@ export function emptyMemoryHookCounts() {
|
|
|
211
224
|
failed: 0,
|
|
212
225
|
skipped: 0,
|
|
213
226
|
skipped_trivial: 0,
|
|
227
|
+
skipped_automated: 0,
|
|
214
228
|
billing_exhausted: 0,
|
|
215
229
|
// `chars` is deliberately NOT here (ticket 3934). An hour in which the
|
|
216
230
|
// hook ran and never printed has no recall to measure, and seeding 41
|
|
@@ -239,6 +253,7 @@ export function summariseMemoryHookWindow(file, event, options) {
|
|
|
239
253
|
viaDirect: 0,
|
|
240
254
|
viaMeasured: false,
|
|
241
255
|
skippedTrivial: 0,
|
|
256
|
+
skippedAutomated: 0,
|
|
242
257
|
billingExhausted: 0,
|
|
243
258
|
chars: blankCharsHistogram(),
|
|
244
259
|
charsMeasured: false,
|
|
@@ -265,6 +280,8 @@ export function summariseMemoryHookWindow(file, event, options) {
|
|
|
265
280
|
// Absent means an older writer never counted one, which sums as zero and
|
|
266
281
|
// is honest: that machine genuinely skipped none, because it could not.
|
|
267
282
|
total.skippedTrivial += counts.skipped_trivial ?? 0;
|
|
283
|
+
// Same rule (BLI-25241): an older writer could not count a notification skip.
|
|
284
|
+
total.skippedAutomated += counts.skipped_automated ?? 0;
|
|
268
285
|
// Same rule (BLI-3891): absent means an older writer never counted one,
|
|
269
286
|
// which sums as zero and is honest — that machine genuinely had none it
|
|
270
287
|
// could name.
|
|
@@ -172,6 +172,7 @@ export declare const MemoryInstallReceiptSchema: z.ZodObject<{
|
|
|
172
172
|
unreadable_samples: "unreadable_samples";
|
|
173
173
|
cleanup_failed: "cleanup_failed";
|
|
174
174
|
}>>;
|
|
175
|
+
failure_reasons: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
|
|
175
176
|
}, z.core.$strict>>;
|
|
176
177
|
}, z.core.$strict>;
|
|
177
178
|
export type MemoryInstallReceipt = z.infer<typeof MemoryInstallReceiptSchema>;
|
|
@@ -63,6 +63,19 @@ export declare function readReadCacheEntry(entryPath: string): ReadCacheEntry |
|
|
|
63
63
|
export declare function writeReadCacheEntryAtomic(entryPath: string, entry: Omit<ReadCacheEntry, "storedAt"> & {
|
|
64
64
|
storedAt?: number;
|
|
65
65
|
}): void;
|
|
66
|
+
/**
|
|
67
|
+
* Where a surface's invalidation marker lives: NEXT TO the surface directory,
|
|
68
|
+
* never inside it, because invalidating removes the directory (BLI-25636).
|
|
69
|
+
*/
|
|
70
|
+
export declare function readCacheInvalidationMarkerPath(stateDir: string, deviceToken: string, surface: ReadCacheSurface): string;
|
|
71
|
+
/**
|
|
72
|
+
* The surface's current invalidation stamp, or `""` when it was never
|
|
73
|
+
* invalidated (or the marker is unreadable). A reader takes the stamp before
|
|
74
|
+
* its request leaves and compares it after the answer returns: a different
|
|
75
|
+
* stamp means a write emptied the surface in between, so the answer is older
|
|
76
|
+
* than the write and must not be cached.
|
|
77
|
+
*/
|
|
78
|
+
export declare function readReadCacheInvalidationStamp(stateDir: string, deviceToken: string, surface: ReadCacheSurface): string;
|
|
66
79
|
/**
|
|
67
80
|
* Throws away every cached read for one surface — the whole answer to "any
|
|
68
81
|
* write through the CLI or MCP invalidates the affected cache" (BLI-10746).
|
|
@@ -71,6 +84,13 @@ export declare function writeReadCacheEntryAtomic(entryPath: string, entry: Omit
|
|
|
71
84
|
* cached queries a given write affects is its own project, and "the next
|
|
72
85
|
* read of this surface is live" costs one extra request, never a wrong
|
|
73
86
|
* answer.
|
|
87
|
+
*
|
|
88
|
+
* It also leaves a marker with a new unique stamp (BLI-25636), because
|
|
89
|
+
* deleting alone cannot stop a read that left BEFORE the write and returns
|
|
90
|
+
* AFTER it from writing its pre-write answer into the emptied surface. The
|
|
91
|
+
* stamp is unique per call (time, pid, random), so two invalidations in the
|
|
92
|
+
* same millisecond still differ. The directory is removed even when the
|
|
93
|
+
* marker could not be written: an emptied surface is the part that matters.
|
|
74
94
|
*/
|
|
75
95
|
export declare function invalidateReadCacheSurface(stateDir: string, deviceToken: string, surface: ReadCacheSurface): {
|
|
76
96
|
ok: true;
|
package/dist/node-read-cache.js
CHANGED
|
@@ -114,6 +114,28 @@ export function writeReadCacheEntryAtomic(entryPath, entry) {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Where a surface's invalidation marker lives: NEXT TO the surface directory,
|
|
119
|
+
* never inside it, because invalidating removes the directory (BLI-25636).
|
|
120
|
+
*/
|
|
121
|
+
export function readCacheInvalidationMarkerPath(stateDir, deviceToken, surface) {
|
|
122
|
+
return path.join(stateDir, "read-cache", operatorScope(deviceToken), `${surface}.invalidated_at`);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The surface's current invalidation stamp, or `""` when it was never
|
|
126
|
+
* invalidated (or the marker is unreadable). A reader takes the stamp before
|
|
127
|
+
* its request leaves and compares it after the answer returns: a different
|
|
128
|
+
* stamp means a write emptied the surface in between, so the answer is older
|
|
129
|
+
* than the write and must not be cached.
|
|
130
|
+
*/
|
|
131
|
+
export function readReadCacheInvalidationStamp(stateDir, deviceToken, surface) {
|
|
132
|
+
try {
|
|
133
|
+
return fs.readFileSync(readCacheInvalidationMarkerPath(stateDir, deviceToken, surface), "utf8");
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return "";
|
|
137
|
+
}
|
|
138
|
+
}
|
|
117
139
|
/**
|
|
118
140
|
* Throws away every cached read for one surface — the whole answer to "any
|
|
119
141
|
* write through the CLI or MCP invalidates the affected cache" (BLI-10746).
|
|
@@ -122,14 +144,31 @@ export function writeReadCacheEntryAtomic(entryPath, entry) {
|
|
|
122
144
|
* cached queries a given write affects is its own project, and "the next
|
|
123
145
|
* read of this surface is live" costs one extra request, never a wrong
|
|
124
146
|
* answer.
|
|
147
|
+
*
|
|
148
|
+
* It also leaves a marker with a new unique stamp (BLI-25636), because
|
|
149
|
+
* deleting alone cannot stop a read that left BEFORE the write and returns
|
|
150
|
+
* AFTER it from writing its pre-write answer into the emptied surface. The
|
|
151
|
+
* stamp is unique per call (time, pid, random), so two invalidations in the
|
|
152
|
+
* same millisecond still differ. The directory is removed even when the
|
|
153
|
+
* marker could not be written: an emptied surface is the part that matters.
|
|
125
154
|
*/
|
|
126
155
|
export function invalidateReadCacheSurface(stateDir, deviceToken, surface) {
|
|
127
156
|
const dir = readCacheSurfaceDir(stateDir, deviceToken, surface);
|
|
157
|
+
let failure = null;
|
|
158
|
+
try {
|
|
159
|
+
const markerPath = readCacheInvalidationMarkerPath(stateDir, deviceToken, surface);
|
|
160
|
+
fs.mkdirSync(path.dirname(markerPath), { recursive: true, mode: 0o700 });
|
|
161
|
+
const stamp = `${Date.now()}-${process.pid}-${crypto.randomBytes(6).toString("hex")}`;
|
|
162
|
+
fs.writeFileSync(markerPath, stamp, { mode: 0o600 });
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
failure = `marker_${error instanceof Error ? error.name : "unknown"}`;
|
|
166
|
+
}
|
|
128
167
|
try {
|
|
129
168
|
const existed = fs.existsSync(dir);
|
|
130
169
|
if (existed)
|
|
131
170
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
132
|
-
return { ok: true, removed: existed };
|
|
171
|
+
return failure ? { ok: false, reason: failure } : { ok: true, removed: existed };
|
|
133
172
|
}
|
|
134
173
|
catch (error) {
|
|
135
174
|
return { ok: false, reason: error instanceof Error ? error.name : "unknown" };
|