[PR #194] [MERGED] fix: include comment deltas in stat processing & add stats reconciliation #290

Closed
opened 2026-02-15 17:16:41 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/openclaw/clawhub/pull/194
Author: @Limitless2023
Created: 2/11/2026
Status: Merged
Merged: 2/12/2026
Merged by: @steipete

Base: mainHead: fix/skill-stats-not-updating


📝 Commits (1)

  • 84d56d0 fix: include comment deltas in action-based stat processing & add stats reconciliation

📊 Changes

3 files changed (+208 additions, -0 deletions)

View changed files

convex/skillStatEvents.test.ts (+110 -0)
📝 convex/skillStatEvents.ts (+2 -0)
📝 convex/statsMaintenance.ts (+96 -0)

📄 Description

Summary

Fixes #193 — Stars and downloads not showing on skill page.

Root Cause Analysis

Bug 1: Comment deltas silently dropped in action-based processing

In applyAggregatedStatsAndUpdateCursor (the cron-driven stat processing path), the comments delta was missing from:

  1. The guard condition — comment-only batches would skip the db.patch entirely:

    // Before (missing comments):
    if (delta.downloads !== 0 || delta.stars !== 0 || delta.installsAllTime !== 0 || delta.installsCurrent !== 0)
    
    // After (fixed):
    if (delta.downloads !== 0 || delta.stars !== 0 || delta.comments !== 0 || delta.installsAllTime !== 0 || delta.installsCurrent !== 0)
    
  2. The applySkillStatDeltas call — even when the patch ran, comment deltas were never passed through.

Note: The older mutation-based processSkillStatEventsInternal correctly handles comments; only the newer action-based path (used by the cron) had this bug.

Bug 2: No stats reconciliation mechanism

If events are missed for any reason (cursor drift, processing errors, race conditions), stats remain permanently stale. There was no way to recover without manual database intervention.

Changes

File Change
convex/skillStatEvents.ts Added comments to guard condition and applySkillStatDeltas call
convex/statsMaintenance.ts Added reconcileSkillStarCounts mutation + runReconcileSkillStarCountsInternal action
convex/skillStatEvents.test.ts Regression tests for comment delta handling

Reconciliation Tool

The new reconcileSkillStarCounts maintenance mutation:

  • Iterates all skills in batches
  • Counts actual records in stars and comments tables
  • Patches any skills where stats.stars or stats.comments differ from actual counts
  • Can be run manually or scheduled as a one-time fix

Testing

  • Unit tests verify comment delta aggregation and the guard condition regression
  • The reconciliation function uses existing indexes (stars.by_skill_user, comments.by_skill)

Greptile Overview

Greptile Summary

Fixed critical bug where comment deltas were silently dropped in the action-based stat processing path (applyAggregatedStatsAndUpdateCursor), preventing comment counts from updating on skill pages. The fix adds comments to both the guard condition and the applySkillStatDeltas call.

Key changes:

  • convex/skillStatEvents.ts:382 - Added delta.comments !== 0 to guard condition so comment-only batches aren't skipped
  • convex/skillStatEvents.ts:389 - Pass comments: delta.comments to applySkillStatDeltas
  • convex/skillStatEvents.test.ts - Added regression tests for comment aggregation and the guard condition bug
  • convex/statsMaintenance.ts - Added reconcileSkillStarCounts mutation and runReconcileSkillStarCountsInternal action to fix stats that got out of sync by counting actual records in stars and comments tables

The mutation-based processing path (processSkillStatEventsInternal) already handled comments correctly - only the newer action-based cron path had this bug.

Confidence Score: 5/5

  • Safe to merge with minimal risk
  • The fix is straightforward and mirrors the existing logic in the mutation-based path. Test coverage validates both the aggregation logic and the guard condition regression. The reconciliation tool provides a recovery mechanism for any existing data corruption.
  • No files require special attention

(2/5) Greptile learns from your feedback when you react with thumbs up/down!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/openclaw/clawhub/pull/194 **Author:** [@Limitless2023](https://github.com/Limitless2023) **Created:** 2/11/2026 **Status:** ✅ Merged **Merged:** 2/12/2026 **Merged by:** [@steipete](https://github.com/steipete) **Base:** `main` ← **Head:** `fix/skill-stats-not-updating` --- ### 📝 Commits (1) - [`84d56d0`](https://github.com/openclaw/clawhub/commit/84d56d0fa1e4de993e1f97526e507bda46a92665) fix: include comment deltas in action-based stat processing & add stats reconciliation ### 📊 Changes **3 files changed** (+208 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `convex/skillStatEvents.test.ts` (+110 -0) 📝 `convex/skillStatEvents.ts` (+2 -0) 📝 `convex/statsMaintenance.ts` (+96 -0) </details> ### 📄 Description ## Summary Fixes #193 — Stars and downloads not showing on skill page. ## Root Cause Analysis ### Bug 1: Comment deltas silently dropped in action-based processing In `applyAggregatedStatsAndUpdateCursor` (the cron-driven stat processing path), the `comments` delta was missing from: 1. **The guard condition** — comment-only batches would skip the `db.patch` entirely: ```ts // Before (missing comments): if (delta.downloads !== 0 || delta.stars !== 0 || delta.installsAllTime !== 0 || delta.installsCurrent !== 0) // After (fixed): if (delta.downloads !== 0 || delta.stars !== 0 || delta.comments !== 0 || delta.installsAllTime !== 0 || delta.installsCurrent !== 0) ``` 2. **The `applySkillStatDeltas` call** — even when the patch ran, comment deltas were never passed through. Note: The older mutation-based `processSkillStatEventsInternal` correctly handles comments; only the newer action-based path (used by the cron) had this bug. ### Bug 2: No stats reconciliation mechanism If events are missed for any reason (cursor drift, processing errors, race conditions), stats remain permanently stale. There was no way to recover without manual database intervention. ## Changes | File | Change | |------|--------| | `convex/skillStatEvents.ts` | Added `comments` to guard condition and `applySkillStatDeltas` call | | `convex/statsMaintenance.ts` | Added `reconcileSkillStarCounts` mutation + `runReconcileSkillStarCountsInternal` action | | `convex/skillStatEvents.test.ts` | Regression tests for comment delta handling | ## Reconciliation Tool The new `reconcileSkillStarCounts` maintenance mutation: - Iterates all skills in batches - Counts actual records in `stars` and `comments` tables - Patches any skills where `stats.stars` or `stats.comments` differ from actual counts - Can be run manually or scheduled as a one-time fix ## Testing - Unit tests verify comment delta aggregation and the guard condition regression - The reconciliation function uses existing indexes (`stars.by_skill_user`, `comments.by_skill`) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Fixed critical bug where comment deltas were silently dropped in the action-based stat processing path (`applyAggregatedStatsAndUpdateCursor`), preventing comment counts from updating on skill pages. The fix adds `comments` to both the guard condition and the `applySkillStatDeltas` call. **Key changes:** - **convex/skillStatEvents.ts:382** - Added `delta.comments !== 0` to guard condition so comment-only batches aren't skipped - **convex/skillStatEvents.ts:389** - Pass `comments: delta.comments` to `applySkillStatDeltas` - **convex/skillStatEvents.test.ts** - Added regression tests for comment aggregation and the guard condition bug - **convex/statsMaintenance.ts** - Added `reconcileSkillStarCounts` mutation and `runReconcileSkillStarCountsInternal` action to fix stats that got out of sync by counting actual records in `stars` and `comments` tables The mutation-based processing path (`processSkillStatEventsInternal`) already handled comments correctly - only the newer action-based cron path had this bug. <h3>Confidence Score: 5/5</h3> - Safe to merge with minimal risk - The fix is straightforward and mirrors the existing logic in the mutation-based path. Test coverage validates both the aggregation logic and the guard condition regression. The reconciliation tool provides a recovery mechanism for any existing data corruption. - No files require special attention <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 17:16:41 -05:00
yindo closed this issue 2026-02-15 17:16:41 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: openclaw/clawhub#290