Skip to content

refactor: extract AgentBroadcasting concern from Agent model #685

@unclesp1d3r

Description

@unclesp1d3r

Summary

The Agent model (390 lines) is approaching God Object territory. Three broadcasting methods (broadcast_index_state, broadcast_index_last_seen, broadcast_tab_updates) plus their after_update_commit callback account for ~40 lines that can be cleanly extracted.

Current State

app/models/agent.rb lines 113-156 contain:

  • broadcast_index_state — replaces state pill on index cards (guarded by saved_change_to_state?)
  • broadcast_index_last_seen — replaces "Last Seen" on index cards (guarded by saved_change_to_last_seen_at?)
  • broadcast_tab_updates — broadcasts to overview, configuration, and capabilities tab streams

These are self-contained and have no dependency on other Agent logic.

Proposed Change

Extract an Agent::Broadcasting concern containing all three methods and the after_update_commit callback. This follows the existing pattern (Agent::Benchmarking, SafeBroadcasting) and would reduce the core model to ~350 lines.

Acceptance Criteria

  • New concern at app/models/concerns/agent/broadcasting.rb
  • Agent model includes the concern and no longer defines broadcasting methods inline
  • All existing agent tests pass without modification
  • Concern includes a REASONING block per project standards

Context

Identified during architecture review. The Agent model has 7+ responsibilities (lifecycle, task assignment, benchmarking, metrics, broadcasting, configuration, state transitions). This extraction reduces cognitive load with zero behavioral change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-systemAgent system related features and issuesenhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions