Skip to content

Commit f9d9b9d

Browse files
authored
fix(ui): stop flagging running automations as overdue and show their state (#123745)
* fix(ui): stop flagging running automations as overdue and show their state The gateway intentionally leaves nextRunAtMs past-due while a run executes (it advances only on the outcome), and agentTurn runs may take up to an hour — 12x the sidebar's 5-minute overdue grace. The overdue chip and the cron table therefore reported healthy in-flight jobs as 'overdue' / 'next run: X minutes ago'. runningAtMs is the recorded fact for an in-flight run (already public and used by the CLI's status), but no UI surface read it. Add the shared isCronJobRunning helper, exclude running jobs from the overdue filter, and render 'Running' in the next-run cell. * test(cron): move running-state row test beside the capped view suite
1 parent 7fb4772 commit f9d9b9d

7 files changed

Lines changed: 58 additions & 3 deletions

File tree

‎ui/src/components/sidebar-attention-items.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { CronJob, ModelAuthStatusResult } from "../api/types.ts";
55
import type { NavigationRouteId } from "../app-navigation.ts";
66
import type { ExecApprovalRequest } from "../app/exec-approval.ts";
77
import { t } from "../i18n/index.ts";
8-
import { isCronJobActiveFailure } from "../lib/cron-status.ts";
8+
import { isCronJobActiveFailure, isCronJobRunning } from "../lib/cron-status.ts";
99
import { clampText } from "../lib/format.ts";
1010
import { isMonitoredAuthProvider } from "../lib/model-auth.ts";
1111
import type { IconName } from "./icons.ts";
@@ -89,6 +89,7 @@ export function buildSidebarAttentionItems(params: {
8989
const overdueCron = params.cronJobs.filter(
9090
(job) =>
9191
job.enabled &&
92+
!isCronJobRunning(job) &&
9293
job.state?.nextRunAtMs != null &&
9394
params.now - job.state.nextRunAtMs > CRON_OVERDUE_GRACE_MS,
9495
);

‎ui/src/components/sidebar-attention.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,22 @@ describe("cron attention details", () => {
153153

154154
expect(overdue?.detail).toBe("Nightly backup\nunnamed-id");
155155
});
156+
157+
it("does not flag an actively running job as overdue", () => {
158+
// The gateway leaves nextRunAtMs past-due during execution; runningAtMs is
159+
// the recorded fact that a run is in flight (agentTurn runs may take up to
160+
// an hour, far beyond the 5-minute overdue grace).
161+
const running = cronJob("running-id");
162+
running.state = { lastRunStatus: "ok", nextRunAtMs: 1, runningAtMs: 2 };
163+
const stalled = cronJob("stalled-id");
164+
stalled.state = { lastRunStatus: "ok", nextRunAtMs: 2 };
165+
166+
const overdue = cronItems([running, stalled], 300_003).find(
167+
(item) => item.kind === "cronOverdue",
168+
);
169+
170+
expect(overdue?.detail).toBe("stalled-id");
171+
});
156172
});
157173

158174
describe("pending approval attention", () => {

‎ui/src/i18n/locales/en.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5839,6 +5839,7 @@ export const en: TranslationMap = {
58395839
runStatusError: "Error",
58405840
runStatusSkipped: "Skipped",
58415841
runStatusUnknown: "Unknown",
5842+
runStatusRunning: "Running",
58425843
deliveryDelivered: "Delivered",
58435844
deliveryNotDelivered: "Not delivered",
58445845
deliveryUnknown: "Unknown",

‎ui/src/lib/cron-status.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ export function resolveCronJobLastRunStatus(job: CronJob): CronJobLastRunStatus
77
return job.state?.lastRunStatus ?? job.state?.lastStatus ?? "unknown";
88
}
99

10+
// The gateway intentionally leaves nextRunAtMs past-due while a run executes
11+
// (it only advances on the outcome), so "overdue" surfaces must not flag a
12+
// job that is actively running. runningAtMs is the recorded fact for that.
13+
export function isCronJobRunning(job: CronJob): boolean {
14+
const runningAtMs = job.state?.runningAtMs;
15+
return typeof runningAtMs === "number" && Number.isFinite(runningAtMs);
16+
}
17+
1018
// "Failed cron" surfaces (cron page, sidebar attention chips) track current
1119
// actionability, so a failure only counts while the job is still enabled.
1220
// Disabled jobs keep their historical `lastRunStatus: "error"` for detail
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Running-state rendering for the Automations (cron) table.
2+
// Lives beside view.test.ts, which sits at the max-lines cap.
3+
import { expect, it } from "vitest";
4+
import {
5+
createCronViewJob as createJob,
6+
renderCronView as renderView,
7+
} from "./view.test-support.ts";
8+
9+
it("shows Running instead of a past-due next-run time while a run executes", () => {
10+
const running = createJob("job-running", {
11+
state: { nextRunAtMs: Date.now() - 600_000, runningAtMs: Date.now() - 60_000 },
12+
});
13+
const container = renderView({ jobs: [running] });
14+
const row = container.querySelector(".cron-table__row");
15+
expect(row?.querySelector(".cron-table__running")?.textContent).toBe("Running");
16+
expect(row?.textContent).not.toContain("ago");
17+
});

‎ui/src/pages/cron/view.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ import {
3636
renderSettingsToggleRow,
3737
} from "../../components/settings-ui.ts";
3838
import { t } from "../../i18n/index.ts";
39-
import { isCronJobActiveFailure, resolveCronJobLastRunStatus } from "../../lib/cron-status.ts";
39+
import {
40+
isCronJobActiveFailure,
41+
isCronJobRunning,
42+
resolveCronJobLastRunStatus,
43+
} from "../../lib/cron-status.ts";
4044
import { parseCronEveryMs } from "../../lib/cron/decimal.ts";
4145
import type {
4246
CronFieldErrors,
@@ -755,7 +759,11 @@ function renderJobRow(job: CronJob, props: CronProps) {
755759
</span>
756760
<span class="cron-table__cell">${formatCronSchedule(job)}</span>
757761
<span class="cron-table__cell">
758-
${hasNextRun ? formatRelativeTimestamp(nextRunAtMs) : t("common.na")}
762+
${isCronJobRunning(job)
763+
? html`<span class="cron-table__running">${t("cron.runs.runStatusRunning")}</span>`
764+
: hasNextRun
765+
? formatRelativeTimestamp(nextRunAtMs)
766+
: t("common.na")}
759767
</span>
760768
<span class="cron-table__cell cron-table__last">${renderLastRunCell(job)}</span>
761769
<span

‎ui/src/styles/cron.css‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@
358358
font-size: var(--control-ui-text-xs);
359359
}
360360

361+
.cron-table__running {
362+
color: var(--accent);
363+
}
364+
361365
.cron-table__cell {
362366
color: var(--text);
363367
font-size: 12.5px;

0 commit comments

Comments
 (0)