Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
show perpetual drains as bounded runtime bars per recurrence, not one endless band
[._.]/ Adam Eivy11bdd087f7c4
diff --git a/client/src/components/cos/tabs/WorkflowTab.jsx b/client/src/components/cos/tabs/WorkflowTab.jsxindex c8cc9a1c19..c3b0174c79 100644--- a/client/src/components/cos/tabs/WorkflowTab.jsx+++ b/client/src/components/cos/tabs/WorkflowTab.jsx@@ -169,16 +169,27 @@ function TimelineRow({ node, occurrences, windows, timeline, hours, timezone, se<button type="button" onClick={() => onSelect(node.id)} className="relative block min-h-12 overflow-hidden text-left"><TrackGrid divisions={divisions} /><span className="absolute inset-y-0 left-0 z-10 border-l border-port-accent/70" />- {windows.map(window => (- <span- key={window.id}- className="absolute inset-y-2 rounded border border-amber-400/40 bg-gradient-to-r from-amber-500/30 via-amber-400/15 to-amber-500/5"- style={{ left: `${timelinePercent(window.startAt, timeline)}%`, right: `${100 - timelinePercent(window.endAt, timeline)}%` }}- title="Actively draining work; duration depends on the backlog"- >- <span className="absolute left-2 top-1/2 -translate-y-1/2 whitespace-nowrap text-[10px] font-medium text-amber-200"><InfinityIcon className="mr-1 inline h-3 w-3" />draining</span>- </span>- ))}+ {windows.map(window => {+ // A live drain is filled; a future recurrence is a washed-out+ // outline, so "running now" stays distinguishable from "runs then".+ const live = window.state === 'draining';+ const label = `${live ? 'Draining since' : 'Drain starts'} ${formatPoint(window.startAt, hours, timezone)}`;+ return (+ <span+ key={window.id}+ aria-label={label}+ className={`absolute inset-y-2 z-10 flex items-center gap-1 overflow-hidden rounded border px-1 ${live ? 'border-amber-400/50 bg-gradient-to-r from-amber-500/35 to-amber-500/10' : 'border-dashed border-amber-400/35 bg-amber-500/10'}`}+ // `minWidth` over-constrains left/right so the box grows right+ // from its start: an hour is ~4% of a 24h track and under 1% of+ // a 7-day one, which would otherwise render as a hairline.+ style={{ left: `${timelinePercent(window.startAt, timeline)}%`, right: `${100 - timelinePercent(window.endAt, timeline)}%`, minWidth: '1.25rem' }}+ title={`${label} · perpetual: the bar shows a nominal hour, the drain continues while backlog remains`}+ >+ <InfinityIcon className="h-3 w-3 shrink-0 text-amber-200" />+ {live && <span className="truncate text-[10px] font-medium text-amber-200">draining</span>}+ </span>+ );+ })}{occurrences.map(occurrence => {const meta = dueNowMeta(occurrence, node, timezone);// Due-now is an amber FILL, collision a warning RING — kept on separate@@ -388,6 +399,7 @@ export default function WorkflowTab({ apps, providers, providersLoaded }) {<span className="inline-flex items-center gap-1"><span className="h-2.5 w-2.5 rounded-sm bg-cyan-400" /> interval job</span><span className="inline-flex items-center gap-1"><span className="h-2.5 w-2.5 rotate-45 rounded-sm bg-amber-300" /> reset/recheck</span><span className="inline-flex items-center gap-1"><span className="h-2.5 w-2.5 rounded-sm bg-amber-400" /> due now (catch-up)</span>+ <span className="inline-flex items-center gap-1"><span className="h-2.5 w-4 rounded-sm border border-dashed border-amber-400/50 bg-amber-500/15" /> perpetual drain (~1h)</span></div><span className="inline-flex items-center gap-1"><CalendarDays className="h-3 w-3" />{graph.timezone}</span></div>@@ -464,7 +476,7 @@ export default function WorkflowTab({ apps, providers, providersLoaded }) {<div className="flex flex-wrap gap-x-4 gap-y-1 text-[10px] text-gray-600"><span><AlertTriangle className="mr-1 inline h-3 w-3 text-port-warning" />A ring means another launch is within 15 minutes; actual overlap depends on runtime.</span><span><Clock3 className="mr-1 inline h-3 w-3 text-amber-300" />An amber marker at Now means the task is already due (catch-up, first run, or overdue) — it launches on the next check rather than waiting for its next cadence slot.</span>- <span><TimerReset className="mr-1 inline h-3 w-3" />Perpetual bands have no fixed end while backlog remains.</span>+ <span><TimerReset className="mr-1 inline h-3 w-3" />A perpetual task gets one bar per recurrence showing a nominal hour of runtime — the drain keeps going while backlog remains, so a run can outlast its bar. A filled bar at Now means it is draining already.</span></div></div>diff --git a/client/src/components/cos/tabs/WorkflowTab.perpetual.test.jsx b/client/src/components/cos/tabs/WorkflowTab.perpetual.test.jsxnew file mode 100644index 0000000000..6911b9eb4e--- /dev/null+++ b/client/src/components/cos/tabs/WorkflowTab.perpetual.test.jsx@@ -0,0 +1,90 @@+/**+ * A perpetual drain used to paint one band from Now to the horizon, so every+ * perpetual task read as "always running" and its next start was invisible.+ * The server now emits bounded runtime bars; this pins that the row renders+ * them as bounded, positioned bars rather than a full-width fill.+ */++import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';+import { render, screen, cleanup, act } from '@testing-library/react';+import { MemoryRouter } from 'react-router';++const api = {+ getCosWorkflow: vi.fn(),+ updateAppTaskTypeOverride: vi.fn(),+ bulkUpdateAppTaskTypeOverride: vi.fn(),+};+vi.mock('../../../services/api', () => api);++const WorkflowTab = (await import('./WorkflowTab')).default;++const NOW = new Date('2026-08-22T00:00:00Z');+const HOUR = 3600 * 1000;+const LATER = new Date(NOW.getTime() + 6 * HOUR);++const GRAPH = {+ timezone: 'UTC',+ timeline: {+ startAt: NOW.toISOString(),+ endAt: new Date(NOW.getTime() + 24 * HOUR).toISOString(),+ occurrences: [],+ windows: [+ {+ id: 'task:drain:draining:0',+ nodeId: 'task:drain',+ startAt: NOW.toISOString(),+ endAt: new Date(NOW.getTime() + HOUR).toISOString(),+ kind: 'perpetual',+ state: 'draining',+ },+ {+ id: 'task:drain:scheduled:1',+ nodeId: 'task:drain',+ startAt: LATER.toISOString(),+ endAt: new Date(LATER.getTime() + HOUR).toISOString(),+ kind: 'perpetual',+ state: 'scheduled',+ },+ ],+ },+ nodes: [{+ id: 'task:drain',+ kind: 'task',+ label: 'branch-reconcile',+ enabled: true,+ schedule: { type: 'cron', perpetual: true, cronExpression: '0 5 * * 5' },+ totalAppCount: 0,+ }],+ edges: [],+};++const pct = (value) => Number.parseFloat(value);++beforeEach(() => {+ vi.clearAllMocks();+ api.getCosWorkflow.mockResolvedValue(GRAPH);+});+afterEach(cleanup);++describe('WorkflowTab perpetual runtime bars', () => {+ it('bounds each drain to its own window instead of filling the track', async () => {+ await act(async () => {+ render(<MemoryRouter><WorkflowTab apps={[]} providers={[]} /></MemoryRouter>);+ });+ await screen.findByText('branch-reconcile');++ // An hour of a 24h horizon — the old full-horizon band left `right: 0%`.+ const live = screen.getByLabelText(/^Draining since/);+ expect(pct(live.style.left)).toBeCloseTo(0, 3);+ expect(pct(live.style.right)).toBeCloseTo(95.8333, 3);+ expect(live).toHaveTextContent('draining');+ expect(live.title).toMatch(/continues while backlog remains/);++ // The future recurrence sits at its own start, and only the live drain+ // carries the word — a scheduled bar is an outline.+ const upcoming = screen.getByLabelText(/^Drain starts/);+ expect(pct(upcoming.style.left)).toBeCloseTo(25, 3);+ expect(pct(upcoming.style.right)).toBeCloseTo(70.8333, 3);+ expect(upcoming).not.toHaveTextContent('draining');+ });+});diff --git a/server/services/workflow.js b/server/services/workflow.jsindex 81329899d7..70c68ef1b5 100644--- a/server/services/workflow.js+++ b/server/services/workflow.js@@ -22,6 +22,7 @@*/import { getScheduleStatus } from './taskSchedule.js';+import { DEFAULT_PERPETUAL_RECHECK_MS } from './taskScheduleConstants.js';import { AUDIT_TASK_TYPES } from '../lib/auditCatalog.js';import * as autonomousJobs from './autonomousJobs.js';import { checkJobGate, hasGate, getRegisteredGates } from './jobGates.js';@@ -32,6 +33,12 @@ import { getUserTimezone } from './userTimezone.js';const HOUR = 3_600_000;const DAY = 24 * HOUR;const MAX_OCCURRENCES_PER_NODE = 200;+// Nominal runtime drawn for one perpetual drain. A drain has no scheduled end —+// it runs until its work-detector finds nothing actionable — but painting that+// as a band from Now to the horizon made every perpetual task read as "always+// running" and hid the one thing the timeline exists to show: when it next+// starts. One bar per recurrence at a fixed nominal length restores that.+const PERPETUAL_NOMINAL_RUN_MS = HOUR;/*** Stage definitions. `taskTypes` are entries from taskSchedule's tasks map;@@ -283,7 +290,8 @@ export async function getWorkflowGraph({ horizonHours = 24, from = new Date() }/*** Project heterogeneous scheduler definitions onto one clock. Occurrences are- * launch/recheck instants; windows describe work that is currently perpetual.+ * launch/recheck instants; windows are bounded runtime bars for perpetual+ * drains — one at Now when a drain is live, plus one per projected recurrence.* Flexible rotation/on-demand tasks intentionally have neither because the* scheduler does not promise them a wall-clock position.*/@@ -405,20 +413,11 @@ function projectPerpetual(node, startMs, endMs, timezone, occurrences, windows)const perpetual = node.perpetualStatus;const allTrackedAppsParked = perpetual?.trackedAppCount > 0 && perpetual.parkedAppCount === perpetual.trackedAppCount;const draining = node.shouldRun && !perpetual?.globalParked && !allTrackedAppsParked && node.statusReason !== 'perpetual-parked';- if (draining) {- windows.push({- id: `${node.id}:active`,- nodeId: node.id,- startAt: new Date(startMs).toISOString(),- endAt: new Date(endMs).toISOString(),- kind: 'perpetual',- state: 'draining'- });- }// A cron+perpetual task rechecks on its own expression (computePerpetualRecheckAt// derives the park from it); an on-demand one uses `recheckCron`.const recheckCron = node.schedule?.cronExpression || node.schedule?.recheckCron;+ const rechecks = [];if (recheckCron) {appendCronOccurrences({node,@@ -426,28 +425,60 @@ function projectPerpetual(node, startMs, endMs, timezone, occurrences, windows)startMs,endMs,timezone,- target: occurrences,+ target: rechecks,kind: 'recheck'});- return;+ } else {+ const nextRecheckMs = node.nextRunAt ? Date.parse(node.nextRunAt) : NaN;+ const cadence = node.schedule?.recheckIntervalMs || DEFAULT_PERPETUAL_RECHECK_MS;+ if (Number.isFinite(nextRecheckMs)) {+ appendIntervalOccurrences({+ node,+ firstMs: nextRecheckMs,+ cadence,+ startMs,+ endMs,+ timezone,+ target: rechecks,+ kind: 'recheck'+ });+ }}-- const nextRecheckMs = node.nextRunAt ? new Date(node.nextRunAt).getTime() : NaN;- const cadence = node.schedule?.recheckIntervalMs || DAY;- if (Number.isFinite(nextRecheckMs)) {- appendIntervalOccurrences({- node,- firstMs: nextRecheckMs,- cadence,- startMs,- endMs,- timezone,- target: occurrences,- kind: 'recheck'- });+ occurrences.push(...rechecks);++ // Each recurrence gets its own bounded runtime bar, so a perpetual task reads+ // as "starts here, runs about this long" rather than one endless band. A+ // recheck cadence shorter than the nominal run (nothing enforces a minimum)+ // would stack bars straight back into that band, so a recurrence already+ // inside the preceding bar is skipped rather than drawn over it.+ let coveredUntilMs = -Infinity;+ if (draining) {+ windows.push(makePerpetualWindow(node, startMs, endMs, 'draining'));+ coveredUntilMs = startMs + PERPETUAL_NOMINAL_RUN_MS;+ }+ for (const recheck of rechecks) {+ const atMs = Date.parse(recheck.at);+ if (atMs < coveredUntilMs) continue;+ windows.push(makePerpetualWindow(node, atMs, endMs, 'scheduled'));+ coveredUntilMs = atMs + PERPETUAL_NOMINAL_RUN_MS;}}+function makePerpetualWindow(node, atMs, endMs, state) {+ return {+ id: `${node.id}:${state}:${atMs}`,+ nodeId: node.id,+ startAt: new Date(atMs).toISOString(),+ // Nominal, not a promise: the drain runs until its work-detector reports+ // nothing actionable, which may be shorter or longer than the bar.+ endAt: new Date(Math.min(atMs + PERPETUAL_NOMINAL_RUN_MS, endMs)).toISOString(),+ kind: 'perpetual',+ // 'draining' = a drain the scheduler considers live right now;+ // 'scheduled' = a future recurrence that will start a drain.+ state+ };+}+function projectIntervalJob(node, startMs, endMs, timezone, occurrences) {const cadence = node.schedule?.intervalMs;if (!cadence) return;diff --git a/server/services/workflow.test.js b/server/services/workflow.test.jsindex d37f2d8c9e..fa49267cd7 100644--- a/server/services/workflow.test.js+++ b/server/services/workflow.test.js@@ -336,27 +336,81 @@ describe('projectWorkflowTimeline', () => {expect(timeline.occurrences).toEqual([]);});- it('renders an active perpetual task as an open-ended drain window and its reset', () => {+ it('bounds an in-progress drain to a nominal hour instead of the whole horizon', () => {const timeline = projectWorkflowTimeline([{id: 'task:drain', kind: 'task', enabled: true, shouldRun: true,schedule: { type: 'on-demand', perpetual: true, recheckCron: '0 9 * * *' }}], range);- expect(timeline.windows[0]).toMatchObject({ nodeId: 'task:drain', state: 'draining' });+ expect(timeline.windows[0]).toMatchObject({+ nodeId: 'task:drain',+ state: 'draining',+ startAt: '2026-07-09T00:00:00.000Z',+ endAt: '2026-07-09T01:00:00.000Z'+ });expect(timeline.occurrences[0]).toMatchObject({ nodeId: 'task:drain', at: '2026-07-09T16:00:00.000Z', kind: 'recheck' });});- it('does not show an app-scoped perpetual task draining when every tracked app is parked', () => {+ it('gives a parked perpetual task a runtime bar at each recurrence rather than none', () => {const timeline = projectWorkflowTimeline([{id: 'task:drain', kind: 'task', enabled: true, shouldRun: true,perpetualStatus: { globalParked: false, trackedAppCount: 2, parkedAppCount: 2 },schedule: { type: 'on-demand', perpetual: true, recheckCron: '0 9 * * *' }}], range);- expect(timeline.windows).toEqual([]);+ // Parked: no bar at Now, but the projected recurrence still shows when the+ // drain next starts.+ expect(timeline.windows).toEqual([+ expect.objectContaining({ nodeId: 'task:drain', state: 'scheduled', startAt: '2026-07-09T16:00:00.000Z' })+ ]);expect(timeline.occurrences[0]).toMatchObject({ nodeId: 'task:drain', kind: 'recheck' });});+ // Nothing enforces a minimum recheck cadence, so a sub-hourly one would stack+ // 200 overlapping bars — the endless band this change exists to remove.+ it('skips a recurrence whose bar the preceding one already covers', () => {+ const timeline = projectWorkflowTimeline([{+ id: 'task:drain', kind: 'task', enabled: true,+ schedule: { type: 'on-demand', perpetual: true, recheckCron: '*/20 * * * *' }+ }], range);++ // Every 20 minutes over 24h is 72 rechecks; an hour apiece leaves 24 bars.+ expect(timeline.occurrences).toHaveLength(72);+ expect(timeline.windows).toHaveLength(24);+ expect(timeline.windows.slice(0, 2).map(item => [item.startAt, item.endAt])).toEqual([+ ['2026-07-09T00:00:00.000Z', '2026-07-09T01:00:00.000Z'],+ ['2026-07-09T01:00:00.000Z', '2026-07-09T02:00:00.000Z']+ ]);+ });++ it('does not double up a recurrence that lands inside the in-progress drain bar', () => {+ const timeline = projectWorkflowTimeline([{+ id: 'task:drain', kind: 'task', enabled: true, shouldRun: true,+ // Half an hour in, so the bar that opens at Now already covers it.+ nextRunAt: '2026-07-09T00:30:00.000Z',+ schedule: { type: 'on-demand', perpetual: true, recheckIntervalMs: 6 * 60 * 60_000 }+ }], range);++ expect(timeline.windows.map(item => [item.state, item.startAt])).toEqual([+ ['draining', '2026-07-09T00:00:00.000Z'],+ ['scheduled', '2026-07-09T06:30:00.000Z'],+ ['scheduled', '2026-07-09T12:30:00.000Z'],+ ['scheduled', '2026-07-09T18:30:00.000Z']+ ]);+ });++ it('clamps a recurrence bar that would overrun the horizon', () => {+ const timeline = projectWorkflowTimeline([{+ id: 'task:drain', kind: 'task', enabled: true,+ nextRunAt: '2026-07-09T23:40:00.000Z',+ schedule: { type: 'on-demand', perpetual: true, recheckIntervalMs: 24 * 60 * 60_000 }+ }], range);++ expect(timeline.windows).toEqual([+ expect.objectContaining({ startAt: '2026-07-09T23:40:00.000Z', endAt: '2026-07-10T00:00:00.000Z' })+ ]);+ });+it('tags an overdue cron task launch as due-now and carries its reason', () => {const timeline = projectWorkflowTimeline([{id: 'task:weekly', kind: 'task', enabled: true, shouldRun: true,