Skip to content

Persist risk-stream history and hydrate dashboard/cases from API fallback#2

Draft
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-dashboard-kafka-integration
Draft

Persist risk-stream history and hydrate dashboard/cases from API fallback#2
Copilot wants to merge 5 commits into
mainfrom
copilot/fix-dashboard-kafka-integration

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

The dashboard was effectively stateless: it only rendered live WebSocket events, so reloads/startup showed empty views and alerts disappeared from analyst workflow. This change adds lightweight persistence and history endpoints in dashboard-api, then updates UI pages to bootstrap from stored data before continuing live streaming.

  • Backend: persistent risk event history + case materialization

    • Added SQLite-backed storage in services/dashboard-api/app/main.py for ingested risk-scores.
    • Persisted each consumed risk event and auto-created a case record for non-APPROVE decisions.
    • Added API endpoints:
      • GET /api/recent-alerts
      • GET /api/stats
      • GET /api/cases
    • Included timestamp safety handling for stats calculations.
  • Frontend: cold-start hydration before WebSocket tailing

    • Updated:
      • services/dashboard/src/pages/Dashboard.tsx
      • services/dashboard/src/pages/Alerts.tsx
      • services/dashboard/src/pages/Cases.tsx
    • Each page now fetches historical data from dashboard-api on load, then continues with existing WS live updates.
    • Replaced new hardcoded API fetches with VITE_DASHBOARD_API_BASE_URL (fallback to http://localhost:8005).
  • API test coverage for new behavior

    • Expanded services/dashboard-api/tests/test_api.py to validate:
      • alert-history filtering (APPROVE excluded),
      • aggregated stats,
      • case list generation from persisted risk events.
# dashboard-api/app/main.py
@app.get("/api/recent-alerts")
async def recent_alerts(limit: int = 20):
    rows = conn.execute(
        """
        SELECT transaction_id, unified_score, decision, created_at
        FROM risk_scores
        WHERE decision != 'APPROVE'
        ORDER BY created_at DESC
        LIMIT ?
        """,
        (max(1, min(limit, 200)),),
    ).fetchall()
    return [dict(row) for row in rows]
Original prompt

complete the remaining tasks given

[Chronological Review: The conversation began with the user running an integration test that resulted in a `ModuleNotFoundError` for the `httpx` module. The user then expressed concerns about the dashboard not being fully integrated with Kafka, leading to an empty dashboard. The user described issues with the dashboard displaying transactions only temporarily and not storing them, prompting a detailed diagnosis of three main problems related to the dashboard's functionality. The conversation included proposed fixes for these issues, focusing on adding persistence to the data flow and enhancing the dashboard's capabilities. The user requested to continue the conversation multiple times, indicating a desire to proceed with the implementation of the discussed solutions. The user finally commanded to commit changes and delegate the task to a cloud agent.]

[Intent Mapping:

  1. "i think dashboard is not fully integrated with kafka" - User suspects integration issues.
  2. "my dashboard is empty" - User describes the problem with the dashboard.
  3. "continue" - User requests to proceed with the conversation.
  4. "Commit Changes and Delegate: 'Delegate to cloud agent'" - User wants to finalize changes and delegate further actions.]

[Technical Inventory:

  • Technologies: FastAPI, PostgreSQL, SQLAlchemy, Kafka, WebSocket.
  • Architectural Decisions: Implementing a REST API for historical data retrieval, adding persistence to the risk-engine's consumer loop, and creating a case management system for analysts.]

[Code Archaeology:

  • File: services/dashboard-api/app/routes/history.py - Added endpoints for fetching recent alerts and dashboard stats.
  • File: services/risk-engine/app/models.py - Introduced RiskScoreRecord and Case models for data persistence.
  • File: services/risk-engine/app/consumer.py - Modified to include persistence logic after scoring.
  • File: services/dashboard-api/app/routes/cases.py - Created REST API for case management.]

[Progress Assessment:

  • Completed: Proposed fixes for the dashboard's integration issues, including REST endpoints and persistence logic.
  • Pending: Implementation of the discussed changes and testing of the new functionality.]

[Context Validation: All necessary context for continuing the work on the dashboard integration and persistence has been captured, including specific code changes and architectural decisions.]

[Recent Commands Analysis:

  • Last Agent Commands: "Commit Changes and Delegate: 'Delegate to cloud agent'" - User requested to finalize changes and delegate tasks.
  • Tool Results Summary: No specific tool results were returned as the command was a request to delegate tasks.
  • Pre-Summary State: The agent was actively working on finalizing the changes discussed in the conversation and preparing to delegate tasks to a cloud agent.
  • Operation Context: The user aimed to ensure that the dashboard issues were addressed and that the changes were committed for further action.]
1. Conversation Overview: - Primary Objectives: The user aimed to resolve issues with the dashboard integration with Kafka, specifically addressing the empty dashboard and lack of data persistence. Key quotes include: "i think dashboard is not fully integrated with kafka" and "my dashboard is empty." - Session Context: The conversation flowed from identifying integration issues to diagnosing specific problems with the dashboard's functionality and proposing solutions. - User Intent Evolution: The user initially sought to understand the integration issues, then focused on implementing fixes, and finally requested to commit changes and delegate tasks.
  1. Technical Foundation:
  • FastAPI: Used for building the REST API for the dashboard.
  • PostgreSQL: Chosen for data persistence.
  • SQLAlchemy: Utilized for ORM and database interactions.
  • Kafka: Employed for message brokering in the risk-engine.
  1. Codebase Status:
  • File Name: services/dashboard-api/app/routes/history.py
    • Purpose: To provide endpoints for fetching recent alerts and dashboard statistics.
    • Current State: New endpoints added for historical data retrieval.
    • Key Code Segments: @router.get("/api/recent-alerts") and @router.get("/api/stats").
  • File Name: services/risk-engine/app/models.py
    • Purpose: To define data models for risk scores and cases.
    • Current State: New models created for persistence.
    • Key Code Segments: class RiskScoreRecord and class Case.
  • File Name: services/risk-engine/app/consumer.py
    • Purpose: To process incoming messages and persist data.
    • Current State: Logic added for data persistence after scoring.
    • Key Code Segments: Persistence logic added after scoring calculations.
  1. Problem Resolution:
  • Issues Encountered: Dashboard empty on load, data not persisted, and alerts scrolling away too quickly.
  • Solutions Implemented: Proposed REST endpoints for historical data, persistence logic in the ...

Created from VS Code.

Copilot AI changed the title [WIP] Fix dashboard integration with Kafka and add data persistence Persist risk-stream history and hydrate dashboard/cases from API fallback May 10, 2026
Copilot AI requested a review from Anuj-verse May 10, 2026 18:17
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.

2 participants