File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import type { CronJob, ModelAuthStatusResult } from "../api/types.ts";
55import type { NavigationRouteId } from "../app-navigation.ts" ;
66import type { ExecApprovalRequest } from "../app/exec-approval.ts" ;
77import { t } from "../i18n/index.ts" ;
8- import { isCronJobActiveFailure } from "../lib/cron-status.ts" ;
8+ import { isCronJobActiveFailure , isCronJobRunning } from "../lib/cron-status.ts" ;
99import { clampText } from "../lib/format.ts" ;
1010import { isMonitoredAuthProvider } from "../lib/model-auth.ts" ;
1111import 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 ) ;
Original file line number Diff line number Diff 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
158174describe ( "pending approval attention" , ( ) => {
Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change @@ -36,7 +36,11 @@ import {
3636 renderSettingsToggleRow ,
3737} from "../../components/settings-ui.ts" ;
3838import { 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" ;
4044import { parseCronEveryMs } from "../../lib/cron/decimal.ts" ;
4145import 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
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments