ui: Add service run history and service DAG state (part 2 of 12)

Closed
SC
12d ago
+643-34

Stack 30/41. Base branch: main. The code here has no caller yet; the callers arrive in parts 3 to 12 of the subject (#3824 to #3834).

Summary

Part 2 of 12 of the service run history work. It adds the UI helpers that later parts use to show the state and the run history of a service DAG, a DAG that runs for years and restarts by itself. It also makes useElementWidth report the content box, the box that ResizeObserver reports.

Changes

  • useElementWidth reports the content box on the first measure and on each resize. Before, it reported the border box.
  • ContinuousPanel subtracts its padding only from the no-layout default, so the samples chart fills the panel.
  • shortRunId shortens scheduler IDs to their UTC date and time:
    • sched-9f8e7d6c5b4a-20261121T090000: sched-9f before, 1121-090000 after
    • restart-1a2b3c4d5e6f-20261108T150405: restart- before, 1108-150405 after
  • dagSchedule: restartsByItself, hasActiveServiceRun (with the 5-minute not-started window of spec 080), getRestartAfterStopSec.
  • useSharedViews merges the workflow and run views of the Workflows page. A save keeps the fields of the other mode.
  • useIsAdminIfSignedIn and useCanManageSkills auth hooks.
  • useServiceDAGsSSE takes a remote node; useDAGsListSSE takes activityWindow.
  • monaco-look shares the editor font, wrap and Unicode-highlight options.
  • AI navigation labels in English, Japanese and Chinese.

Core change

useElementWidth reads the content box both times: from clientWidth less the padding on the first measure, then from the ResizeObserver entry. The panel uses that measure as is, and subtracts its padding only from the default. A scheduler ID becomes its date and time, because the hash is the same for every run of a DAG in most schemes.

// ui/src/hooks/useElementWidth.ts:30-36
const read = (next: number) => setWidth(next > 0 ? next : null);
read(contentWidth(element));
if (typeof ResizeObserver !== 'function') return;
const observer = new ResizeObserver((entries) => {
  const entry = entries[entries.length - 1];
  read(entry ? entry.contentRect.width : contentWidth(element));
});

// ui/src/features/workflow-workspace/continuous/ContinuousPanel.tsx:111-113
// The measure is the content box; the default is the whole panel.
const chartWidth =
  useElementWidth(rootRef) ?? DEFAULT_WIDTH_PX - PANEL_PAD_PX;

// ui/src/lib/shortRunId.ts:8-9, 21-24
const SCHEDULER_ID =
  /^(?:sched|restart|catchup|oneoff)-([0-9a-f]{6,})(?:-\d{4}(\d{4})T(\d{6}))?$/;
    const [, hash = '', date, time] = scheduled;
    return date && time
      ? `${date}-${time}`
      : hash.slice(0, SHORT_RUN_ID_LENGTH);

Testing

  • ContinuousPanel.test.tsx, "fills the measured width of the panel": failed before the panel fix (208 points instead of 214).
  • shortRunId.test.ts: the restart, schedule and daily-schedule cases failed before the ID change.
  • pnpm exec vitest run on the ContinuousPanel, shortRunId, SSEManager, useElementWidth and RunTimeline tests: 160 passed.
  • pnpm typecheck, plus eslint and prettier --check on the changed files.

Performance

No performance risk: the change adds no polling, SSE topic, timer or persisted data. useElementWidth keeps one ResizeObserver per element and adds one computed-style read per mount.

Review guide

  • Mechanical: i18n/messages.ts, and the clientWidth stubs in RunTimeline.test.tsx.
  • Needs judgment: the useElementWidth contract. Its other callers now get their inner width:
    • TimelineChart's frame loses its 1px borders.
    • The canvas toolbar row loses its px-2 before the compact threshold.
    • RunTimeline's frame has no padding and does not change.

Out of scope

  • The callers of the new hooks and helpers (#3824 to #3834).
  • hasActiveServiceRun reads queuedAt or startedAt, while the server reads CreatedAt (internal/runtime/manager.go:642). DAGRunSummary has no createdAt, so matching them needs an API field. That goes with the first caller.
  • Part 7's SamplesPanel.test.tsx expects the old aaaa-113000 form. It needs 1108-113000 when that part is rebased.

Summary by cubic

Adds the UI groundwork for the service run history and service DAG state (part 2 of 12), so the Workflows list, page header, and run timeline can reflect whether a service is active.

  • New useSharedViews hook merges the workflow and run views of the Workflows page; saving a view keeps the fields of the other mode untouched.
  • useElementWidth now reports the content box width, matching what ResizeObserver sends, instead of the border box.
  • New dagSchedule helpers decide when a service DAG has an active run (including the 5-minute not-started window of spec 080) and when a stopped run restarts; shortRunId drops the shared scheme from scheduler restart, catchup, and oneoff run IDs.
  • New useCanManageSkills and useIsAdminIfSignedIn auth hooks; managing skills and notifications requires a server-wide developer role.
  • SSEManager maps the /events/service-dags endpoint, and useServiceDAGsSSE accepts a remote node.
  • New monaco-look module shares editor font, word-wrap, and unicode-highlight options; i18n adds AI navigation labels in English, Japanese, and Chinese.

Summary by CodeRabbit

  • New Features
    • Added a unified view for workflow and run views, with sorting and support for creating, updating, and deleting views.
    • Added service-DAG status and restart information, including support for updates from remote nodes.
    • Added permission checks for administrator access and skill management.
    • Added clearer short IDs for scheduled, catchup, and one-off runs.
  • Improvements
    • Improved editor sizing to account for padding.
    • Added translated navigation labels and AI section descriptions in English, Simplified Chinese, and Japanese.