Skip to content

Conversation

@twells46
Copy link
Contributor

@twells46 twells46 commented Jan 15, 2026

The issue #627 "Challenge Event Updates at program end" was caused by the scheduleSaveChallengeCompletion_ method in src/pages/ChallengeRoot.tsx. This method implemented a naive throttling mechanism that would simply drop save requests if they occurred within 1 second of the previous save.

When a program ends, it triggers event updates (e.g., challenge success) and scene synchronization almost simultaneously. If a save had occurred recently (e.g., from an earlier event or auto-save), these final updates would be dropped and never saved to the database, causing the challenge completion to be lost.

I have fixed this by:

  • Refactoring scheduleSaveChallengeCompletion_ to use a throttle with trailing execution pattern. Now, if a save is requested too soon, it schedules a timeout to execute the save as soon as the throttle period expires. This ensures that the latest state is always eventually saved.
  • Adding a cleanup step in componentWillUnmount to flush any pending saves immediately when the user navigates away or the component is unmounted, preventing data loss on exit.

Fixes #627.

Open in Cursor Open in Web

- Implement proper throttle with trailing execution for challenge completion saving
- Flush pending saves on unmount
- Fixes #627

Co-authored-by: twells <twells@kipr.org>
@cursor
Copy link

cursor bot commented Jan 15, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@twells46
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Challenge Event Updates at program end

3 participants