@fnndsc/salsa 4.5.6 → 4.6.0

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 (158) hide show
  1. package/README.md +0 -2
  2. package/dist/compute/index.d.ts +0 -9
  3. package/dist/compute/index.js +0 -16
  4. package/dist/compute/index.js.map +1 -1
  5. package/dist/dag/feedData.js +166 -73
  6. package/dist/dag/feedData.js.map +1 -1
  7. package/dist/dag/feedLoad.d.ts +1 -1
  8. package/dist/dag/feedLoad.js +6 -4
  9. package/dist/dag/feedLoad.js.map +1 -1
  10. package/dist/dicom/pixels.js +95 -36
  11. package/dist/dicom/pixels.js.map +1 -1
  12. package/dist/dicom/series.d.ts +4 -1
  13. package/dist/dicom/series.js +80 -31
  14. package/dist/dicom/series.js.map +1 -1
  15. package/dist/dicom/tags.d.ts +28 -0
  16. package/dist/dicom/tags.js +30 -0
  17. package/dist/dicom/tags.js.map +1 -1
  18. package/dist/files/copy.d.ts +197 -0
  19. package/dist/files/copy.js +636 -0
  20. package/dist/files/copy.js.map +1 -0
  21. package/dist/files/copyFolder.d.ts +103 -0
  22. package/dist/files/copyFolder.js +199 -0
  23. package/dist/files/copyFolder.js.map +1 -0
  24. package/dist/files/create.d.ts +178 -0
  25. package/dist/files/create.js +444 -0
  26. package/dist/files/create.js.map +1 -0
  27. package/dist/files/download.d.ts +188 -0
  28. package/dist/files/download.js +541 -0
  29. package/dist/files/download.js.map +1 -0
  30. package/dist/files/index.d.ts +69 -141
  31. package/dist/files/index.js +184 -535
  32. package/dist/files/index.js.map +1 -1
  33. package/dist/files/listing.d.ts +132 -0
  34. package/dist/files/listing.js +179 -0
  35. package/dist/files/listing.js.map +1 -0
  36. package/dist/files/move.d.ts +125 -0
  37. package/dist/files/move.js +334 -0
  38. package/dist/files/move.js.map +1 -0
  39. package/dist/files/pathMapper.d.ts +24 -1
  40. package/dist/files/pathMapper.js +108 -47
  41. package/dist/files/pathMapper.js.map +1 -1
  42. package/dist/files/proof.d.ts +315 -0
  43. package/dist/files/proof.js +574 -0
  44. package/dist/files/proof.js.map +1 -0
  45. package/dist/files/removal.d.ts +223 -0
  46. package/dist/files/removal.js +318 -0
  47. package/dist/files/removal.js.map +1 -0
  48. package/dist/files/replace.d.ts +175 -0
  49. package/dist/files/replace.js +582 -0
  50. package/dist/files/replace.js.map +1 -0
  51. package/dist/files/upload.d.ts +205 -0
  52. package/dist/files/upload.js +478 -0
  53. package/dist/files/upload.js.map +1 -0
  54. package/dist/index.d.ts +14 -2
  55. package/dist/index.js +45 -32
  56. package/dist/index.js.map +1 -1
  57. package/dist/jobs/index.d.ts +1 -1
  58. package/dist/jobs/index.js +2 -2
  59. package/dist/jobs/index.js.map +1 -1
  60. package/dist/jobs/jobOps.d.ts +20 -13
  61. package/dist/jobs/jobOps.js +41 -37
  62. package/dist/jobs/jobOps.js.map +1 -1
  63. package/dist/pacs/anonymise.d.ts +17 -36
  64. package/dist/pacs/anonymise.js +29 -67
  65. package/dist/pacs/anonymise.js.map +1 -1
  66. package/dist/pipelines/index.d.ts +1 -13
  67. package/dist/pipelines/index.js +0 -38
  68. package/dist/pipelines/index.js.map +1 -1
  69. package/dist/pipelines/invocation.js +321 -167
  70. package/dist/pipelines/invocation.js.map +1 -1
  71. package/dist/pipelines/manifest.js.map +1 -1
  72. package/dist/pipelines/packages.d.ts +11 -8
  73. package/dist/pipelines/packages.js +253 -77
  74. package/dist/pipelines/packages.js.map +1 -1
  75. package/dist/plugins/adminToken.d.ts +67 -0
  76. package/dist/plugins/adminToken.js +77 -0
  77. package/dist/plugins/adminToken.js.map +1 -0
  78. package/dist/plugins/index.d.ts +0 -7
  79. package/dist/plugins/index.js +0 -16
  80. package/dist/plugins/index.js.map +1 -1
  81. package/dist/plugins/peer_search.d.ts +0 -15
  82. package/dist/plugins/peer_search.js +0 -25
  83. package/dist/plugins/peer_search.js.map +1 -1
  84. package/dist/plugins/plugin_add.d.ts +14 -2
  85. package/dist/plugins/plugin_add.js +42 -13
  86. package/dist/plugins/plugin_add.js.map +1 -1
  87. package/dist/plugins/plugin_docker.d.ts +25 -0
  88. package/dist/plugins/plugin_docker.js +33 -0
  89. package/dist/plugins/plugin_docker.js.map +1 -1
  90. package/dist/plugins/plugin_register.d.ts +0 -10
  91. package/dist/plugins/plugin_register.js +3 -54
  92. package/dist/plugins/plugin_register.js.map +1 -1
  93. package/dist/plugins/plugin_sync.js +45 -22
  94. package/dist/plugins/plugin_sync.js.map +1 -1
  95. package/dist/plugins/plugin_validate.js +47 -13
  96. package/dist/plugins/plugin_validate.js.map +1 -1
  97. package/dist/plugins/store_import.d.ts +0 -9
  98. package/dist/plugins/store_import.js +3 -29
  99. package/dist/plugins/store_import.js.map +1 -1
  100. package/dist/retrieve/task.d.ts +137 -0
  101. package/dist/retrieve/task.js +41 -0
  102. package/dist/retrieve/task.js.map +1 -0
  103. package/dist/retrieve/watch.d.ts +2 -118
  104. package/dist/retrieve/watch.js +452 -321
  105. package/dist/retrieve/watch.js.map +1 -1
  106. package/dist/vfs/providers/etc.d.ts +6 -4
  107. package/dist/vfs/providers/etc.js +12 -4
  108. package/dist/vfs/providers/etc.js.map +1 -1
  109. package/dist/vfs/providers/native.d.ts +116 -39
  110. package/dist/vfs/providers/native.js +291 -347
  111. package/dist/vfs/providers/native.js.map +1 -1
  112. package/dist/vfs/providers/pacs.d.ts +29 -3
  113. package/dist/vfs/providers/pacs.js +303 -73
  114. package/dist/vfs/providers/pacs.js.map +1 -1
  115. package/dist/vfs/providers/pacs_content.js +22 -6
  116. package/dist/vfs/providers/pacs_content.js.map +1 -1
  117. package/dist/vfs/providers/proc/backfill.d.ts +46 -0
  118. package/dist/vfs/providers/proc/backfill.js +147 -0
  119. package/dist/vfs/providers/proc/backfill.js.map +1 -0
  120. package/dist/vfs/providers/proc/book.d.ts +176 -0
  121. package/dist/vfs/providers/proc/book.js +73 -0
  122. package/dist/vfs/providers/proc/book.js.map +1 -0
  123. package/dist/vfs/providers/proc/catchup.d.ts +69 -0
  124. package/dist/vfs/providers/proc/catchup.js +125 -0
  125. package/dist/vfs/providers/proc/catchup.js.map +1 -0
  126. package/dist/vfs/providers/proc/feedIndex.d.ts +146 -0
  127. package/dist/vfs/providers/proc/feedIndex.js +354 -0
  128. package/dist/vfs/providers/proc/feedIndex.js.map +1 -0
  129. package/dist/vfs/providers/proc/feedTopology.d.ts +85 -0
  130. package/dist/vfs/providers/proc/feedTopology.js +192 -0
  131. package/dist/vfs/providers/proc/feedTopology.js.map +1 -0
  132. package/dist/vfs/providers/proc/locate.d.ts +60 -0
  133. package/dist/vfs/providers/proc/locate.js +103 -0
  134. package/dist/vfs/providers/proc/locate.js.map +1 -0
  135. package/dist/vfs/providers/proc/path.d.ts +50 -0
  136. package/dist/vfs/providers/proc/path.js +106 -0
  137. package/dist/vfs/providers/proc/path.js.map +1 -0
  138. package/dist/vfs/providers/proc/roster.d.ts +95 -0
  139. package/dist/vfs/providers/proc/roster.js +425 -0
  140. package/dist/vfs/providers/proc/roster.js.map +1 -0
  141. package/dist/vfs/providers/proc/rows.d.ts +120 -0
  142. package/dist/vfs/providers/proc/rows.js +181 -0
  143. package/dist/vfs/providers/proc/rows.js.map +1 -0
  144. package/dist/vfs/providers/proc/subtree.d.ts +73 -0
  145. package/dist/vfs/providers/proc/subtree.js +125 -0
  146. package/dist/vfs/providers/proc/subtree.js.map +1 -0
  147. package/dist/vfs/providers/proc/sweep.d.ts +89 -0
  148. package/dist/vfs/providers/proc/sweep.js +297 -0
  149. package/dist/vfs/providers/proc/sweep.js.map +1 -0
  150. package/dist/vfs/providers/proc.d.ts +47 -346
  151. package/dist/vfs/providers/proc.js +349 -1806
  152. package/dist/vfs/providers/proc.js.map +1 -1
  153. package/dist/vfs/providers/share.js +4 -1
  154. package/dist/vfs/providers/share.js.map +1 -1
  155. package/package.json +3 -3
  156. package/dist/pacs/resultDecode.d.ts +0 -13
  157. package/dist/pacs/resultDecode.js +0 -19
  158. package/dist/pacs/resultDecode.js.map +0 -1
@@ -4,7 +4,9 @@
4
4
  *
5
5
  * Surfaces ChRIS plugin instances as a navigable DAG under /proc/jobs/.
6
6
  * Backed by ProcCache: an accumulating index whose terminal entries are
7
- * immutable and whose freshness is visit-driven.
7
+ * immutable and whose freshness is visit-driven. The reading of the tree
8
+ * lives in `./proc/` (the feed index, feed topology, visits and roster,
9
+ * the topology sweep); this module is the VFS face over it.
8
10
  *
9
11
  * Freshness model (every visit is a cheap delta, never a re-crawl):
10
12
  * - ls /proc/jobs → roster delta: each collection's newest page, read
@@ -13,418 +15,46 @@
13
15
  * the last walk's — a total that moved (a share, an
14
16
  * unshare, a deletion) promotes the visit to the
15
17
  * full index walk, which also runs once the roster
16
- * is older than {@link ROSTER_FULL_WALK_MS};
18
+ * is older than `ROSTER_FULL_WALK_MS`;
17
19
  * - a feed the roster lacks, asked for by name or id, is asked of CUBE live
18
- * and adopted ({@link procFeed_probe});
20
+ * and adopted (`procFeed_probe`);
19
21
  * - ls /proc/jobs/N → first visit loads the topology once; every later
20
22
  * visit runs {@link feedVisit_sync}: one feed-row
21
23
  * fetch (job counters), then, only when something
22
24
  * moved, a `min_end_date` delta walk (nodes created
23
25
  * or finished since the cursor) plus an `active=true`
24
26
  * sweep for the nodes still running;
25
- * - settled feeds → re-checked at most once per {@link FEED_RECHECK_MS},
27
+ * - settled feeds → re-checked at most once per `FEED_RECHECK_MS`,
26
28
  * so work appended to a finished feed is still seen;
27
29
  * - cat .../status → getPluginInstance(id), always live.
28
30
  *
31
+ * Key components:
32
+ * - ProcVfsProvider: the VFS verbs over `/proc/jobs`.
33
+ * - feedStatus_derive: a feed's aggregate status from its job counters.
34
+ *
35
+ * Typical usage:
36
+ * ```typescript
37
+ * const items: Result<VFSItem[]> = await new ProcVfsProvider().list('/proc/jobs/feed_7');
38
+ * ```
39
+ *
40
+ * Dependencies: `@fnndsc/cumin` (cache, CUBE contracts), `@fnndsc/fond` (VFS outcomes),
41
+ * `../../jobs` (job status, log, cancel), `./proc/*` (the reading of the tree).
42
+ *
29
43
  * @module
30
44
  */
31
45
  Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.ProcVfsProvider = exports.ROSTER_DELTA_MIN_MS = exports.ROSTER_LIST_BUDGET_MS = exports.ROSTER_DELTA_PAGE = exports.FEED_VISIT_COALESCE_MS = exports.ROSTER_FULL_WALK_MS = exports.FEED_RECHECK_MS = exports.FEED_WALK_IN_FLIGHT = void 0;
33
- exports.feedInstances_ensureStarted = feedInstances_ensureStarted;
34
- exports.procFeed_refreshStart = procFeed_refreshStart;
35
- exports.feedInstances_ensureLoaded = feedInstances_ensureLoaded;
46
+ exports.ProcVfsProvider = void 0;
36
47
  exports.feedStatus_derive = feedStatus_derive;
37
- exports.procPath_parse = procPath_parse;
38
- exports.procFeed_ensureLoaded = procFeed_ensureLoaded;
39
- exports.feedMeta_ensure = feedMeta_ensure;
40
- exports.procFeed_probe = procFeed_probe;
41
- exports.feedStatus_refresh = feedStatus_refresh;
42
- exports.feedCached_isSettled = feedCached_isSettled;
43
- exports.procPipelineBackfill_status = procPipelineBackfill_status;
44
- exports.procPipeline_backfillStart = procPipeline_backfillStart;
45
- exports.feedVisit_sync = feedVisit_sync;
46
- exports.procRoster_sync = procRoster_sync;
47
- exports.procRoster_syncWithin = procRoster_syncWithin;
48
- exports.procRoster_syncStart = procRoster_syncStart;
49
- exports.procRoster_bootSync = procRoster_bootSync;
50
- exports.procTopologyCatchup_enqueue = procTopologyCatchup_enqueue;
51
- exports.procTopologyCatchup_status = procTopologyCatchup_status;
52
- exports.procTopologyCatchup_await = procTopologyCatchup_await;
53
- exports.procTarget_parse = procTarget_parse;
54
- exports.procTarget_locate = procTarget_locate;
55
- exports.procVisitState_reset = procVisitState_reset;
56
- exports.procDataFacts_start = procDataFacts_start;
57
- exports.procTopology_warmup = procTopology_warmup;
58
- exports.procTopology_reconcileFeeds = procTopology_reconcileFeeds;
59
- exports.procTopology_retry = procTopology_retry;
60
- exports.procTopology_status = procTopology_status;
61
- exports.procTopology_await = procTopology_await;
62
- exports.procCache_refresh = procCache_refresh;
63
- const fond_1 = require("@fnndsc/fond");
64
48
  const cumin_1 = require("@fnndsc/cumin");
49
+ const fond_1 = require("@fnndsc/fond");
50
+ const backfill_js_1 = require("./proc/backfill.js");
51
+ const book_js_1 = require("./proc/book.js");
52
+ const feedIndex_js_1 = require("./proc/feedIndex.js");
53
+ const feedTopology_js_1 = require("./proc/feedTopology.js");
54
+ const path_js_1 = require("./proc/path.js");
55
+ const roster_js_1 = require("./proc/roster.js");
56
+ const subtree_js_1 = require("./proc/subtree.js");
65
57
  const index_js_1 = require("../../jobs/index.js");
66
- const feedJoins_js_1 = require("../../dag/feedJoins.js");
67
- const feedData_js_1 = require("../../dag/feedData.js");
68
- const packages_js_1 = require("../../pipelines/packages.js");
69
- /** Virtual filenames inside each instance directory. */
70
- const INSTANCE_FILES = new Set(['status', 'params', 'log', 'data']);
71
- /** Virtual filenames inside each feed directory. */
72
- const FEED_FILES = new Set(['status', 'title', 'note']);
73
- const PROC_JOBS_PREFIX = '/proc/jobs';
74
- const PAGE = 100;
75
- /** Pages of one feed's topology walk fetched at once (PACS plural's precedent: four). */
76
- exports.FEED_WALK_IN_FLIGHT = 4;
77
- /** How long a settled feed's counters are trusted before a visit re-checks them. */
78
- exports.FEED_RECHECK_MS = 10 * 60 * 1000;
79
- /** How old the roster may be before a visit walks the whole feed index again. */
80
- exports.ROSTER_FULL_WALK_MS = 10 * 60 * 1000;
81
- /** Visits to one feed closer together than this share the first visit's result. */
82
- exports.FEED_VISIT_COALESCE_MS = 1000;
83
- /**
84
- * Rows of a collection's newest page a roster delta reads. CUBE orders feeds
85
- * newest first, so the page holds every feed newer than the roster unless
86
- * more than this many arrived between two visits; it is small because the
87
- * surfaces re-ask the roster on a timer.
88
- */
89
- exports.ROSTER_DELTA_PAGE = 20;
90
- /**
91
- * How long listing `/proc/jobs` waits for the roster's sync before answering
92
- * from the cache: long enough for a quick CUBE to show a feed shared since
93
- * the last look, short enough that a slow one is never felt.
94
- */
95
- exports.ROSTER_LIST_BUDGET_MS = 250;
96
- /** The least time between two unforced roster deltas. */
97
- exports.ROSTER_DELTA_MIN_MS = 60 * 1000;
98
- const feedVisits = new Map();
99
- const feedVisitInflight = new Map();
100
- let rosterWalkedAt = 0;
101
- let rosterSyncInflight = null;
102
- /** Whether the sync in flight walks the whole index (a forced one waits out a delta, then walks). */
103
- let rosterSyncInflightFull = false;
104
- /** When the last roster sync settled (0: none yet). */
105
- let rosterSyncedAt = 0;
106
- let rosterTotals = { owned: null, public: null };
107
- let procTopologyPromise = null;
108
- let procTopologyFailure;
109
- let procTopologyResumeState = null;
110
- let procTopologyScopedResumeFeedIDs = null;
111
- /** Converts a CUBE feed row into the cache's feed model. */
112
- function procFeed_create(feed) {
113
- return {
114
- id: Number(feed.id),
115
- title: String(feed.name),
116
- ownerUsername: String(feed.owner_username ?? ''),
117
- public: Boolean(feed.public ?? false),
118
- creationDate: String(feed.creation_date ?? ''),
119
- finishedJobs: Number(feed.finished_jobs ?? 0),
120
- erroredJobs: Number(feed.errored_jobs ?? 0),
121
- startedJobs: Number(feed.started_jobs ?? 0),
122
- scheduledJobs: Number(feed.scheduled_jobs ?? 0),
123
- cancelledJobs: Number(feed.cancelled_jobs ?? 0),
124
- createdJobs: Number(feed.created_jobs ?? 0),
125
- };
126
- }
127
- /**
128
- * Indexes one complete paginated CUBE feed collection into the shared cache.
129
- *
130
- * @param page_fetch - Fetches one page of the collection.
131
- * @param indexed - The feeds indexed so far, keyed by id; this walk adds to it.
132
- * @returns The collection's total as the walk latched it, or null when no page carried one.
133
- */
134
- async function procFeeds_index(page_fetch, indexed) {
135
- let total = null;
136
- for await (const step of (0, cumin_1.listPages_walk)((offset, limit) => page_fetch({ limit, offset }), { pageSize: PAGE })) {
137
- total = step.total ?? total;
138
- for (const feed of step.items) {
139
- const procFeed = procFeed_create(feed);
140
- indexed.set(procFeed.id, procFeed);
141
- }
142
- }
143
- return total;
144
- }
145
- // ── Cache build ────────────────────────────────────────────────────────────
146
- /** The feed-index walk in flight, which every caller that needs one joins. */
147
- let procCacheBuildPromise = null;
148
- /**
149
- * Builds the feed index, joining a walk already in flight. A cold boot
150
- * walks it behind the listening daemon (#1280), so a `/proc` read can
151
- * arrive before it lands: the read waits on that walk instead of starting
152
- * a second one.
153
- *
154
- * @returns IDs whose topology is new, changed, or currently active.
155
- */
156
- function procCache_build() {
157
- if (procCacheBuildPromise)
158
- return procCacheBuildPromise;
159
- const build = procCache_buildRun().finally(() => {
160
- if (procCacheBuildPromise === build)
161
- procCacheBuildPromise = null;
162
- });
163
- procCacheBuildPromise = build;
164
- return build;
165
- }
166
- /**
167
- * Builds the feed index (fast). Fetches owned/shared and public feeds with job counters.
168
- * Instance topology is loaded separately via procTopology_warmup().
169
- */
170
- async function procCache_buildRun() {
171
- const cache = (0, cumin_1.procCache_get)();
172
- const client = await cumin_1.chrisConnection.client_get();
173
- if (!client) {
174
- cumin_1.errorStack.stack_push('error', 'procCache_build: not connected');
175
- throw new Error('not connected');
176
- }
177
- const indexed = new Map();
178
- const ownedTotal = await procFeeds_index((params) => (0, cumin_1.feedsPage_get)(client, params), indexed);
179
- // Older CUBEs lack a public-feeds endpoint: the contract answers null
180
- // without a wire call, and an empty first page ends the index loop.
181
- const publicBefore = indexed.size;
182
- let publicTotal = await procFeeds_index(async (params) => (await (0, cumin_1.publicFeedsPage_get)(client, params)) ?? { data: [], totalCount: 0 }, indexed);
183
- // An empty public walk while the cache already holds public feeds is a
184
- // failed SOURCE, not an authoritative absence: reconciling against it
185
- // would amputate every public feed from the roster (and the checkpoint
186
- // watcher would persist the amputation). Keep what we know and say so.
187
- if (indexed.size === publicBefore) {
188
- const knownPublic = cache.feeds_find('').filter((feed) => feed.public);
189
- if (knownPublic.length > 0) {
190
- cumin_1.errorStack.stack_push('warning', `proc roster: public-feeds source returned nothing while ${knownPublic.length} public feeds are known; keeping them`);
191
- for (const feed of knownPublic)
192
- indexed.set(feed.id, feed);
193
- // No yardstick from a failed source: the next delta takes what it reads.
194
- publicTotal = null;
195
- }
196
- }
197
- rosterTotals = { owned: ownedTotal, public: publicTotal };
198
- const knownBefore = new Set(cache.feedIDs_get());
199
- const reconciliationTargets = cache.feeds_reconcile(Array.from(indexed.values()));
200
- for (const feedID of reconciliationTargets)
201
- feedVisits.delete(feedID);
202
- // Feeds the walk brought in — created since, or shared to this identity —
203
- // are annunciated; a first build has no "before", so nothing arrives.
204
- if (knownBefore.size > 0) {
205
- const arrived = Array.from(indexed.keys()).filter((feedID) => !knownBefore.has(feedID));
206
- cache.arrivals_note(arrived);
207
- await arrivalsUnseen_mark(cache, arrived);
208
- }
209
- cache.built_set();
210
- rosterWalkedAt = Date.now();
211
- // The feeds this walk leaves without topology — arrivals, and a restored
212
- // roster's feeds whose shards were never written — land behind the prompt.
213
- procTopologyCatchup_roster(cache);
214
- return reconciliationTargets;
215
- }
216
- /** Ensures the feed index is built, building it on first access. */
217
- async function cache_ensure() {
218
- if (!(0, cumin_1.procCache_get)().built) {
219
- await procCache_build();
220
- }
221
- }
222
- /**
223
- * Ensures what one path needs. `/proc/jobs` itself needs the whole index. A
224
- * path naming one feed needs that feed alone: its row is read and kept while
225
- * the index builds on behind, so a fresh session's `ls /proc/jobs/feed_N` (or
226
- * a `cd` into its `data`) answers in that feed's time, not every feed's
227
- * (#1364: minutes before the first line, with the index warming).
228
- *
229
- * @param pathStr - The path asked for.
230
- */
231
- async function cacheFor_ensure(pathStr) {
232
- const cache = (0, cumin_1.procCache_get)();
233
- if (cache.built)
234
- return;
235
- const { feedID } = procPath_parse(pathStr.replace(/\/$/, ''));
236
- if (feedID === null) {
237
- await cache_ensure();
238
- return;
239
- }
240
- // The index lands behind the prompt; this read does not wait for it.
241
- procCache_build().catch(() => { });
242
- if (cache.feed_get(feedID) !== undefined)
243
- return;
244
- const client = await cumin_1.chrisConnection.client_get();
245
- if (!client)
246
- return;
247
- const row = await feedRow_fetch(client, feedID);
248
- if (row !== null)
249
- cache.feed_add(procFeed_create(row.feed));
250
- }
251
- /**
252
- * Loads instance topology for a single feed.
253
- * Uses in-flight map to prevent duplicate API calls.
254
- */
255
- /** Pulls the execution metrics a CUBE list row carries, defined-only. */
256
- function instanceMetrics_extract(inst) {
257
- // Which pipeline run made the job: null is a direct run. The client drops
258
- // a row's null fields, so a run made by no pipeline arrives without them.
259
- const row = inst;
260
- const pipelineName = typeof row.pipeline_name === 'string' && row.pipeline_name !== '' ? row.pipeline_name : null;
261
- const workflowID = row.workflow_id === null || row.workflow_id === undefined ? null : Number(row.workflow_id);
262
- return {
263
- pipelineName,
264
- workflowID,
265
- ...(typeof inst.start_date === 'string' ? { startedAt: inst.start_date } : {}),
266
- ...(typeof inst.end_date === 'string' ? { finishedAt: inst.end_date } : {}),
267
- ...(typeof inst.size === 'number' ? { outputBytes: inst.size } : {}),
268
- ...(typeof inst.compute_resource_name === 'string' && inst.compute_resource_name !== '' ? { computeResource: inst.compute_resource_name } : {}),
269
- };
270
- }
271
- /**
272
- * Converts a CUBE plugin-instance list row into the cache's instance model.
273
- *
274
- * @param inst - One list row.
275
- * @returns The instance as ProcCache stores it (params unresolved).
276
- */
277
- function procInstance_buildFromRow(inst) {
278
- const prevID = (inst.previous_id !== null && inst.previous_id !== undefined)
279
- ? Number(inst.previous_id)
280
- : null;
281
- return {
282
- id: Number(inst.id),
283
- feedID: Number(inst.feed_id),
284
- parentID: prevID,
285
- pluginName: String(inst.plugin_name),
286
- pluginType: inst.plugin_type !== undefined ? String(inst.plugin_type) : undefined,
287
- params: null,
288
- outputPath: outputPath_normalize(inst.output_path) ?? undefined,
289
- status: String(inst.status ?? 'unknown'),
290
- ...instanceMetrics_extract(inst),
291
- };
292
- }
293
- /**
294
- * Merges one CUBE list row into the cache: a known instance takes the row's
295
- * status and metrics (terminal status never regresses), an unknown one is
296
- * added to the topology.
297
- *
298
- * @param cache - The process cache.
299
- * @param inst - One list row.
300
- * @returns True when the row introduced a new instance.
301
- */
302
- function procInstanceRow_merge(cache, inst) {
303
- const id = Number(inst.id);
304
- if (cache.instance_get(id)) {
305
- cache.status_update(id, String(inst.status ?? 'unknown'));
306
- cache.instanceMetrics_set(id, instanceMetrics_extract(inst));
307
- return false;
308
- }
309
- cache.instance_add(procInstance_buildFromRow(inst));
310
- return true;
311
- }
312
- /**
313
- * The newer of two ISO timestamps, tolerant of absent values.
314
- *
315
- * @param a - A timestamp or null.
316
- * @param b - A timestamp, or undefined when the row carried none.
317
- * @returns The later of the two, or whichever exists.
318
- */
319
- function isoNewest_pick(a, b) {
320
- if (typeof b !== 'string' || b === '')
321
- return a;
322
- if (a === null)
323
- return b;
324
- return Date.parse(b) > Date.parse(a) ? b : a;
325
- }
326
- async function feedInstances_load(feedID) {
327
- const cache = (0, cumin_1.procCache_get)();
328
- const client = await cumin_1.chrisConnection.client_get();
329
- if (!client)
330
- throw new Error('not connected');
331
- const instances = new Map();
332
- // A first visit to a large feed is a page walk of a minute or more; the
333
- // prompt and the status strip carry its progress so it never reads as a
334
- // hang. The register is cleared on every exit, including failure.
335
- cache.feedLoad_progress(feedID, 0, 0);
336
- try {
337
- // Several pages in flight: the rows are keyed by id and committed as a
338
- // whole when the walk lands, so the order pages arrive in is nothing
339
- // to this consumer, and the walk is as long as the slowest page in
340
- // each window rather than the sum of every page.
341
- for await (const step of (0, cumin_1.listPages_walkWindowed)((offset, limit) => (0, cumin_1.pluginInstancesPage_get)(client, { feed_id: feedID, limit, offset }), { pageSize: PAGE, inFlight: exports.FEED_WALK_IN_FLIGHT })) {
342
- for (const instance of step.items)
343
- instances.set(Number(instance.id), instance);
344
- cache.feedLoad_progress(feedID, instances.size, step.total ?? 0);
345
- }
346
- for (const inst of instances.values())
347
- cache.instance_add(procInstance_buildFromRow(inst));
348
- cache.topologyLoaded_mark(feedID);
349
- cache.feedLoad_clear(feedID);
350
- // What the feed's data is: read once, now its root is known.
351
- void (0, feedData_js_1.procDataFacts_feed)(feedID, dataFactsIO_get());
352
- }
353
- catch (error) {
354
- // A walk that stops names where it stopped and stays annunciated for a
355
- // minute; the next visit starts again from the beginning.
356
- cache.feedLoad_fail(feedID, error instanceof Error ? error.message : String(error));
357
- throw error;
358
- }
359
- }
360
- /**
361
- * Ensures a feed's topology walk is at least under way, without waiting for
362
- * it. Index movement never holds the session's lane: a cold feed's walk is
363
- * started here and runs detached, deduped by the in-flight map, annunciated
364
- * by the load register, and committed to the cache when it lands (which
365
- * emits the feed's change event, the signal a watch answers).
366
- *
367
- * @param feedID - The feed whose topology is wanted.
368
- * @returns `ready` when the cache has it, `pending` when a walk is running.
369
- */
370
- function feedInstances_ensureStarted(feedID) {
371
- const cache = (0, cumin_1.procCache_get)();
372
- if (cache.topologyLoaded_has(feedID))
373
- return 'ready';
374
- if (cache.loading_get(feedID) !== undefined)
375
- return 'pending';
376
- const walk = feedInstances_load(feedID);
377
- cache.loading_set(feedID, walk);
378
- walk
379
- .catch(() => { })
380
- .finally(() => { cache.loading_clear(feedID); });
381
- return 'pending';
382
- }
383
- /**
384
- * Drops one feed's topology from the cache and re-reads its row (job
385
- * counters), so the next walk starts from nothing the cache remembers
386
- * about the graph. The roster row STAYS: a feed the identity sees through
387
- * the public listing is not in the own-feeds endpoint, and a refresh that
388
- * removed the row and could not re-read it left the feed "not found".
389
- *
390
- * @param feedID - The feed to evict.
391
- */
392
- async function procFeed_evict(feedID) {
393
- const cache = (0, cumin_1.procCache_get)();
394
- feedVisits.delete(feedID);
395
- cache.feedTopology_evict(feedID);
396
- const client = await cumin_1.chrisConnection.client_get();
397
- if (!client)
398
- return;
399
- const row = await feedRow_fetch(client, feedID);
400
- if (row)
401
- cache.feed_add(procFeed_create(row.feed));
402
- }
403
- /**
404
- * The operator's `proc refresh <feed>`: evicts the feed and STARTS its
405
- * re-walk. The walk is index movement, finished off the lane; the caller
406
- * answers `pending` and the prompt carries the count.
407
- *
408
- * @param feedID - The feed to re-index.
409
- * @returns `pending` while the walk runs (always, right after an eviction).
410
- */
411
- async function procFeed_refreshStart(feedID) {
412
- await procFeed_evict(feedID);
413
- return feedInstances_ensureStarted(feedID);
414
- }
415
- /**
416
- * Ensures topology for a feed is loaded.
417
- * Per-feed loads proceed immediately even while the global sweep is running —
418
- * instance_add is idempotent so concurrent additions are safe.
419
- */
420
- async function feedInstances_ensureLoaded(feedID) {
421
- const cache = (0, cumin_1.procCache_get)();
422
- if (feedInstances_ensureStarted(feedID) === 'ready')
423
- return;
424
- const inflight = cache.loading_get(feedID);
425
- if (inflight)
426
- await inflight;
427
- }
428
58
  // ── Aggregate status ───────────────────────────────────────────────────────
429
59
  /** Derives aggregate feed status from stored job counters — no API call. */
430
60
  function feedStatus_derive(feed) {
@@ -439,57 +69,6 @@ function feedStatus_derive(feed) {
439
69
  return 'finishedSuccessfully';
440
70
  return 'empty';
441
71
  }
442
- // ── Path parsing ───────────────────────────────────────────────────────────
443
- function procPath_parse(pathStr) {
444
- let relativePath = pathStr;
445
- if (pathStr === PROC_JOBS_PREFIX) {
446
- relativePath = '';
447
- }
448
- else if (pathStr.startsWith(`${PROC_JOBS_PREFIX}/`)) {
449
- relativePath = pathStr.slice(PROC_JOBS_PREFIX.length + 1);
450
- }
451
- const parts = relativePath.split('/').filter(Boolean);
452
- let feedID = null;
453
- let instanceID = null;
454
- let virtualFile = null;
455
- let dataRemainder = null;
456
- if (parts.length >= 1) {
457
- const feedMatch = parts[0].match(/^feed_(\d+)$/);
458
- if (feedMatch)
459
- feedID = parseInt(feedMatch[1], 10);
460
- }
461
- // A `data` segment directly after an instance segment starts the link's
462
- // subtree: the instance is the one before it, whatever follows is the
463
- // remainder inside the CFS target.
464
- for (let index = 2; index < parts.length; index++) {
465
- if (parts[index] !== 'data')
466
- continue;
467
- const instMatch = parts[index - 1].match(/_(\d+)$/);
468
- if (!instMatch)
469
- continue;
470
- instanceID = parseInt(instMatch[1], 10);
471
- virtualFile = 'data';
472
- dataRemainder = parts.slice(index + 1).join('/');
473
- return { feedID, instanceID, virtualFile, dataRemainder };
474
- }
475
- if (parts.length >= 2) {
476
- const lastPart = parts[parts.length - 1];
477
- if (FEED_FILES.has(lastPart) || INSTANCE_FILES.has(lastPart)) {
478
- virtualFile = lastPart;
479
- if (parts.length >= 3) {
480
- const instMatch = parts[parts.length - 2].match(/_(\d+)$/);
481
- if (instMatch)
482
- instanceID = parseInt(instMatch[1], 10);
483
- }
484
- }
485
- else {
486
- const instMatch = lastPart.match(/_(\d+)$/);
487
- if (instMatch)
488
- instanceID = parseInt(instMatch[1], 10);
489
- }
490
- }
491
- return { feedID, instanceID, virtualFile, dataRemainder };
492
- }
493
72
  /** Formats instance params as key=value lines. */
494
73
  function params_render(inst) {
495
74
  if (!inst.params || Object.keys(inst.params).length === 0)
@@ -498,24 +77,6 @@ function params_render(inst) {
498
77
  .map(([k, v]) => `${k}=${String(v)}`)
499
78
  .join('\n');
500
79
  }
501
- /**
502
- * Normalizes CUBE's output-path spelling into an absolute CFS path.
503
- *
504
- * @param value - Raw `output_path` value from a plugin-instance resource.
505
- * @returns Absolute CFS path, or null when no usable path was supplied.
506
- */
507
- function outputPath_normalize(value) {
508
- if (typeof value !== 'string' || value.trim() === '')
509
- return null;
510
- const clean = value.trim();
511
- return clean.startsWith('/') ? clean : `/${clean}`;
512
- }
513
- /**
514
- * Resolves and memoizes the authoritative CFS output directory for one job.
515
- *
516
- * @param instanceID - Plugin-instance ID whose output path is needed.
517
- * @returns Absolute output path, or null when CUBE has not recorded one.
518
- */
519
80
  /**
520
81
  * Resolves a path inside an instance's `data` link to its CFS target.
521
82
  *
@@ -526,37 +87,14 @@ function outputPath_normalize(value) {
526
87
  async function dataTarget_resolve(instanceID, remainder, feedID = null) {
527
88
  // A fresh session knows no job until its feed's topology is read: read it, as a listing of the node would.
528
89
  if (feedID !== null && (0, cumin_1.procCache_get)().instance_get(instanceID) === undefined)
529
- await feedInstances_ensureLoaded(feedID);
530
- const outputPath = await instanceOutputPath_ensure(instanceID);
90
+ await (0, feedTopology_js_1.feedInstances_ensureLoaded)(feedID);
91
+ const outputPath = await (0, feedTopology_js_1.instanceOutputPath_ensure)(instanceID);
531
92
  if (!outputPath) {
532
93
  cumin_1.errorStack.stack_push('error', `No CFS output path is available for job ${instanceID}`);
533
94
  return (0, cumin_1.Err)();
534
95
  }
535
96
  return (0, cumin_1.Ok)(remainder === '' ? outputPath : `${outputPath}/${remainder}`);
536
97
  }
537
- async function instanceOutputPath_ensure(instanceID) {
538
- const cache = (0, cumin_1.procCache_get)();
539
- const inst = cache.instance_get(instanceID);
540
- if (!inst)
541
- return null;
542
- if (inst.outputPath !== undefined)
543
- return inst.outputPath;
544
- const client = await cumin_1.chrisConnection.client_get();
545
- if (!client)
546
- return null;
547
- try {
548
- const handle = await (0, cumin_1.pluginInstance_get)(client, instanceID);
549
- const outputPath = outputPath_normalize(handle?.data?.output_path);
550
- cache.outputPath_update(instanceID, outputPath);
551
- return outputPath;
552
- }
553
- catch (error) {
554
- // "No CFS output path" downstream must not mask a failed fetch.
555
- const msg = error instanceof Error ? error.message : String(error);
556
- cumin_1.errorStack.stack_push("warning", `Could not fetch output path for instance ${instanceID}: ${msg}`);
557
- return null;
558
- }
559
- }
560
98
  /**
561
99
  * Reads every page of effective parameter values from one plugin instance.
562
100
  *
@@ -565,7 +103,7 @@ async function instanceOutputPath_ensure(instanceID) {
565
103
  */
566
104
  async function instanceParams_fetch(handle) {
567
105
  const params = {};
568
- for await (const step of (0, cumin_1.listPages_walk)((offset, limit) => handle.parametersPage_get({ limit, offset }), { pageSize: PAGE })) {
106
+ for await (const step of (0, cumin_1.listPages_walk)((offset, limit) => handle.parametersPage_get({ limit, offset }), { pageSize: book_js_1.PAGE })) {
569
107
  for (const item of step.items) {
570
108
  if (item.param_name)
571
109
  params[item.param_name] = item.value;
@@ -573,6 +111,130 @@ async function instanceParams_fetch(handle) {
573
111
  }
574
112
  return params;
575
113
  }
114
+ /**
115
+ * Adds every feed at the mount to a subtree walk: each feed's row, with
116
+ * its status, then what is inside it.
117
+ *
118
+ * @param walk - The walk.
119
+ */
120
+ function subtreeFeeds_add(walk) {
121
+ for (const id of walk.cache.feedIDs_get()) {
122
+ const feed = walk.cache.feed_get(id);
123
+ const name = `feed_${id}`;
124
+ const status = feed ? feedStatus_derive(feed) : 'unknown';
125
+ walk.entries.push({ rel: name, depth: 1, item: { name, type: 'job', size: 0, owner: '', date: feed?.creationDate ?? '', title: feed?.title ?? name, status }, attrs: { status } });
126
+ (0, subtree_js_1.subtreeFeed_add)(walk, id, name, 2);
127
+ }
128
+ }
129
+ /**
130
+ * Reads a file beneath a job's `data` link: the store's file, its links
131
+ * followed.
132
+ *
133
+ * @param instanceID - The job.
134
+ * @param dataRemainder - The path below `data`.
135
+ * @param feedID - The job's feed, when the path names it.
136
+ * @returns The file's text, or Err.
137
+ */
138
+ async function dataLinkFile_read(instanceID, dataRemainder, feedID) {
139
+ const target = await dataTarget_resolve(instanceID, dataRemainder, feedID);
140
+ if (!target.ok)
141
+ return (0, cumin_1.Err)();
142
+ const { vfsDispatcher } = await import('../dispatcher.js');
143
+ return (0, fond_1.vfsOutcome_convertToResult)(await vfsDispatcher.read(target.value), 'read', target.value);
144
+ }
145
+ /**
146
+ * Reads a feed's virtual file: its status, title or note.
147
+ *
148
+ * @param cache - The cache.
149
+ * @param feedID - The feed.
150
+ * @param virtualFile - The file's name.
151
+ * @returns Its text; '' for a feed the cache lacks; Err for any other name or a note that cannot be read.
152
+ */
153
+ async function feedFile_read(cache, feedID, virtualFile) {
154
+ const feed = cache.feed_get(feedID);
155
+ if (!feed)
156
+ return (0, cumin_1.Ok)('');
157
+ if (virtualFile === 'status')
158
+ return (0, cumin_1.Ok)(feedStatus_derive(feed));
159
+ if (virtualFile === 'title')
160
+ return (0, cumin_1.Ok)(feed.title);
161
+ if (virtualFile === 'note') {
162
+ const note = await (0, cumin_1.feedNote_get)(feedID);
163
+ return note.ok ? (0, cumin_1.Ok)(note.value.content) : (0, cumin_1.Err)();
164
+ }
165
+ return (0, cumin_1.Err)();
166
+ }
167
+ /**
168
+ * Reads a job's virtual file — all live or cached-on-first-read: its
169
+ * status, its parameters or its log.
170
+ *
171
+ * @param cache - The cache.
172
+ * @param feedID - The job's feed, whose topology is read first.
173
+ * @param instanceID - The job.
174
+ * @param virtualFile - The file's name.
175
+ * @returns Its text; '' for a job the cache lacks; Err for any other name.
176
+ */
177
+ async function instanceFile_read(cache, feedID, instanceID, virtualFile) {
178
+ await (0, feedTopology_js_1.feedInstances_ensureLoaded)(feedID);
179
+ const inst = cache.instance_get(instanceID);
180
+ if (!inst)
181
+ return (0, cumin_1.Ok)('');
182
+ if (virtualFile === 'status')
183
+ return instanceStatus_read(cache, inst, instanceID);
184
+ if (virtualFile === 'params') {
185
+ if (inst.params === null)
186
+ await instanceParams_load(cache, instanceID);
187
+ return (0, cumin_1.Ok)(params_render(inst));
188
+ }
189
+ if (virtualFile === 'log') {
190
+ const logResult = await (0, index_js_1.job_logFetch)(instanceID);
191
+ return (0, cumin_1.Ok)(logResult.ok ? logResult.value : '(log unavailable)');
192
+ }
193
+ return (0, cumin_1.Err)();
194
+ }
195
+ /**
196
+ * A job's status: a settled job's from the cache, with no call; an active
197
+ * job's live, cached when it answers, else the last known.
198
+ *
199
+ * @param cache - The cache.
200
+ * @param inst - The job as cached.
201
+ * @param instanceID - The job's id.
202
+ * @returns The status.
203
+ */
204
+ async function instanceStatus_read(cache, inst, instanceID) {
205
+ // Settled jobs never change — return the cached terminal status, no call.
206
+ if ((0, cumin_1.status_isTerminal)(inst.status))
207
+ return (0, cumin_1.Ok)(inst.status);
208
+ const fresh = await (0, index_js_1.job_statusFetch)(instanceID);
209
+ if (fresh.ok)
210
+ cache.status_update(instanceID, fresh.value);
211
+ return (0, cumin_1.Ok)(fresh.ok ? fresh.value : (inst.status ?? 'unknown'));
212
+ }
213
+ /**
214
+ * Loads a job's effective parameters into the cache, when a client is
215
+ * connected and CUBE knows the job.
216
+ *
217
+ * CUBE stores the effective run values in the parameter sub-resource; the
218
+ * instance detail payload itself is operational metadata.
219
+ *
220
+ * @param cache - The cache.
221
+ * @param instanceID - The job.
222
+ */
223
+ async function instanceParams_load(cache, instanceID) {
224
+ const client = await cumin_1.chrisConnection.client_get();
225
+ if (!client)
226
+ return;
227
+ try {
228
+ const handle = await (0, cumin_1.pluginInstance_get)(client, instanceID);
229
+ if (handle)
230
+ cache.params_update(instanceID, await instanceParams_fetch(handle));
231
+ }
232
+ catch {
233
+ // Deliberate absorption, adjudicated 2026-08: parameters are a
234
+ // lazy display enrichment; a failed fetch renders as
235
+ // "(no parameters)" and the next read retries.
236
+ }
237
+ }
576
238
  /** Collects all instance IDs for a feed recursively. */
577
239
  function feedInstanceIDs_list(feedID, cache) {
578
240
  const result = [];
@@ -584,12 +246,129 @@ function feedInstanceIDs_list(feedID, cache) {
584
246
  }
585
247
  return result;
586
248
  }
249
+ // ── Listings ───────────────────────────────────────────────────────────────
250
+ /**
251
+ * One job's row in a feed's or a job's listing.
252
+ *
253
+ * @param inst - The job.
254
+ * @param id - Its plugin-instance id.
255
+ * @returns The row, named `<plugin>_<id>`.
256
+ */
257
+ function jobItem_make(inst, id) {
258
+ return {
259
+ name: `${inst.pluginName}_${id}`,
260
+ type: 'job',
261
+ size: 0,
262
+ owner: '',
263
+ date: '',
264
+ status: inst.status ?? 'unknown',
265
+ };
266
+ }
267
+ /**
268
+ * Lists `/proc/jobs`: every feed with its aggregate status from its counters,
269
+ * after waiting the listing's budget for the roster's sync.
270
+ *
271
+ * @param cache - The process cache.
272
+ * @returns One row per feed.
273
+ */
274
+ async function jobsRoot_list(cache) {
275
+ await (0, roster_js_1.procRoster_syncWithin)(book_js_1.ROSTER_LIST_BUDGET_MS);
276
+ const items = cache.feedIDs_get().map((feedID) => {
277
+ const feed = cache.feed_get(feedID);
278
+ const status = feed ? feedStatus_derive(feed) : 'unknown';
279
+ return {
280
+ name: `feed_${feedID}`,
281
+ type: 'job',
282
+ size: 0,
283
+ owner: '',
284
+ date: '',
285
+ title: feed?.title ?? `feed_${feedID}`,
286
+ status,
287
+ };
288
+ });
289
+ return (0, cumin_1.Ok)(items);
290
+ }
291
+ /**
292
+ * Lists `/proc/jobs/feed_N`: the feed's own files and its root jobs.
293
+ *
294
+ * @param cache - The process cache.
295
+ * @param feedID - The feed.
296
+ * @returns The feed's rows; empty when CUBE does not list the feed.
297
+ */
298
+ async function feedFolder_list(cache, feedID) {
299
+ // A feed the roster lacks is asked of CUBE first: shared to this
300
+ // identity, or made public, since the walk, it is adopted here and
301
+ // listed as any other; a feed CUBE does not list is an empty listing.
302
+ if (cache.feed_get(feedID) === undefined && (await (0, feedIndex_js_1.procFeedAbsent_probe)(feedID)) === null)
303
+ return (0, cumin_1.Ok)([]);
304
+ const wasLoaded = cache.topologyLoaded_has(feedID);
305
+ await (0, feedTopology_js_1.feedInstances_ensureLoaded)(feedID);
306
+ const feed = cache.feed_get(feedID);
307
+ if (!feed)
308
+ return (0, cumin_1.Ok)([]);
309
+ // The initial load already carried live status and topology; a revisit
310
+ // is a delta (feed counters, then only what moved).
311
+ if (wasLoaded)
312
+ await (0, roster_js_1.feedVisit_sync)(feedID);
313
+ const rootIDs = cache.feedRoots_get(feedID);
314
+ const items = [];
315
+ items.push({ name: 'status', type: 'file', size: 0, owner: '', date: '' });
316
+ items.push({ name: 'title', type: 'file', size: 0, owner: '', date: '' });
317
+ // The feed's note: CUBE's one scratchpad per feed, read and written as a file.
318
+ items.push({ name: 'note', type: 'file', size: 0, owner: '', date: '' });
319
+ for (const rootID of rootIDs) {
320
+ const inst = cache.instance_get(rootID);
321
+ if (!inst)
322
+ continue;
323
+ items.push(jobItem_make(inst, rootID));
324
+ }
325
+ return (0, cumin_1.Ok)(items);
326
+ }
327
+ /**
328
+ * Lists `/proc/jobs/feed_N/plugin_ID`: the job's own files, its `data` link
329
+ * and its children.
330
+ *
331
+ * @param cache - The process cache.
332
+ * @param feedID - The job's feed.
333
+ * @param instanceID - The job.
334
+ * @returns The job's rows; empty when the feed holds no such job.
335
+ */
336
+ async function jobFolder_list(cache, feedID, instanceID) {
337
+ const wasLoaded = cache.topologyLoaded_has(feedID);
338
+ await (0, feedTopology_js_1.feedInstances_ensureLoaded)(feedID);
339
+ const inst = cache.instance_get(instanceID);
340
+ if (!inst)
341
+ return (0, cumin_1.Ok)([]);
342
+ if (wasLoaded)
343
+ await (0, roster_js_1.feedVisit_sync)(feedID);
344
+ const childIDs = cache.children_get(instanceID);
345
+ const items = [];
346
+ items.push({ name: 'status', type: 'file', size: 0, owner: '', date: '' });
347
+ items.push({ name: 'params', type: 'file', size: 0, owner: '', date: '' });
348
+ items.push({ name: 'log', type: 'file', size: 0, owner: '', date: '' });
349
+ // `data` is structural: list it without fetching the per-instance detail
350
+ // endpoint. Its target is resolved only when `cd data` follows the link.
351
+ // A known null means CUBE has no output directory, so omit it entirely.
352
+ if (inst.outputPath !== null) {
353
+ const dataLink = { name: 'data', type: 'link', size: 0, owner: '', date: '' };
354
+ if (inst.outputPath)
355
+ dataLink.target = inst.outputPath;
356
+ items.push(dataLink);
357
+ }
358
+ for (const childID of childIDs) {
359
+ const child = cache.instance_get(childID);
360
+ if (!child)
361
+ continue;
362
+ items.push(jobItem_make(child, childID));
363
+ }
364
+ return (0, cumin_1.Ok)(items);
365
+ }
587
366
  // ── Provider ───────────────────────────────────────────────────────────────
588
367
  /**
589
368
  * VFS provider exposing running jobs and feeds under the /proc namespace.
590
369
  */
591
370
  class ProcVfsProvider {
592
- prefix = PROC_JOBS_PREFIX;
371
+ prefix = path_js_1.PROC_JOBS_PREFIX;
593
372
  /**
594
373
  * Resolves the synthetic `data` link for one job only when navigation asks
595
374
  * to follow it. This keeps `/proc` topology listings and recursive trees
@@ -599,9 +378,9 @@ class ProcVfsProvider {
599
378
  * @returns The authoritative CFS output path, or an error when absent.
600
379
  */
601
380
  async linkTarget_resolve(pathStr) {
602
- await cacheFor_ensure(pathStr);
381
+ await (0, feedIndex_js_1.cacheFor_ensure)(pathStr);
603
382
  const clean = pathStr.replace(/\/$/, '');
604
- const { feedID, instanceID, virtualFile } = procPath_parse(clean);
383
+ const { feedID, instanceID, virtualFile } = (0, path_js_1.procPath_parse)(clean);
605
384
  if (feedID === null || instanceID === null || virtualFile !== 'data') {
606
385
  cumin_1.errorStack.stack_push('error', `Not a /proc job data link: ${pathStr}`);
607
386
  return (0, cumin_1.Err)();
@@ -620,9 +399,9 @@ class ProcVfsProvider {
620
399
  * the job has no output space.
621
400
  */
622
401
  async storePath_resolve(pathStr) {
623
- await cacheFor_ensure(pathStr);
402
+ await (0, feedIndex_js_1.cacheFor_ensure)(pathStr);
624
403
  const clean = pathStr.replace(/\/$/, '');
625
- const { feedID, instanceID, virtualFile, dataRemainder } = procPath_parse(clean);
404
+ const { feedID, instanceID, virtualFile, dataRemainder } = (0, path_js_1.procPath_parse)(clean);
626
405
  if (instanceID === null || virtualFile !== 'data' || dataRemainder === null)
627
406
  return (0, cumin_1.Ok)(null);
628
407
  return dataTarget_resolve(instanceID, dataRemainder, feedID);
@@ -642,106 +421,67 @@ class ProcVfsProvider {
642
421
  if (!cache.built)
643
422
  return null;
644
423
  const clean = pathStr.replace(/\/$/, '');
645
- const { feedID, instanceID, virtualFile } = procPath_parse(clean);
424
+ const { feedID, instanceID, virtualFile } = (0, path_js_1.procPath_parse)(clean);
646
425
  if (virtualFile !== null)
647
426
  return { entries: [], unanswered: [] };
648
- const entries = [];
649
- const unanswered = [];
650
- const file = (rel, name, depth) => {
651
- entries.push({ rel: rel === '' ? name : `${rel}/${name}`, depth, item: { name, type: 'file', size: 0, owner: '', date: '' } });
652
- };
653
- const job = (id, rel, depth) => {
654
- const inst = cache.instance_get(id);
655
- if (inst === undefined)
656
- return;
657
- const name = `${inst.pluginName}_${id}`;
658
- const here = rel === '' ? name : `${rel}/${name}`;
659
- entries.push({
660
- rel: here, depth,
661
- item: { name, type: 'job', size: 0, owner: '', date: inst.startedAt ?? '', status: inst.status ?? 'unknown' },
662
- attrs: {
663
- status: inst.status ?? 'unknown',
664
- plugin: inst.pluginName,
665
- // Which pipeline run made it: '' for a direct run; absent until a row said.
666
- ...(inst.pipelineName !== undefined ? { pipeline: inst.pipelineName ?? '' } : {}),
667
- ...(inst.workflowID !== undefined ? { workflow: inst.workflowID === null ? '' : String(inst.workflowID) } : {}),
668
- },
669
- });
670
- jobInside(id, here, depth + 1);
671
- };
672
- const jobInside = (id, rel, depth) => {
673
- const inst = cache.instance_get(id);
674
- if (inst === undefined)
675
- return;
676
- for (const name of ['status', 'params', 'log'])
677
- file(rel, name, depth);
678
- if (inst.outputPath !== null)
679
- entries.push({ rel: `${rel}/data`, depth, item: { name: 'data', type: 'link', size: 0, owner: '', date: '' } });
680
- for (const child of cache.children_get(id))
681
- job(child, rel, depth);
682
- };
683
- const feedInside = (id, rel, depth) => {
684
- if (!cache.topologyLoaded_has(id)) {
685
- unanswered.push(rel);
686
- return;
687
- }
688
- for (const name of ['status', 'title', 'note'])
689
- file(rel, name, depth);
690
- for (const root of cache.feedRoots_get(id))
691
- job(root, rel, depth);
692
- };
427
+ const walk = { cache, entries: [], unanswered: [] };
693
428
  // Rows restored from before the cache kept a job's pipeline run are read
694
429
  // again once, behind the prompt; until then those jobs say they do not know.
695
- procPipeline_backfillStart();
696
- if (clean === PROC_JOBS_PREFIX) {
697
- for (const id of cache.feedIDs_get()) {
698
- const feed = cache.feed_get(id);
699
- const name = `feed_${id}`;
700
- const status = feed ? feedStatus_derive(feed) : 'unknown';
701
- entries.push({ rel: name, depth: 1, item: { name, type: 'job', size: 0, owner: '', date: feed?.creationDate ?? '', title: feed?.title ?? name, status }, attrs: { status } });
702
- feedInside(id, name, 2);
703
- }
430
+ (0, backfill_js_1.procPipeline_backfillStart)();
431
+ if (clean === path_js_1.PROC_JOBS_PREFIX) {
432
+ subtreeFeeds_add(walk);
704
433
  }
705
434
  else if (feedID !== null && instanceID === null) {
706
435
  if (cache.feed_get(feedID) === undefined)
707
436
  return null;
708
- feedInside(feedID, '', 1);
709
- if (unanswered.length > 0)
437
+ (0, subtree_js_1.subtreeFeed_add)(walk, feedID, '', 1);
438
+ if (walk.unanswered.length > 0)
710
439
  return null;
711
440
  }
712
441
  else if (feedID !== null && instanceID !== null) {
713
442
  if (cache.instance_get(instanceID) === undefined)
714
443
  return null;
715
- jobInside(instanceID, '', 1);
444
+ (0, subtree_js_1.subtreeJobInside_add)(walk, instanceID, '', 1);
716
445
  }
717
446
  else {
718
447
  return null;
719
448
  }
720
- return { entries, unanswered };
449
+ return { entries: walk.entries, unanswered: walk.unanswered };
450
+ }
451
+ /**
452
+ * Refuses a listing of a feed's or a job's own file (`note`, `status`,
453
+ * `log`): it is no folder, and a reader names it from its parent's row.
454
+ *
455
+ * @param clean - The path as asked, for the message.
456
+ * @param instanceID - The job's id, or null for a feed's own file.
457
+ * @param virtualFile - The file's name below the feed or job.
458
+ * @returns Err, with "Not a directory" for a file the folder lists and
459
+ * "No such file or directory" for any other name.
460
+ */
461
+ virtualFileListing_refuse(clean, instanceID, virtualFile) {
462
+ const listed = instanceID === null ? path_js_1.FEED_FILES : path_js_1.INSTANCE_FILES;
463
+ cumin_1.errorStack.stack_push('error', `${clean}: ${listed.has(virtualFile) ? 'Not a directory' : 'No such file or directory'}`);
464
+ return (0, cumin_1.Err)();
721
465
  }
466
+ /**
467
+ * Lists a `/proc/jobs` folder: the feeds, a feed's files and root jobs, a
468
+ * job's files and children; under a job's `data` link, the link target's
469
+ * listing.
470
+ *
471
+ * @param pathStr - Absolute `/proc/jobs/...` path.
472
+ * @param _options - Sort options, passed on to the link target's listing.
473
+ * @param _options.sort - The key the target's listing sorts by.
474
+ * @param _options.reverse - Whether it sorts in reverse.
475
+ * @returns The folder's rows, or Err when it is no folder.
476
+ */
722
477
  async list(pathStr, _options) {
723
- await cacheFor_ensure(pathStr);
478
+ await (0, feedIndex_js_1.cacheFor_ensure)(pathStr);
724
479
  const cache = (0, cumin_1.procCache_get)();
725
480
  const clean = pathStr.replace(/\/$/, '');
726
481
  // /proc/jobs — list all feeds with aggregate status from counters
727
- if (clean === PROC_JOBS_PREFIX) {
728
- await procRoster_syncWithin(exports.ROSTER_LIST_BUDGET_MS);
729
- const items = cache.feedIDs_get().map((feedID) => {
730
- const feed = cache.feed_get(feedID);
731
- const status = feed ? feedStatus_derive(feed) : 'unknown';
732
- return {
733
- name: `feed_${feedID}`,
734
- type: 'job',
735
- size: 0,
736
- owner: '',
737
- date: '',
738
- title: feed?.title ?? `feed_${feedID}`,
739
- status,
740
- };
741
- });
742
- return (0, cumin_1.Ok)(items);
743
- }
744
- const { feedID, instanceID, virtualFile, dataRemainder } = procPath_parse(clean);
482
+ if (clean === path_js_1.PROC_JOBS_PREFIX)
483
+ return jobsRoot_list(cache);
484
+ const { feedID, instanceID, virtualFile, dataRemainder } = (0, path_js_1.procPath_parse)(clean);
745
485
  // Anything under an instance's `data` link belongs to the link's CFS
746
486
  // target: resolve and delegate, so `ls .../data` (and deeper) shows the
747
487
  // target's real contents instead of silently re-listing the instance.
@@ -752,81 +492,14 @@ class ProcVfsProvider {
752
492
  const { vfsDispatcher } = await import('../dispatcher.js');
753
493
  return vfsDispatcher.list(target.value, _options);
754
494
  }
495
+ if (feedID !== null && virtualFile !== null)
496
+ return this.virtualFileListing_refuse(clean, instanceID, virtualFile);
755
497
  // /proc/jobs/feed_N — list root instances + feed virtual files
756
- if (feedID !== null && instanceID === null) {
757
- // A feed the roster lacks is asked of CUBE first: shared to this
758
- // identity, or made public, since the walk, it is adopted here and
759
- // listed as any other; a feed CUBE does not list is an empty listing.
760
- if (cache.feed_get(feedID) === undefined && (await procFeedAbsent_probe(feedID)) === null)
761
- return (0, cumin_1.Ok)([]);
762
- const wasLoaded = cache.topologyLoaded_has(feedID);
763
- await feedInstances_ensureLoaded(feedID);
764
- const feed = cache.feed_get(feedID);
765
- if (!feed)
766
- return (0, cumin_1.Ok)([]);
767
- // The initial load already carried live status and topology; a revisit
768
- // is a delta (feed counters, then only what moved).
769
- if (wasLoaded)
770
- await feedVisit_sync(feedID);
771
- const rootIDs = cache.feedRoots_get(feedID);
772
- const items = [];
773
- items.push({ name: 'status', type: 'file', size: 0, owner: '', date: '' });
774
- items.push({ name: 'title', type: 'file', size: 0, owner: '', date: '' });
775
- // The feed's note: CUBE's one scratchpad per feed, read and written as a file.
776
- items.push({ name: 'note', type: 'file', size: 0, owner: '', date: '' });
777
- for (const rootID of rootIDs) {
778
- const inst = cache.instance_get(rootID);
779
- if (!inst)
780
- continue;
781
- items.push({
782
- name: `${inst.pluginName}_${rootID}`,
783
- type: 'job',
784
- size: 0,
785
- owner: '',
786
- date: '',
787
- status: inst.status ?? 'unknown',
788
- });
789
- }
790
- return (0, cumin_1.Ok)(items);
791
- }
498
+ if (feedID !== null && instanceID === null)
499
+ return feedFolder_list(cache, feedID);
792
500
  // /proc/jobs/feed_N/plugin_ID — list children + virtual files
793
- if (feedID !== null && instanceID !== null) {
794
- const wasLoaded = cache.topologyLoaded_has(feedID);
795
- await feedInstances_ensureLoaded(feedID);
796
- const inst = cache.instance_get(instanceID);
797
- if (!inst)
798
- return (0, cumin_1.Ok)([]);
799
- if (wasLoaded)
800
- await feedVisit_sync(feedID);
801
- const childIDs = cache.children_get(instanceID);
802
- const items = [];
803
- items.push({ name: 'status', type: 'file', size: 0, owner: '', date: '' });
804
- items.push({ name: 'params', type: 'file', size: 0, owner: '', date: '' });
805
- items.push({ name: 'log', type: 'file', size: 0, owner: '', date: '' });
806
- // `data` is structural: list it without fetching the per-instance detail
807
- // endpoint. Its target is resolved only when `cd data` follows the link.
808
- // A known null means CUBE has no output directory, so omit it entirely.
809
- if (inst.outputPath !== null) {
810
- const dataLink = { name: 'data', type: 'link', size: 0, owner: '', date: '' };
811
- if (inst.outputPath)
812
- dataLink.target = inst.outputPath;
813
- items.push(dataLink);
814
- }
815
- for (const childID of childIDs) {
816
- const child = cache.instance_get(childID);
817
- if (!child)
818
- continue;
819
- items.push({
820
- name: `${child.pluginName}_${childID}`,
821
- type: 'job',
822
- size: 0,
823
- owner: '',
824
- date: '',
825
- status: child.status ?? 'unknown',
826
- });
827
- }
828
- return (0, cumin_1.Ok)(items);
829
- }
501
+ if (feedID !== null && instanceID !== null)
502
+ return jobFolder_list(cache, feedID, instanceID);
830
503
  return (0, cumin_1.Ok)([]);
831
504
  }
832
505
  /** @inheritdoc */
@@ -843,9 +516,9 @@ class ProcVfsProvider {
843
516
  * @returns The file's bytes.
844
517
  */
845
518
  async bytes_read(pathStr) {
846
- await cacheFor_ensure(pathStr);
519
+ await (0, feedIndex_js_1.cacheFor_ensure)(pathStr);
847
520
  const clean = pathStr.replace(/\/$/, '');
848
- const { feedID, instanceID, virtualFile, dataRemainder } = procPath_parse(clean);
521
+ const { feedID, instanceID, virtualFile, dataRemainder } = (0, path_js_1.procPath_parse)(clean);
849
522
  if (instanceID !== null && virtualFile === 'data' && dataRemainder !== null && dataRemainder !== '') {
850
523
  const target = await dataTarget_resolve(instanceID, dataRemainder, feedID);
851
524
  if (!target.ok)
@@ -866,82 +539,29 @@ class ProcVfsProvider {
866
539
  return (0, fond_1.vfsOutcome_convertFromResult)(await this.text_read(pathStr), 'ENOENT');
867
540
  }
868
541
  async text_read(pathStr) {
869
- await cacheFor_ensure(pathStr);
542
+ await (0, feedIndex_js_1.cacheFor_ensure)(pathStr);
870
543
  const cache = (0, cumin_1.procCache_get)();
871
544
  const clean = pathStr.replace(/\/$/, '');
872
- const { feedID, instanceID, virtualFile, dataRemainder } = procPath_parse(clean);
545
+ const { feedID, instanceID, virtualFile, dataRemainder } = (0, path_js_1.procPath_parse)(clean);
873
546
  // A file under the `data` link is the store's file, its links followed.
874
547
  if (instanceID !== null && virtualFile === 'data' && dataRemainder !== null && dataRemainder !== '') {
875
- const target = await dataTarget_resolve(instanceID, dataRemainder, feedID);
876
- if (!target.ok)
877
- return (0, cumin_1.Err)();
878
- const { vfsDispatcher } = await import('../dispatcher.js');
879
- return (0, fond_1.vfsOutcome_convertToResult)(await vfsDispatcher.read(target.value), 'read', target.value);
548
+ return dataLinkFile_read(instanceID, dataRemainder, feedID);
880
549
  }
881
550
  // Feed-level virtual files
882
- if (feedID !== null && instanceID === null && virtualFile !== null) {
883
- const feed = cache.feed_get(feedID);
884
- if (!feed)
885
- return (0, cumin_1.Ok)('');
886
- if (virtualFile === 'status')
887
- return (0, cumin_1.Ok)(feedStatus_derive(feed));
888
- if (virtualFile === 'title')
889
- return (0, cumin_1.Ok)(feed.title);
890
- if (virtualFile === 'note') {
891
- const note = await (0, cumin_1.feedNote_get)(feedID);
892
- return note.ok ? (0, cumin_1.Ok)(note.value.content) : (0, cumin_1.Err)();
893
- }
894
- return (0, cumin_1.Err)();
895
- }
896
- // Instance-level virtual files — all live or cached-on-first-read
897
- if (instanceID !== null && virtualFile !== null) {
898
- await feedInstances_ensureLoaded(feedID);
899
- const inst = cache.instance_get(instanceID);
900
- if (!inst)
901
- return (0, cumin_1.Ok)('');
902
- if (virtualFile === 'status') {
903
- // Settled jobs never change — return the cached terminal status, no call.
904
- if ((0, cumin_1.status_isTerminal)(inst.status))
905
- return (0, cumin_1.Ok)(inst.status);
906
- const fresh = await (0, index_js_1.job_statusFetch)(instanceID);
907
- if (fresh.ok)
908
- cache.status_update(instanceID, fresh.value);
909
- return (0, cumin_1.Ok)(fresh.ok ? fresh.value : (inst.status ?? 'unknown'));
910
- }
911
- if (virtualFile === 'params') {
912
- if (inst.params === null) {
913
- // CUBE stores the effective run values in the parameter sub-resource;
914
- // the instance detail payload itself is operational metadata.
915
- const client = await cumin_1.chrisConnection.client_get();
916
- if (client) {
917
- try {
918
- const handle = await (0, cumin_1.pluginInstance_get)(client, instanceID);
919
- if (handle)
920
- cache.params_update(instanceID, await instanceParams_fetch(handle));
921
- }
922
- catch {
923
- // Deliberate absorption, adjudicated 2026-08: parameters are a
924
- // lazy display enrichment; a failed fetch renders as
925
- // "(no parameters)" and the next read retries.
926
- }
927
- }
928
- }
929
- return (0, cumin_1.Ok)(params_render(inst));
930
- }
931
- if (virtualFile === 'log') {
932
- const logResult = await (0, index_js_1.job_logFetch)(instanceID);
933
- return (0, cumin_1.Ok)(logResult.ok ? logResult.value : '(log unavailable)');
934
- }
935
- }
551
+ if (feedID !== null && instanceID === null && virtualFile !== null)
552
+ return feedFile_read(cache, feedID, virtualFile);
553
+ // Instance-level virtual files
554
+ if (instanceID !== null && virtualFile !== null)
555
+ return instanceFile_read(cache, feedID, instanceID, virtualFile);
936
556
  // Anything else is no file /proc reads: a folder (the dispatcher then
937
557
  // says it is a directory) or nothing there.
938
558
  return (0, cumin_1.Err)();
939
559
  }
940
560
  async feedJobs_cancel(pathStr, _options) {
941
- await cache_ensure();
561
+ await (0, feedIndex_js_1.cache_ensure)();
942
562
  const cache = (0, cumin_1.procCache_get)();
943
563
  const clean = pathStr.replace(/\/$/, '');
944
- const { feedID, instanceID } = procPath_parse(clean);
564
+ const { feedID, instanceID } = (0, path_js_1.procPath_parse)(clean);
945
565
  if (feedID !== null && instanceID === null) {
946
566
  const allIDs = feedInstanceIDs_list(feedID, cache);
947
567
  const statusMap = await (0, index_js_1.jobs_statusBatch)(allIDs);
@@ -989,29 +609,38 @@ class ProcVfsProvider {
989
609
  async touch(_pathStr) { return false; }
990
610
  async upload(_localPath, _remotePath) { return false; }
991
611
  /** @inheritdoc */
992
- async write(pathStr, content) {
993
- return (0, fond_1.vfsOutcome_convertFromBoolean)(await this.file_write(pathStr, content), 'EROFS');
612
+ async write(pathStr, content, options = {}) {
613
+ return (0, fond_1.vfsOutcome_convertFromBoolean)(await this.file_write(pathStr, content, options), 'EROFS');
994
614
  }
995
615
  /**
996
616
  * Writes a projected file. One file under /proc takes writes: a feed's
997
617
  * note (`/proc/jobs/feed_N/note`), whose content is replaced whole; its
998
- * title stands. Anything else is refused by name.
618
+ * title stands. Anything else is refused by name. Given the identity it
619
+ * was read under, the write is made on that binding's client and asked of
620
+ * it after the lookups, immediately before CUBE is changed; an identity
621
+ * that is no binding of CUBE's (a read made with no connection) refuses it.
999
622
  *
1000
623
  * @param pathStr - The projected path.
1001
624
  * @param content - The new content, whole.
625
+ * @param options - The identity it was read under, when given.
1002
626
  * @returns True when it was written.
1003
627
  */
1004
- async file_write(pathStr, content) {
1005
- const { feedID, instanceID, virtualFile } = procPath_parse(pathStr.replace(/\/$/, ''));
628
+ async file_write(pathStr, content, options) {
629
+ const { feedID, instanceID, virtualFile } = (0, path_js_1.procPath_parse)(pathStr.replace(/\/$/, ''));
630
+ const bound = options.identity instanceof cumin_1.HolderClient ? options.identity : undefined;
631
+ if (options.identity !== undefined && bound === undefined) {
632
+ cumin_1.errorStack.stack_push('error', `${pathStr}: not saved: there was no connection to CUBE when it was read; nothing was asked`);
633
+ return false;
634
+ }
1006
635
  if (feedID !== null && instanceID === null && virtualFile === 'note') {
1007
- const done = await (0, cumin_1.feedNote_update)(feedID, { content });
636
+ const done = await (0, cumin_1.feedNote_update)(feedID, { content }, bound);
1008
637
  return done.ok;
1009
638
  }
1010
639
  if (feedID !== null && instanceID === null && virtualFile === 'title') {
1011
640
  // The title is the feed's name: its first line, trimmed, renames it,
1012
641
  // and the roster the cache serves says so at once.
1013
642
  const name = (content.split('\n')[0] ?? '').trim();
1014
- const done = await (0, cumin_1.feed_rename)(feedID, name);
643
+ const done = await (0, cumin_1.feed_rename)(feedID, name, bound);
1015
644
  if (done.ok) {
1016
645
  const feed = (0, cumin_1.procCache_get)().feed_get(feedID);
1017
646
  if (feed !== undefined)
@@ -1024,1090 +653,4 @@ class ProcVfsProvider {
1024
653
  }
1025
654
  }
1026
655
  exports.ProcVfsProvider = ProcVfsProvider;
1027
- /**
1028
- * Ensures instance topology is loaded for a feed without clearing existing data.
1029
- * Use this from proc find — it respects already-loaded feeds and the in-flight map.
1030
- * Use procCache_refresh(feedID) only when a forced reload is desired.
1031
- */
1032
- async function procFeed_ensureLoaded(feedID) {
1033
- const cache = (0, cumin_1.procCache_get)();
1034
- if (!cache.feed_get(feedID)) {
1035
- cache.feed_add({
1036
- id: feedID, title: `feed_${feedID}`, ownerUsername: '', public: false, creationDate: '',
1037
- finishedJobs: 0, erroredJobs: 0, startedJobs: 0,
1038
- scheduledJobs: 0, cancelledJobs: 0, createdJobs: 0,
1039
- });
1040
- }
1041
- await feedInstances_ensureLoaded(feedID);
1042
- }
1043
- // ── Public API ─────────────────────────────────────────────────────────────
1044
- /**
1045
- * Refreshes volatile job status for one feed via a single paginated LIST sweep.
1046
- *
1047
- * The plugin-instance list response carries `status`, so one feed-scoped list call
1048
- * updates every node — far cheaper than per-node detail fetches. Terminal statuses
1049
- * are frozen by {@link ProcCache.status_update} and never regress.
1050
- *
1051
- * @param feedID - Feed whose instance statuses should be refreshed.
1052
- */
1053
- /**
1054
- * Ensures a feed's metadata (title + job counters, needed for aggregate status) is cached
1055
- * with real values. No-op when the feed is already present with real metadata; fetches one
1056
- * `getFeeds({id})` only when the feed is missing or a zero-counter placeholder. Does NOT
1057
- * touch instance topology — reuse of the warm cache is the whole point.
1058
- *
1059
- * @param feedID - Feed whose metadata to ensure.
1060
- */
1061
- async function feedMeta_ensure(feedID) {
1062
- const cache = (0, cumin_1.procCache_get)();
1063
- const existing = cache.feed_get(feedID);
1064
- if (existing && existing.creationDate !== '')
1065
- return;
1066
- await procFeed_probe(feedID);
1067
- }
1068
- /**
1069
- * Reads one feed's row, from the owned-and-shared collection first and the
1070
- * public one after.
1071
- *
1072
- * @param client - Connected chrisapi client.
1073
- * @param feedID - The feed to read.
1074
- * @returns The row and its collection, or null when neither lists the feed for this identity.
1075
- */
1076
- async function feedRow_fetch(client, feedID) {
1077
- const own = await (0, cumin_1.feedsPage_get)(client, { id: feedID, limit: 1, offset: 0 });
1078
- const ownRow = own.data[0];
1079
- if (ownRow)
1080
- return { feed: ownRow, collection: 'owned' };
1081
- const pub = (await (0, cumin_1.publicFeedsPage_get)(client, { id: feedID, limit: 1, offset: 0 })) ?? { data: [], totalCount: 0 };
1082
- const pubRow = pub.data[0];
1083
- return pubRow ? { feed: pubRow, collection: 'public' } : null;
1084
- }
1085
- /**
1086
- * Asks CUBE for one feed, live, and adopts it into the roster: the way a
1087
- * feed shared to this identity, or made public, since the roster was
1088
- * walked is seen when it is asked for by name or id. A feed the roster
1089
- * already holds has its row refreshed. The yardsticks move with an
1090
- * adoption, so the next delta does not walk again for what this ask found.
1091
- *
1092
- * @param feedID - The feed to ask for.
1093
- * @returns The feed as the roster now holds it, or null when CUBE lists it
1094
- * in neither collection for this identity — not shared, or shared to a
1095
- * group the identity is not in.
1096
- * @throws {Error} When not connected.
1097
- */
1098
- async function procFeed_probe(feedID) {
1099
- const cache = (0, cumin_1.procCache_get)();
1100
- const client = await cumin_1.chrisConnection.client_get();
1101
- if (!client)
1102
- throw new Error('not connected');
1103
- const row = await feedRow_fetch(client, feedID);
1104
- if (row === null)
1105
- return null;
1106
- const feed = procFeed_create(row.feed);
1107
- const known = cache.feed_get(feedID) !== undefined;
1108
- cache.feed_add(feed);
1109
- if (!known) {
1110
- rosterTotal_bump(row.collection);
1111
- // A public feed is in the public collection whichever one listed it first.
1112
- if (feed.public && row.collection === 'owned')
1113
- rosterTotal_bump('public');
1114
- cache.arrivals_note([feedID]);
1115
- await arrivalsUnseen_mark(cache, [feedID]);
1116
- procTopologyCatchup_enqueue([feedID]);
1117
- }
1118
- return feed;
1119
- }
1120
- /**
1121
- * Marks arrivals shared with this identity as NEW since the last visit: a
1122
- * feed another identity owns and has not made public. A feed this
1123
- * identity made is not news to it, and a public feed anyone on CUBE made
1124
- * is not addressed to it; neither is marked.
1125
- *
1126
- * @param cache - The process cache.
1127
- * @param feedIDs - The feeds that just arrived.
1128
- */
1129
- async function arrivalsUnseen_mark(cache, feedIDs) {
1130
- if (feedIDs.length === 0)
1131
- return;
1132
- // Who this identity is decides what is news; not knowing, nothing is marked.
1133
- let me = null;
1134
- try {
1135
- me = await cumin_1.chrisConnection.user_get();
1136
- }
1137
- catch {
1138
- return;
1139
- }
1140
- if (me === null)
1141
- return;
1142
- cache.unseen_add(feedIDs.filter((feedID) => {
1143
- const feed = cache.feed_get(feedID);
1144
- return feed !== undefined && !feed.public && feed.ownerUsername !== '' && feed.ownerUsername !== me;
1145
- }));
1146
- }
1147
- /**
1148
- * Asks CUBE for a feed the roster lacks, on a visit to its path, and says
1149
- * on the error stack when the ask itself failed; an absent feed is a null.
1150
- *
1151
- * @param feedID - The feed to ask for.
1152
- * @returns The adopted feed, or null.
1153
- */
1154
- async function procFeedAbsent_probe(feedID) {
1155
- try {
1156
- return await procFeed_probe(feedID);
1157
- }
1158
- catch (error) {
1159
- const msg = error instanceof Error ? error.message : String(error);
1160
- cumin_1.errorStack.stack_push('warning', `proc: asking CUBE for feed_${feedID} failed (${msg})`);
1161
- return null;
1162
- }
1163
- }
1164
- /** Moves one collection's yardstick by one adopted feed; an unknown yardstick stays unknown. */
1165
- function rosterTotal_bump(collection) {
1166
- const total = rosterTotals[collection];
1167
- if (total !== null)
1168
- rosterTotals[collection] = total + 1;
1169
- }
1170
- async function feedStatus_refresh(feedID) {
1171
- const cache = (0, cumin_1.procCache_get)();
1172
- const client = await cumin_1.chrisConnection.client_get();
1173
- if (!client)
1174
- return;
1175
- for await (const step of (0, cumin_1.listPages_walk)((offset, limit) => (0, cumin_1.pluginInstancesPage_get)(client, { feed_id: feedID, limit, offset }), { pageSize: PAGE })) {
1176
- for (const inst of step.items) {
1177
- cache.status_update(Number(inst.id), String(inst.status ?? 'unknown'));
1178
- cache.instanceMetrics_set(Number(inst.id), instanceMetrics_extract(inst));
1179
- }
1180
- }
1181
- }
1182
- // ── Visit-driven freshness ─────────────────────────────────────────────────
1183
- /**
1184
- * Whether every cached instance of a feed carries a terminal status. A fully
1185
- * settled feed can only change by having work appended to it, which the
1186
- * feed-row counters reveal.
1187
- *
1188
- * @param cache - The process cache.
1189
- * @param feedID - The feed to inspect.
1190
- * @returns True when no cached instance could still change status.
1191
- */
1192
- function feedCached_isSettled(cache, feedID) {
1193
- for (const id of cache.feedInstanceIDs_get(feedID)) {
1194
- const inst = cache.instance_get(id);
1195
- if (inst === undefined || !(0, cumin_1.status_isTerminal)(inst.status))
1196
- return false;
1197
- }
1198
- return true;
1199
- }
1200
- /**
1201
- * Derives a feed's delta cursor from what the cache already holds: the newest
1202
- * start or end timestamp across its instances.
1203
- *
1204
- * @param cache - The process cache.
1205
- * @param feedID - The feed whose rows to scan.
1206
- * @returns The newest timestamp, or null when no row carried one.
1207
- */
1208
- function feedCursor_derive(cache, feedID) {
1209
- let newest = null;
1210
- for (const id of cache.feedInstanceIDs_get(feedID)) {
1211
- const inst = cache.instance_get(id);
1212
- if (!inst)
1213
- continue;
1214
- newest = isoNewest_pick(newest, inst.startedAt);
1215
- newest = isoNewest_pick(newest, inst.finishedAt);
1216
- }
1217
- return newest;
1218
- }
1219
- /** How many pages the pipeline backfill reads at once. */
1220
- const PIPELINE_BACKFILL_LANES = 6;
1221
- /** The backfill of jobs' pipeline runs, once per session; null until started. */
1222
- let pipelineBackfill = null;
1223
- /** How far the backfill has read: pages known so far, pages read, and whether it is reading. */
1224
- const pipelineBackfillProgress = { pages: 0, read: 0, running: false };
1225
- /**
1226
- * How far the backfill of jobs' pipeline runs has read, for `proc stat`.
1227
- *
1228
- * @returns Pages known so far, pages read, and whether it is reading now.
1229
- */
1230
- function procPipelineBackfill_status() {
1231
- return { ...pipelineBackfillProgress };
1232
- }
1233
- /**
1234
- * Runs tasks a few at a time, in the order given.
1235
- *
1236
- * @param tasks - The work, each started when a lane is free.
1237
- * @param lanes - How many run at once.
1238
- */
1239
- async function tasks_runInLanes(tasks, lanes) {
1240
- let next = 0;
1241
- const lane = async () => {
1242
- for (let at = next++; at < tasks.length; at = next++)
1243
- await tasks[at]();
1244
- };
1245
- await Promise.all(Array.from({ length: Math.min(lanes, tasks.length) }, lane));
1246
- }
1247
- /**
1248
- * Reads every visible job's row once more so the cache learns which
1249
- * pipeline run made each (rows restored from an older checkpoint lack it),
1250
- * behind the prompt: started the first time a `find` needs it, and never
1251
- * again once every job knows. Off the lane; a failure leaves the jobs as
1252
- * they were.
1253
- *
1254
- * Page by page across all lanes, not feed by feed: the unknown jobs sit in
1255
- * a few feeds of tens of thousands of jobs each (on one account, three
1256
- * feeds held all 118k), and a feed read one page after another kept every
1257
- * other lane idle for hours (#1253). Each feed's first page says how long
1258
- * it is; every page after it goes in one queue the lanes share.
1259
- *
1260
- * @returns Nothing; the walk runs on.
1261
- */
1262
- function procPipeline_backfillStart() {
1263
- if (pipelineBackfill !== null)
1264
- return;
1265
- const cache = (0, cumin_1.procCache_get)();
1266
- let unknown = false;
1267
- for (const id of cache.feedIDs_get()) {
1268
- for (const instID of cache.feedInstanceIDs_get(id)) {
1269
- if (cache.instance_get(instID)?.pipelineName === undefined) {
1270
- unknown = true;
1271
- break;
1272
- }
1273
- }
1274
- if (unknown)
1275
- break;
1276
- }
1277
- if (!unknown)
1278
- return;
1279
- pipelineBackfill = (async () => {
1280
- const client = await cumin_1.chrisConnection.client_get();
1281
- if (!client)
1282
- return;
1283
- pipelineBackfillProgress.running = true;
1284
- const feeds = cache.feedIDs_get().filter((id) => cache.feedInstanceIDs_get(id).some((instID) => cache.instance_get(instID)?.pipelineName === undefined));
1285
- const merge = (page) => {
1286
- for (const inst of page.data) {
1287
- const instID = Number(inst.id);
1288
- if (cache.instance_get(instID) !== undefined)
1289
- cache.instanceMetrics_set(instID, instanceMetrics_extract(inst));
1290
- }
1291
- pipelineBackfillProgress.read += 1;
1292
- };
1293
- const page_read = async (feedID, offset) => await (0, cumin_1.pluginInstancesPage_get)(client, { feed_id: feedID, limit: PAGE, offset });
1294
- const unknownIn = (feedID) => cache.feedInstanceIDs_get(feedID)
1295
- .filter((instID) => cache.instance_get(instID)?.pipelineName === undefined);
1296
- // Pages from `from` to the feed's end, queued for the lanes.
1297
- const pages_queue = async (lists) => {
1298
- const rest = [];
1299
- for (const { feedID, from, total } of lists) {
1300
- for (let offset = from; offset < total; offset += PAGE)
1301
- rest.push({ feedID, offset });
1302
- }
1303
- pipelineBackfillProgress.pages += rest.length;
1304
- await tasks_runInLanes(rest.map(({ feedID, offset }) => async () => {
1305
- merge(await page_read(feedID, offset));
1306
- }), PIPELINE_BACKFILL_LANES);
1307
- };
1308
- pipelineBackfillProgress.pages = feeds.length;
1309
- const lists = [];
1310
- await tasks_runInLanes(feeds.map((feedID) => async () => {
1311
- const first = await page_read(feedID, 0);
1312
- merge(first);
1313
- const total = first.totalCount ?? first.data.length;
1314
- // CUBE lists a feed newest first, and the jobs an older checkpoint
1315
- // lacks are its older ones: an earlier pass learned the newest, so a
1316
- // pass after a restart starts where the unknown ones begin rather
1317
- // than reading the known head again. One page before it, in case the
1318
- // count drifted; a feed not listed newest first is read whole.
1319
- const ids = first.data.map((row) => Number(row.id));
1320
- const newestFirst = ids.every((id, at) => at === 0 || id < ids[at - 1]);
1321
- const unknown = unknownIn(feedID);
1322
- const newestUnknown = unknown.length === 0 ? 0 : Math.max(...unknown);
1323
- const knownAbove = cache.feedInstanceIDs_get(feedID).filter((instID) => instID > newestUnknown).length;
1324
- const from = newestFirst ? Math.max(PAGE, Math.floor(knownAbove / PAGE) * PAGE - PAGE) : PAGE;
1325
- lists.push({ feedID, from, total });
1326
- }), PIPELINE_BACKFILL_LANES);
1327
- await pages_queue(lists);
1328
- // What the skip passed over and should not have: read those feeds whole.
1329
- const missed = lists
1330
- .filter(({ feedID, from }) => from > PAGE && unknownIn(feedID).length > 0)
1331
- .map(({ feedID, from }) => ({ feedID, from: PAGE, total: from }));
1332
- if (missed.length > 0)
1333
- await pages_queue(missed);
1334
- })().catch((error) => {
1335
- const msg = error instanceof Error ? error.message : String(error);
1336
- cumin_1.errorStack.stack_push('warning', `proc: reading jobs' pipeline runs failed (${msg})`);
1337
- pipelineBackfill = null;
1338
- }).finally(() => {
1339
- pipelineBackfillProgress.running = false;
1340
- });
1341
- }
1342
- /**
1343
- * Walks one filtered plugin-instance listing for a feed, merging every row.
1344
- *
1345
- * @param cache - The process cache.
1346
- * @param client - Connected chrisapi client.
1347
- * @param params - CUBE filter params beyond feed_id/limit/offset.
1348
- * @param feedID - The feed being walked.
1349
- * @param cursor - The cursor to advance with the rows' timestamps.
1350
- * @returns The advanced cursor.
1351
- */
1352
- async function feedRows_merge(cache, client, params, feedID, cursor) {
1353
- let newest = cursor;
1354
- for await (const step of (0, cumin_1.listPages_walk)((offset, limit) => (0, cumin_1.pluginInstancesPage_get)(client, { ...params, feed_id: feedID, limit, offset }), { pageSize: PAGE })) {
1355
- for (const inst of step.items) {
1356
- procInstanceRow_merge(cache, inst);
1357
- newest = isoNewest_pick(newest, inst.start_date);
1358
- newest = isoNewest_pick(newest, inst.end_date);
1359
- }
1360
- }
1361
- return newest;
1362
- }
1363
- /**
1364
- * Brings one already-loaded feed up to date with CUBE at the cost the change
1365
- * warrants: a settled feed pays one feed-row fetch per {@link FEED_RECHECK_MS};
1366
- * a feed with running work pays that fetch on every visit; and only when the
1367
- * counters moved (or work is running) does the visit walk the delta —
1368
- * `min_end_date` from the cursor, which yields nodes created OR finished since
1369
- * (CUBE stamps end_date at creation and again at completion) — followed by an
1370
- * `active=true` sweep for the nodes still in flight.
1371
- *
1372
- * Concurrent visits share one in-flight sync, and visits within
1373
- * {@link FEED_VISIT_COALESCE_MS} of each other share the first one's result
1374
- * (a pane tick and an `ls` in the same second are one visit). Failures are
1375
- * surfaced as warnings and never fail the visit: the cache stays as it was.
1376
- *
1377
- * @param feedID - A feed whose topology is already loaded.
1378
- * @param force - Ignore the settled-feed throttle (an explicit refresh).
1379
- * @returns True when the cache reflects CUBE as of this visit (including a
1380
- * visit that needed no wire), false when the sync failed.
1381
- */
1382
- async function feedVisit_sync(feedID, force = false) {
1383
- const inflight = feedVisitInflight.get(feedID);
1384
- if (inflight)
1385
- return inflight;
1386
- const run = feedVisit_run(feedID, force)
1387
- .then(() => true)
1388
- .catch((error) => {
1389
- const msg = error instanceof Error ? error.message : String(error);
1390
- cumin_1.errorStack.stack_push('warning', `proc feed_${feedID}: live sync failed (${msg}); showing cached state`);
1391
- return false;
1392
- })
1393
- .finally(() => { feedVisitInflight.delete(feedID); });
1394
- feedVisitInflight.set(feedID, run);
1395
- return run;
1396
- }
1397
- async function feedVisit_run(feedID, force) {
1398
- const cache = (0, cumin_1.procCache_get)();
1399
- const feed = cache.feed_get(feedID);
1400
- if (!feed || !cache.topologyLoaded_has(feedID))
1401
- return;
1402
- const visit = feedVisits.get(feedID);
1403
- const settled = feedCached_isSettled(cache, feedID) && !(0, cumin_1.feed_isActive)(feed);
1404
- const now = Date.now();
1405
- if (!force && visit && now - visit.checkedAt < exports.FEED_VISIT_COALESCE_MS)
1406
- return;
1407
- if (!force && settled && visit && now - visit.checkedAt < exports.FEED_RECHECK_MS)
1408
- return;
1409
- const client = await cumin_1.chrisConnection.client_get();
1410
- if (!client)
1411
- return;
1412
- const page = await (0, cumin_1.feedsPage_get)(client, { id: feedID, limit: 1, offset: 0 });
1413
- const row = page.data[0];
1414
- let moved = !settled || force;
1415
- if (row) {
1416
- const fresh = procFeed_create(row);
1417
- if ((0, cumin_1.feedTopology_changed)(feed, fresh))
1418
- moved = true;
1419
- cache.feed_add(fresh);
1420
- }
1421
- if (!moved) {
1422
- feedVisits.set(feedID, { checkedAt: now, cursor: visit?.cursor ?? null });
1423
- return;
1424
- }
1425
- let cursor = visit?.cursor ?? feedCursor_derive(cache, feedID);
1426
- const since = cursor ? { min_end_date: cursor } : {};
1427
- cursor = await feedRows_merge(cache, client, since, feedID, cursor);
1428
- cursor = await feedRows_merge(cache, client, { active: true }, feedID, cursor);
1429
- feedVisits.set(feedID, { checkedAt: Date.now(), cursor });
1430
- }
1431
- /**
1432
- * Brings the feed roster up to date on a `/proc/jobs` visit. While the roster
1433
- * is younger than {@link ROSTER_FULL_WALK_MS} this is a delta: feeds whose id
1434
- * exceeds the highest known one, from both the owned/shared and the public
1435
- * collections (one call each when nothing is new). Once older, it is the full
1436
- * index walk, which is the only way a feed shared later, or one deleted, is
1437
- * seen. A roster still owned by warmup (not yet `current`) is left alone.
1438
- *
1439
- * @param force - Walk the whole index regardless of age.
1440
- * @returns Feed IDs the sync brought in or found changed: after a full
1441
- * walk, the reconciliation targets (new, changed, or active feeds); after
1442
- * a delta, the newly seen feeds. Empty when nothing moved or the roster
1443
- * was left alone.
1444
- */
1445
- async function procRoster_sync(force = false) {
1446
- if (rosterSyncInflight) {
1447
- // A forced walk asked during a delta is not that delta: it waits for it,
1448
- // then walks (the operator's REFRESH would otherwise see nothing new).
1449
- if (!force || rosterSyncInflightFull)
1450
- return rosterSyncInflight;
1451
- await rosterSyncInflight.catch(() => []);
1452
- return procRoster_sync(true);
1453
- }
1454
- const cache = (0, cumin_1.procCache_get)();
1455
- const kind = procRosterSync_kind(cache, force);
1456
- if (rosterDelta_throttled(kind, force))
1457
- return [];
1458
- if (kind !== null)
1459
- cache.rosterSync_progress(kind);
1460
- const run = procRoster_run(force)
1461
- .catch((error) => {
1462
- const msg = error instanceof Error ? error.message : String(error);
1463
- cumin_1.errorStack.stack_push('warning', `proc roster: live sync failed (${msg}); showing cached roster`);
1464
- return [];
1465
- })
1466
- .finally(() => { rosterSyncInflight = null; rosterSyncInflightFull = false; rosterSyncedAt = Date.now(); cache.rosterSync_clear(); });
1467
- rosterSyncInflight = run;
1468
- rosterSyncInflightFull = kind === 'full';
1469
- return run;
1470
- }
1471
- /**
1472
- * Whether an unforced delta comes too soon after the last sync to be worth
1473
- * a word to CUBE: every `/proc/jobs` listing (and every `cd` into a feed,
1474
- * which lists it) would otherwise ask, and the surfaces re-ask on a timer.
1475
- * REFRESH forces one; a full walk is never throttled.
1476
- *
1477
- * @param kind - The sync that would run.
1478
- * @param force - Whether the operator asked for it.
1479
- * @returns True when it is skipped.
1480
- */
1481
- function rosterDelta_throttled(kind, force) {
1482
- if (force || kind !== 'delta' || rosterSyncedAt === 0)
1483
- return false;
1484
- const since = Date.now() - rosterSyncedAt;
1485
- return since >= 0 && since < exports.ROSTER_DELTA_MIN_MS;
1486
- }
1487
- /** Which roster walk a sync would run now, or null when the cache is not in service. */
1488
- function procRosterSync_kind(cache, force) {
1489
- if (!cache.built || cache.lifecycle_get().state !== 'current')
1490
- return null;
1491
- return force || Date.now() - rosterWalkedAt >= exports.ROSTER_FULL_WALK_MS ? 'full' : 'delta';
1492
- }
1493
- /**
1494
- * Waits for the roster's sync at most `budgetMs`: a quick CUBE lands what it
1495
- * found in the answer (a share is seen on the next look), a slow one is left
1496
- * to land behind it, announced as arrivals, and the listing answers from the
1497
- * cache. A listing never waits on CUBE longer than the budget.
1498
- *
1499
- * @param budgetMs - How long the caller may wait.
1500
- */
1501
- async function procRoster_syncWithin(budgetMs) {
1502
- let timer = null;
1503
- const budget = new Promise((resolve) => {
1504
- timer = setTimeout(resolve, budgetMs);
1505
- timer.unref?.();
1506
- });
1507
- try {
1508
- await Promise.race([procRoster_sync().then(() => undefined), budget]);
1509
- }
1510
- finally {
1511
- if (timer !== null)
1512
- clearTimeout(timer);
1513
- }
1514
- }
1515
- /**
1516
- * Starts the roster's sync and returns at once. The roster is index
1517
- * movement: a command that lists it answers from the cache now, the walk
1518
- * runs off the session's lane (deduped with any sync in flight), the
1519
- * prompt names it while it runs, and arrivals land as they do today.
1520
- *
1521
- * @param force - Whether to run the full walk regardless of the timer.
1522
- * @returns The walk started or already in flight, or `none` when the cache is not in service.
1523
- */
1524
- function procRoster_syncStart(force = false) {
1525
- const cache = (0, cumin_1.procCache_get)();
1526
- const inflight = cache.rosterSync_get();
1527
- if (inflight === 'delta' && force) {
1528
- // The operator's REFRESH during a delta: the whole walk follows it.
1529
- void procRoster_sync(true);
1530
- return 'full';
1531
- }
1532
- if (inflight !== null)
1533
- return inflight;
1534
- const kind = procRosterSync_kind(cache, force);
1535
- if (kind === null || rosterDelta_throttled(kind, force))
1536
- return 'none';
1537
- void procRoster_sync(force);
1538
- return kind;
1539
- }
1540
- async function procRoster_run(force) {
1541
- const cache = (0, cumin_1.procCache_get)();
1542
- if (!cache.built || cache.lifecycle_get().state !== 'current')
1543
- return [];
1544
- if (force || Date.now() - rosterWalkedAt >= exports.ROSTER_FULL_WALK_MS) {
1545
- return procCache_build();
1546
- }
1547
- const client = await cumin_1.chrisConnection.client_get();
1548
- if (!client)
1549
- return [];
1550
- return procRosterDelta_run(cache, client);
1551
- }
1552
- /**
1553
- * One collection's newest page, read unfiltered. CUBE orders feeds newest
1554
- * first, so the page carries every feed newer than the roster's highest id
1555
- * unless more than a page arrived, and its total is the collection's whole
1556
- * count — the yardstick a share, an unshare or a deletion moves.
1557
- *
1558
- * @param page_fetch - Fetches one page of the collection.
1559
- * @param maxKnown - The roster's highest feed id (0 for an empty roster).
1560
- * @returns The newer feeds, the total, and whether the page overflowed.
1561
- */
1562
- async function rosterCollection_peek(page_fetch, maxKnown) {
1563
- const page = await page_fetch({ limit: exports.ROSTER_DELTA_PAGE, offset: 0 });
1564
- const rows = page.data.map(procFeed_create);
1565
- const newer = rows.filter((feed) => feed.id > maxKnown);
1566
- const overflow = rows.length > 0 && newer.length === rows.length
1567
- && page.totalCount !== null && page.totalCount > rows.length;
1568
- return { newer, total: page.totalCount, overflow };
1569
- }
1570
- /**
1571
- * Whether a collection's total moved by more than its newer rows account
1572
- * for: a feed arrived or left under the newest page, which only the full
1573
- * walk can place. An overflowed page, or a collection without a yardstick,
1574
- * cannot say.
1575
- *
1576
- * @param collection - The collection peeked.
1577
- * @param peek - What its newest page read.
1578
- * @returns True when the total moved.
1579
- */
1580
- function rosterTotal_moved(collection, peek) {
1581
- const expected = rosterTotals[collection];
1582
- if (expected === null || peek.total === null || peek.overflow)
1583
- return false;
1584
- return peek.total !== expected + peek.newer.length;
1585
- }
1586
- /**
1587
- * Brings the roster up to date without walking the whole index: each
1588
- * collection's newest page is read, its feeds newer than the roster are
1589
- * adopted, and its total is held against the last walk's. A total that
1590
- * moved otherwise — a feed shared to this identity, one unshared, one
1591
- * deleted — promotes the visit to the full walk, which places it. A page
1592
- * that overflowed is followed by the walk of everything newer than the
1593
- * roster, by id.
1594
- *
1595
- * @param cache - The process cache.
1596
- * @param client - Connected chrisapi client.
1597
- * @returns The feed IDs added; after a promotion, the full walk's reconciliation targets.
1598
- */
1599
- async function procRosterDelta_run(cache, client) {
1600
- const knownIDs = cache.feedIDs_get();
1601
- const maxKnown = knownIDs.length > 0 ? Math.max(...knownIDs) : 0;
1602
- const ownedFetch = (params) => (0, cumin_1.feedsPage_get)(client, params);
1603
- const publicFetch = async (params) => (await (0, cumin_1.publicFeedsPage_get)(client, params)) ?? { data: [], totalCount: 0 };
1604
- const owned = await rosterCollection_peek(ownedFetch, maxKnown);
1605
- const pub = await rosterCollection_peek(publicFetch, maxKnown);
1606
- if (rosterTotal_moved('owned', owned) || rosterTotal_moved('public', pub)) {
1607
- cache.rosterSync_progress('full');
1608
- return procCache_build();
1609
- }
1610
- const fresh = new Map();
1611
- for (const feed of [...owned.newer, ...pub.newer])
1612
- fresh.set(feed.id, feed);
1613
- if (owned.overflow || pub.overflow) {
1614
- const minID = maxKnown + 1;
1615
- await procFeeds_index((params) => ownedFetch({ ...params, min_id: minID }), fresh);
1616
- await procFeeds_index((params) => publicFetch({ ...params, min_id: minID }), fresh);
1617
- }
1618
- rosterTotals = { owned: owned.total, public: pub.total };
1619
- for (const feed of fresh.values())
1620
- cache.feed_add(feed);
1621
- cache.arrivals_note(Array.from(fresh.keys()));
1622
- await arrivalsUnseen_mark(cache, Array.from(fresh.keys()));
1623
- procTopologyCatchup_roster(cache);
1624
- return Array.from(fresh.keys());
1625
- }
1626
- /**
1627
- * Brings a restored roster into service at boot without walking the whole
1628
- * feed index: feeds newer than the highest restored id are added (one call
1629
- * per collection when nothing is new), and the cache is marked built so
1630
- * visits can begin. Counters of restored feeds stay as checkpointed until a
1631
- * visit or the full walk the host runs in the background afterwards.
1632
- *
1633
- * @returns The feed IDs added.
1634
- * @throws {Error} When not connected or the roster is empty (nothing was
1635
- * restored) — the host then falls back to the full index build.
1636
- */
1637
- async function procRoster_bootSync() {
1638
- const cache = (0, cumin_1.procCache_get)();
1639
- if (cache.feedIDs_get().length === 0)
1640
- throw new Error('no restored roster to bring into service');
1641
- const client = await cumin_1.chrisConnection.client_get();
1642
- if (!client)
1643
- throw new Error('not connected');
1644
- const added = await procRosterDelta_run(cache, client);
1645
- cache.built_set();
1646
- return added;
1647
- }
1648
- // ── Topology catch-up ──────────────────────────────────────────────────────
1649
- //
1650
- // A feed the roster gains after the sweep — found by the watcher's delta,
1651
- // shared to this identity, or restored from a roster whose shard was never
1652
- // written — has a row but no jobs, so its SIZE and TIME read as dashes
1653
- // until someone opens it (the only thing that walked a feed's jobs). Every
1654
- // roster sync now queues the feeds it leaves without topology, and one
1655
- // detached walk at a time lands them: a feed-scoped page or two each, off
1656
- // the lane, annunciated by the load register like a visit's walk.
1657
- /** Feeds waiting for their topology walk, in the order the roster found them. */
1658
- const topologyCatchupQueue = [];
1659
- /** The feeds queued, for a cheap membership test. */
1660
- const topologyCatchupQueued = new Set();
1661
- /** The runner draining the queue, when one is. */
1662
- let topologyCatchupRun = null;
1663
- /**
1664
- * Queues roster feeds whose topology the cache lacks, and starts the walk
1665
- * when none is running. Nothing is queued while the global sweep is the
1666
- * one bringing topology in (it covers every feed), nor for a feed already
1667
- * loaded, loading or queued.
1668
- *
1669
- * @param feedIDs - Candidate feed IDs (a sync's arrivals, or the roster).
1670
- * @returns How many feeds this call queued.
1671
- */
1672
- function procTopologyCatchup_enqueue(feedIDs) {
1673
- const cache = (0, cumin_1.procCache_get)();
1674
- if (!cache.warmupComplete || procTopologyPromise !== null)
1675
- return 0;
1676
- let queued = 0;
1677
- for (const feedID of feedIDs) {
1678
- if (!cache.feed_get(feedID) || cache.topologyLoaded_has(feedID))
1679
- continue;
1680
- if (cache.loading_get(feedID) !== undefined || topologyCatchupQueued.has(feedID))
1681
- continue;
1682
- topologyCatchupQueue.push(feedID);
1683
- topologyCatchupQueued.add(feedID);
1684
- queued++;
1685
- }
1686
- if (queued > 0 && topologyCatchupRun === null) {
1687
- topologyCatchupRun = procTopologyCatchup_run().finally(() => { topologyCatchupRun = null; });
1688
- }
1689
- return queued;
1690
- }
1691
- /** Walks the queued feeds one at a time until the queue is empty. */
1692
- async function procTopologyCatchup_run() {
1693
- const cache = (0, cumin_1.procCache_get)();
1694
- for (;;) {
1695
- const feedID = topologyCatchupQueue.shift();
1696
- if (feedID === undefined)
1697
- return;
1698
- topologyCatchupQueued.delete(feedID);
1699
- if (!cache.feed_get(feedID) || cache.topologyLoaded_has(feedID))
1700
- continue;
1701
- // A sweep that started meanwhile covers the rest.
1702
- if (procTopologyPromise !== null) {
1703
- procTopologyCatchup_reset();
1704
- return;
1705
- }
1706
- feedInstances_ensureStarted(feedID);
1707
- const walk = cache.loading_get(feedID);
1708
- if (walk)
1709
- await walk.catch(() => { });
1710
- }
1711
- }
1712
- /**
1713
- * How many feeds still wait for their topology, and whether a walk runs.
1714
- *
1715
- * @returns The catch-up's state.
1716
- */
1717
- function procTopologyCatchup_status() {
1718
- return { queued: topologyCatchupQueue.length, running: topologyCatchupRun !== null };
1719
- }
1720
- /**
1721
- * Waits for the catch-up to drain (tests, and a readout that wants whole numbers).
1722
- *
1723
- * @returns Resolves when no walk is queued or running.
1724
- */
1725
- async function procTopologyCatchup_await() {
1726
- while (topologyCatchupRun !== null)
1727
- await topologyCatchupRun;
1728
- }
1729
- /** Forgets the queue (a sweep took over, or a cache cleared underneath us). */
1730
- function procTopologyCatchup_reset() {
1731
- topologyCatchupQueue.length = 0;
1732
- topologyCatchupQueued.clear();
1733
- }
1734
- /**
1735
- * Queues every roster feed without topology — what a roster sync leaves
1736
- * behind when the sweep is already over.
1737
- *
1738
- * @param cache - The process cache.
1739
- * @returns How many feeds were queued.
1740
- */
1741
- function procTopologyCatchup_roster(cache) {
1742
- return procTopologyCatchup_enqueue(cache.feedIDs_get());
1743
- }
1744
- /**
1745
- * What a jump target names: a feed only (`feed_4389`), a node only
1746
- * (`pl-dicom_repack_639204`, or `_639204`), or a bare number that may be
1747
- * either. Null for anything else.
1748
- *
1749
- * @param target - What the operator typed.
1750
- * @returns The id and which kinds it may name, or null.
1751
- */
1752
- function procTarget_parse(target) {
1753
- const text = target.trim();
1754
- const feed = /^feed_(\d+)$/.exec(text);
1755
- if (feed !== null)
1756
- return { id: Number(feed[1]), feed: true, node: false };
1757
- const node = /^[\w.-]*_(\d+)$/.exec(text);
1758
- if (node !== null)
1759
- return { id: Number(node[1]), feed: false, node: true };
1760
- if (/^\d+$/.test(text))
1761
- return { id: Number(text), feed: true, node: true };
1762
- return null;
1763
- }
1764
- /**
1765
- * Finds where a jump target lands, asking CUBE live for what the roster
1766
- * and the index lack: a feed shared since the roster was walked, or a node
1767
- * in one. A node's feed is adopted into the roster on the way, so the
1768
- * place the answer names can be entered at once. A bare number that is
1769
- * both a feed and a node answers both; the caller asks which.
1770
- *
1771
- * @param target - A feed id, a node id, or a `feed_N` / `<plugin>_N` name.
1772
- * @returns Every place it names that this identity can see; empty for none.
1773
- */
1774
- async function procTarget_locate(target) {
1775
- const parsed = procTarget_parse(target);
1776
- if (parsed === null)
1777
- return [];
1778
- const cache = (0, cumin_1.procCache_get)();
1779
- const found = [];
1780
- if (parsed.feed) {
1781
- const feed = cache.feed_get(parsed.id) ?? (await procFeedAbsent_probe(parsed.id));
1782
- if (feed !== null)
1783
- found.push({ kind: 'feed', feedId: feed.id, name: `feed_${feed.id}`, title: feed.title });
1784
- }
1785
- if (parsed.node) {
1786
- const node = await procNode_find(parsed.id);
1787
- if (node !== null) {
1788
- const feed = cache.feed_get(node.feedId) ?? (await procFeedAbsent_probe(node.feedId));
1789
- if (feed !== null) {
1790
- found.push({ kind: 'node', feedId: node.feedId, nodeId: parsed.id, name: `${node.pluginName}_${parsed.id}`, title: feed.title });
1791
- }
1792
- }
1793
- }
1794
- return found;
1795
- }
1796
- /**
1797
- * A node's feed and plugin, from the index or, when the index lacks it,
1798
- * from CUBE.
1799
- *
1800
- * @param nodeId - The plugin instance id.
1801
- * @returns Its feed and plugin name, or null when CUBE shows no such node to this identity.
1802
- */
1803
- async function procNode_find(nodeId) {
1804
- const known = (0, cumin_1.procCache_get)().instance_get(nodeId);
1805
- if (known !== undefined)
1806
- return { feedId: known.feedID, pluginName: known.pluginName };
1807
- const client = await cumin_1.chrisConnection.client_get();
1808
- if (!client)
1809
- return null;
1810
- try {
1811
- const handle = await (0, cumin_1.pluginInstance_get)(client, nodeId);
1812
- const feedId = Number(handle?.data?.feed_id);
1813
- const pluginName = String(handle?.data?.plugin_name ?? '');
1814
- return Number.isFinite(feedId) && feedId > 0 && pluginName !== '' ? { feedId, pluginName } : null;
1815
- }
1816
- catch {
1817
- return null;
1818
- }
1819
- }
1820
- /**
1821
- * Forgets all visit bookkeeping (tests, and a cache cleared underneath us).
1822
- */
1823
- function procVisitState_reset() {
1824
- feedVisits.clear();
1825
- feedVisitInflight.clear();
1826
- rosterWalkedAt = 0;
1827
- rosterSyncInflight = null;
1828
- rosterSyncInflightFull = false;
1829
- rosterSyncedAt = 0;
1830
- pipelineBackfill = null;
1831
- Object.assign(pipelineBackfillProgress, { pages: 0, read: 0, running: false });
1832
- rosterTotals = { owned: null, public: null };
1833
- procTopologyCatchup_reset();
1834
- }
1835
- /**
1836
- * Background topology warm-up — single paginated sweep of all plugin instances
1837
- * across all feeds. Replaces the per-feed fan-out that was O(feeds) round trips.
1838
- *
1839
- * Scoped per-feed loads may run concurrently for navigation; the completed
1840
- * global sweep reconciles the cache to its authoritative instance set.
1841
- *
1842
- * @param state - Private pagination and reconciliation state for this sweep.
1843
- * @returns A promise that settles when the complete topology has been reconciled.
1844
- */
1845
- async function procTopology_run(state) {
1846
- await cache_ensure();
1847
- const cache = (0, cumin_1.procCache_get)();
1848
- cache.lifecycle_set('reconciling');
1849
- if (state.total > 0) {
1850
- cache.warmup_progress(state.fetchedInstanceIDs.size, state.total);
1851
- }
1852
- const client = await cumin_1.chrisConnection.client_get();
1853
- if (!client)
1854
- throw new Error('not connected');
1855
- // state.total of 0 encodes "unknown" in the persisted sweep state; the
1856
- // walker's null encoding is translated at this boundary so a resumed
1857
- // sweep keeps its latched total and offset.
1858
- for await (const step of (0, cumin_1.listPages_walk)((offset, limit) => (0, cumin_1.pluginInstancesPage_get)(client, { limit, offset }), { pageSize: PAGE, startOffset: state.offset, startTotal: state.total > 0 ? state.total : null })) {
1859
- if (state.total === 0 && step.total !== null) {
1860
- state.total = step.total;
1861
- if (state.total > 0)
1862
- cache.warmup_progress(0, state.total);
1863
- }
1864
- for (const inst of step.items) {
1865
- const instanceID = Number(inst.id);
1866
- const feedID = Number(inst.feed_id);
1867
- state.fetchedInstanceIDs.add(instanceID);
1868
- if (!cache.feed_get(feedID))
1869
- continue;
1870
- cache.instance_add(procInstance_buildFromRow(inst));
1871
- state.seenInstanceIDs.add(instanceID);
1872
- state.seenFeedIDs.add(feedID);
1873
- }
1874
- state.offset = step.offset + step.items.length;
1875
- if (state.total > 0)
1876
- cache.warmup_progress(state.fetchedInstanceIDs.size, state.total);
1877
- }
1878
- cache.topology_reconcile(state.seenInstanceIDs);
1879
- for (const feedID of state.seenFeedIDs)
1880
- cache.topologyLoaded_mark(feedID);
1881
- if (state.total === 0) {
1882
- cache.warmup_progress(state.fetchedInstanceIDs.size, state.fetchedInstanceIDs.size);
1883
- }
1884
- cache.warmup_complete();
1885
- }
1886
- /**
1887
- * Creates an empty continuation for a fresh global topology sweep.
1888
- *
1889
- * @returns New private pagination and reconciliation state.
1890
- */
1891
- function procTopologyState_create() {
1892
- return {
1893
- offset: 0,
1894
- total: 0,
1895
- fetchedInstanceIDs: new Set(),
1896
- seenInstanceIDs: new Set(),
1897
- seenFeedIDs: new Set(),
1898
- };
1899
- }
1900
- /**
1901
- * Starts one topology sweep from the supplied private continuation state.
1902
- *
1903
- * @param state - Private pagination and reconciliation state to run or resume.
1904
- * @returns The in-flight topology sweep promise.
1905
- */
1906
- function procTopology_start(state) {
1907
- procTopologyFailure = undefined;
1908
- procTopologyResumeState = state;
1909
- procTopologyScopedResumeFeedIDs = null;
1910
- const sweep = procTopology_run(state);
1911
- procTopologyPromise = sweep;
1912
- sweep.then(() => {
1913
- if (procTopologyPromise !== sweep)
1914
- return;
1915
- procTopologyPromise = null;
1916
- if ((0, cumin_1.procCache_get)().warmupComplete) {
1917
- procTopologyFailure = undefined;
1918
- procTopologyResumeState = null;
1919
- procSettlementTails_run();
1920
- }
1921
- else {
1922
- procTopologyFailure = 'the topology sweep ended before the index completed';
1923
- }
1924
- }, (error) => {
1925
- if (procTopologyPromise !== sweep)
1926
- return;
1927
- procTopologyPromise = null;
1928
- (0, cumin_1.procCache_get)().warmup_abort();
1929
- procTopologyFailure = error instanceof Error ? error.message : String(error);
1930
- });
1931
- return sweep;
1932
- }
1933
- /** The data-facts reader, with this provider's output paths. */
1934
- function dataFactsIO_get() {
1935
- return (0, feedData_js_1.dataFactsIO_build)(instanceOutputPath_ensure);
1936
- }
1937
- /**
1938
- * Reads the data facts of every feed that has none yet (see
1939
- * `dag/feedData.ts`): the index's tail after a sweep, and the one a daemon
1940
- * that restored its checkpoint starts itself, since no sweep runs then.
1941
- *
1942
- * @returns How many feeds were read; zero when a sweep is already under way.
1943
- */
1944
- async function procDataFacts_start() {
1945
- try {
1946
- return await (0, feedData_js_1.procDataFacts_sweep)(dataFactsIO_get());
1947
- }
1948
- catch {
1949
- return 0;
1950
- }
1951
- }
1952
- /**
1953
- * Kicks the quiet settlement tails once the topology index is complete:
1954
- * every unresolved `ts` join resolves in the background (so first diagrams
1955
- * are pure cache, and the checkpoint persists them), and the pipeline
1956
- * package store sweeps unseen registered pipelines. Both are best-effort —
1957
- * a failure leaves the lazy paths intact.
1958
- */
1959
- function procSettlementTails_run() {
1960
- void (0, feedJoins_js_1.procJoins_sweep)().catch(() => { });
1961
- void procDataFacts_start();
1962
- void (0, packages_js_1.pipelinePackages_sweep)().catch(() => { });
1963
- }
1964
- /**
1965
- * Runs a feed-scoped topology reconciliation selected after checkpoint restore.
1966
- *
1967
- * @param feedIDs - Canonical feed IDs whose topology needs a fresh load.
1968
- * @returns A promise that settles after the supplied feeds are reconciled.
1969
- */
1970
- async function procTopologyScoped_run(feedIDs) {
1971
- const cache = (0, cumin_1.procCache_get)();
1972
- cache.lifecycle_set('reconciling');
1973
- for (const feedID of feedIDs)
1974
- await procCache_refresh(feedID);
1975
- cache.warmup_complete();
1976
- procSettlementTails_run();
1977
- }
1978
- /**
1979
- * Starts one scoped reconciliation and retains its targets for `proc retry`.
1980
- *
1981
- * @param feedIDs - Canonical feed IDs selected by the fresh feed index.
1982
- * @returns The in-flight scoped reconciliation promise.
1983
- */
1984
- function procTopologyScoped_start(feedIDs) {
1985
- const targets = [...feedIDs];
1986
- procTopologyFailure = undefined;
1987
- procTopologyResumeState = null;
1988
- procTopologyScopedResumeFeedIDs = targets;
1989
- const sweep = procTopologyScoped_run(targets);
1990
- procTopologyPromise = sweep;
1991
- sweep.then(() => {
1992
- if (procTopologyPromise !== sweep)
1993
- return;
1994
- procTopologyPromise = null;
1995
- if ((0, cumin_1.procCache_get)().warmupComplete) {
1996
- procTopologyFailure = undefined;
1997
- procTopologyScopedResumeFeedIDs = null;
1998
- }
1999
- else {
2000
- procTopologyFailure = 'the scoped topology reconciliation ended before the index completed';
2001
- }
2002
- }, (error) => {
2003
- if (procTopologyPromise !== sweep)
2004
- return;
2005
- procTopologyPromise = null;
2006
- (0, cumin_1.procCache_get)().warmup_abort();
2007
- procTopologyFailure = error instanceof Error ? error.message : String(error);
2008
- });
2009
- return sweep;
2010
- }
2011
- /**
2012
- * Starts or joins the session's global plugin-instance topology sweep.
2013
- *
2014
- * @returns The single in-flight sweep promise.
2015
- */
2016
- function procTopology_warmup() {
2017
- if (procTopologyPromise)
2018
- return procTopologyPromise;
2019
- return procTopology_start(procTopologyState_create());
2020
- }
2021
- /**
2022
- * Reconciles topology only for feed IDs selected by a restored-cache feed-index
2023
- * comparison. This preserves the checkpointed topology for unchanged terminal
2024
- * feeds while refreshing new, changed, and active feeds from CUBE.
2025
- *
2026
- * @param feedIDs - Canonical CUBE feed IDs whose topology must be reloaded.
2027
- * @returns A promise that resolves after all supplied feeds have been refreshed.
2028
- */
2029
- function procTopology_reconcileFeeds(feedIDs) {
2030
- if (procTopologyPromise)
2031
- return procTopologyPromise;
2032
- return procTopologyScoped_start(feedIDs);
2033
- }
2034
- /**
2035
- * Continues a failed topology reconciliation from its retained global page or
2036
- * scoped feed set.
2037
- *
2038
- * @returns The resumed sweep promise, or the active sweep when one is running.
2039
- * @throws {Error} When there is no failed sweep continuation to retry.
2040
- */
2041
- function procTopology_retry() {
2042
- if (procTopologyPromise)
2043
- return procTopologyPromise;
2044
- if (procTopologyFailure === undefined) {
2045
- throw new Error('no failed topology sweep to retry');
2046
- }
2047
- if (procTopologyResumeState)
2048
- return procTopology_start(procTopologyResumeState);
2049
- if (procTopologyScopedResumeFeedIDs)
2050
- return procTopologyScoped_start(procTopologyScopedResumeFeedIDs);
2051
- throw new Error('no failed topology sweep to retry');
2052
- }
2053
- /**
2054
- * Reports the session topology sweep lifecycle.
2055
- *
2056
- * @returns A snapshot of the lifecycle state and any failure reason.
2057
- */
2058
- function procTopology_status() {
2059
- if (procTopologyPromise)
2060
- return { state: 'running', failure: undefined };
2061
- if (procTopologyFailure !== undefined)
2062
- return { state: 'failed', failure: procTopologyFailure };
2063
- if ((0, cumin_1.procCache_get)().warmupComplete)
2064
- return { state: 'complete', failure: undefined };
2065
- return { state: 'idle', failure: undefined };
2066
- }
2067
- /**
2068
- * Waits for the active topology sweep without starting another.
2069
- *
2070
- * @returns A promise that resolves when the active sweep finishes, or
2071
- * immediately when no sweep is running.
2072
- */
2073
- async function procTopology_await() {
2074
- const sweep = procTopologyPromise;
2075
- if (sweep)
2076
- await sweep;
2077
- }
2078
- /**
2079
- * Rebuilds the ProcCache, optionally scoped to one feed.
2080
- *
2081
- * A full refresh returns feeds whose topology merits reload after the feed-index
2082
- * comparison. Callers performing an explicit `proc refresh` can ignore that
2083
- * result and run a global topology sweep; restored startup uses it to stay scoped.
2084
- *
2085
- * @param feedID - One feed to force-refresh, or undefined for the full feed index.
2086
- * @returns IDs whose topology is new, changed, or currently active.
2087
- */
2088
- async function procCache_refresh(feedID) {
2089
- if (feedID !== undefined) {
2090
- await procFeed_evict(feedID);
2091
- await feedInstances_ensureLoaded(feedID);
2092
- return [feedID];
2093
- }
2094
- else {
2095
- const activeSweep = procTopologyPromise;
2096
- if (activeSweep) {
2097
- try {
2098
- await activeSweep;
2099
- }
2100
- catch {
2101
- // A full refresh replaces any failed sweep with a new idle lifecycle.
2102
- }
2103
- }
2104
- procTopologyPromise = null;
2105
- procTopologyFailure = undefined;
2106
- procTopologyResumeState = null;
2107
- procTopologyScopedResumeFeedIDs = null;
2108
- (0, cumin_1.procCache_get)().warmup_reset();
2109
- feedVisits.clear();
2110
- return procCache_build();
2111
- }
2112
- }
2113
656
  //# sourceMappingURL=proc.js.map