fix: correct pet needs decay accumulation - #13
Merged
Merged
Conversation
… verbosity - snap needsUpdatedAt to last interval boundary instead of wall clock so sub-interval remainder carries over to the next run - return intervals from calculateDecayedNeeds to support snapping - condense urgent needs check in startExpedition using PET_NEED_KEYS.some Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
🚅 Deployed to the widgetable-pr-13 environment in widgetable
|
…goose subdoc serialization issue Co-Authored-By: Claude Sonnet 4.6 <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.
Issues fixed
1. Pet needs not decaying at all
pet.needsis a Mongoose subdocument — spreading it with{ ...needs }copies internal Mongoose state instead of plain values.calculateDecayedNeedswas computing decay on garbage data and writing the original unchanged values back to the DB. Fixed by extracting a plain object viaPET_NEED_KEYSbefore passing to the function.2. Decay intervals being silently lost
needsUpdatedAtwas saved as wall-clocknew Date()after each decay write, discarding the sub-interval remainder. Under normal 5s polling with any timing jitter, up to 50% of decay intervals could be lost each cycle. Fixed by snappingneedsUpdatedAttolastUpdatedAt + intervals * PET_UPDATE_INTERVALso the remainder carries over to the next run.calculateDecayedNeedsnow returnsintervalsto support this.3. Verbose urgent needs check
The
startExpeditionurgent needs guard used 5 individualifstatements. Condensed to a singlePET_NEED_KEYS.some(...)call.Test plan
/pets/:idor/pets/user