Description
In code/js/ai.js, cluster validation assumes every LLM response item has a defined source field. When the model returns a malformed cluster (missing source or source: undefined), c.source.length throws a TypeError and kills the entire GitHub Actions workflow.
This should be treated as an invalid response and trigger the existing retry logic (lines 30-76), not abort execution.
Stack trace:
file:///home/runner/work/NewsBucket/NewsBucket/code/js/ai.js:72
clusters.every((c) => c.count === c.source.length);
^
TypeError: Cannot read properties of undefined (reading 'length')
at file:///home/runner/work/NewsBucket/NewsBucket/code/js/ai.js:72:47
at Array.every (<anonymous>)
at file:///home/runner/work/NewsBucket/NewsBucket/code/js/ai.js:72:13
Affected code (code/js/ai.js, lines 71-75):
const ok = clusters.length > 0 &&
clusters.every((c) => c.count === c.source.length);
if (ok) break;
const why = clusters.length === 0 ? "empty" : "count mismatch";
if (!attempt) console.warn(` ↻ retry 1/1 (${why})`);
Steps to reproduce
- Run
pnpm ai (or the Update news GitHub Actions workflow) against a feed with enough articles from the last 24 hours.
- Wait for the LLM to return parseable JSON where at least one cluster is missing
source or has a non-array source.
- Observe that validation at line 72 throws
TypeError before ok can evaluate to false.
Expected behavior
- A malformed cluster (
source missing, null, or not an array) should fail validation safely.
- The pipeline should enter the retry path (
↻ retry 1/1), same as for empty responses or count mismatches.
- Only after retries are exhausted should it throw an explicit error, never an unhandled
TypeError during validation.
Actual behavior
Array.every() calls c.source.length without checking that source exists.
- A single malformed cluster causes
TypeError: Cannot read properties of undefined (reading 'length').
- The GitHub Actions job fails completely; no retry runs and remaining feeds are never processed.
OS version
Linux Other
Confirmation
Description
In
code/js/ai.js, cluster validation assumes every LLM response item has a definedsourcefield. When the model returns a malformed cluster (missingsourceorsource: undefined),c.source.lengththrows aTypeErrorand kills the entire GitHub Actions workflow.This should be treated as an invalid response and trigger the existing retry logic (lines 30-76), not abort execution.
Stack trace:
Affected code (
code/js/ai.js, lines 71-75):Steps to reproduce
pnpm ai(or theUpdate newsGitHub Actions workflow) against a feed with enough articles from the last 24 hours.sourceor has a non-arraysource.TypeErrorbeforeokcan evaluate tofalse.Expected behavior
sourcemissing,null, or not an array) should fail validation safely.↻ retry 1/1), same as for empty responses or count mismatches.TypeErrorduring validation.Actual behavior
Array.every()callsc.source.lengthwithout checking thatsourceexists.TypeError: Cannot read properties of undefined (reading 'length').OS version
Linux Other
Confirmation