fix(sim): gcEvents drops events still referenced by modifiers/factions/subjects - #40
Merged
Merged
Conversation
…factions/subjects gcEvents() only tracked references from eventLog, empire history, system history, and dynasty chronicle before sweeping state.events. It missed three other live pointers into state.events: RelationModifier.sourceEventId, Faction.historicalEventIds, and SubjectRelation.historicalEventIds. Since grievance modifiers can stay active for 3600 ticks — far longer than the 128-event GC interval — their source event was almost always purged well before the modifier expired, silently corrupting summarizeGrievances()'s oldestAgeTicks (a balance-tuning signal) and dropping the "from [tick] Title" annotation in the exported report. Extends gcEvents' referenced-set collection to include those three pointers before sweeping. Adds Events.test.ts covering all three previously-missed cases plus the baseline "still collects true orphans" behavior.
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
gcEvents()insrc/sim/Events.tssweptstate.eventsusing a "referenced" set built only fromeventLog, per-empire history, per-system recent events, and dynasty chronicle. Three other live pointers intostate.eventswere never counted:RelationModifier.sourceEventIdFaction.historicalEventIdsSubjectRelation.historicalEventIdsThe GC sweep runs every 128 events created, but a grievance modifier stays active for up to 3600 ticks — far longer than 128 events typically takes to elapse in a running galaxy. So the modifier's source event was almost always purged long before the modifier itself expired, silently corrupting:
summarizeGrievances()'soldestAgeTicks(a balance-tuning read-out surfaced in the headless report and in-app grievance summary), and[tick] Title" annotation on grievances in the exported report (buildReport()inApp.tsx), which just silently disappears once the source event ages out.Confirmed empirically: at the same seed/tick count,
oldestAgeTicksat tick 3000 went from 304 (before fix) to 637 (after fix) — matching the predicted corruption.Changes
gcEvents()'s referenced-set collection to includeRelationModifier.sourceEventId(via each empire's relationship modifiers),Faction.historicalEventIds, andSubjectRelation.historicalEventIds, before sweeping unreferenced events.src/sim/Events.test.tscovering all three previously-missed cases, plus a baseline test that true orphans are still collected.Idreference intostate.eventsmust be added togcEvents()'s referenced set.Test plan
npm run typecheck/npm run buildnpm run lintnpm run test:unit(9/9 passing, including 4 new tests inEvents.test.ts)npm run report(headless health check, 1000/3000-tick milestones) — passes, andoldestAgeTicksnow reflects the fixnpm run report --milestones 500, byte-identical replay)Generated by Claude Code