fix(votes): persist upvote counts reliably across merge and hook dispatch - #565
Merged
Merged
Conversation
…atch
Two independent defects caused team-wide upvote counts to stay at 0
while recall counts accumulated normally:
- mergeDeltas merged upvoted_count via remote+delta but last_upvoted_at
via max(local,remote), producing orphan timestamps (count 0 with a
last_upvoted_at set). Now clears the timestamp when the merged count
is 0, and recallFeedback clears last_upvoted_at when a downvote brings
the count to 0. Prevents the inconsistent state from propagating.
- parseStdin returned null on malformed STDIN, short-circuiting the
entire hook dispatch so votes-sync (and other handlers) never ran when
a concurrent hook delivered corrupt STDIN. Now degrades to {} and
continues; handlers that need STDIN fields self-skip. Also normalizes
valid-but-non-object JSON (null/number/array) and logs a diagnostic
preview of the unparseable payload.
Adds unit tests for both paths.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Team-wide upvote counts were stuck at 0 while recall counts accumulated normally. Investigation across 20 members' vote data (3433 recalls, 19/20 members with
upvoted_count=0) traced this to two independent defects in the vote persistence path. This PR fixes both.1.
mergeDeltastimestamp/count inconsistency (src/votes.ts)mergeDeltasmergedupvoted_countasremote + deltabutlast_upvoted_atasmax(local, remote). Whenupvoted_delta === 0(recall without upvote) and remote count was 0, the result was an orphan state:upvoted_count: 0with alast_upvoted_atset. Confirmed against real team data (e.g. 11 such entries in one member's file).last_upvoted_atwhenupvoted_count === 0and resetlast_recalled_atwhenrecalled_count === 0.recallFeedbacknow clearslast_upvoted_atwhen a downvote brings the count to 0, closing the source of dirty data.2. Hook dispatch short-circuit on malformed STDIN (
src/hook-dispatch-cli.ts)parseStdinreturnednullon unparseable STDIN, which madehookDispatchClireturn early and skip every handler — includingvotes-sync. Under concurrent hook invocations some processes received truncated/corrupt STDIN, so vote sync silently never ran.{}and continue dispatch; handlers that need STDIN fields (e.g.votes-syncrequirestranscript_path) self-skip, while STDIN-independent handlers still run.null/ number / array) so it also degrades cleanly instead of throwing.Scope note
These fixes make accumulated vote data consistent and stop the dispatch from being silently dropped, but they do not by themselves start upvote accumulation on installs that predate the collection-path fix (
4567e02, first inv0.22.0-beta.3). They also cannot recover the upvote from the specific invocation whose STDIN was corrupted. Teams on older CLIs still need to upgrade to>= v0.22.0-beta.3.Test Plan
npx vitest run— 3081 passed, no regressionsnpx tsc --noEmit— cleanmergeDeltas(upvote→0, recall→0, positive-count preservation),recallFeedbacknegative→0,parseStdin(malformed / empty / valid / non-object JSON)mergeDeltas— dirty timestamp cleared, normal upvote path unaffectedhook-dispatch stop— exits 0, no crash, diagnostic logged, downstream handlers reached🤖 Generated with Claude Code