eyaltoledano/claude-task-master · error

Invalid run ID: ${id1}

Error message

Invalid run ID: ${id1}

What it means

compareRunIds() is a chronological comparator for run IDs, which are ISO 8601 UTC timestamps (e.g. '2024-01-15T10:00:00.000Z'). It validates id1 via isValidRunId() before comparing and throws if id1 is not a valid timestamp string.

Source

Thrown at packages/tm-core/src/common/utils/run-id-generator.ts:117

/**
 * Compares two run IDs chronologically.
 * Returns a negative number if id1 is earlier, positive if id1 is later, or 0 if equal.
 * Can be used as a comparator function for Array.sort().
 *
 * @param {string} id1 - First run ID to compare
 * @param {string} id2 - Second run ID to compare
 * @returns {number} Negative if id1 < id2, positive if id1 > id2, zero if equal
 * @throws {Error} If either run ID is invalid
 *
 * @example
 * compareRunIds('2024-01-15T10:00:00.000Z', '2024-01-15T11:00:00.000Z') // returns negative number
 * ['2024-01-15T14:00:00.000Z', '2024-01-15T10:00:00.000Z'].sort(compareRunIds)
 * // returns ['2024-01-15T10:00:00.000Z', '2024-01-15T14:00:00.000Z']
 */
export function compareRunIds(id1: string, id2: string): number {
	if (!isValidRunId(id1)) {
		throw new Error(`Invalid run ID: ${id1}`);
	}

	if (!isValidRunId(id2)) {
		throw new Error(`Invalid run ID: ${id2}`);
	}

	// String comparison works for ISO 8601 timestamps
	// because they are lexicographically sortable
	if (id1 < id2) return -1;
	if (id1 > id2) return 1;
	return 0;
}

View on GitHub (pinned to c0c98d367c)

Solutions

  1. Filter the collection before sorting: ids.filter(isValidRunId)
  2. Regenerate the invalid ID with generateRunId()
  3. Check the ID source — if legacy, migrate or parse with parseRunId() which returns null instead of throwing

Example fix

// before
const sorted = runs.map(r => r.id).sort(compareRunIds); // throws on bad id
// after
const ids = runs.map(r => r.id).filter(isValidRunId);
if (ids.length !== runs.length) console.warn('Dropped invalid run IDs');
const sorted = ids.sort(compareRunIds);
Defensive patterns

Strategy: validation

Validate before calling

if (!isValidRunId(id1)) throw new Error(`Cannot compare invalid run ID: ${id1}`);
const sorted = ids.filter(isValidRunId).sort(compareRunIds);

Type guard

function isSortableRunId(id: unknown): id is string {
  return typeof id === 'string' && isValidRunId(id);
}

Try / catch

try {
  return ids.sort(compareRunIds);
} catch (err) {
  if (err.message.startsWith('Invalid run ID')) {
    console.warn('Dropping malformed run IDs:', err.message);
    return ids.filter(isValidRunId).sort(compareRunIds);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling compareRunIds('run-123', validId) with a non-timestamp ID; sorting an array containing null/undefined/legacy IDs via [...ids].sort(compareRunIds); IDs produced by older versions of the generator with a different format.

Common situations: Mixing run IDs from different storage/backends or legacy formats; uninitialized array entries; hand-crafted IDs pasted from logs.

Related errors


AI-assisted analysis of eyaltoledano/claude-task-master@c0c98d367c (2026-08-29). Data as JSON: /api/errors/f81c42c9052bebc3. Report an issue: GitHub.