Skip to content

Start and close sync sessions with a disk connection #383

Description

@bjester

Overview

Hosts can create a disk connection and start a sync session that writes to a new archive file. This issue is part of milestone M6 (disk connection).

Background & Motivation

MorangoProfileController.create_disk_connection is a stub today, and it is missing self. Infrastructure managers of large Kolibri instances need to export facility data to archive files and store them offline.

The Connection interface from #370 defines the session lifecycle for all connection types. DiskSyncConnection implements this lifecycle for an archive. The connection mints an archive certificate, so that the archive acts as a standalone instance with a clear scope.

Design: spec. Plan: implementation plan, Task 22.

User Story

As a Kolibri developer,
I want to open a disk connection to a file path and start a sync session,
So that infrastructure managers can export facility data to an archive for offline storage.

Description & Expected Outcomes

A host calls create_disk_connection(path) and gets a DiskSyncConnection. The connection refuses a path that already exists. Phase 1 supports export to new archives only.

When the host starts a sync session, the connection creates the archive, writes the archive identity, and mints an archive certificate. The archive certificate is a child of the client certificate, with the same scope and no private key. The archive stores the certificate chain, its own sync session, and a manifest. The local database stores a sync session with connection_kind="disk".

If a step fails during sync session creation, the connection discards the archive and raises the error. No partial file or lock remains.

When the host closes the sync session, the connection finalizes the archive only if every transfer session in it completed. Otherwise, the connection discards the archive. Resume is not available for disk connections in Phase 1.

Deliverables & Contracts

The feature delivers these capabilities:

  • MorangoProfileController.create_disk_connection(path, **kwargs) returns a DiskSyncConnection.
  • DiskSyncConnection implements the lifecycle, identity and certificate members of Connection, as spec §3.6 describes.
  • create_sync_session(client_cert, peer_cert=None, chunk_size=None) creates the archive and both sync session records.
  • close_sync_session finalizes or discards the archive. close() discards an archive that is not finalized.
  • resume_sync_session raises MorangoResumeSyncError.
  • get_remote_certificates returns an empty list.

Acceptance Criteria

  • create_disk_connection(path) returns a DiskSyncConnection.
  • A connection to an existing path raises MorangoArchiveExists.
  • create_sync_session(cert) creates an archive SyncSession with is_server=True and the minted certificate as server_certificate.
  • create_sync_session(cert) creates a local SyncSession with connection_kind="disk".
  • The minted certificate passes check_certificate(), has no private key, and has the same scope as its parent.
  • The archive holds the chain plus the minted certificate and their ScopeDefinition, and the manifest has no filter.
  • The archive SyncSession is written to the archive alias, and no archive write reaches default.
  • A peer_cert that is not None raises ValueError.
  • A client certificate without a private key raises MorangoError, and no .partial or .lock file remains.
  • If ASYNC_OPERATIONS is not in CAPABILITIES, create_sync_session raises MorangoError.
  • resume_sync_session raises MorangoResumeSyncError.
  • Two calls to close() do not raise.
  • close_sync_session without a completed transfer session discards the archive.

Technical Pointers & Architecture

  • Target Components / Context: morango/sync/syncsession.py (DiskSyncConnection), morango/sync/controller.py:44 (create_disk_connection).
  • Related Patterns: NetworkSyncConnection.push_signed_client_certificate_chain (morango/sync/syncsession.py:397-433) mints and signs a child certificate.
  • Data Model & Schema Considerations: Uses existing models and ArchiveManifestEntry from Store archive metadata in a morango table #376.
  • Resilience & Failure Modes: Every failure in create_sync_session discards the archive, then raises the original error.

Notes & Tradeoffs

Metadata

  • Complexity: High
  • Target Branch: release-v0.9.x

AI Usage

Drafted with Claude (Claude Code) from the approved design spec and implementation plan. The author reviewed the requirements, and the code references were checked against the release-v0.9.x codebase.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions