Feature/quest persistence#412
Open
Kaycee276 wants to merge 2 commits into
Open
Conversation
… automatic daily resets
|
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.



Description
This PR implements persistent file-based storage for the gamification quest system, resolving an issue where agent progress and quest claims were lost on every server restart/deploy (Closes #187 ). It ensures that quest data remains durable using atomic write patterns (similar to the x402 receipt store).
Changes Made
Atomic File Persistence (
quest-persistence.ts):__openStellarQuestStore__and__openStellarQuestCompletions__in-memory structures with disk reads/writes to/.data/quest-progress.json.writeFileSyncto a.tmpextension followed byrenameSyncto the final.jsonpath) to prevent partial file corruption if the process crashes mid-write.Daily Auto-Reset Mechanism:
lastResetDatekey to the schema.dailyscoped quests from the activeStoredQuestlists the first time the file is read after midnight UTC.Idempotent Time-Bound Claim Tracking (
quest-completions.ts):QuestCompletionRecordnow stores theclaimedAttimestamp andquestType.hasClaimedQuestdynamically determines if the quest was completed within the current reset cycle (today fordaily, this week forweekly) preventing agents from double-dipping, while avoiding deletion of historical completion records.Quest History Endpoint:
GET /api/quests/[agentId]/historyendpoint.page,pageSize), returning up to the last 30 completed quests sorted descending by claim time, seamlessly hydrated against staticQUEST_DEFINITIONSand actively tracked subtasks.Comprehensive Testing:
lib/gamification/__tests__/quest-persistence.test.ts.node:fsand running isolated in-memory clears.renameSyncatomic flows and strict UTC midnight time boundary resets using fake timers.Acceptance Criteria Met