Skip to content

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

fix: read a live runner agent's numeric startedAt through the shared toEpochMs coercion (#3637)

[._.]/ Adam Eivy64d865826fa7
diff --git a/server/lib/gitCommitProbe.js b/server/lib/gitCommitProbe.js
index b308703708..8d88b6e041 100644
--- a/server/lib/gitCommitProbe.js
+++ b/server/lib/gitCommitProbe.js
@@ -57,6 +57,22 @@ export async function commitsSince(workspacePath, sinceMs) {
return Number.isFinite(count) ? count : 0;
}
+/**
+ * Coerce an agent record's `startedAt` to epoch ms, whichever shape it is in.
+ * The in-memory agent maps stamp `Date.now()` (a NUMBER); the persisted record
+ * stamps an ISO string. `Date.parse(1754696324000)` stringifies its argument and
+ * returns NaN, so a bare `Date.parse` silently drops the numeric half — and a
+ * dropped window means the commit probe is skipped for that whole spawn path.
+ *
+ * @returns {number} epoch ms, or NaN when there is no usable timestamp.
+ */
+export function toEpochMs(startedAt) {
+ if (typeof startedAt === 'number') return startedAt;
+ if (typeof startedAt === 'string') return Date.parse(startedAt);
+ if (startedAt instanceof Date) return startedAt.getTime();
+ return NaN;
+}
+
/**
* Boolean form of `commitsSince` — "did this run leave a commit behind?".
* The shape every agent-completion path actually wants.
diff --git a/server/lib/gitCommitProbe.test.js b/server/lib/gitCommitProbe.test.js
index 77958780de..21d619a1b3 100644
--- a/server/lib/gitCommitProbe.test.js
+++ b/server/lib/gitCommitProbe.test.js
@@ -3,7 +3,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('./execGit.js', () => ({ execGit: vi.fn() }));
import { execGit } from './execGit.js';
-import { commitsSince, committedDuringRun } from './gitCommitProbe.js';
+import { commitsSince, committedDuringRun, toEpochMs } from './gitCommitProbe.js';
const SINCE = Date.parse('2026-08-08T18:23:30.000Z');
@@ -69,6 +69,31 @@ describe('commitsSince (#3637)', () => {
});
});
+describe('toEpochMs (#3637)', () => {
+ // The in-memory agent maps stamp `Date.now()` (a number); the persisted record
+ // stamps an ISO string. A bare `Date.parse` silently drops the numeric half —
+ // `Date.parse(1754696324000)` stringifies its argument and returns NaN — which
+ // would skip the commit probe for every live runner/TUI/CLI run.
+ it('passes a numeric epoch through untouched', () => {
+ expect(toEpochMs(1754696324000)).toBe(1754696324000);
+ expect(toEpochMs(0)).toBe(0);
+ });
+
+ it('parses the persisted ISO string', () => {
+ expect(toEpochMs('2026-08-09T00:00:00.000Z')).toBe(Date.parse('2026-08-09T00:00:00.000Z'));
+ });
+
+ it('accepts a Date instance', () => {
+ expect(toEpochMs(new Date(1754696324000))).toBe(1754696324000);
+ });
+
+ it('is NaN for anything unusable, so callers can gate on Number.isFinite', () => {
+ for (const bad of [null, undefined, {}, [], 'not-a-date']) {
+ expect(Number.isFinite(toEpochMs(bad))).toBe(false);
+ }
+ });
+});
+
describe('committedDuringRun (#3637)', () => {
it('is true when the run left at least one commit behind', async () => {
vi.mocked(execGit).mockResolvedValue({ exitCode: 0, stdout: '1\n', stderr: '' });
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index a02e7709d3..42d24f4803 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -50,7 +50,7 @@ import { createToolExecution, startExecution, completeExecution, errorExecution
import { determineLane, acquire, release } from './executionLanes.js';
import { analyzeAgentFailure } from './agentErrorAnalysis.js';
import { createAgentRun } from './agentRunTracking.js';
-import { committedDuringRun } from '../lib/gitCommitProbe.js';
+import { committedDuringRun, toEpochMs } from '../lib/gitCommitProbe.js';
import { buildAgentPrompt, getAppWorkspace } from './agentPromptBuilder.js';
import { isOllamaClaudeProvider, isClaudeCommand, providerSuppliesGithubToken } from '../lib/providerModels.js';
import { canTypeSlashCommands } from '../lib/slashdoInvocation.js';
@@ -1002,7 +1002,9 @@ export async function handleAgentCompletion(agentId, exitCode, success, duration
// Post-execution validation: a non-zero exit that still left a commit inside
// the run's own window DID the work (#3637 — the probe is the window, not a
// task-id commit marker no agent ever emitted).
- const runStartedAt = Date.parse(agent.startedAt);
+ // `runnerAgents` (in-memory) stamps `startedAt: Date.now()` — a NUMBER — while
+ // the persisted record stores an ISO string; toEpochMs handles both.
+ const runStartedAt = toEpochMs(agent.startedAt);
let effectiveSuccess = success;
if (!effectiveSuccess && task?.id) {
const workspacePath = agent.workspacePath || ROOT_DIR;
diff --git a/server/services/agentManagement.js b/server/services/agentManagement.js
index e20154666f..9fcc6e5fc5 100644
--- a/server/services/agentManagement.js
+++ b/server/services/agentManagement.js
@@ -29,7 +29,7 @@ import { isRetryHeld, clearedRetryHoldMetadata } from '../lib/taskRetryHold.js';
import { syncRunnerAgents } from './agentRunnerSync.js';
import { flushRunnerOutputBatcher } from './agentRunnerOutputBatchers.js';
import { completeAgentRun } from './agentRunTracking.js';
-import { committedDuringRun } from '../lib/gitCommitProbe.js';
+import { committedDuringRun, toEpochMs } from '../lib/gitCommitProbe.js';
import { dispatchRecoveredTaskOutputHook } from './agentFinalization.js';
import { PATHS, tryReadFile } from '../lib/fileUtils.js';
import { readHostShutdownMarker, clearHostShutdownMarker, HOST_SHUTDOWN_REASON } from '../lib/hostShutdown.js';
@@ -839,12 +839,9 @@ export async function handleOrphanedTask(taskId, agentId, getTaskByIdFn, { agent
// Scoped to the dead run's OWN window (#3637): the retired task-id commit marker
// was never emitted by anything, and an unbounded `git log` would credit this
// task with any commit in the repo — including another agent's.
- // Accepts both shapes the agent record can carry: the persisted ISO string
- // (`registerAgent`) and a raw epoch-ms number. `Date.parse(1754696324000)`
- // stringifies its argument and returns NaN, so a number MUST NOT go through it.
- const orphanRunStartedAt = typeof agentStartedAt === 'number'
- ? agentStartedAt
- : Date.parse(agentStartedAt);
+ // Both shapes the agent record can carry — the persisted ISO string and a raw
+ // epoch-ms number (see toEpochMs for why a bare Date.parse drops the latter).
+ const orphanRunStartedAt = toEpochMs(agentStartedAt);
const commitFound = Number.isFinite(orphanRunStartedAt)
&& await committedDuringRun(agentMetadata?.workspacePath || ROOT_DIR, orphanRunStartedAt);
if (commitFound) {
diff --git a/server/services/agentManagement.test.js b/server/services/agentManagement.test.js
index 50b31b7666..d1c1e4e991 100644
--- a/server/services/agentManagement.test.js
+++ b/server/services/agentManagement.test.js
@@ -53,7 +53,8 @@ vi.mock('./cosEvents.js', () => ({
emitLog: vi.fn()
}));
-vi.mock('../lib/gitCommitProbe.js', () => ({
+vi.mock('../lib/gitCommitProbe.js', async (importOriginal) => ({
+ ...(await importOriginal()),
committedDuringRun: vi.fn().mockResolvedValue(false),
}));
vi.mock('./agentRunTracking.js', () => ({