Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

Menu bar "Failing — N jobs" counts jobs that are disabled in PULSE.toml

Open bak3r opened this issue 2 months ago • 1 comments

What happens

Since #1768, Pulse prunes state.jobs entries for jobs removed from the config. That fix deliberately keeps history for jobs that are only enabled = false, so that re-enabling a job doesn't reset it. That's a sensible choice.

The menu bar still counts every entry in state.jobs:

// LIFEOS/PULSE/modules/menubar.ts:129
const failingJobs = Object.values(jobs).filter((j: any) => (j?.consecutiveFailures ?? 0) >= 3).length

So if a job reaches 3 failures and you then disable it, the badge shows red "Failing" permanently. The counter never resets, because a disabled job never runs again. On my install the badge reported 3 failing jobs for 54 days, all of them disabled on purpose. /healthz already applies the enabled-only rule, so the two surfaces disagree.

menubar.ts reads only state.json and can't see which jobs are enabled.

Fix

At boot, Pulse writes the enabled job names into state, and the menu bar counts failures only for those. State files written before this change have no enabledJobs key, so the menu bar falls back to the old behaviour instead of showing zero.

--- a/LifeOS/install/LIFEOS/PULSE/lib.ts
+++ b/LifeOS/install/LIFEOS/PULSE/lib.ts
@@ -89,5 +89,11 @@
 export interface DaemonState {
   version: 1
   jobs: Record<string, JobState>
   startedAt: number
+  /**
+   * Names of jobs currently enabled in config, written at boot. state.jobs keeps
+   * history for disabled jobs (#1768), so readers that only have state.json need
+   * this to tell a real failure from a disabled job's leftover counter.
+   */
+  enabledJobs?: string[]
 }
--- a/LifeOS/install/LIFEOS/PULSE/pulse.ts
+++ b/LifeOS/install/LIFEOS/PULSE/pulse.ts
@@ -671,2 +671,8 @@
   const enabledJobs = config.jobs.filter((j) => j.enabled)
+  // Publish the enabled set so state-only readers can ignore leftover
+  // counters from switched-off jobs.
+  state.enabledJobs = enabledJobs.map((j) => j.name)
+  // Persist now: state is otherwise only written after a job RUNS, so a freshly
+  // booted daemon would serve a stale badge until the first tick.
+  await writeState(STATE_PATH, state).catch(() => {})
--- a/LifeOS/install/LIFEOS/PULSE/modules/menubar.ts
+++ b/LifeOS/install/LIFEOS/PULSE/modules/menubar.ts
@@ -129 +129,9 @@
-    const failingJobs = Object.values(jobs).filter((j: any) => (j?.consecutiveFailures ?? 0) >= 3).length
+    // Only ENABLED jobs can be "failing". state.jobs keeps history for disabled
+    // jobs (#1768). Same rule /healthz applies. Older state files have no
+    // enabledJobs key; fall back to counting everything rather than zero.
+    const enabled: string[] | undefined = Array.isArray(st.enabledJobs) ? st.enabledJobs : undefined
+    const failingJobs = Object.entries(jobs).filter(
+      ([name, j]: [string, any]) =>
+        (enabled === undefined || enabled.includes(name)) && (j?.consecutiveFailures ?? 0) >= 3,
+    ).length

Not covered

When the Pulse API can't be reached, the Swift app's offline fallback (MenuBar/PulseMenuBar.swift:152) reads state.json itself and has the same count. The same one-line filter on enabledJobs would fix it there. I haven't changed or tested the Swift side.

Verified

This has run on my install since 2026-08-26. state.json now carries enabledJobs (8 of 12 jobs), and /api/menubar reports failingJobs: 0. Before the change, the badge read "Failing — 3 jobs" for jobs that were disabled.

bak3r avatar Sep 21 '26 05:09 bak3r

Thanks @bak3r. Pulse now writes the enabled job names into state at boot. The menu bar counts failures only for those jobs, falling back to the old count for state files written before the change (LIFEOS/PULSE/modules/menubar.ts, with a test). Next release carries it.

danielmiessler avatar Oct 03 '26 04:10 danielmiessler