Skip to content

[P1] State Sync Audit: Components with phase-awareness gaps #235

Description

@frankbria

Background

The TaskStats bug fix (PR #234, fixes #233) exposed a broader architectural pattern: components that use useAgentState() hook without considering project phase may show incorrect data during non-development phases.

This is the "late-joining user" scenario - when a user opens the Dashboard after certain actions have occurred, they may see stale or incorrect data because the component is looking at the wrong data source.

Root Cause

The application has two parallel data systems:

Data Source Phase Update Mechanism
REST API (issues endpoint) Planning HTTP polling/SWR
WebSocket (agent state) Development/Review Real-time push

Components that rely solely on one data source without phase awareness are vulnerable to showing incorrect data.

At-Risk Components (Audit Needed)

High Priority

Component Risk Current Behavior
AgentPanel HIGH May show "no agents" during planning when agents are planned but not yet active
ProgressIndicator HIGH May calculate 0% progress during planning phase
TaskTreeView MEDIUM May show empty tree if only reading agent state

Medium Priority

Component Risk Current Behavior
MetricsCharts / CostDashboard LOW Should show "Metrics available during development" during planning
QualityGates LOW Should show configured gates during planning (pending execution)

Pattern to Apply

Each affected component should follow the pattern established in PR #234:

interface ComponentProps {
  phase?: string;          // Current project phase
  issuesData?: IssuesResponse;  // REST API data for planning phase
}

function Component({ phase, issuesData }: ComponentProps) {
  const agentState = useAgentState();  // Always call (hooks rules)
  
  const data = useMemo(() => {
    if (phase === 'planning') {
      return calculateFromIssuesData(issuesData);
    }
    return agentState;  // development/review phases
  }, [phase, issuesData, agentState]);
}

Testing Strategy

Each component should have "late-joining user" tests that verify:

  • Correct display during planning phase
  • Correct display during development phase
  • Smooth data source switching during phase transitions
  • Graceful degradation when data is loading

Acceptance Criteria

  • Audit all components using useAgentState() for phase-awareness
  • Apply phase-aware pattern to high-priority components
  • Add unit tests for phase-aware behavior
  • Add E2E "late-joining user" tests for each fixed component
  • Document pattern in architecture docs

Related

References

  • Beads issue: codeframe-7pya
  • Code review: docs/code-review/2026-01-08-taskstats-phase-awareness-review.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-high-betaHigh priority - should fix before beta for best experiencearchitectureSystem architecture and design patternsenhancementNew feature or requestux

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions