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
fix: harden the run-window commit probe against out-of-range epochs, numeric orphan timestamps, and unprefixed coordinator buckets (#3637)
[._.]/ Adam Eivy0c668876183e
diff --git a/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.js b/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.jsindex 325e6a5d9d..9e3a655f48 100644--- a/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.js+++ b/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.js@@ -67,6 +67,12 @@ export const PRESERVED_BUCKETS = new Set(['user-task','self-improve:layered-intelligence', // migration 197...[...NON_COMMITTING_COORDINATOR_TASK_TYPES].map((t) => `self-improve:${t}`), // migration 198+ // The bare form too. extractTaskType prefixes any task carrying an+ // `analysisType`, which a scheduled coordinator always does — but a task typed+ // on `taskType` alone (a shape `isNonCommittingCoordinatorTask` recognizes and+ // exempts) can land in a bucket without the prefix. Purging that would delete+ // honest history for a run the old criterion never judged.+ ...NON_COMMITTING_COORDINATOR_TASK_TYPES,]);/** The buckets this migration would purge from a given `byTaskType` map. Pure. */diff --git a/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.test.js b/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.test.jsindex b531aa00ef..5707b461f3 100644--- a/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.test.js+++ b/scripts/migrations/234-purge-commit-criterion-poisoned-learning-buckets.test.js@@ -103,6 +103,11 @@ describe('234-purge-commit-criterion-poisoned-learning-buckets (#3637)', () => {// must be exempt here too, or this migration would purge its honest history.expect(PRESERVED_BUCKETS.has('self-improve:branch-cleanup')).toBe(true);expect(PRESERVED_BUCKETS.has('self-improve:jira-status-report')).toBe(true);+ // The bare form too: extractTaskType only prefixes a task carrying an+ // `analysisType`, so a coordinator typed on `taskType` alone can land in an+ // unprefixed bucket — and it was exempt from the old criterion either way.+ expect(PRESERVED_BUCKETS.has('branch-reconcile')).toBe(true);+ expect(selectPoisonedBuckets({ 'branch-reconcile': {}, 'auto-fix': {} })).toEqual(['auto-fix']);expect(selectPoisonedBuckets({ 'self-improve:branch-cleanup': {}, 'auto-fix': {} })).toEqual(['auto-fix']);expect(selectPoisonedBuckets(null)).toEqual([]);expect(selectPoisonedBuckets([])).toEqual([]);diff --git a/server/lib/gitCommitProbe.js b/server/lib/gitCommitProbe.jsindex 89f66d8acf..b308703708 100644--- a/server/lib/gitCommitProbe.js+++ b/server/lib/gitCommitProbe.js@@ -34,12 +34,24 @@ import { execGit } from './execGit.js';export async function commitsSince(workspacePath, sinceMs) {if (!workspacePath || typeof workspacePath !== 'string') return 0;if (!Number.isFinite(sinceMs)) return 0;- const since = new Date(sinceMs).toISOString();+ // `Number.isFinite` is not enough: a finite but out-of-range epoch (±1e15)+ // makes `toISOString()` throw RangeError, which would break this function's+ // non-throwing contract on a path that runs outside the request lifecycle.+ const since = new Date(sinceMs);+ if (Number.isNaN(since.getTime())) return 0;// `ignoreExitCode` so a repo with no HEAD resolves to a non-zero exit we can// read as "no commits" rather than rejecting — the house convention for// probe-shaped git calls (see git.js `isRepo` / `getRemote`).- const result = await execGit(['rev-list', '--count', `--since=${since}`, 'HEAD'], workspacePath, { ignoreExitCode: true })- .catch(() => null);+ //+ // `timeout` preserves the retired marker-grep's 10s bound rather than taking+ // execGit's 30s default: this sits on the agent-completion path, and a git+ // wedged on a locked index or a slow network mount must not hold finalize open+ // for half a minute. A timeout rejects, which the catch below reads as 0.+ const result = await execGit(+ ['rev-list', '--count', `--since=${since.toISOString()}`, 'HEAD'],+ workspacePath,+ { ignoreExitCode: true, timeout: 10_000 },+ ).catch(() => null);if (!result || result.exitCode !== 0) return 0;const count = parseInt(result.stdout.trim(), 10);return Number.isFinite(count) ? count : 0;diff --git a/server/lib/gitCommitProbe.test.js b/server/lib/gitCommitProbe.test.jsindex 5f84f01d0b..77958780de 100644--- a/server/lib/gitCommitProbe.test.js+++ b/server/lib/gitCommitProbe.test.js@@ -16,7 +16,7 @@ describe('commitsSince (#3637)', () => {expect(execGit).toHaveBeenCalledWith(['rev-list', '--count', '--since=2026-08-08T18:23:30.000Z', 'HEAD'],'/tmp/ws',- { ignoreExitCode: true }+ { ignoreExitCode: true, timeout: 10_000 });});@@ -49,6 +49,24 @@ describe('commitsSince (#3637)', () => {expect(await commitsSince('/tmp/ws', NaN)).toBe(0);expect(execGit).not.toHaveBeenCalled();});++ // `Number.isFinite` passes these, but `new Date(x).toISOString()` throws+ // RangeError on them — which would break the non-throwing contract on a path+ // that runs outside the request lifecycle.+ it('is 0 (never throws) for a finite but out-of-range epoch', async () => {+ // The Date range is ±8.64e15 ms; beyond it `toISOString()` throws.+ expect(await commitsSince('/tmp/ws', 1e16)).toBe(0);+ expect(await commitsSince('/tmp/ws', -1e16)).toBe(0);+ expect(execGit).not.toHaveBeenCalled();+ });++ // The retired marker grep bounded its git at 10s; execGit's own default is 30s,+ // and this runs on the agent-completion path, so the tighter bound is explicit.+ it('bounds the git call at 10s rather than taking execGit’s 30s default', async () => {+ vi.mocked(execGit).mockResolvedValue({ exitCode: 0, stdout: '0\n', stderr: '' });+ await commitsSince('/tmp/ws', SINCE);+ expect(execGit).toHaveBeenCalledWith(expect.anything(), '/tmp/ws', { ignoreExitCode: true, timeout: 10_000 });+ });});describe('committedDuringRun (#3637)', () => {diff --git a/server/services/agentManagement.js b/server/services/agentManagement.jsindex 562cf7d040..e20154666f 100644--- a/server/services/agentManagement.js+++ b/server/services/agentManagement.js@@ -839,7 +839,12 @@ 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.- const orphanRunStartedAt = Date.parse(agentStartedAt);+ // 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);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.jsindex 1de1d1986d..50b31b7666 100644--- a/server/services/agentManagement.test.js+++ b/server/services/agentManagement.test.js@@ -909,6 +909,21 @@ describe('orphan retries resume what the dead run left behind', () => {expect(updateTask).toHaveBeenCalledWith('task-1', { status: 'completed' }, 'user');});+ // `Date.parse(1754696324000)` stringifies its argument and returns NaN, which+ // would silently skip the probe for any caller holding an epoch-ms start time.+ it('accepts a raw epoch-ms start time, not just the persisted ISO string', async () => {+ committedDuringRun.mockResolvedValueOnce(true);+ getTaskById.mockResolvedValue({ id: 'task-1', taskType: 'user', status: 'in_progress', metadata: {} });++ await handleOrphanedTask('task-1', 'agent-dead', getTaskById, {+ agentMetadata: { workspacePath: '/example-app' },+ agentStartedAt: 1754696324000,+ });++ expect(committedDuringRun).toHaveBeenCalledWith('/example-app', 1754696324000);+ expect(updateTask).toHaveBeenCalledWith('task-1', { status: 'completed' }, 'user');+ });+// Without a run window there is nothing to attribute a commit to — probing an// unbounded `git log` would credit this task with any commit already in the// repo, including another agent's, and complete a task that did nothing (#3637).diff --git a/server/services/agentTuiSpawning.test.js b/server/services/agentTuiSpawning.test.jsindex b0e696fe2f..c3e3ac9122 100644--- a/server/services/agentTuiSpawning.test.js+++ b/server/services/agentTuiSpawning.test.js@@ -1119,7 +1119,7 @@ describe('spawnTuiAgent runtime', () => {expect(gitService.execGit).toHaveBeenCalledWith(['rev-list', '--count', expect.stringMatching(/^--since=\d{4}-/), 'HEAD'],'/tmp/ws',- { ignoreExitCode: true }+ { ignoreExitCode: true, timeout: 10_000 });});