Skip to content

Refactor: sync/watch lifecycle via SyncCoordinator #497

Closed

Description

@phernandez

Refactor: sync/watch lifecycle via SyncCoordinator

Why

Background sync + watch lifecycle is a cross-cutting concern that can easily leak into initialization, routers, and MCP lifespan. Centralizing lifecycle improves reliability and reduces coupling.

Scope

  • Introduce a SyncCoordinator responsible for:
    • starting/stopping watch service
    • scheduling background sync
    • reporting status
  • Entrypoints decide when to start it (API/MCP/CLI) via their containers.

Acceptance criteria

  • Lifecycle logic centralized in one place.
  • Fewer scattered background-task conditionals.
  • Stable shutdown behavior (especially in Postgres test mode where hangs were previously noted).

Dependencies

  • After containers + deps split.

Activity

  1. claude commented on Dec 31, 2025

    @claude
    Contributor

    Claude finished @phernandez's task in 1m 43s —— View job


    Issue Triage Analysis

    Tasks

    • Read CLAUDE.md for context
    • Search for duplicate issues
    • Classify issue type, priority, component, and complexity
    • Add appropriate labels
    • Provide triage summary

    Classification

    Type: Enhancement (architectural refactoring)

    Priority: Medium

    • Improves reliability and reduces coupling
    • Not critical/blocking, but addresses technical debt
    • Will improve stability (especially in Postgres test mode where hangs were noted)

    Component: Sync/Watch Services

    • Located in /sync directory
    • Cross-cutting concern affecting API, MCP, and CLI initialization

    Complexity: Complex

    • Architectural change requiring careful refactoring
    • Touches multiple entry points (API/MCP/CLI)
    • Needs to handle lifecycle management across different runtime modes
    • Must ensure stable shutdown behavior

    Duplicate Check

    No duplicates found. This is a unique refactoring initiative.

    Related Issues:

    Analysis

    This refactoring addresses a legitimate architectural concern. The sync/watch lifecycle is currently scattered across multiple initialization points, leading to:

    • Coupling between initialization code and background services
    • Difficulty managing stable shutdown (Postgres test hangs mentioned)
    • Scattered background-task conditionals

    Proposed Solution:
    Introduce SyncCoordinator to centralize:

    • Starting/stopping watch service
    • Scheduling background sync
    • Status reporting

    Dependencies:

    Labels Applied

    • enhancement - Architectural improvement to existing functionality

    Recommendation

    This is a well-scoped refactoring with clear acceptance criteria. The dependency on #491 is appropriate since container/dependency refactoring should happen first. Once #491 is complete, this would be a good candidate for implementation.

    Next Steps:

    1. Wait for Refactor: split deps.py into feature modules + reduce import graph #491 to be completed
    2. When ready to implement, consider:
      • Reviewing existing sync/watch initialization code across API/MCP/CLI
      • Designing SyncCoordinator interface
      • Ensuring test coverage for lifecycle scenarios
      • Special attention to shutdown behavior in Postgres mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions