Personal_AI_Infrastructure icon indicating copy to clipboard operation
Personal_AI_Infrastructure copied to clipboard

[Bug] RatingCapture: explicit ratings stored without `source` field — trending.json shows explicit=0

Open rikitikitavi2012-debug opened this issue 9 months ago • 1 comments

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.json by_source.explicit is 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

  1. Update RatingEntry interface to include 'explicit':

    interface RatingEntry {
      source?: 'implicit' | 'explicit';
    }
    
  2. 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.ts missing — this is a separate upstream data issue in RatingCapture.hook.ts itself

rikitikitavi2012-debug avatar Feb 22 '26 21:02 rikitikitavi2012-debug

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!

kaimagnus avatar Mar 01 '26 02:03 kaimagnus