@milabench/bujang 0.1.12 → 0.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -121,6 +121,8 @@ export interface SlurmJobsResponse {
121
121
  export interface SlurmJobSubmitRequest {
122
122
  script: string;
123
123
  job_name?: string;
124
+ /** the template the script came from (meta/template.txt: the script of the Overview layouts) */
125
+ template?: string;
124
126
  sbatch_args?: string[];
125
127
  // Script arguments extracted from export statements
126
128
  script_args?: Record<string, string>;
@@ -139,7 +141,7 @@ export interface SlurmJobSubmitRequest {
139
141
  dependency?: [string, string][]
140
142
  }
141
143
 
142
- /** A file attached to a submission: lands in <job folder>/input/<name> ($JR_INPUT_DIR). */
144
+ /** A file attached to a submission: lands in <job folder>/input/<name> ($BUJANG_INPUT_DIR). */
143
145
  export interface JobAttachment {
144
146
  /** Relative path, sub folders allowed (data/train.csv). */
145
147
  name: string;
@@ -243,7 +245,7 @@ export interface SlurmJobAccounting {
243
245
 
244
246
  export interface PersitedJobInfo {
245
247
  name: string;
246
- /** JR_JOB_LABEL of the script (or the label given at submission), resolved: meta/label.txt */
248
+ /** BUJANG_JOB_LABEL of the script (or the label given at submission), resolved: meta/label.txt */
247
249
  label?: string | null;
248
250
  cluster?: string;
249
251
  creation_time: string;
@@ -342,7 +344,7 @@ export interface PipelineJob {
342
344
  env?: Record<string, string>;
343
345
  // slurm steps: SOCKS proxy to the login node, unset: the cluster's `proxy` setting
344
346
  proxy?: boolean;
345
- /** label template ("train lr={LR}"): names the job, wins over its group's and the script's JR_JOB_LABEL */
347
+ /** label template ("train lr={LR}"): names the job, wins over its group's and the script's BUJANG_JOB_LABEL */
346
348
  label?: string;
347
349
  job_id?: string;
348
350
  slurm_jobid?: string;
@@ -364,15 +366,24 @@ export interface PipelineRunResponse {
364
366
  /** submitting: the jobs are being submitted; failed: the submission failed (nothing runs) */
365
367
  export type PipelineSubmissionStatus = 'submitting' | 'submitted' | 'failed';
366
368
 
369
+ /** State of the jobs of a submitted run */
370
+ export type PipelineRunState = 'running' | 'failing' | 'failed' | 'completed' | 'unknown';
371
+
367
372
  /** A pipeline run in the list of runs */
368
373
  export interface PipelineRunSummary {
369
374
  run_id: string;
370
375
  name: string;
371
376
  /** the saved pipeline it was started from; runs older than this field have none */
372
377
  template?: string | null;
378
+ /** the clusters its steps ran on */
379
+ clusters?: string[];
373
380
  started: number;
374
381
  status: PipelineSubmissionStatus;
375
382
  error?: string | null;
383
+ /** last known state of its jobs (saved each time its progress is read), null when never read */
384
+ state?: PipelineRunState | null;
385
+ /** when `state` was read (epoch seconds) */
386
+ checked?: number | null;
376
387
  }
377
388
 
378
389
  /** A step of a run with its current state (sacct/squeue state, HELD, or the ssh step state) */
@@ -394,7 +405,7 @@ export interface PipelineRunStatus {
394
405
  status: PipelineSubmissionStatus;
395
406
  error?: string | null;
396
407
  // once submitted
397
- state?: 'running' | 'failing' | 'failed' | 'completed' | 'unknown';
408
+ state?: PipelineRunState;
398
409
  steps?: PipelineRunStep[];
399
410
  log?: string;
400
411
  /** the definition the run was started with (the saved pipeline may have changed since) */
@@ -596,12 +607,12 @@ export interface SettingsOrigin {
596
607
  path: string | null;
597
608
  }
598
609
 
599
- /** One editable field of the user file (local_cache, workdir, database_url). */
600
- export interface SettingsField {
610
+ /** One editable field of the user file (local_cache, workdir, database_url, show_examples). */
611
+ export interface SettingsField<T = string> {
601
612
  /** Value the running server uses (database_url: password masked). */
602
- value: string | null;
613
+ value: T | null;
603
614
  /** Value in the user file, null when absent. */
604
- file: string | null;
615
+ file: T | null;
605
616
  origin: SettingsOrigin;
606
617
  /** Name of the BUJANG_* variable when it is set (it wins over the file). */
607
618
  env: string | null;
@@ -617,6 +628,14 @@ export interface SettingsField {
617
628
 
618
629
  export type SettingsFieldName = 'local_cache' | 'workdir' | 'database_url';
619
630
 
631
+ export type SettingsFields = Record<SettingsFieldName, SettingsField> & {
632
+ show_examples: SettingsField<boolean>;
633
+ /** What the MCP server tells the agents when they connect (null: general.mcp.default_instructions). */
634
+ mcp_instructions: SettingsField;
635
+ /** The default layout of the Overview tab (null: the built-in one). */
636
+ overview_layout: SettingsField<OverviewLayout>;
637
+ };
638
+
620
639
  export interface SettingsCluster {
621
640
  name: string;
622
641
  ssh: string;
@@ -669,6 +688,8 @@ export interface SettingsMcp {
669
688
  url: string | null;
670
689
  /** Turned off (--no-mcp). */
671
690
  disabled: boolean;
691
+ /** The instructions sent to the agents when mcp_instructions is empty. */
692
+ default_instructions: string;
672
693
  }
673
694
 
674
695
  export interface SettingsGeneral {
@@ -690,7 +711,7 @@ export interface SettingsInfo {
690
711
  writable: boolean;
691
712
  read_only_reason: string | null;
692
713
  user_file: { path: string | null; exists: boolean; user_config_dir: string | null; error: string | null };
693
- fields: Record<SettingsFieldName, SettingsField>;
714
+ fields: SettingsFields;
694
715
  secrets_file: string;
695
716
  clusters: SettingsCluster[];
696
717
  sources: {
@@ -895,6 +916,55 @@ export interface JobDataField {
895
916
  values?: string[] | null;
896
917
  }
897
918
 
919
+ /** A panel of the Overview tab: the log view, or a chart of an event */
920
+ export type OverviewPanel =
921
+ | { kind: 'logs'; title?: string; levels?: string[]; files?: string }
922
+ | {
923
+ kind: 'chart';
924
+ title?: string;
925
+ event?: string;
926
+ /** comma separated paths or globs, relative to the job folder */
927
+ files?: string;
928
+ /** Vega-Lite, its data the named dataset "rows"; else the builder fields below; neither: guessed */
929
+ spec?: Record<string, unknown>;
930
+ mark?: string;
931
+ x?: string;
932
+ y?: string;
933
+ aggregate?: string;
934
+ color?: string;
935
+ column?: string;
936
+ row?: string;
937
+ log_x?: boolean;
938
+ log_y?: boolean;
939
+ zero?: boolean;
940
+ };
941
+
942
+ export interface OverviewLayout {
943
+ panels: OverviewPanel[];
944
+ }
945
+
946
+ export type OverviewScope = 'experiment' | 'script';
947
+
948
+ /** GET /jobs/<jr>/overview/layout */
949
+ export interface JobOverviewLayout {
950
+ layout: OverviewLayout;
951
+ /** where it comes from: saved for the experiment / script, a plugin, the setting, the built-in one */
952
+ source: { kind: OverviewScope | 'plugin' | 'setting' | 'default'; name: string | null };
953
+ /** what a layout can be saved for */
954
+ keys: { experiment: string | null; script: string };
955
+ }
956
+
957
+ /** GET /overview/layouts */
958
+ export interface SavedOverviewLayout {
959
+ scope: OverviewScope;
960
+ key: string;
961
+ layout: OverviewLayout;
962
+ updated: number | null;
963
+ }
964
+
965
+ /** What an event of a JSONL file is for: plotted, shown in the log view, or neither */
966
+ export type JobDataRole = 'metric' | 'log' | 'other';
967
+
898
968
  /** GET /jobs/<jr>/data: the JSONL files of the artifact folders of a job and their schema */
899
969
  export interface JobData {
900
970
  jr_job_id: string;
@@ -904,13 +974,33 @@ export interface JobData {
904
974
  size?: number;
905
975
  mtime?: number;
906
976
  rows?: number;
907
- /** per event ("" for the records without an event envelope), its row count and fields */
908
- events?: { event: string; count: number; truncated: boolean; fields: JobDataField[] }[];
977
+ /** the JSONL processor that read the file ("generic", or one of a plugin) */
978
+ processor?: string;
979
+ /** per event ("" for the records without an event envelope), its role, row count and fields */
980
+ events?: { event: string; role: JobDataRole; count: number; truncated: boolean; fields: JobDataField[] }[];
909
981
  error?: string;
910
982
  }[];
911
983
  truncated: boolean;
912
984
  }
913
985
 
986
+ /** GET /job/environment: what a job of a cluster finds in its environment */
987
+ export interface JobEnvironment {
988
+ cluster: string;
989
+ /** an example job id: the prefix is the job name, the suffix is drawn at submission */
990
+ job_id: string;
991
+ remote_folder: string;
992
+ variables: {
993
+ name: string;
994
+ /** resolved for this cluster and name; null when it does not apply (no label, not a pipeline step) */
995
+ value: string | null;
996
+ /** when the value is known: at submission, when the job runs, or for pipeline steps only */
997
+ known: 'submission' | 'run' | 'pipeline';
998
+ description: string;
999
+ }[];
1000
+ /** the job folder, one line each (a text tree) */
1001
+ tree: string[];
1002
+ }
1003
+
914
1004
  /** GET /sync: when the job index was last synced with the clusters (POST /sync adds `synced`) */
915
1005
  export interface SyncStatus {
916
1006
  /** unix time of the last background sync, null before the first one */
@@ -920,6 +1010,10 @@ export interface SyncStatus {
920
1010
  /** seconds between two background syncs, null when the server does not run them */
921
1011
  interval: number | null;
922
1012
  jobs: number;
1013
+ /** unix time of the soonest next round of the background sync (a cluster), null when none is planned */
1014
+ next?: number | null;
1015
+ /** the clusters being synced now */
1016
+ running?: string[];
923
1017
  /** per cluster: true synced, false failed, 'recent': not asked, a full rsync ran less than min_refresh_interval ago */
924
1018
  synced?: Record<string, boolean | 'recent'>;
925
1019
  skipped?: string;
@@ -990,12 +1084,18 @@ export interface JanitorQueueTicket {
990
1084
  expires: number;
991
1085
  }
992
1086
 
1087
+ /** A periodic task (state.db `periodic`): sync:<cluster>, book_keeping:<cluster>, reindex, ... */
993
1088
  export interface JanitorPeriodic {
994
- /** APScheduler job id, null when only its history is known */
995
- id: string | null;
1089
+ id: string;
996
1090
  name: string;
1091
+ cluster: string | null;
1092
+ /** seconds between two runs, null: runs when asked (the scheduled-job checker) */
997
1093
  interval: number | null;
1094
+ /** unix time of the next run (a request makes it sooner), null when none is planned */
998
1095
  next_run: number | null;
1096
+ /** a run was asked for (Refresh, a slow rsync) and has not started yet */
1097
+ requested: number | null;
1098
+ running: boolean;
999
1099
  last: JanitorRun | null;
1000
1100
  }
1001
1101
 
@@ -40,6 +40,7 @@ import type {
40
40
  ApiError,
41
41
  JanitorArchiveResult,
42
42
  JanitorOverview,
43
+ JanitorPeriodic,
43
44
  JanitorRun,
44
45
  JanitorSkipped,
45
46
  JanitorStaleResult,
@@ -207,45 +208,113 @@ const RunningCard: React.FC<{ data: JanitorOverview }> = ({ data }) => {
207
208
  // ─── Periodic jobs ──────────────────────────────────────────────────
208
209
 
209
210
  const PERIODIC_HELP: Record<string, string> = {
210
- 'full sync': 'pulls the job folders of the clusters that have unfinished jobs (rsync), then updates the index of the jobs page for what changed. Not a database sync.',
211
- book_keeping: 'hourly: full rsync of each cluster, accounting of the finished jobs, then removal of their folders on the cluster',
211
+ 'full sync': 'pulls the job folders of the cluster while it has unfinished jobs (rsync), then updates the index of the jobs page for what changed. A slow rsync asks for a book keeping.',
212
+ book_keeping: 'full rsync of the cluster, accounting of the finished jobs, then removal of their folders on the cluster. Also runs when a sync of the cluster is slow.',
213
+ reindex: 'every job folder against the index, then the organizer folders',
212
214
  scheduled_check: 'submits the scheduled jobs that are due',
213
215
  janitor_prune: 'removes the history older than the retention',
214
216
  index: 'every job folder against the index (after the book keeping)',
215
217
  organize: 'the organizer folders (clusters/, experiments/, groups/)',
216
218
  };
217
219
 
218
- const PeriodicCard: React.FC<{ data: JanitorOverview }> = ({ data }) => (
219
- <LinkableCard id="periodic" icon={<LuCalendarClock />} title="Periodic jobs" subtitle="What runs on its own, when it runs next and how its last run went.">
220
- {data.periodic.length === 0 ? <Muted>No periodic job (the server was started without its scheduler).</Muted> : (
221
- <Table.Root size="sm" variant="outline">
222
- <Table.Header>
223
- <Table.Row>
224
- {['Job', 'What it does', 'Every', 'Next run', 'Last run', 'Took', 'Data', 'Status'].map(h => <Table.ColumnHeader key={h}>{h}</Table.ColumnHeader>)}
225
- </Table.Row>
226
- </Table.Header>
227
- <Table.Body>
228
- {data.periodic.map(p => (
229
- <Table.Row key={p.name}>
230
- <Table.Cell>
231
- <Tooltip content={PERIODIC_HELP[p.name] || p.name} showArrow>
232
- <Text fontFamily="mono" fontSize="xs">{p.name}</Text>
233
- </Tooltip>
234
- </Table.Cell>
235
- <Table.Cell fontSize="xs" color="var(--color-text-muted)" maxW="380px">{PERIODIC_HELP[p.name] || '—'}</Table.Cell>
236
- <Table.Cell>{p.interval ? formatDuration(p.interval) : p.id ? 'when due' : '—'}</Table.Cell>
237
- <Table.Cell fontSize="xs">{p.next_run ? <Tooltip content={when(p.next_run)} showArrow><span>{ago(p.next_run)}</span></Tooltip> : '—'}</Table.Cell>
238
- <Table.Cell fontSize="xs">{p.last ? <Tooltip content={when(p.last.ended)} showArrow><span>{ago(p.last.ended)}</span></Tooltip> : 'never'}</Table.Cell>
239
- <Table.Cell>{formatDuration(p.last?.duration)}</Table.Cell>
240
- <Table.Cell fontSize="xs"><Bytes bytesIn={p.last?.bytes_in} bytesOut={p.last?.bytes_out} /></Table.Cell>
241
- <Table.Cell><StatusBadge status={p.last?.status} error={p.last?.error} /></Table.Cell>
220
+ /** The tasks of one name (full sync, book_keeping: one per cluster) as one row */
221
+ interface PeriodicGroup {
222
+ name: string;
223
+ members: JanitorPeriodic[];
224
+ }
225
+
226
+ function groupPeriodic(rows: JanitorPeriodic[]): PeriodicGroup[] {
227
+ const groups = new Map<string, JanitorPeriodic[]>();
228
+ for (const p of rows) groups.set(p.name, [...(groups.get(p.name) ?? []), p]);
229
+ return [...groups.entries()].map(([name, members]) => ({ name, members }));
230
+ }
231
+
232
+ /** The soonest next run, the latest last run, the ones running now */
233
+ function summarize(members: JanitorPeriodic[]) {
234
+ const nexts = members.map(m => m.next_run).filter((t): t is number => !!t);
235
+ const lasts = members.map(m => m.last).filter((l): l is JanitorRun => !!l);
236
+ return {
237
+ next: nexts.length ? Math.min(...nexts) : null,
238
+ requested: members.some(m => m.requested),
239
+ running: members.filter(m => m.running).map(m => m.cluster || m.name),
240
+ last: lasts.length ? lasts.reduce((a, b) => (b.ended > a.ended ? b : a)) : null,
241
+ interval: members[0]?.interval ?? null,
242
+ };
243
+ }
244
+
245
+ const PeriodicCells: React.FC<{ next: number | null; requested: boolean | number | null; running: boolean | string[]; last: JanitorRun | null; interval: number | null }> = ({ next, requested, running, last, interval }) => {
246
+ const runningText = Array.isArray(running) ? (running.length ? `running: ${running.join(', ')}` : '') : (running ? 'running now' : '');
247
+ return (
248
+ <>
249
+ <Table.Cell>{interval ? formatDuration(interval) : 'when due'}</Table.Cell>
250
+ <Table.Cell fontSize="xs">
251
+ {runningText || (next ? <Tooltip content={when(next)} showArrow><span>{requested ? 'asked, ' : ''}{ago(next)}</span></Tooltip> : '—')}
252
+ </Table.Cell>
253
+ <Table.Cell fontSize="xs">{last ? <Tooltip content={when(last.ended)} showArrow><span>{ago(last.ended)}</span></Tooltip> : 'never'}</Table.Cell>
254
+ <Table.Cell>{formatDuration(last?.duration)}</Table.Cell>
255
+ <Table.Cell fontSize="xs"><Bytes bytesIn={last?.bytes_in} bytesOut={last?.bytes_out} /></Table.Cell>
256
+ <Table.Cell><StatusBadge status={last?.status} error={last?.error} /></Table.Cell>
257
+ </>
258
+ );
259
+ };
260
+
261
+ /** One cluster of a per-cluster task: a chip colored by its last run, the details in its tooltip */
262
+ const ClusterChip: React.FC<{ p: JanitorPeriodic }> = ({ p }) => {
263
+ const status = p.running ? 'running' : p.last?.status;
264
+ const tip = [
265
+ p.cluster,
266
+ p.running ? 'running now' : p.next_run ? `next ${p.requested ? '(asked) ' : ''}${ago(p.next_run)}` : 'nothing planned',
267
+ p.last ? `last ${ago(p.last.ended)}, took ${formatDuration(p.last.duration)}: ${p.last.status}` : 'never ran (no job on it)',
268
+ p.last?.error || '',
269
+ ].filter(Boolean).join('\n');
270
+ return (
271
+ <Tooltip content={<Text whiteSpace="pre-line">{tip}</Text>} showArrow>
272
+ <Badge size="xs" variant={p.last || p.running ? 'subtle' : 'outline'}
273
+ colorPalette={status === 'running' ? 'blue' : status ? STATUS_COLORS[status as JanitorStatus] || 'gray' : 'gray'}
274
+ fontFamily="mono">
275
+ {p.cluster}
276
+ </Badge>
277
+ </Tooltip>
278
+ );
279
+ };
280
+
281
+ const PeriodicCard: React.FC<{ data: JanitorOverview }> = ({ data }) => {
282
+ const groups = useMemo(() => groupPeriodic(data.periodic), [data.periodic]);
283
+ return (
284
+ <LinkableCard id="periodic" icon={<LuCalendarClock />} title="Periodic jobs" subtitle="What runs on its own, when it runs next and how its last run went. The sync and the book keeping run per cluster: hover a cluster for its own runs.">
285
+ {groups.length === 0 ? <Muted>No periodic job (the server has not started its background tasks).</Muted> : (
286
+ <Table.Root size="sm" variant="outline">
287
+ <Table.Header>
288
+ <Table.Row>
289
+ {['Job', 'Clusters', 'What it does', 'Every', 'Next run', 'Last run', 'Took', 'Data', 'Status'].map(h => <Table.ColumnHeader key={h}>{h}</Table.ColumnHeader>)}
242
290
  </Table.Row>
243
- ))}
244
- </Table.Body>
245
- </Table.Root>
246
- )}
247
- </LinkableCard>
248
- );
291
+ </Table.Header>
292
+ <Table.Body>
293
+ {groups.map(g => {
294
+ const perCluster = g.members.some(m => m.cluster);
295
+ return (
296
+ <Table.Row key={g.name}>
297
+ <Table.Cell>
298
+ <Tooltip content={PERIODIC_HELP[g.name] || g.name} showArrow>
299
+ <Text fontFamily="mono" fontSize="xs">{g.name}</Text>
300
+ </Tooltip>
301
+ </Table.Cell>
302
+ <Table.Cell maxW="260px">
303
+ {perCluster
304
+ ? <HStack gap={1} flexWrap="wrap">{g.members.map(p => <ClusterChip key={p.id} p={p} />)}</HStack>
305
+ : <Text fontSize="xs" color="var(--color-text-muted)">—</Text>}
306
+ </Table.Cell>
307
+ <Table.Cell fontSize="xs" color="var(--color-text-muted)" maxW="380px">{PERIODIC_HELP[g.name] || '—'}</Table.Cell>
308
+ <PeriodicCells {...summarize(g.members)} />
309
+ </Table.Row>
310
+ );
311
+ })}
312
+ </Table.Body>
313
+ </Table.Root>
314
+ )}
315
+ </LinkableCard>
316
+ );
317
+ };
249
318
 
250
319
  // ─── Runs ───────────────────────────────────────────────────────────
251
320