[Bug] RatingCapture: explicit ratings stored without `source` field — trending.json shows explicit=0
Summary
When a user submits an explicit rating (e.g., 9, 8 - great work), RatingCapture.hook.ts writes the JSONL entry without a source field. As a result, trending.json always reports explicit: { count: 0, avg: null } even when explicit ratings have been submitted.
Root Cause
Implicit path — correctly sets source:
// Line 454-461 — implicit entry
const entry: RatingEntry = {
timestamp: getISOTimestamp(),
rating: sentiment.rating,
session_id: data.session_id,
source: 'implicit', // ✅ set
sentiment_summary: sentiment.summary,
confidence: sentiment.confidence,
};
Explicit path — missing source:
// Line 371-376 — explicit entry
const entry: RatingEntry = {
timestamp: getISOTimestamp(),
rating: explicitResult.rating,
session_id: data.session_id,
// ❌ source field not added
};
if (explicitResult.comment) entry.comment = explicitResult.comment;
The writeRating() function has the classification logic (entry.source === 'implicit' ? 'implicit' : 'explicit') but only for logging purposes — it doesn't fix the missing field in the stored JSON.
Type definition also incomplete:
interface RatingEntry {
source?: 'implicit'; // ← 'explicit' not even in the union type
}
Impact
trending.jsonby_source.explicitis always{ count: 0, avg: null }- All user explicit ratings are "unclassified" (no source field in JSONL)
- Quality signal from deliberate user ratings is invisible to the learning system
- Distribution stats mix explicit and implicit ratings without proper segmentation
Proposed Fix
-
Update
RatingEntryinterface to include'explicit':interface RatingEntry { source?: 'implicit' | 'explicit'; } -
Add
source: 'explicit'to the explicit rating entry:const entry: RatingEntry = { timestamp: getISOTimestamp(), rating: explicitResult.rating, session_id: data.session_id, source: 'explicit', // ← add this };
Evidence
Example of affected records in MEMORY/LEARNING/SIGNALS/ratings.jsonl:
// Old implicit records — correctly tagged:
{"timestamp":"...","rating":5,"session_id":"abc","source":"implicit","sentiment_summary":"...","confidence":0.8}
// New explicit records — missing source:
{"timestamp":"...","rating":9,"session_id":"def","comment":"great work"}
{"timestamp":"...","rating":8,"session_id":"ghi"}
And in trending.json:
"by_source": {
"explicit": { "count": 0, "avg": null }, // ← always 0 despite explicit ratings submitted
"implicit": { "count": 108, "avg": 5.19 }
}
Related
- Issue #769 covers
TrendingAnalysis.tsmissing — this is a separate upstream data issue inRatingCapture.hook.tsitself
Fixed in v4.0.2 — added 'explicit' to the source union type and explicit ratings now include source: 'explicit' in the entry. Thanks for catching this!