Skip to content

fix(game-api): compute live swarm experiment metrics - #70

Merged
christopherjnelson merged 1 commit into
mainfrom
fix/live-swarm-metrics
Sep 22, 2026
Merged

christopherjnelson merged 1 commit into
mainfrom
fix/live-swarm-metrics

Conversation

@christopherjnelson

Copy link
Copy Markdown
Member

Final PR of the zero-swarm migration. Follows #69.

What

  • Live World Lab experiment metrics always read zero. The snapshot passed an empty resolved-action array to calculateExperimentMetrics. A new calculateRetainedExperimentMetrics derives them from the retained swarm ticks, using the same resolved-action, provider-attempt and control-change derivation as an all-agents, entire-retained export. It scopes to the initial and current roster as the export does, so a captured agent's history still counts.
  • movementDirectionDistribution, longestRepeatedDirectionStreak and recentCellRevisits were never assigned after the legacy turn records were removed, so they always fell back to schema defaults. They are now computed from accepted agent-moved events, which already carry both cells, using the existing geographicDirectionBetweenCells classifier. No new plumbing was needed.
  • One legacy flaw fixed along the way. The old implementation walked every scoped move as a single sequence, so aggregate streaks ran across interleaved agents. Each agent's path is now walked separately; aggregates sum direction counts and revisits and report the longest single-agent streak.

Tests

  • experiment-export.test.ts (new) pins the movement semantics. It includes an interleaved move by a second agent that would produce a streak of three under the old single-sequence walk.
  • simulation-service.swarm.test.ts asserts that live snapshot metrics equal the metrics of an all-agents, entire-retained export after three ticks.

Both tests fail when the source fix is reverted.

Docs

  • ROADMAP.md: the known-open-work entries are resolved and recorded as part of the migration.
  • docs/ARCHITECTURE.md and docs/TESTING.md: document the metric semantics and the new coverage.

Validation

Run locally by the repository owner and reported green:

pnpm validate     # 226 tests passed
pnpm test:e2e     # 2 passed

🤖 Generated with Claude Code

Live World Lab experiment metrics always read zero: the snapshot passed an
empty resolved-action array to calculateExperimentMetrics even though the
retained swarm ticks carry every committed action. Derive them instead through
a new calculateRetainedExperimentMetrics, which uses the same resolved-action,
provider-attempt and control-change derivation as an all-agents,
entire-retained export, so live and exported metrics cannot drift apart. It
scopes to the initial and current roster, as the export does, so a captured
agent's history still counts.

movementDirectionDistribution, longestRepeatedDirectionStreak and
recentCellRevisits were declared in the metrics schema but never assigned
after the legacy turn records were removed, so they always fell back to their
defaults. Compute them from accepted agent-moved events, which already carry
both cells, using the existing geographicDirectionBetweenCells classifier. The
legacy implementation walked every scoped move as one sequence, so an
aggregate streak ran across interleaved agents; each agent's path is now
walked separately, with aggregates summing counts and revisits and reporting
the longest single-agent streak.

Both new tests fail against the previous code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@christopherjnelson
christopherjnelson marked this pull request as ready for review September 22, 2026 18:16
@christopherjnelson
christopherjnelson merged commit b1275ab into main Sep 22, 2026
2 checks passed
@christopherjnelson
christopherjnelson deleted the fix/live-swarm-metrics branch September 22, 2026 18:16
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.

1 participant