Skip to content

Commit ff4ffa6

Browse files
committed
docs: update files.md, changelog.md, task.md for token double-counting fix (#32)
1 parent c8d33ed commit ff4ffa6

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ Format based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
### Fixed
10+
11+
- Fixed token double-counting bug in message handlers (fixes #32)
12+
- Message handlers (upsert, batchUpsert) were accumulating per-message promptTokens/completionTokens onto the session record
13+
- Since session-level sync already sets these as authoritative absolute values, the accumulation resulted in inflated token totals
14+
- Removed all token accumulation from message handlers
15+
- Session tokens are now set exclusively by session-level sync (the authoritative source)
16+
- Message handlers only update messageCount and searchableText
17+
- Co-authored-by: Shah (Shahfarzane)
18+
919
### Added
1020

1121
- Batch deletion system with reactive UI progress tracking (fixes #30)

files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Backend functions and schema.
3030
| `convex.config.ts` | Convex app configuration |
3131
| `users.ts` | User queries/mutations: getOrCreate, me (returns enabledAgents with cursor->cursor-sync normalization, deletionStatus/deletionProgress for reactive UI), stats, API key management, updateEnabledAgents (normalizes cursor->cursor-sync), deleteAllData (initiates batch deletion via orchestrateBatchDeletion), deleteAccount (initiates batch deletion then deletes WorkOS account), clearDeletionStatus. Batch deletion system: orchestrateBatchDeletion (internalAction orchestrator), updateDeletionStatus, deletePartsBatch, deleteMessagesBatch, deleteSessionsBatch, deleteSessionEmbeddingsBatch, deleteMessageEmbeddingsBatch, deleteDailyWrappedBatch, deleteApiLogsBatch, deleteUserRecord, initiateDeletion. All batch mutations use BATCH_SIZE=200 to stay under 4096 read limit. |
3232
| `sessions.ts` | Session CRUD: list, get, getPublic, setVisibility, remove, getMarkdown, upsert (with 10s dedup window, idempotency, cursor->cursor-sync normalization), batchUpsert (with source normalization), listExternalIds, exportAllDataCSV |
33-
| `messages.ts` | Message mutations: upsert (with 5s dedup, combined session patch, parallel parts ops, cursor->cursor-sync normalization), batchUpsert for bulk sync (with source normalization) |
33+
| `messages.ts` | Message mutations: upsert (with 5s dedup, combined session patch, parallel parts ops, cursor->cursor-sync normalization), batchUpsert for bulk sync (with source normalization). Message handlers only update messageCount and searchableText on sessions; token values (promptTokens, completionTokens, totalTokens) are set exclusively by session-level sync to avoid double-counting (fixes #32). |
3434
| `analytics.ts` | Analytics queries with source filtering: dailyStats, modelStats, projectStats, providerStats, summaryStats, sessionsWithDetails, sourceStats, publicPlatformStats (no auth, for homepage leaderboard, limited to last 1000 sessions with null-safe token handling), publicMessageCount (no auth, uses async iteration for large datasets), publicMessageGrowth (no auth, daily growth with cumulative totals, uses async iteration to avoid 16MB read limit). Includes inferProvider helper with OAuth provider normalization (antigravity-oauth to google, anthropic-oauth to anthropic) and model-based provider detection (including Codex models mapped to openai) |
3535
| `search.ts` | Full-text and semantic search: searchSessions, searchSessionsPaginated, searchMessages, searchMessagesPaginated, semanticSearch, hybridSearch, semanticSearchMessages, hybridSearchMessages |
3636
| `embeddings.ts` | Vector embedding generation with idempotency checks and replace pattern for session-level and message-level semantic search |

task.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ OpenSync supports two AI coding tools: **OpenCode** and **Claude Code**.
88

99
- [ ] (add next task here)
1010

11+
## Recently Completed (Token Double-Counting Fix - Issue #32, PR #33)
12+
13+
- [x] Fixed token double-counting bug in message handlers
14+
- Root cause: messages.upsert and messages.batchUpsert were accumulating per-message promptTokens/completionTokens onto the session record
15+
- Session-level sync already sets absolute token values, so accumulation caused inflated totals
16+
- Removed sessionPromptTokens/sessionCompletionTokens variables from both mutations
17+
- Removed token accumulation calculations (newPromptTokens, newCompletionTokens, totalPromptTokens, totalCompletionTokens)
18+
- Removed token fields from session patch operations
19+
- Message handlers now only update messageCount and searchableText
20+
- Session tokens set exclusively by sessions.upsert (authoritative source from CLI plugins)
21+
- Co-authored fix with Shah (Shahfarzane) from PR #33
22+
1123
## Recently Completed (Batch Deletion System - Issue #30)
1224

1325
- [x] Fixed "Too many reads in a single function execution" error in deleteUserData

0 commit comments

Comments
 (0)