@yaks/tracker 0.0.0-stage → 0.2.36

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.
Files changed (198) hide show
  1. package/Histogram.js +71 -0
  2. package/Histogram.js.map +1 -0
  3. package/Histogram.ts +100 -0
  4. package/LICENSE +202 -0
  5. package/README.md +639 -2
  6. package/_dist/brief.d.ts +25 -0
  7. package/_dist/brief.d.ts.map +1 -0
  8. package/_dist/changes.d.ts +9 -0
  9. package/_dist/changes.d.ts.map +1 -0
  10. package/_dist/chart.d.ts +24 -0
  11. package/_dist/chart.d.ts.map +1 -0
  12. package/_dist/digest.d.ts +64 -0
  13. package/_dist/digest.d.ts.map +1 -0
  14. package/_dist/effects.d.ts +73 -0
  15. package/_dist/effects.d.ts.map +1 -0
  16. package/_dist/errors.d.ts +14 -0
  17. package/_dist/errors.d.ts.map +1 -0
  18. package/_dist/everywhere.d.ts +13 -0
  19. package/_dist/everywhere.d.ts.map +1 -0
  20. package/_dist/fault.d.ts +29 -0
  21. package/_dist/fault.d.ts.map +1 -0
  22. package/_dist/file.d.ts +6 -0
  23. package/_dist/file.d.ts.map +1 -0
  24. package/_dist/fixtime.d.ts +20 -0
  25. package/_dist/fixtime.d.ts.map +1 -0
  26. package/_dist/frames.d.ts +6 -0
  27. package/_dist/frames.d.ts.map +1 -0
  28. package/_dist/graph.d.ts +3 -0
  29. package/_dist/graph.d.ts.map +1 -0
  30. package/_dist/group.d.ts +21 -0
  31. package/_dist/group.d.ts.map +1 -0
  32. package/_dist/instrument.d.ts +37 -0
  33. package/_dist/instrument.d.ts.map +1 -0
  34. package/_dist/intake.d.ts +21 -0
  35. package/_dist/intake.d.ts.map +1 -0
  36. package/_dist/merge.d.ts +11 -0
  37. package/_dist/merge.d.ts.map +1 -0
  38. package/_dist/mod.d.ts +7 -0
  39. package/_dist/mod.d.ts.map +1 -0
  40. package/_dist/model.d.ts +20 -0
  41. package/_dist/model.d.ts.map +1 -0
  42. package/_dist/outage.d.ts +7 -0
  43. package/_dist/outage.d.ts.map +1 -0
  44. package/_dist/people.d.ts +3 -0
  45. package/_dist/people.d.ts.map +1 -0
  46. package/_dist/poll.d.ts +101 -0
  47. package/_dist/poll.d.ts.map +1 -0
  48. package/_dist/poll_thread.d.ts +8 -0
  49. package/_dist/poll_thread.d.ts.map +1 -0
  50. package/_dist/reading.d.ts +34 -0
  51. package/_dist/reading.d.ts.map +1 -0
  52. package/_dist/remote.d.ts +61 -0
  53. package/_dist/remote.d.ts.map +1 -0
  54. package/_dist/report.d.ts +324 -0
  55. package/_dist/report.d.ts.map +1 -0
  56. package/_dist/resolution.d.ts +22 -0
  57. package/_dist/resolution.d.ts.map +1 -0
  58. package/_dist/routes.d.ts +33 -0
  59. package/_dist/routes.d.ts.map +1 -0
  60. package/_dist/script.d.ts +8 -0
  61. package/_dist/script.d.ts.map +1 -0
  62. package/_dist/service.d.ts +30 -0
  63. package/_dist/service.d.ts.map +1 -0
  64. package/_dist/sync_health.d.ts +4 -0
  65. package/_dist/sync_health.d.ts.map +1 -0
  66. package/_dist/ticket.d.ts +14 -0
  67. package/_dist/ticket.d.ts.map +1 -0
  68. package/_dist/tools.d.ts +39 -0
  69. package/_dist/tools.d.ts.map +1 -0
  70. package/_dist/trace-intake.d.ts +25 -0
  71. package/_dist/trace-intake.d.ts.map +1 -0
  72. package/_dist/views.d.ts +11 -0
  73. package/_dist/views.d.ts.map +1 -0
  74. package/_dist/vocab.d.ts +9 -0
  75. package/_dist/vocab.d.ts.map +1 -0
  76. package/box.json +51 -0
  77. package/brief.js +86 -0
  78. package/brief.js.map +1 -0
  79. package/brief.ts +120 -0
  80. package/changes.js +57 -0
  81. package/changes.js.map +1 -0
  82. package/changes.ts +70 -0
  83. package/chart.js +186 -0
  84. package/chart.js.map +1 -0
  85. package/chart.ts +193 -0
  86. package/deno.json +1 -0
  87. package/digest.js +329 -0
  88. package/digest.js.map +1 -0
  89. package/digest.ts +406 -0
  90. package/effects.js +136 -0
  91. package/effects.js.map +1 -0
  92. package/effects.ts +178 -0
  93. package/errors.js +130 -0
  94. package/errors.js.map +1 -0
  95. package/errors.ts +185 -0
  96. package/everywhere.js +46 -0
  97. package/everywhere.js.map +1 -0
  98. package/everywhere.ts +66 -0
  99. package/fault.js +65 -0
  100. package/fault.js.map +1 -0
  101. package/fault.ts +107 -0
  102. package/file.js +87 -0
  103. package/file.js.map +1 -0
  104. package/file.ts +93 -0
  105. package/fixtime.js +67 -0
  106. package/fixtime.js.map +1 -0
  107. package/fixtime.ts +86 -0
  108. package/frames.js +77 -0
  109. package/frames.js.map +1 -0
  110. package/frames.ts +69 -0
  111. package/graph.js +7 -0
  112. package/graph.js.map +1 -0
  113. package/graph.ts +8 -0
  114. package/group.js +444 -0
  115. package/group.js.map +1 -0
  116. package/group.ts +533 -0
  117. package/inspect.js +471 -0
  118. package/inspect.js.map +1 -0
  119. package/inspect.ts +693 -0
  120. package/instrument.js +69 -0
  121. package/instrument.js.map +1 -0
  122. package/instrument.ts +93 -0
  123. package/intake.js +43 -0
  124. package/intake.js.map +1 -0
  125. package/intake.ts +84 -0
  126. package/merge.js +126 -0
  127. package/merge.js.map +1 -0
  128. package/merge.ts +115 -0
  129. package/migrate.ts +36 -0
  130. package/mod.js +8 -0
  131. package/mod.js.map +1 -0
  132. package/mod.ts +19 -0
  133. package/model.js +8 -0
  134. package/model.js.map +1 -0
  135. package/model.ts +27 -0
  136. package/outage.js +129 -0
  137. package/outage.js.map +1 -0
  138. package/outage.ts +158 -0
  139. package/package.json +133 -4
  140. package/page.d.ts +2 -0
  141. package/page.js +905 -0
  142. package/people.js +51 -0
  143. package/people.js.map +1 -0
  144. package/people.ts +82 -0
  145. package/poll.js +277 -0
  146. package/poll.js.map +1 -0
  147. package/poll.ts +411 -0
  148. package/poll_thread.js +104 -0
  149. package/poll_thread.js.map +1 -0
  150. package/poll_thread.ts +126 -0
  151. package/poll_worker.ts +45 -0
  152. package/reading.js +122 -0
  153. package/reading.js.map +1 -0
  154. package/reading.ts +162 -0
  155. package/reconcile.js +113 -0
  156. package/reconcile.js.map +1 -0
  157. package/reconcile.ts +130 -0
  158. package/remote.js +312 -0
  159. package/remote.js.map +1 -0
  160. package/remote.ts +397 -0
  161. package/report.js +825 -0
  162. package/report.js.map +1 -0
  163. package/report.ts +944 -0
  164. package/resolution.js +114 -0
  165. package/resolution.js.map +1 -0
  166. package/resolution.ts +123 -0
  167. package/routes.js +130 -0
  168. package/routes.js.map +1 -0
  169. package/routes.ts +163 -0
  170. package/script.js +13 -0
  171. package/script.js.map +1 -0
  172. package/script.ts +16 -0
  173. package/service.js +174 -0
  174. package/service.js.map +1 -0
  175. package/service.ts +215 -0
  176. package/spread.js +94 -0
  177. package/spread.js.map +1 -0
  178. package/spread.ts +101 -0
  179. package/sync_health.js +36 -0
  180. package/sync_health.js.map +1 -0
  181. package/sync_health.ts +65 -0
  182. package/ticket.js +6 -0
  183. package/ticket.js.map +1 -0
  184. package/ticket.ts +24 -0
  185. package/tools.js +305 -0
  186. package/tools.js.map +1 -0
  187. package/tools.ts +411 -0
  188. package/trace-intake.js +164 -0
  189. package/trace-intake.js.map +1 -0
  190. package/trace-intake.ts +148 -0
  191. package/views.js +247 -0
  192. package/views.js.map +1 -0
  193. package/views.ts +254 -0
  194. package/vocab.js +20 -0
  195. package/vocab.js.map +1 -0
  196. package/vocab.json +834 -0
  197. package/vocab.ts +14 -0
  198. package/yak-tracker@.service +22 -0
package/service.js ADDED
@@ -0,0 +1,174 @@
1
+ import { clock } from "@yaks/process/clock";
2
+ import { freshFetch } from "@yaks/process/http";
3
+ import { each, intake } from "./intake.js";
4
+ export { intake } from "./intake.js";
5
+ import { sleep } from "@yaks/effects";
6
+ import { files } from "./file.js";
7
+ import { caught, spool } from "./report.js";
8
+ import { delivery, Unavailable } from "./remote.js";
9
+ import { reconcile } from "./reconcile.js";
10
+ import { syncing, syncNotice } from "./sync_health.js";
11
+ let errors = (record)=>record.rows.filter((row)=>row.error || row.request);
12
+ export let service = async (host, options = {}, signal = AbortSignal.abort())=>{
13
+ let dir = options.spool ?? host.config?.tracker?.spool;
14
+ let source = options.source ?? (dir ? files(dir).source : undefined);
15
+ if (!source) return;
16
+ let send = options.remote ? delivery(options.remote, options.fetch ?? freshFetch()) : undefined;
17
+ // An already aborted signal requests one complete pass. A live service stops
18
+ // between records, finishing the record in hand before releasing its lease.
19
+ let stop = signal.aborted ? undefined : signal;
20
+ let local = async function*() {
21
+ for await (let record of source()){
22
+ if (stop?.aborted) return;
23
+ if (send && errors(record).some((row)=>row.error)) {
24
+ if (record.admitted) continue;
25
+ yield {
26
+ ...record,
27
+ ack: record.admit ?? (()=>{})
28
+ };
29
+ } else if (record.admitted) await record.ack();
30
+ else yield record;
31
+ }
32
+ };
33
+ let forward = async (signal)=>{
34
+ if (!send) return;
35
+ let pending = [], bundles = 0, unanswered = false;
36
+ let flush = async ()=>{
37
+ if (!pending.length) return;
38
+ let batch = pending;
39
+ pending = [];
40
+ bundles = 0;
41
+ // The signed intake admits up to 100 bundles. A spool receipt is not
42
+ // acknowledged until every bundle in this batch reached that door.
43
+ await send(batch.flatMap(errors));
44
+ for (let record of batch)await record.ack();
45
+ };
46
+ let failures = [];
47
+ let attempt = async ()=>{
48
+ try {
49
+ await flush();
50
+ } catch (error) {
51
+ failures.push(error);
52
+ // The tracker could not answer: the rest waits for the next pass,
53
+ // which ends a pass within a request's minute while it is down.
54
+ if (error instanceof Unavailable) unanswered = true;
55
+ }
56
+ };
57
+ await each(source, signal, async (record)=>{
58
+ if (unanswered) return;
59
+ let rows = errors(record);
60
+ if (!rows.some((row)=>row.error)) return;
61
+ let admitted = record.admitted ?? (record.admit ? false : undefined);
62
+ if (admitted === undefined) {
63
+ let known = new Set((await host.graph.get(record.rows.map((row)=>row.entity.eid))).filter((row)=>Object.keys(row).some((name)=>name != 'entity')).map((row)=>row.entity.eid));
64
+ admitted = record.rows.every((row)=>known.has(row.entity.eid));
65
+ }
66
+ if (!admitted) return;
67
+ if (rows.length > 100) {
68
+ throw Error('Tracker record exceeds remote intake bound');
69
+ }
70
+ if (bundles + rows.length > 100) await attempt();
71
+ pending.push(record);
72
+ bundles += rows.length;
73
+ if (bundles == 100) await attempt();
74
+ }).catch((error)=>failures.push(error));
75
+ await attempt();
76
+ if (!failures.length) return;
77
+ // Batches the tracker could not answer for now are one outage, not a bug.
78
+ let bug = failures.find((error)=>!(error instanceof Unavailable));
79
+ if (failures.length == 1 || !bug) throw failures.at(-1);
80
+ throw new AggregateError(failures, 'Tracker delivery batches failed', {
81
+ cause: bug
82
+ });
83
+ };
84
+ let every = options.every ?? 1000;
85
+ let reconcileEvery = options.reconcileEvery ?? 30_000;
86
+ let notices = options.notice ? undefined : syncNotice(host.graph, clock);
87
+ let health = (direction, every)=>syncing(direction, options.notice ?? notices, {
88
+ every,
89
+ clock: options.clock,
90
+ signal: stop,
91
+ log: options.log
92
+ });
93
+ let outward = health('delivery', every);
94
+ let inward = health('standing', reconcileEvery);
95
+ // The tag of the remote standing the last reconciliation applied in full.
96
+ let seen = {};
97
+ // A failed intake pass is reported, each record's failure for itself, so a
98
+ // refused capture files under its refusal and a locked database under its
99
+ // lock, never together under a count. A sync's failure is its watch's to
100
+ // tell (./sync_health.ts), so a failed retry never reports into its own
101
+ // outbox.
102
+ let unadmitted = async (failure)=>{
103
+ let each = failure instanceof AggregateError ? failure.errors : [
104
+ failure
105
+ ];
106
+ for (let error of each){
107
+ try {
108
+ if (options.report) {
109
+ options.report(error, {
110
+ tags: {
111
+ handler: 'tracker_intake'
112
+ }
113
+ });
114
+ } else if (dir) {
115
+ await caught(error, {
116
+ sink: spool(files(dir).append),
117
+ tags: {
118
+ handler: 'tracker_intake'
119
+ }
120
+ });
121
+ } else console.error(error);
122
+ } catch {}
123
+ }
124
+ };
125
+ let run = async (pass, tell = async ()=>{}, wait = every)=>{
126
+ do {
127
+ try {
128
+ await pass();
129
+ } catch (error) {
130
+ if (stop?.aborted && error === stop.reason) return;
131
+ await tell(error);
132
+ if (signal.aborted) throw error;
133
+ }
134
+ if (signal.aborted) return;
135
+ await sleep(wait, signal);
136
+ }while (!signal.aborted)
137
+ };
138
+ let standing = ()=>inward((signal)=>reconcile(host.graph, options.remote, options.fetch, signal, seen));
139
+ // Intake, delivery, then the standing sync. One pass (an aborted signal)
140
+ // runs each in turn, so delivery sends what intake just admitted; a live
141
+ // service runs them side by side, so neither remote refusal nor a minute of
142
+ // connection retries can delay a later local record. Either way each runs
143
+ // whatever another's failure, which is told for itself. The retained
144
+ // immutable eids make every loop replayable.
145
+ let loops = [
146
+ ()=>run(()=>intake(host.graph, local, stop), unadmitted),
147
+ ...send ? [
148
+ ()=>run(()=>outward(forward)),
149
+ ()=>run(standing, undefined, reconcileEvery)
150
+ ] : []
151
+ ];
152
+ try {
153
+ let results = [];
154
+ if (signal.aborted) {
155
+ for (let loop of loops){
156
+ results.push(...await Promise.allSettled([
157
+ loop()
158
+ ]));
159
+ }
160
+ } else results = await Promise.allSettled(loops.map((loop)=>loop()));
161
+ let failures = results.flatMap((result)=>result.status == 'rejected' ? [
162
+ result.reason
163
+ ] : []);
164
+ if (failures.length == 1) throw failures[0];
165
+ if (failures.length) {
166
+ throw new AggregateError(failures, 'Tracker service passes failed');
167
+ }
168
+ } finally{
169
+ outward.close();
170
+ inward.close();
171
+ await notices?.close();
172
+ }
173
+ };
174
+ //# sourceMappingURL=service.js.map
package/service.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sources":["./service.ts"],"names":[],"mappings":"AAAA,SAAS,KAAK,mCAAwC;AACtD,SAAS,UAAU,kCAAuC;AAK1D,SAAS,IAAI,EAAE,MAAM,sBAA+C;AACpE,SAAS,MAAM,sBAA+C;AAC9D,SAAS,KAAK,6BAAkC;AAChD,SAAS,KAAK,oBAAmB;AACjC,SAAS,MAAM,EAAgB,KAAK,sBAAqB;AACzD,SAAS,QAAQ,EAAe,WAAW,sBAAqB;AAChE,SAAS,SAAS,yBAAwB;AAE1C,SAGE,OAA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O,OAAO,EAAE;MACpB,MAAM,MAAM,MAAM;IACpB,QAAS,CAAC,OAAO,OAAO,CAAC;EAC3B;EACA,IAAI,WAAW,IACb,OAAO,CAAC,SACN,UAAU,KAAK,KAAK,EAAE,QAAQ,MAAM,EAAG,QAAQ,KAAK,EAAE,QAAQ;EAElE,yEAAyE;EACzE,yEAAyE;EACzE,4EAA4E;EAC5E,0EAA0E;EAC1E,qEAAqE;EACrE,6CAA6C;EAC7C,IAAI,QAAQ;IACV,IAAM,IAAI,IAAM,OAAO,KAAK,KAAK,EAAE,OAAO,OAAO;OAC9C,OACC;MACA,IAAM,IAAI,IAAM,QAAQ;MACxB,IAAM,IAAI,UAAU,WAAW;KAChC,GACC,EAAE;GACP;EACD,IAAI;IACF,IAAI,UAAwC,EAAE;IAC9C,IAAI,OAAO,OAAO,EAAE;MAClB,KAAK,IAAI,QAAQ,MAAO;QACtB,QAAQ,IAAI,IAAI,MAAM,QAAQ,UAAU,CAAC;UAAC;SAAO;MACnD;IACF,OAAO,UAAU,MAAM,QAAQ,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,OAAS;IAC9D,IAAI,WAAW,QAAQ,OAAO,CAAC,CAAC,SAC9B,OAAO,MAAM,IAAI,aAAa;QAAC,OAAO,MAAM;OAAC,GAAG,EAAE;IAEpD,IAAI,SAAS,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,EAAE;IAC3C,IAAI,SAAS,MAAM,EAAE;MACnB,MAAM,IAAI,eAAe,UAAU;IACrC;EACF,SAAU;IACR,QAAQ,KAAK;IACb,OAAO,KAAK;IACZ,MAAM,SAAS;EACjB;AACF,EAAC"}
package/service.ts ADDED
@@ -0,0 +1,215 @@
1
+ import { clock } from '@yaks/process/clock'
2
+ import { freshFetch } from '@yaks/process/http'
3
+ // Local admission and remote delivery share a durable outbox, not a clock.
4
+ // Only admission plus successful forwarding may acknowledge an error record.
5
+
6
+ import type { Graph } from 'jsr:@yaks/graph@0.2.36'
7
+ import { each, intake, type Record, type Source } from './intake.js'
8
+ export { intake, type Record, type Source } from './intake.js'
9
+ import { sleep } from '@yaks/effects'
10
+ import { files } from './file.js'
11
+ import { caught, type Context, spool } from './report.js'
12
+ import { delivery, type Remote, Unavailable } from './remote.js'
13
+ import { reconcile } from './reconcile.js'
14
+ import type { Clock } from 'jsr:@yaks/fp@0.2.36'
15
+ import {
16
+ type Direction,
17
+ type Notice,
18
+ syncing,
19
+ syncNotice,
20
+ } from './sync_health.js'
21
+
22
+ export type Options = {
23
+ source?: Source
24
+ spool?: string
25
+ every?: number
26
+ report?: (error: unknown, context?: Partial<Context>) => void
27
+ remote?: Remote
28
+ fetch?: typeof fetch
29
+ /** what time it is and how a wait is set for the syncs' passes
30
+ * (./outage.ts), so a test can hold the clock */
31
+ clock?: Clock
32
+ /** Independent local notice path; never forwarded into the failing outbox. */
33
+ notice?: Notice
34
+ /** a sync the platform tracker could not answer, and its answering again
35
+ * (default: `console.warn`) */
36
+ log?: (line: string) => void
37
+ reconcileEvery?: number
38
+ }
39
+
40
+ let errors = (record: Record) =>
41
+ record.rows.filter((row) => row.error || row.request)
42
+
43
+ export let service = async (
44
+ host: {
45
+ graph: Graph
46
+ config?: { tracker?: { spool: string } }
47
+ },
48
+ options: Options = {},
49
+ signal: AbortSignal = AbortSignal.abort(),
50
+ ): Promise<void> => {
51
+ let dir = options.spool ?? host.config?.tracker?.spool
52
+ let source = options.source ?? (dir ? files(dir).source : undefined)
53
+ if (!source) return
54
+ let send = options.remote
55
+ ? delivery(options.remote, options.fetch ?? freshFetch())
56
+ : undefined
57
+ // An already aborted signal requests one complete pass. A live service stops
58
+ // between records, finishing the record in hand before releasing its lease.
59
+ let stop = signal.aborted ? undefined : signal
60
+ let local = async function* () {
61
+ for await (let record of source()) {
62
+ if (stop?.aborted) return
63
+ if (send && errors(record).some((row) => row.error)) {
64
+ if (record.admitted) continue
65
+ yield { ...record, ack: record.admit ?? (() => {}) }
66
+ } else if (record.admitted) await record.ack()
67
+ else yield record
68
+ }
69
+ }
70
+ let forward = async (signal: AbortSignal) => {
71
+ if (!send) return
72
+ let pending: Record[] = [], bundles = 0, unanswered = false
73
+ let flush = async () => {
74
+ if (!pending.length) return
75
+ let batch = pending
76
+ pending = []
77
+ bundles = 0
78
+ // The signed intake admits up to 100 bundles. A spool receipt is not
79
+ // acknowledged until every bundle in this batch reached that door.
80
+ await send(batch.flatMap(errors))
81
+ for (let record of batch) await record.ack()
82
+ }
83
+ let failures: unknown[] = []
84
+ let attempt = async () => {
85
+ try {
86
+ await flush()
87
+ } catch (error) {
88
+ failures.push(error)
89
+ // The tracker could not answer: the rest waits for the next pass,
90
+ // which ends a pass within a request's minute while it is down.
91
+ if (error instanceof Unavailable) unanswered = true
92
+ }
93
+ }
94
+ await each(source, signal, async (record) => {
95
+ if (unanswered) return
96
+ let rows = errors(record)
97
+ if (!rows.some((row) => row.error)) return
98
+ let admitted = record.admitted ?? (record.admit ? false : undefined)
99
+ if (admitted === undefined) {
100
+ let known = new Set(
101
+ (await host.graph.get(record.rows.map((row) => row.entity.eid)))
102
+ .filter((row) => Object.keys(row).some((name) => name != 'entity'))
103
+ .map((row) => row.entity.eid),
104
+ )
105
+ admitted = record.rows.every((row) => known.has(row.entity.eid))
106
+ }
107
+ if (!admitted) return
108
+ if (rows.length > 100) {
109
+ throw Error('Tracker record exceeds remote intake bound')
110
+ }
111
+ if (bundles + rows.length > 100) await attempt()
112
+ pending.push(record)
113
+ bundles += rows.length
114
+ if (bundles == 100) await attempt()
115
+ }).catch((error) => failures.push(error))
116
+ await attempt()
117
+ if (!failures.length) return
118
+ // Batches the tracker could not answer for now are one outage, not a bug.
119
+ let bug = failures.find((error) => !(error instanceof Unavailable))
120
+ if (failures.length == 1 || !bug) throw failures.at(-1)
121
+ throw new AggregateError(failures, 'Tracker delivery batches failed', {
122
+ cause: bug,
123
+ })
124
+ }
125
+ let every = options.every ?? 1000
126
+ let reconcileEvery = options.reconcileEvery ?? 30_000
127
+ let notices = options.notice ? undefined : syncNotice(host.graph, clock)
128
+ let health = (direction: Direction, every: number) =>
129
+ syncing(direction, options.notice ?? notices!, {
130
+ every,
131
+ clock: options.clock,
132
+ signal: stop,
133
+ log: options.log,
134
+ })
135
+ let outward = health('delivery', every)
136
+ let inward = health('standing', reconcileEvery)
137
+ // The tag of the remote standing the last reconciliation applied in full.
138
+ let seen: { tag?: string } = {}
139
+
140
+ // A failed intake pass is reported, each record's failure for itself, so a
141
+ // refused capture files under its refusal and a locked database under its
142
+ // lock, never together under a count. A sync's failure is its watch's to
143
+ // tell (./sync_health.ts), so a failed retry never reports into its own
144
+ // outbox.
145
+ let unadmitted = async (failure: unknown) => {
146
+ let each = failure instanceof AggregateError ? failure.errors : [failure]
147
+ for (let error of each) {
148
+ try {
149
+ if (options.report) {
150
+ options.report(error, { tags: { handler: 'tracker_intake' } })
151
+ } else if (dir) {
152
+ await caught(error, {
153
+ sink: spool(files(dir).append),
154
+ tags: { handler: 'tracker_intake' },
155
+ })
156
+ } else console.error(error)
157
+ } catch { /* keep the spool */ }
158
+ }
159
+ }
160
+ let run = async (
161
+ pass: () => Promise<void>,
162
+ tell: (error: unknown) => Promise<void> = async () => {},
163
+ wait = every,
164
+ ) => {
165
+ do {
166
+ try {
167
+ await pass()
168
+ } catch (error) {
169
+ if (stop?.aborted && error === stop.reason) return
170
+ await tell(error)
171
+ if (signal.aborted) throw error
172
+ }
173
+ if (signal.aborted) return
174
+ await sleep(wait, signal)
175
+ } while (!signal.aborted)
176
+ }
177
+ let standing = () =>
178
+ inward((signal) =>
179
+ reconcile(host.graph, options.remote!, options.fetch, signal, seen)
180
+ )
181
+ // Intake, delivery, then the standing sync. One pass (an aborted signal)
182
+ // runs each in turn, so delivery sends what intake just admitted; a live
183
+ // service runs them side by side, so neither remote refusal nor a minute of
184
+ // connection retries can delay a later local record. Either way each runs
185
+ // whatever another's failure, which is told for itself. The retained
186
+ // immutable eids make every loop replayable.
187
+ let loops = [
188
+ () => run(() => intake(host.graph, local, stop), unadmitted),
189
+ ...send
190
+ ? [
191
+ () => run(() => outward(forward)),
192
+ () => run(standing, undefined, reconcileEvery),
193
+ ]
194
+ : [],
195
+ ]
196
+ try {
197
+ let results: PromiseSettledResult<void>[] = []
198
+ if (signal.aborted) {
199
+ for (let loop of loops) {
200
+ results.push(...await Promise.allSettled([loop()]))
201
+ }
202
+ } else results = await Promise.allSettled(loops.map((loop) => loop()))
203
+ let failures = results.flatMap((result) =>
204
+ result.status == 'rejected' ? [result.reason] : []
205
+ )
206
+ if (failures.length == 1) throw failures[0]
207
+ if (failures.length) {
208
+ throw new AggregateError(failures, 'Tracker service passes failed')
209
+ }
210
+ } finally {
211
+ outward.close()
212
+ inward.close()
213
+ await notices?.close()
214
+ }
215
+ }
package/spread.js ADDED
@@ -0,0 +1,94 @@
1
+ // What a bug's retained occurrences have in common and where they differ:
2
+ // how many share each commit, process, tag or entity, and when they came.
3
+ // Retention keeps the newest hundred and the first of each commit, so these
4
+ // describe that sample; the bug's own hits are the count of all of them.
5
+ import { comp, str } from "./model.js";
6
+ /// let e = (at: string, commit: string) => ({ entity: { eid: commit }, error: { at } })
7
+ /// tally([e('1', 'a'), e('3', 'b'), e('2', 'a')], (b) => b.entity.eid).map((t) => [t.value, t.n, t.first, t.last]) -> [['a', 2, '1', '2'], ['b', 1, '3', '3']]
8
+ /** The values `pick` reads off each occurrence, most shared first, then the
9
+ * most recent. An occurrence without one is left out. */ export let tally = (errors, pick)=>{
10
+ let seen = new Map();
11
+ for (let b of errors){
12
+ let value = pick(b);
13
+ if (!value) continue;
14
+ let at = str(comp(b, 'error').at);
15
+ let t = seen.get(value);
16
+ if (!t) seen.set(value, {
17
+ value,
18
+ n: 1,
19
+ first: at,
20
+ last: at
21
+ });
22
+ else {
23
+ t.n++;
24
+ if (at < t.first) t.first = at;
25
+ if (at > t.last) t.last = at;
26
+ }
27
+ }
28
+ return [
29
+ ...seen.values()
30
+ ].sort((a, b)=>b.n - a.n || b.last.localeCompare(a.last));
31
+ };
32
+ /// tags({ entity: { eid: 'a' }, error: { tags: { handler: 'h', n: 2 } } }) -> [['handler', 'h'], ['n', '2']]
33
+ /** An occurrence's tags as `[key, value]` pairs, in the order caught. */ export let tags = (b)=>{
34
+ let t = comp(b, 'error').tags;
35
+ return t && typeof t == 'object' ? Object.entries(t).filter(([, v])=>v != null && v !== '').map(([k, v])=>[
36
+ k,
37
+ typeof v == 'object' ? JSON.stringify(v) : str(v)
38
+ ]) : [];
39
+ };
40
+ let during = (key)=>(b)=>str(comp(b, 'during')[key]);
41
+ /** The places a bug's occurrences came from, newest commit first, and only
42
+ * the ones any occurrence recorded. */ export let spread = (errors)=>[
43
+ {
44
+ name: 'commit',
45
+ tallies: tally(errors, (b)=>str(comp(b, 'error').commit)).sort((a, b)=>b.last.localeCompare(a.last))
46
+ },
47
+ ...[
48
+ ...new Set(errors.flatMap((b)=>tags(b).map(([k])=>k)))
49
+ ].map((key)=>({
50
+ name: key,
51
+ tallies: tally(errors, (b)=>tags(b).find(([k])=>k == key)?.[1])
52
+ })),
53
+ {
54
+ name: 'process',
55
+ tallies: tally(errors, during('process'))
56
+ },
57
+ {
58
+ name: 'app',
59
+ tallies: tally(errors, during('app'))
60
+ },
61
+ {
62
+ name: 'space',
63
+ tallies: tally(errors, during('space'))
64
+ },
65
+ {
66
+ name: 'kind',
67
+ tallies: tally(errors, during('kind'))
68
+ },
69
+ {
70
+ name: 'request',
71
+ tallies: tally(errors, during('request'))
72
+ },
73
+ {
74
+ name: 'entity',
75
+ tallies: tally(errors, during('entity'))
76
+ },
77
+ {
78
+ name: 'environment',
79
+ tallies: tally(errors, (b)=>str(comp(b, 'error').environment))
80
+ }
81
+ ].filter((s)=>s.tallies.length);
82
+ /// bins(['2026-10-01T00:00:00Z', '2026-10-01T00:30:00Z', '2026-10-01T09:59:00Z'], Date.parse('2026-10-01T00:00:00Z'), Date.parse('2026-10-01T10:00:00Z'), 10) -> [2, 0, 0, 0, 0, 0, 0, 0, 0, 1]
83
+ /** How many moments fall in each of `n` equal stretches from `from` to `to`;
84
+ * one at `to` counts in the last. */ export let bins = (ats, from, to, n)=>{
85
+ let out = Array(n).fill(0);
86
+ let span = Math.max(1, to - from);
87
+ for (let at of ats){
88
+ let t = Date.parse(at);
89
+ if (!Number.isFinite(t) || t < from || t > to) continue;
90
+ out[Math.min(n - 1, Math.floor((t - from) / span * n))]++;
91
+ }
92
+ return out;
93
+ };
94
+ //# sourceMappingURL=spread.js.map
package/spread.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spread.js","sources":["./spread.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,0EAA0E;AAC1E,4EAA4E;AAC5E,yEAAyE;AAGzE,SAAS,IAAI,EAAE,GAAG,qBAAoB;AAKtC,wFAAwF;AACxF,+JAA+J;AAC/J;uDACuD,GACvD,OAAO,IAAI,QAAQ,CACjB,QACA;EAEA,IAAI,OAAO,IAAI;EACf,KAAK,IAAI,KAAK,OAAQ;IACpB,IAAI,QAAQ,KAAK;IACjB,IAAI,CAAC,OAAO;IACZ,IAAI,KAAK,IAAI,KAAK,GAAG,SAAS,EAAE;IAChC,IAAI,IAAI,KAAK,GAAG,CAAC;IACjB,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,OAAO;MAAE;MAAO,GAAG;MAAG,OAAO;MAAI,MAAM;IAAG;SACtD;MACH,EAAE,CAAC;MACH,IAAI,KAAK,EAAE,KAAK,EAAE,EAAE,KAAK,GAAG;MAC5B,IAAI,KAAK,EAAE,IAAI,EAAE,EAAE,IAAI,GAAG;IAC5B;EACF;EACA,OAAO;OAAI,KAAK,MAAM;GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,IACjC,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,EAAE,IAAI;AAE5C,EAAC;AAED,6GAA6G;AAC7G,uEAAuE,GACvE,OAAO,IAAI,OAAO,CAAC;EACjB,IAAI,IAAI,KAAK,GAAG,SAAS,IAAI;EAC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WAAW;IAChE;GACD,CAAC,MAAM,CAAC,CAAC,IAAM,EAAE,OAAO,CAAC,MAAM,EAAC;AAEnC,gMAAgM;AAChM;mCACmC,GACnC,OAAO,IAAI,OAAO,CAChB,KACA,MACA,IACA;EAEA,IAAI,MAAM,MAAc,GAAG,IAAI,CAAC;EAChC,IAAI,OAAO,KAAK,GAAG,CAAC,GAAG,KAAK;EAC5B,KAAK,IAAI,MAAM,IAAK;IAClB,IAAI,IAAI,KAAK,KAAK,CAAC;IACnB,IAAI,CAAC,OAAO,QAAQ,CAAC,MAAM,IAAI,QAAQ,IAAI,IAAI;IAC/C,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,KAAK,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,OAAO,IAAI;EACzD;EACA,OAAO;AACT,EAAC"}
package/spread.ts ADDED
@@ -0,0 +1,101 @@
1
+ // What a bug's retained occurrences have in common and where they differ:
2
+ // how many share each commit, process, tag or entity, and when they came.
3
+ // Retention keeps the newest hundred and the first of each commit, so these
4
+ // describe that sample; the bug's own hits are the count of all of them.
5
+
6
+ import type { Bundle } from 'jsr:@yaks/graph@0.2.36'
7
+ import { comp, str } from './model.js'
8
+
9
+ /** One value occurrences share: how many, and the first and last of them. */
10
+ export type Tally = { value: string; n: number; first: string; last: string }
11
+
12
+ /// let e = (at: string, commit: string) => ({ entity: { eid: commit }, error: { at } })
13
+ /// tally([e('1', 'a'), e('3', 'b'), e('2', 'a')], (b) => b.entity.eid).map((t) => [t.value, t.n, t.first, t.last]) -> [['a', 2, '1', '2'], ['b', 1, '3', '3']]
14
+ /** The values `pick` reads off each occurrence, most shared first, then the
15
+ * most recent. An occurrence without one is left out. */
16
+ export let tally = (
17
+ errors: Bundle[],
18
+ pick: (b: Bundle) => string | undefined,
19
+ ): Tally[] => {
20
+ let seen = new Map<string, Tally>()
21
+ for (let b of errors) {
22
+ let value = pick(b)
23
+ if (!value) continue
24
+ let at = str(comp(b, 'error').at)
25
+ let t = seen.get(value)
26
+ if (!t) seen.set(value, { value, n: 1, first: at, last: at })
27
+ else {
28
+ t.n++
29
+ if (at < t.first) t.first = at
30
+ if (at > t.last) t.last = at
31
+ }
32
+ }
33
+ return [...seen.values()].sort((a, b) =>
34
+ b.n - a.n || b.last.localeCompare(a.last)
35
+ )
36
+ }
37
+
38
+ /// tags({ entity: { eid: 'a' }, error: { tags: { handler: 'h', n: 2 } } }) -> [['handler', 'h'], ['n', '2']]
39
+ /** An occurrence's tags as `[key, value]` pairs, in the order caught. */
40
+ export let tags = (b: Bundle): [string, string][] => {
41
+ let t = comp(b, 'error').tags
42
+ return t && typeof t == 'object'
43
+ ? Object.entries(t as Record<string, unknown>)
44
+ .filter(([, v]) => v != null && v !== '')
45
+ .map(([k, v]) => [k, typeof v == 'object' ? JSON.stringify(v) : str(v)])
46
+ : []
47
+ }
48
+
49
+ /** What a bug's occurrences ran in: each a name and its tallies. */
50
+ export type Spread = { name: string; tallies: Tally[] }[]
51
+
52
+ let during = (key: string) => (b: Bundle) => str(comp(b, 'during')[key])
53
+
54
+ /** The places a bug's occurrences came from, newest commit first, and only
55
+ * the ones any occurrence recorded. */
56
+ export let spread = (errors: Bundle[]): Spread =>
57
+ [
58
+ {
59
+ name: 'commit',
60
+ tallies: tally(errors, (b) => str(comp(b, 'error').commit))
61
+ .sort((a, b) => b.last.localeCompare(a.last)),
62
+ },
63
+ ...[
64
+ ...new Set(errors.flatMap((b) => tags(b).map(([k]) => k))),
65
+ ].map((key) => ({
66
+ name: key,
67
+ tallies: tally(
68
+ errors,
69
+ (b) => tags(b).find(([k]) => k == key)?.[1],
70
+ ),
71
+ })),
72
+ { name: 'process', tallies: tally(errors, during('process')) },
73
+ { name: 'app', tallies: tally(errors, during('app')) },
74
+ { name: 'space', tallies: tally(errors, during('space')) },
75
+ { name: 'kind', tallies: tally(errors, during('kind')) },
76
+ { name: 'request', tallies: tally(errors, during('request')) },
77
+ { name: 'entity', tallies: tally(errors, during('entity')) },
78
+ {
79
+ name: 'environment',
80
+ tallies: tally(errors, (b) => str(comp(b, 'error').environment)),
81
+ },
82
+ ].filter((s) => s.tallies.length)
83
+
84
+ /// bins(['2026-10-01T00:00:00Z', '2026-10-01T00:30:00Z', '2026-10-01T09:59:00Z'], Date.parse('2026-10-01T00:00:00Z'), Date.parse('2026-10-01T10:00:00Z'), 10) -> [2, 0, 0, 0, 0, 0, 0, 0, 0, 1]
85
+ /** How many moments fall in each of `n` equal stretches from `from` to `to`;
86
+ * one at `to` counts in the last. */
87
+ export let bins = (
88
+ ats: string[],
89
+ from: number,
90
+ to: number,
91
+ n: number,
92
+ ): number[] => {
93
+ let out = Array<number>(n).fill(0)
94
+ let span = Math.max(1, to - from)
95
+ for (let at of ats) {
96
+ let t = Date.parse(at)
97
+ if (!Number.isFinite(t) || t < from || t > to) continue
98
+ out[Math.min(n - 1, Math.floor((t - from) / span * n))]++
99
+ }
100
+ return out
101
+ }
package/sync_health.js ADDED
@@ -0,0 +1,36 @@
1
+ // What the tracker service's syncs with the platform tracker report, and
2
+ // where. Which failure is reported, and when, is ./outage.ts's, as it is for
3
+ // the poll: a pass the platform tracker could not answer for a moment is a
4
+ // line in the log, one unanswered for OUTAGE reports once, and any other
5
+ // failure at once. Each report names the sync that failed, its cause why.
6
+ //
7
+ // Sync failures are admitted straight to the local tracker, whose mail duty
8
+ // is independent of remote delivery. They must never enter their own outbox.
9
+ import { ingest } from "./intake.js";
10
+ import { coalesce, report } from "./report.js";
11
+ import { outage } from "./outage.js";
12
+ /** The passes of one sync, each failure to fix told to `notice`. */ export let syncing = (direction, notice, opts)=>outage({
13
+ ...opts,
14
+ name: `Tracker ${direction} sync`,
15
+ report: (error)=>void notice(Error(`Tracker ${direction} sync failed: ${error instanceof Error ? error.message : String(error)}`, {
16
+ cause: error
17
+ }), direction).catch((failure)=>console.error('tracker sync notice failed —', failure))
18
+ });
19
+ /** Sync failures admitted to `graph` itself, a flood of one coalesced
20
+ * (./report.ts `coalesce`); `close` sends the repeats a window holds. */ export let syncNotice = (graph, clock)=>{
21
+ let sink = coalesce((rows)=>ingest(graph, rows), {
22
+ clock
23
+ });
24
+ return Object.assign((error, direction)=>report(error, {
25
+ sink,
26
+ version: Date.now(),
27
+ tags: {
28
+ source: 'box',
29
+ handler: 'tracker_sync',
30
+ direction
31
+ }
32
+ }), {
33
+ close: sink.close
34
+ });
35
+ };
36
+ //# sourceMappingURL=sync_health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync_health.js","sources":["./sync_health.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,6EAA6E;AAC7E,2EAA2E;AAC3E,yEAAyE;AACzE,0EAA0E;AAC1E,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAE7E,SAAS,MAAM,sBAAqB;AACpC,SAAS,QAAQ,EAAkB,MAAM,sBAAuC;AAEhF,SAAS,MAAM,sBAAmC;AAQlD,kEAAkE,GAClE,OAAO,IAAI,UAAU,CACnB,WACA,QACA,OAOA,OAAO;IACL,GAAG,IAAI;IACP,MAAM,CAAC,QAAQ,EAAE,UAAU,KAAK,CAAC;IACjC,QAAQ,CAAC,QACP,KAAK,OACH,MACE,CAAC,QAAQ,EAAE,UAAU,cAAc,EACjC,iBAAiB,QAAQ,MAAM,OAAO,GAAG,OAAO,QAChD,EACF;QAAE,OAAO;MAAM,IAEjB,WACA,KAAK,CAAC,CAAC,UACP,QAAQ,KAAK,CAAC,gCAAgC;EAEpD,GAAE;AAEJ;uEACuE,GACvE,OAAO,IAAI,aAAa,CACtB,OACA;EAEA,IAAI,OAAO,SAAS,CAAC,OAAS,OAAO,OAAO,OAAO;IAAE;EAAM;EAC3D,OAAO,OAAO,MAAM,CAClB,CAAC,OAAc,YACb,OAAO,OAAO;MACZ;MACA,SAAS,KAAK,GAAG;MACjB,MAAM;QAAE,QAAQ;QAAO,SAAS;QAAgB;MAAU;IAC5D,IACF;IAAE,OAAO,KAAK,KAAK;EAAC;AAExB,EAAC"}