@tai42/api-client 32.0.0 → 34.0.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 (100) hide show
  1. package/dist/client/backend-client.d.ts +27 -0
  2. package/dist/client/backend-client.d.ts.map +1 -1
  3. package/dist/client/backup-client.d.ts +4 -0
  4. package/dist/client/backup-client.d.ts.map +1 -1
  5. package/dist/client/config-client.d.ts +31 -0
  6. package/dist/client/config-client.d.ts.map +1 -1
  7. package/dist/client/index.d.ts +148 -1
  8. package/dist/client/index.d.ts.map +1 -1
  9. package/dist/client/index.js +5 -0
  10. package/dist/client/index.js.map +1 -1
  11. package/dist/client/manifest-client.d.ts +33 -1
  12. package/dist/client/manifest-client.d.ts.map +1 -1
  13. package/dist/client/manifest-client.js +3 -3
  14. package/dist/client/manifest-client.js.map +1 -1
  15. package/dist/client/marketplace-client.d.ts +40 -0
  16. package/dist/client/marketplace-client.d.ts.map +1 -1
  17. package/dist/client/profiles-client.d.ts +4 -0
  18. package/dist/client/profiles-client.d.ts.map +1 -1
  19. package/dist/client/tool-extensions-client.d.ts +4 -0
  20. package/dist/client/tool-extensions-client.d.ts.map +1 -1
  21. package/dist/client/tools-client.d.ts +1 -0
  22. package/dist/client/tools-client.d.ts.map +1 -1
  23. package/dist/failed-mcp-roster.d.ts +30 -0
  24. package/dist/failed-mcp-roster.d.ts.map +1 -0
  25. package/dist/failed-mcp-roster.js +56 -0
  26. package/dist/failed-mcp-roster.js.map +1 -0
  27. package/dist/failed-reply-roll.d.ts +22 -0
  28. package/dist/failed-reply-roll.d.ts.map +1 -0
  29. package/dist/failed-reply-roll.js +46 -0
  30. package/dist/failed-reply-roll.js.map +1 -0
  31. package/dist/fleet-report.d.ts +122 -50
  32. package/dist/fleet-report.d.ts.map +1 -1
  33. package/dist/fleet-report.js +168 -89
  34. package/dist/fleet-report.js.map +1 -1
  35. package/dist/generated/api-routes.d.ts +4 -4
  36. package/dist/generated/api-routes.js +1 -1
  37. package/dist/generated/api-routes.js.map +1 -1
  38. package/dist/generated/openapi-schemas.d.ts +303 -30
  39. package/dist/generated/openapi-schemas.d.ts.map +1 -1
  40. package/dist/generated/openapi-schemas.js +14 -13
  41. package/dist/generated/openapi-schemas.js.map +1 -1
  42. package/dist/generated/served-schemas.d.ts +1 -1
  43. package/dist/generated/served-schemas.js +1 -1
  44. package/dist/generated/served-schemas.js.map +1 -1
  45. package/dist/http.d.ts.map +1 -1
  46. package/dist/http.js +5 -2
  47. package/dist/http.js.map +1 -1
  48. package/dist/index.d.ts +8 -3
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +4 -1
  51. package/dist/index.js.map +1 -1
  52. package/dist/mcp-failure.d.ts +18 -0
  53. package/dist/mcp-failure.d.ts.map +1 -0
  54. package/dist/mcp-failure.js +39 -0
  55. package/dist/mcp-failure.js.map +1 -0
  56. package/dist/schemas/backup.d.ts +8 -0
  57. package/dist/schemas/backup.d.ts.map +1 -1
  58. package/dist/schemas/fleet.d.ts +49 -10
  59. package/dist/schemas/fleet.d.ts.map +1 -1
  60. package/dist/schemas/fleet.js +20 -11
  61. package/dist/schemas/fleet.js.map +1 -1
  62. package/dist/schemas/manifest-mcp.d.ts +9 -6
  63. package/dist/schemas/manifest-mcp.d.ts.map +1 -1
  64. package/dist/schemas/manifest-mcp.js +4 -3
  65. package/dist/schemas/manifest-mcp.js.map +1 -1
  66. package/dist/schemas/marketplace.d.ts +44 -2
  67. package/dist/schemas/marketplace.d.ts.map +1 -1
  68. package/dist/schemas/marketplace.js +8 -2
  69. package/dist/schemas/marketplace.js.map +1 -1
  70. package/dist/schemas/profiles.d.ts +13 -7
  71. package/dist/schemas/profiles.d.ts.map +1 -1
  72. package/dist/schemas/profiles.js +9 -7
  73. package/dist/schemas/profiles.js.map +1 -1
  74. package/dist/schemas/served.d.ts +1 -1
  75. package/dist/schemas/system-kinds.d.ts +4 -0
  76. package/dist/schemas/system-kinds.d.ts.map +1 -1
  77. package/dist/schemas/system-kinds.js +5 -4
  78. package/dist/schemas/system-kinds.js.map +1 -1
  79. package/dist/schemas/tools.d.ts +5 -1
  80. package/dist/schemas/tools.d.ts.map +1 -1
  81. package/dist/schemas/tools.js +3 -1
  82. package/dist/schemas/tools.js.map +1 -1
  83. package/package.json +1 -1
  84. package/src/client/index.ts +5 -0
  85. package/src/client/manifest-client.ts +4 -4
  86. package/src/failed-mcp-roster.ts +70 -0
  87. package/src/failed-reply-roll.ts +71 -0
  88. package/src/fleet-report.ts +306 -118
  89. package/src/generated/api-routes.ts +1 -1
  90. package/src/generated/openapi-schemas.ts +16 -13
  91. package/src/generated/served-schemas.ts +1 -1
  92. package/src/http.ts +5 -2
  93. package/src/index.ts +13 -2
  94. package/src/mcp-failure.ts +46 -0
  95. package/src/schemas/fleet.ts +20 -11
  96. package/src/schemas/manifest-mcp.ts +4 -3
  97. package/src/schemas/marketplace.ts +8 -2
  98. package/src/schemas/profiles.ts +9 -7
  99. package/src/schemas/system-kinds.ts +5 -4
  100. package/src/schemas/tools.ts +3 -1
@@ -3,19 +3,28 @@
3
3
  * fleet broadcast. Every mutation surface (connector, backup, mcp-config, env,
4
4
  * extensions, single-MCP reload, fleet reload) routes its broadcast report through
5
5
  * this one function so a FAILED propagation is never invisible: an unconfirmed
6
- * sibling (any non-`applied` outcome) or an unreachable bus becomes an explicit
7
- * summary the UI renders as a loud, user-visible state — never a faked success on a
8
- * worker that did not converge.
6
+ * sibling (any non-`applied` outcome the operation's recycle roll did not settle) or an
7
+ * unreachable bus becomes an explicit summary the UI renders as a loud, user-visible
8
+ * state — never a faked success on a worker that did not converge.
9
9
  *
10
- * A mutation embeds its broadcast in one of two shapes: the mode-wrapped
11
- * {@link FleetReportFanout} (`fanout` field) or the bare {@link FleetResult} (the
12
- * fleet-reload and single-MCP-reload bodies). Both normalize to a
10
+ * A mutation embeds its broadcast in one of three shapes: the mode-wrapped
11
+ * {@link FleetReportFanout} (`fanout` field), the fleet soft restart's
12
+ * {@link FleetReloadResult}, or the bare {@link FleetResult} (the single-MCP reload,
13
+ * deregister and tool reload/remove bodies). Each normalizes to a
13
14
  * {@link FleetReportSummary} through the functions here; the SDK's `FleetReport`
14
15
  * component renders the summary.
15
16
  */
16
- import type { FleetOutcome, FleetReportFanout, FleetResult } from './schemas';
17
+ import type {
18
+ AwaitingWorker,
19
+ FleetOutcome,
20
+ FleetReloadResult,
21
+ FleetReportFanout,
22
+ FleetResult,
23
+ RecycleEntry,
24
+ RecycleRoll,
25
+ } from './schemas';
17
26
 
18
- /** A per-worker propagation FAILURE: a worker that did not confirm `applied`. */
27
+ /** The outcome of a worker's broadcast row that did not confirm `applied`. */
19
28
  export type FleetFailureOutcome = Exclude<FleetOutcome, 'applied'>;
20
29
 
21
30
  /** One worker that failed to converge, with the report's message for it. */
@@ -24,28 +33,50 @@ export interface FleetWorkerFailure {
24
33
  readonly outcome: FleetFailureOutcome;
25
34
  /** The failed apply's `error`, or the publisher's computed-outcome `detail`. */
26
35
  readonly message: string | null;
36
+ /**
37
+ * True when the reply states its reload was refused at its epoch build
38
+ * (the `withheld` {@link AwaitingRestartReading}): trying again may be refused the same way
39
+ * until the stored config is fixed.
40
+ */
41
+ readonly withheld: boolean;
27
42
  }
28
43
 
29
44
  /**
30
45
  * The interpreted state of one broadcast.
31
- * - `converged` — the bus was reached and every worker applied (or the change was
32
- * local-only on a lone worker). The caller renders its own success; the report
46
+ * - `converged` — the bus was reached and every worker applied or was settled by the
47
+ * operation's roll (or the change was local-only on a lone worker). The caller renders its own success; the report
33
48
  * needs no loud state.
34
- * - `degraded` — the bus was reached but one or more workers did not confirm; the
35
- * named `failures` are stale/unreached siblings the operator must see.
49
+ * - `degraded` — the bus was reached but one or more workers did not confirm and the
50
+ * operation's roll did not settle them; the named `failures` are stale/unreached
51
+ * siblings the operator must see.
36
52
  * - `unreachable` — the bus itself could not be reached, so no sibling was told;
37
53
  * `error` carries the transport failure.
38
54
  */
39
55
  export type FleetReportStatus = 'converged' | 'degraded' | 'unreachable';
40
56
 
41
57
  /**
42
- * One worker whose reload named recycle-class keys awaiting a respawn: their value
43
- * changed since the worker bound it (at boot, or when the plugin that declares them was
58
+ * What the reply says about a worker awaiting a respawn:
59
+ * - `restartable` — it carries the worker's broadcast row or recycle line, and neither
60
+ * states a refused build, so a restart applies its settings.
61
+ * - `withheld` — its reload was refused at its epoch build: the stored config did not build
62
+ * on it, so the operation left it running on its current config and a restart may fail
63
+ * the same way until that config is fixed. Its broadcast row is `failed` with a
64
+ * `discarded` payload, or its recycle line is `withheld`.
65
+ * - `unstated` — it carries neither a row nor a line for the worker (an upgrade-all's reply
66
+ * has no rows, nor has a lone worker's `local-only` fan-out), so it does not say which of
67
+ * the other two the worker is.
68
+ */
69
+ export type AwaitingRestartReading = 'restartable' | 'withheld' | 'unstated';
70
+
71
+ /**
72
+ * One worker an operation names as still awaiting a respawn: its recycle-class keys
73
+ * changed since the worker bound them (at boot, or when the plugin that declares them was
44
74
  * loaded), and they take effect only when it is respawned.
45
75
  */
46
76
  export interface FleetWorkerAwaitingRespawn {
47
77
  readonly name: string;
48
78
  readonly keys: readonly string[];
79
+ readonly reading: AwaitingRestartReading;
49
80
  }
50
81
 
51
82
  export interface FleetReportSummary {
@@ -56,8 +87,15 @@ export interface FleetReportSummary {
56
87
  readonly failures: readonly FleetWorkerFailure[];
57
88
  /** The bus-unreachable transport error — non-null only when `unreachable`. */
58
89
  readonly error: string | null;
59
- /** The workers whose reload named recycle-class keys awaiting a respawn. */
90
+ /** The workers the operation names as still awaiting a respawn. */
60
91
  readonly awaiting: readonly FleetWorkerAwaitingRespawn[];
92
+ /** The workers whose roll line is `self-deferred`: a restart the reply cannot confirm. */
93
+ readonly restartsPending: readonly string[];
94
+ /**
95
+ * The workers the roll settled without a confirmed fresh life whose broadcast row did not
96
+ * confirm `applied`: the reply states no restart is outstanding, not that they applied.
97
+ */
98
+ readonly reloadsUnconfirmed: readonly string[];
61
99
  /**
62
100
  * The config store's error releasing its exclusive write span after the persist, or
63
101
  * `null` when it released. Non-null means the change landed but the store may hold
@@ -66,18 +104,6 @@ export interface FleetReportSummary {
66
104
  readonly spanReleaseError: string | null;
67
105
  }
68
106
 
69
- /**
70
- * The recycle-class keys a worker's reload payload names under `awaiting_respawn`.
71
- * The per-worker payload is opaque on the wire, so it is read defensively: a payload
72
- * that is not a reload result names nothing.
73
- */
74
- function awaitingKeys(payload: unknown): string[] {
75
- if (typeof payload !== 'object' || payload === null || Array.isArray(payload)) return [];
76
- const keys = (payload as Record<string, unknown>).awaiting_respawn;
77
- if (!Array.isArray(keys)) return [];
78
- return keys.filter((key): key is string => typeof key === 'string');
79
- }
80
-
81
107
  /**
82
108
  * True when a summary describes a failure the operator must be shown: a propagation
83
109
  * that did not converge, or a write span the store did not release.
@@ -87,24 +113,219 @@ export function isFleetReportFailure(summary: FleetReportSummary | null): boolea
87
113
  }
88
114
 
89
115
  /**
90
- * Interpret a bare {@link FleetResult} (the fleet-reload / single-MCP-reload body).
91
- * An unreachable bus is `unreachable`; a reachable report with any non-`applied`
92
- * worker is `degraded` (those workers named); otherwise `converged`. Every worker whose
93
- * reload payload names `awaiting_respawn` keys is listed under `awaiting`, whatever the
94
- * status.
116
+ * Interpret a bare {@link FleetResult} (the single-MCP reload, deregister, and tool
117
+ * reload/remove bodies). An unreachable bus is `unreachable`; a reachable report with
118
+ * any non-`applied` worker is `degraded` (those workers named); otherwise `converged`.
119
+ * A bare report states no verdict on workers awaiting a respawn, so `awaiting` is empty.
95
120
  */
96
121
  export function summarizeFleetResult(result: Omit<FleetResult, 'ok'>): FleetReportSummary {
97
- const awaiting: FleetWorkerAwaitingRespawn[] = result.results
98
- .map((entry) => ({ name: entry.name, keys: awaitingKeys(entry.payload) }))
99
- .filter((entry) => entry.keys.length > 0);
100
- return summarizeWith(result, awaiting, null);
122
+ return summarizeWith(result, [], NO_ROLL, null);
123
+ }
124
+
125
+ /**
126
+ * What a reload's reply says of a worker it holds no broadcast row for:
127
+ * - `recycled` — a roll line confirms its old life gone and new capacity up.
128
+ * - `outcome-open` — a roll line of any other status, the roll's stop or the awaiting verdict
129
+ * names it: the reply leaves its outcome open.
130
+ * - `confirmed-clean` — `skipped` names it: it confirmed no restart is due and was left running.
131
+ * - `new-life` — only `fresh` names it: a new ready life, which the reply ties to no restart.
132
+ * - `roll-handed-off` — only `roll_deferred_to` names it: it carries out the roll after the reply.
133
+ */
134
+ export type FleetReloadWorkerStatement =
135
+ 'recycled' | 'outcome-open' | 'confirmed-clean' | 'new-life' | 'roll-handed-off';
136
+
137
+ /** A worker a reload's reply names beyond its one row, with what the reply says of it. */
138
+ export interface FleetReloadNamedWorker {
139
+ readonly name: string;
140
+ readonly statement: FleetReloadWorkerStatement;
141
+ }
142
+
143
+ /**
144
+ * The workers a fleet reload's report covers: every worker on the bus (`fleet`), the workers the
145
+ * request named (`selected`), only the answering worker, because the deployment has no worker bus
146
+ * (`no-bus`) or no other worker is on it (`alone-on-bus`), or one row with nothing to say the
147
+ * worker was alone (`one-row`): `others` holds the other workers the reply names, each with what it
148
+ * says of them, and is empty when the roll could not read the bus and so names none.
149
+ */
150
+ export type FleetReloadReach =
151
+ | { readonly kind: 'fleet' }
152
+ | { readonly kind: 'selected'; readonly count: number }
153
+ | { readonly kind: 'no-bus' }
154
+ | { readonly kind: 'alone-on-bus' }
155
+ | {
156
+ readonly kind: 'one-row';
157
+ readonly worker: string;
158
+ readonly others: readonly FleetReloadNamedWorker[];
159
+ };
160
+
161
+ /** A fleet reload's report, with the workers it covers. */
162
+ export interface FleetReloadSummary extends FleetReportSummary {
163
+ /** The workers the report covers. */
164
+ readonly reach: FleetReloadReach;
165
+ }
166
+
167
+ /**
168
+ * Interpret a fleet soft restart's {@link FleetReloadResult}: its per-worker report
169
+ * judged as {@link summarizeFleetResult} judges it, with `awaiting` the operation's own
170
+ * `awaiting_respawn` verdict. Each worker's reload payload states the keys that worker
171
+ * found moved before the operation's recycle roll ran; the roll restarts those workers,
172
+ * so only the verdict says which still await a respawn. Its rows and its roll's lines
173
+ * give the reading of each ({@link AwaitingRestartReading}), and the roll settles the
174
+ * workers whose rows did not confirm ({@link settledWorkers}).
175
+ *
176
+ * `targets` is what the request named, `null` for the whole fleet: the reply does not echo it,
177
+ * and a reply naming one target has the same shape as a lone worker's.
178
+ */
179
+ export function summarizeFleetReload(
180
+ reply: Omit<FleetReloadResult, 'ok'>,
181
+ targets: readonly string[] | null,
182
+ ): FleetReloadSummary {
183
+ return {
184
+ ...summarizeWith(reply, reply.awaiting_respawn, reply.recycle ?? NO_ROLL, null),
185
+ reach: reloadReach(reply, targets),
186
+ };
187
+ }
188
+
189
+ /**
190
+ * The workers a reload's report covers. A reachable reply holds one row per expected worker, the
191
+ * answering worker's own among them, plus the gap rows, and its roll and verdict can still name a
192
+ * worker with no row. So a single row means the worker was alone on the bus only when the
193
+ * reply names no one else and its roll read the bus: a roll that stopped on no named worker stopped
194
+ * reading the bus, so its reply names no one because it could not tell.
195
+ */
196
+ function reloadReach(
197
+ reply: Omit<FleetReloadResult, 'ok'>,
198
+ targets: readonly string[] | null,
199
+ ): FleetReloadReach {
200
+ if (reply.local_only) return { kind: 'no-bus' };
201
+ if (targets !== null) return { kind: 'selected', count: targets.length };
202
+ const [row, ...otherRows] = reply.results;
203
+ if (row === undefined || otherRows.length > 0) return { kind: 'fleet' };
204
+ const others = workersNamedBeyondRow(reply, row.name);
205
+ const rollCouldNotReadBus = reply.recycle?.recycle_stopped?.name === null;
206
+ return others.length > 0 || rollCouldNotReadBus
207
+ ? { kind: 'one-row', worker: row.name, others }
208
+ : { kind: 'alone-on-bus' };
209
+ }
210
+
211
+ /**
212
+ * The workers a reload's reply names under each statement, the leading statement first: an open
213
+ * outcome leads a settled one, and what the roll states of a worker's restart leads what only the
214
+ * reply's lists state.
215
+ */
216
+ function workersByStatement(
217
+ reply: Omit<FleetReloadResult, 'ok'>,
218
+ ): readonly (readonly [FleetReloadWorkerStatement, readonly string[]])[] {
219
+ const roll = reply.recycle;
220
+ const lines = roll?.recycle ?? [];
221
+ const stoppedAt = roll?.recycle_stopped?.name ?? null;
222
+ return [
223
+ [
224
+ 'outcome-open',
225
+ [
226
+ ...lines.filter((line) => line.status !== 'recycled').map((line) => line.name),
227
+ ...(stoppedAt === null ? [] : [stoppedAt]),
228
+ ...reply.awaiting_respawn.map((worker) => worker.name),
229
+ ],
230
+ ],
231
+ ['recycled', lines.filter((line) => line.status === 'recycled').map((line) => line.name)],
232
+ ['confirmed-clean', roll?.skipped ?? []],
233
+ ['new-life', roll?.fresh.map((life) => life.name) ?? []],
234
+ ['roll-handed-off', reply.roll_deferred_to === null ? [] : [reply.roll_deferred_to]],
235
+ ];
236
+ }
237
+
238
+ /** Each worker a reload's reply names beyond its row, once, with the statement that leads for it. */
239
+ function workersNamedBeyondRow(
240
+ reply: Omit<FleetReloadResult, 'ok'>,
241
+ rowWorker: string,
242
+ ): FleetReloadNamedWorker[] {
243
+ const statementOf = new Map<string, FleetReloadWorkerStatement>();
244
+ for (const [statement, names] of workersByStatement(reply)) {
245
+ for (const name of names) {
246
+ if (name !== rowWorker && !statementOf.has(name)) statementOf.set(name, statement);
247
+ }
248
+ }
249
+ return [...statementOf].map(([name, statement]) => ({ name, statement }));
250
+ }
251
+
252
+ /** What a roll states of each worker: its lines, and the workers it left running as clean. */
253
+ type RollStatements = NonNullable<FleetFanoutReply['recycle']>;
254
+
255
+ const NO_ROLL: RollStatements = { recycle: [], skipped: [] };
256
+
257
+ /** Whether a broadcast row states that its worker's reload was refused at its epoch build. */
258
+ function statesDiscardedBuild(row: FleetResult['results'][number]): boolean {
259
+ if (row.outcome !== 'failed') return false;
260
+ const payload = row.payload;
261
+ return (
262
+ typeof payload === 'object' &&
263
+ payload !== null &&
264
+ (payload as Record<string, unknown>).status === 'discarded'
265
+ );
266
+ }
267
+
268
+ /**
269
+ * The workers the reply states as withheld, the one reading of it: a broadcast row states
270
+ * a discarded build, or a recycle line is `withheld`.
271
+ */
272
+ function withheldWorkers(
273
+ rows: FleetResult['results'],
274
+ recycle: readonly RecycleEntry[],
275
+ ): ReadonlySet<string> {
276
+ return new Set([
277
+ ...rows.filter(statesDiscardedBuild).map((row) => row.name),
278
+ ...recycle.filter((line) => line.status === 'withheld').map((line) => line.name),
279
+ ]);
280
+ }
281
+
282
+ /**
283
+ * The workers whose latest statement is the roll's and leaves nothing to converge, the one
284
+ * reading of it, whatever their broadcast rows say: a line `recycled` or `self-deferred`, or a
285
+ * worker named in `skipped`. A discarded build with no moved keys is skipped on that row alone,
286
+ * with no later statement, so its row still stands: the stored configuration did not build there.
287
+ */
288
+ function settledWorkers(rows: FleetResult['results'], roll: RollStatements): ReadonlySet<string> {
289
+ const discarded = new Set(rows.filter(statesDiscardedBuild).map((row) => row.name));
290
+ return new Set([
291
+ ...roll.recycle
292
+ .filter((line) => line.status === 'recycled' || line.status === 'self-deferred')
293
+ .map((line) => line.name),
294
+ ...roll.skipped.filter((name) => !discarded.has(name)),
295
+ ]);
296
+ }
297
+
298
+ function awaitingWorkers(
299
+ verdict: readonly AwaitingWorker[],
300
+ rows: FleetResult['results'],
301
+ recycle: readonly RecycleEntry[],
302
+ ): FleetWorkerAwaitingRespawn[] {
303
+ const withheld = withheldWorkers(rows, recycle);
304
+ const stated = new Set([...rows, ...recycle].map((statement) => statement.name));
305
+ return verdict.map((worker) => ({
306
+ name: worker.name,
307
+ keys: worker.keys,
308
+ reading: withheld.has(worker.name)
309
+ ? 'withheld'
310
+ : stated.has(worker.name)
311
+ ? 'restartable'
312
+ : 'unstated',
313
+ }));
314
+ }
315
+
316
+ /** The worker lines of one status, by name. */
317
+ function linesWith(roll: RollStatements, status: string): string[] {
318
+ return roll.recycle.filter((line) => line.status === status).map((line) => line.name);
101
319
  }
102
320
 
103
321
  function summarizeWith(
104
322
  result: Omit<FleetResult, 'ok'>,
105
- awaiting: readonly FleetWorkerAwaitingRespawn[],
323
+ verdict: readonly AwaitingWorker[],
324
+ roll: RollStatements,
106
325
  spanReleaseError: string | null,
107
326
  ): FleetReportSummary {
327
+ const awaiting = awaitingWorkers(verdict, result.results, roll.recycle);
328
+ const restartsPending = linesWith(roll, 'self-deferred');
108
329
  if (!result.reachable) {
109
330
  return {
110
331
  status: 'unreachable',
@@ -112,15 +333,22 @@ function summarizeWith(
112
333
  failures: [],
113
334
  error: result.error,
114
335
  awaiting,
336
+ restartsPending,
337
+ reloadsUnconfirmed: [],
115
338
  spanReleaseError,
116
339
  };
117
340
  }
118
- const failures: FleetWorkerFailure[] = result.results
119
- .filter((entry) => entry.outcome !== 'applied')
341
+ const withheld = withheldWorkers(result.results, roll.recycle);
342
+ const settled = settledWorkers(result.results, roll);
343
+ const recycled = new Set(linesWith(roll, 'recycled'));
344
+ const unconfirmed = result.results.filter((entry) => entry.outcome !== 'applied');
345
+ const failures: FleetWorkerFailure[] = unconfirmed
346
+ .filter((entry) => !settled.has(entry.name))
120
347
  .map((entry) => ({
121
348
  name: entry.name,
122
349
  outcome: entry.outcome as FleetFailureOutcome,
123
350
  message: entry.error ?? entry.detail ?? null,
351
+ withheld: withheld.has(entry.name),
124
352
  }));
125
353
  return {
126
354
  status: failures.length > 0 ? 'degraded' : 'converged',
@@ -128,96 +356,56 @@ function summarizeWith(
128
356
  failures,
129
357
  error: null,
130
358
  awaiting,
359
+ restartsPending,
360
+ reloadsUnconfirmed: unconfirmed
361
+ .map((entry) => entry.name)
362
+ .filter((name) => settled.has(name) && !recycled.has(name)),
131
363
  spanReleaseError,
132
364
  };
133
365
  }
134
366
 
135
367
  /**
136
- * Interpret a mutation's mode-wrapped {@link FleetReportFanout}. `null`/`undefined`
137
- * (the response path mutated no manifest) yields `null` — there is nothing to report.
138
- * A `local-only` fan-out is `converged` with its note; `fleet`/`unreachable` carry a
139
- * bare {@link FleetResult} judged as {@link summarizeFleetResult} judges its failures.
140
- * `awaiting` is the mutation's own verdict (its response's `awaiting_respawn`, or `[]`
141
- * for a mutation that states none): the operation knows whether its recycle roll
142
- * carried a worker's moved env, so its per-worker rows are never re-read for it.
143
- * `spanReleaseError` is the response's `span_release_error`: a non-null value makes the
144
- * summary a failure ({@link isFleetReportFailure}) whatever the fan-out reports, and a
145
- * response that mutated no manifest still yields a summary carrying it.
368
+ * The slice of a mutation's reply its fleet report reads, under the reply's own field names.
369
+ * A reply states only what its operation has: `fanout` is absent or `null` when it reloaded
370
+ * no manifest, `awaiting_respawn` absent when it states no verdict, and `recycle` absent or
371
+ * `null` when it ran no roll.
146
372
  */
147
- export function summarizeFleetFanout(
148
- fanout: FleetReportFanout | null | undefined,
149
- awaiting: readonly FleetWorkerAwaitingRespawn[],
150
- spanReleaseError: string | null,
151
- ): FleetReportSummary | null {
152
- if (fanout === null || fanout === undefined) {
153
- if (spanReleaseError === null) return null;
154
- return {
155
- status: 'converged',
156
- note: null,
157
- failures: [],
158
- error: null,
159
- awaiting,
160
- spanReleaseError,
161
- };
162
- }
163
- if (fanout.mode === 'local-only') {
373
+ export interface FleetFanoutReply {
374
+ readonly fanout?: FleetReportFanout | null;
375
+ readonly awaiting_respawn?: readonly AwaitingWorker[];
376
+ /** The roll the operation ran. A reply carrying its roll's fields flat passes itself here. */
377
+ readonly recycle?: Pick<RecycleRoll, 'recycle' | 'skipped'> | null;
378
+ readonly span_release_error: string | null;
379
+ }
380
+
381
+ /**
382
+ * Interpret a mutation's reply. A reply with no fan-out, no unreleased span and no worker
383
+ * awaiting a respawn yields `null`: there is nothing to report. A `local-only` fan-out is
384
+ * `converged` with its note; `fleet`/`unreachable` carry a bare {@link FleetResult} judged
385
+ * as {@link summarizeFleetResult} judges it. `awaiting_respawn` is the operation's own
386
+ * verdict: it knows whether its recycle roll carried a worker's moved env, so its per-worker
387
+ * rows are never re-read for it. The roll's lines, with the broadcast rows, give the reading of
388
+ * each worker it names ({@link AwaitingRestartReading}), and the roll settles the workers whose
389
+ * rows did not confirm ({@link settledWorkers}). A non-null `span_release_error` makes the summary a failure
390
+ * ({@link isFleetReportFailure}) whatever the fan-out reports.
391
+ */
392
+ export function summarizeFleetFanout(reply: FleetFanoutReply): FleetReportSummary | null {
393
+ const { fanout, span_release_error: spanReleaseError } = reply;
394
+ const verdict = reply.awaiting_respawn ?? [];
395
+ const roll = reply.recycle ?? NO_ROLL;
396
+ if (fanout === null || fanout === undefined || fanout.mode === 'local-only') {
397
+ const note = fanout?.note ?? null;
398
+ if (note === null && spanReleaseError === null && verdict.length === 0) return null;
164
399
  return {
165
400
  status: 'converged',
166
- note: fanout.note,
401
+ note,
167
402
  failures: [],
168
403
  error: null,
169
- awaiting,
404
+ awaiting: awaitingWorkers(verdict, [], roll.recycle),
405
+ restartsPending: linesWith(roll, 'self-deferred'),
406
+ reloadsUnconfirmed: [],
170
407
  spanReleaseError,
171
408
  };
172
409
  }
173
- return summarizeWith(fanout, awaiting, spanReleaseError);
174
- }
175
-
176
- /** One MCP server skipped by the viability check — its title, a coarse status, and the
177
- * credential-free failure detail the platform records when present: `category` (`auth`
178
- * for a 401/403, `unreachable` for a transport error or timeout, `error` otherwise),
179
- * the redacted `message`, and the `http_status` the failure carried (`null` for a pure
180
- * transport failure). The three detail fields are absent when the reporting server
181
- * omitted them. */
182
- export interface FailedMcpEntry {
183
- readonly title: string;
184
- readonly status: string;
185
- readonly category?: string;
186
- readonly message?: string;
187
- readonly http_status?: number | null;
188
- }
189
-
190
- /**
191
- * The failed-MCP roster carried by a `GET /api/mcp-status/failed` broadcast report.
192
- * The query op rides the fleet fan-out primitive, so each worker's own failed list
193
- * arrives as its per-worker `payload` (opaque on the wire). This unions those lists
194
- * by title — a server failed on ANY worker is a server the operator must see — and
195
- * name-sorts the result, tolerating a worker whose payload is absent or malformed
196
- * (skipped, never a throw: a partial fleet report still yields the roster it can).
197
- */
198
- export function failedMcpsFromReport(result: Omit<FleetResult, 'ok'>): FailedMcpEntry[] {
199
- const byTitle = new Map<string, FailedMcpEntry>();
200
- for (const worker of result.results) {
201
- const payload: unknown = worker.payload;
202
- if (!Array.isArray(payload)) continue;
203
- for (const entry of payload) {
204
- if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) continue;
205
- const record = entry as Record<string, unknown>;
206
- const { title, status, category, message } = record;
207
- if (typeof title !== 'string' || title === '') continue;
208
- // First-seen wins: a server's earliest failure record carries the whole row,
209
- // detail fields included, and a later worker's echo of the same title is ignored.
210
- if (byTitle.has(title)) continue;
211
- byTitle.set(title, {
212
- title,
213
- status: typeof status === 'string' ? status : 'unavailable',
214
- ...(typeof category === 'string' ? { category } : {}),
215
- ...(typeof message === 'string' ? { message } : {}),
216
- ...(typeof record.http_status === 'number' || record.http_status === null
217
- ? { http_status: record.http_status }
218
- : {}),
219
- });
220
- }
221
- }
222
- return [...byTitle.values()].sort((a, b) => a.title.localeCompare(b.title));
410
+ return summarizeWith(fanout, verdict, roll, spanReleaseError);
223
411
  }
@@ -101,6 +101,7 @@ export const apiRoutes = {
101
101
  get_api_mcp_config_schema: { method: "GET", path: "/api/mcp-config/schema" },
102
102
  get_api_mcp_status: { method: "GET", path: "/api/mcp-status" },
103
103
  get_api_mcp_status_failed: { method: "GET", path: "/api/mcp-status/failed" },
104
+ get_api_mcp_status_title_advertised_tools: { method: "GET", path: "/api/mcp-status/{title}/advertised-tools" },
104
105
  get_api_notifications: { method: "GET", path: "/api/notifications" },
105
106
  get_api_observability_capabilities: { method: "GET", path: "/api/observability/capabilities" },
106
107
  get_api_observability_metrics: { method: "GET", path: "/api/observability/metrics" },
@@ -216,7 +217,6 @@ export const apiRoutes = {
216
217
  post_api_mcp_config_entries: { method: "POST", path: "/api/mcp-config/entries" },
217
218
  post_api_mcp_config_secret_env: { method: "POST", path: "/api/mcp-config/secret-env" },
218
219
  post_api_mcp_status_reload_failed: { method: "POST", path: "/api/mcp-status/reload-failed" },
219
- post_api_mcp_status_title_advertised_tools: { method: "POST", path: "/api/mcp-status/{title}/advertised-tools" },
220
220
  post_api_mcp_status_title_deregister: { method: "POST", path: "/api/mcp-status/{title}/deregister" },
221
221
  post_api_mcp_status_title_reload: { method: "POST", path: "/api/mcp-status/{title}/reload" },
222
222
  post_api_notifications: { method: "POST", path: "/api/notifications" },