Skip to content

District unlock event history: persist unlock events per agent for replay and debugging #319

Description

@leocagli

Context

District unlocks fire district.unlocked events but currently there is no persistent log of which agent unlocked which district and when. This makes debugging gamification bugs ("why didn't this agent unlock district 3?") hard.

What to implement

Event log store

On every district.unlocked event, append to a per-agent log:

interface DistrictUnlockEvent {
  agentId: string
  districtId: string
  unlockedAt: string   // ISO timestamp
  xpAtUnlock: number   // agent's XP at the moment of unlock
}

Route: GET /api/agents/:id/districts/history

Returns the agent's full district unlock history, sorted by unlockedAt descending.

Response:

{
  "agentId": "bot-1",
  "unlocks": [
    { "districtId": "district-3", "unlockedAt": "2026-06-26T10:00:00Z", "xpAtUnlock": 1200 }
  ]
}

No duplicates

If the same district is unlocked twice (edge case), dedupe by districtId keeping the earliest unlock.

Acceptance criteria

  • Unlocking a district appends an entry with correct agentId, districtId, and xpAtUnlock
  • GET /api/agents/:id/districts/history returns entries sorted newest-first
  • Duplicate district unlock: only the first entry kept
  • Agent with no unlocks returns { unlocks: [] }
  • Unit tests: single unlock, multiple districts, dedup, empty agent

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions