Skip to content

[STORY] Self-Monitoring Configuration and Service #72

@jsbattig

Description

@jsbattig

Part of: #71

Feature: Self-Monitoring Core Infrastructure

Story: Self-Monitoring Configuration and Service

Overview

Objective: Implement the configuration infrastructure and scheduled service for self-monitoring.

User Value: As an admin, I want to configure self-monitoring settings (enable/disable, cadence, model, prompt) via the existing config system so that the system can automatically analyze logs on a schedule.

Acceptance Criteria

AC1: SelfMonitoringConfig Dataclass

Given the CIDX server configuration system
When SelfMonitoringConfig is added to config_manager.py
Then it includes fields: enabled (bool), cadence_minutes (int), model (str), prompt_template (str), prompt_user_modified (bool)
And default values are: enabled=False, cadence_minutes=60, model="opus", prompt_template="", prompt_user_modified=False
And it is added to ServerConfig as self_monitoring_config field
And __post_init__ initializes it if None

AC2: SQLite Schema for Operational Data

Given the database_manager.py schema definitions
When self-monitoring tables are added
Then self_monitoring_scans table exists with: scan_id, started_at, completed_at, status, log_id_start, log_id_end, issues_created, error_message
And self_monitoring_issues table exists with: id, scan_id, github_issue_number, github_issue_url, classification, title, source_log_ids, created_at
And appropriate indexes are created

AC3: SelfMonitoringService Scheduled Task

Given SelfMonitoringConfig.enabled is true
When the server starts
Then SelfMonitoringService starts a background timer thread
And the timer fires based on cadence_minutes setting
And jobs are submitted to existing Claude job queue
And jobs are tagged as "self_monitoring" type
And no concurrent scans are allowed (single-threaded queue)

AC4: Prompt Upgrade Lifecycle

Given a default prompt file at src/code_indexer/server/self_monitoring/prompts/default_analysis_prompt.md
When self-monitoring is enabled for the first time
Then prompt_template is seeded from the source file if empty
And prompt_user_modified remains false

Given prompt_user_modified is false
When CIDX is upgraded with a new default prompt
Then prompt_template is updated to new version

Given prompt_user_modified is true
When CIDX is upgraded
Then prompt_template is preserved (not overwritten)

AC5: GitHub CI/CD Validation

Given a user attempts to enable self-monitoring
When GitHub CI/CD is not configured in server settings
Then enabling fails with clear error message
And the feature remains disabled

Technical Requirements

Files to Create

  • src/code_indexer/server/self_monitoring/init.py
  • src/code_indexer/server/self_monitoring/service.py (SelfMonitoringService)
  • src/code_indexer/server/self_monitoring/prompts/default_analysis_prompt.md

Files to Modify

  • src/code_indexer/server/utils/config_manager.py (add SelfMonitoringConfig)
  • src/code_indexer/server/storage/database_manager.py (add tables)
  • src/code_indexer/server/server_lifecycle_manager.py (initialize service)

Patterns to Follow

  • ScheduledCatchupService for timer pattern
  • BackgroundJobsSqliteBackend for SQLite backend pattern
  • Existing config dataclass patterns in config_manager.py

Testing Requirements

  • Unit tests for SelfMonitoringConfig dataclass
  • Unit tests for SQLite schema creation
  • Unit tests for service start/stop lifecycle
  • Unit tests for prompt upgrade logic
  • Integration test for GitHub validation

Definition of Done

  • SelfMonitoringConfig dataclass implemented with all fields
  • SQLite tables created and migrated
  • SelfMonitoringService starts on server startup when enabled
  • Timer fires on configured cadence
  • Prompt upgrade lifecycle works correctly
  • GitHub CI/CD validation prevents enabling without config
  • All unit tests pass
  • Code review approved

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions