Skip to content

Agent session replay: store last N events per agent for debugging #321

Description

@leocagli

Context

When an agent goes offline or fails a quest, there's no way to see what events led to the failure. A per-agent event replay buffer (last 50 events) enables post-mortem debugging without external logging infrastructure.

What to implement

Ring buffer per agent

Store the last 50 OS events (any type) for each agentId:

interface ReplayEvent {
  type: string        // e.g. 'agent.status', 'quest.completed'
  payload: object
  recordedAt: string  // ISO timestamp
}

Implemented as a fixed-size ring buffer — oldest entry dropped when full.

Route: GET /api/agents/:id/replay

Returns the agent's event buffer, newest first:

{ "agentId": "bot-1", "events": [...], "bufferSize": 50, "count": 23 }

Route: DELETE /api/agents/:id/replay

Clears the buffer (useful for test isolation).

Acceptance criteria

  • Events are recorded as they fire through the OS event bus
  • Buffer wraps at 50 entries — 51st event evicts the oldest
  • GET returns events newest-first
  • DELETE clears the buffer; subsequent GET returns count: 0
  • Agent with no events returns { events: [], count: 0 }
  • Unit tests: fill buffer past 50, wrap behaviour, clear

🎁 Evidencia visual = reward extra

  • Si tu PR incluye video demo o capturas de pantalla mostrando la funcionalidad pedida funcionando end-to-end, va a ser considerado para rewards de GrantFox en esta issue. No es obligatorio, pero suma mucho para la evaluación.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions