okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge main (87dfca0e7) into f-own-int: the 0.2.14 app branch, fixtures and CI fixes, the Qwen4-readiness tools, the shape-engine build scriptsffb3d9b31

main
3.0 KiB46 linesraw
1import type { NativeJob } from './native';
2
3/** What the host says about a job a restart cut short. */
4export const INTERRUPTED = 'The host restarted before completion. Check diagnostics, then retry; completed files are kept.';
5const updateKinds = new Set(['update-strata', 'update-engine']);
6
7/**
8 * A later finished update of the same component settles the restart interruption of an earlier one (ported from #3578 by medking82).
9 * The records are never changed: a running retry, another component or an ordinary failure stays a plain failure.
10 */
11export function recoveredInterruptions(jobs: readonly NativeJob[]): Set<string> {
12  const time = (job: NativeJob) => Date.parse(job.startedAt);
13  return new Set(jobs.filter(job => job.state === 'error' && updateKinds.has(job.kind) && job.error === INTERRUPTED && Number.isFinite(time(job))
14    && jobs.some(later => later.state === 'done' && later.kind === job.kind && Number.isFinite(time(later)) && time(later) > time(job))).map(job => job.id));
15}
16
17/** The text of a failed job's alert. The alert stays red; an interruption a later update has settled says so in plain words. */
18export function jobErrorText(job: NativeJob, jobs: readonly NativeJob[]): string {
19  return recoveredInterruptions(jobs).has(job.id)
20    ? 'This update was cut short when the app restarted. A later update finished, so nothing needs doing.'
21    : job.error ?? job.summary;
22}
23
24/**
25 * The failed update Settings > About shows under its buttons: per component, the last failed one, and only while no later update of the same
26 * component has finished. A failure a later update made right (the first-run engine card’s “A model is running … then press Continue”
27 * after Continue installed the engine, QAGUI-STRIX 11-09) is history: it stays in Diagnostics, not in About. Jobs are kept across restarts
28 * (native-jobs.json), so without this the line stayed there for good.
29 */
30export function currentUpdateFailure(jobs: readonly NativeJob[]): NativeJob | undefined {
31  const time = (job: NativeJob) => Date.parse(job.startedAt);
32  const failures = jobs.filter(job => job.state === 'error' && updateKinds.has(job.kind)
33    && !jobs.some(later => later.state === 'done' && later.kind === job.kind && Number.isFinite(time(later)) && (!Number.isFinite(time(job)) || time(later) > time(job))));
34  return failures.at(-1);
35}
36
37/**
38 * A Strata or engine update that finished after the update check shown was made: that check is out of date (it still says “Update available”,
39 * and its cache is keyed to the Control version that runs until a restart). Settings > About then checks again. The job’s id, or undefined.
40 */
41export function updateFinishedAfter(jobs: readonly NativeJob[], checkedAt: string | undefined): string | undefined {
42  const checked = Date.parse(checkedAt ?? '');
43  if (!Number.isFinite(checked)) return undefined;
44  const ended = (job: NativeJob) => Date.parse((job as NativeJob & { finishedAt?: string }).finishedAt ?? job.startedAt);
45  return jobs.filter(job => job.state === 'done' && updateKinds.has(job.kind) && ended(job) > checked).at(-1)?.id;
46}