Skip to content

feat: implement workspace sync with Mutagen (Phase 2)#3

Merged
VAIBHAVSING merged 5 commits intofeat/remote-coasts-phase0from
feat/remote-coast-phase2
Mar 31, 2026
Merged

feat: implement workspace sync with Mutagen (Phase 2)#3
VAIBHAVSING merged 5 commits intofeat/remote-coasts-phase0from
feat/remote-coast-phase2

Conversation

@VAIBHAVSING
Copy link
Copy Markdown
Owner

Summary

Implements Phase 2: Workspace Sync for Remote Coasts using Mutagen for reliable file synchronization between local development machine and remote VMs.

This PR builds on coast-guard#168 (Phase 0) and adds complete workspace synchronization functionality.

What's New

🔄 Mutagen Integration

  • Full Mutagen sync session lifecycle management
  • Unidirectional sync (local → remote) using one-way-safe mode
  • Automatic Mutagen agent installation on remote (~10MB)
  • Session naming: coast-<project>-<branch>-<remote>
  • Remote workspace path: ~/coast-workspaces/<project>/<branch>/

🎯 CLI Commands

# Create sync session
coast sync create <project> <remote> --local-path <path> --branch <branch>

# Check status
coast sync status [project]

# Control sync
coast sync pause <project>
coast sync resume <project>
coast sync flush <project>

# Cleanup
coast sync terminate <project>

📁 Features

  • .coastignore support - Respects ignore patterns (node_modules, .git, *.log, etc.)
  • Real-time sync - Changes detected and synced automatically
  • Pause/Resume - Control when sync happens
  • Status tracking - Monitor sync state (Initial, Syncing, Paused, Error)
  • Multiple projects - Sync multiple projects to same remote simultaneously

🏗️ Architecture

  • MutagenManager in coast-daemon/src/remote/mutagen.rs (697 lines)
  • CLI commands in coast-cli/src/commands/sync.rs (406 lines)
  • Protocol extensions in coast-core/src/protocol/remote.rs
  • State persistence in sync_sessions table
  • Handler integration with analytics support

🧪 Testing

  • Comprehensive test scripts (test_sync_simple.sh, test_sync_quick.sh)
  • Setup automation (setup_test.sh, install_mutagen.sh)
  • Detailed guides (QUICK_TEST.md, TEST_SYNC.md)
  • Tests cover: initial sync, real-time updates, ignore patterns, pause/resume

Technical Details

Mutagen Requirements:

  • Local: ~100MB (one-time install)
  • Remote: ~10MB agent (auto-installed via SSH)

Sync Behavior:

  • Mode: one-way-safe (local → remote only)
  • Transport: SSH with optional key configuration
  • Conflict handling: Local always wins
  • Delete propagation: Safe deletes only

State Management:

  • In-memory session cache for fast lookups
  • SQLite persistence in sync_sessions table
  • Status tracking: last_sync_at, status, mutagen_session_id

Testing Instructions

Prerequisites

  1. A VM with SSH access
  2. Mutagen installed locally (or use ./install_mutagen.sh)
  3. Coast built in release mode

Quick Test

# Setup
./setup_test.sh
export PATH="$HOME/.local/bin:$(pwd)/target/release:$PATH"

# Run test (replace with your VM)
./test_sync_simple.sh ubuntu@192.168.1.100

# Or with SSH key
./test_sync_simple.sh ubuntu@192.168.1.100 ~/.ssh/id_rsa

See QUICK_TEST.md for detailed instructions.

Changes

New Files

  • coast-daemon/src/remote/mutagen.rs - Mutagen manager implementation
  • coast-cli/src/commands/sync.rs - CLI sync commands
  • QUICK_TEST.md - Quick testing guide
  • TEST_SYNC.md - Comprehensive manual testing guide
  • install_mutagen.sh - Mutagen installation script
  • setup_test.sh - One-command test setup
  • test_sync_simple.sh - Automated test script

Modified Files

  • coast-core/src/protocol/remote.rs - Add sync request/response types
  • coast-daemon/src/handlers/remote.rs - Add sync handlers (6 variants)
  • coast-daemon/src/state/remotes.rs - Add sync session state methods
  • coast-daemon/src/server.rs - Initialize MutagenManager
  • coast-daemon/src/analytics.rs - Track sync operations
  • coast-cli/src/lib.rs - Add Sync command

Stack

Add complete Mutagen-based file synchronization for Remote Coasts:

Core Implementation:
- MutagenManager for sync session lifecycle (create, pause, resume, flush, terminate)
- One-way sync (local → remote) with 'one-way-safe' mode
- Session naming: coast-<project>-<branch>-<remote>
- Remote workspace path: ~/coast-workspaces/<project>/<branch>/
- Support for .coastignore patterns (node_modules, .git, *.log)
- State persistence in sync_sessions table

CLI Commands:
- coast sync create <project> <remote> --local-path <path> --branch <branch>
- coast sync status [project] - list active sync sessions
- coast sync pause/resume <project> - control sync
- coast sync flush <project> - force immediate sync
- coast sync terminate <project> - stop and remove session

Protocol:
- SyncCreateRequest/Response with local_path, branch, remote
- SyncStatusRequest/Response with session info
- SyncPauseRequest/Response, SyncResumeRequest/Response
- SyncFlushRequest/Response, SyncTerminateRequest/Response

Testing:
- Comprehensive test scripts (test_sync_simple.sh, test_sync_quick.sh)
- Setup automation (setup_test.sh, install_mutagen.sh)
- Detailed testing guides (QUICK_TEST.md, TEST_SYNC.md)
- Tests: initial sync, real-time updates, ignore patterns, pause/resume

Technical Details:
- Mutagen ~100MB on local, ~10MB agent on remote (auto-installed)
- Uses SSH for transport with optional key configuration
- Sync status tracking: Initial, Syncing, Paused, Error
- Handler integration in handlers/remote.rs
- Analytics support for all sync operations

Phase 2 complete - workspace sync fully functional.
Next: Phase 3 (remote build/run), Phase 4 (remote exec/logs)
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 336753f4-a26d-4bee-ab4a-218fb8a6079d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/remote-coast-phase2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Installs Docker, Docker Compose, and Mutagen on remote VM
- Builds coastd-dev binary on remote (avoids glibc mismatch)
- Starts daemon and creates workspace directories
- Supports manual remote development environment setup
Add remote daemon client and request forwarding infrastructure:

- Create RemoteDaemonClient for communicating with remote daemons
  over SSH tunnels (coast-daemon/src/remote/client.rs)
- Add get_remote_route() to check project mode and tunnel status
- Add ensure_synced() to flush Mutagen before remote operations
- Add forward_streaming_to_remote() for proxying streaming responses
- Modify handle_build_streaming() to route to remote when configured
- Modify handle_run_streaming() to route to remote when configured

Flow: CLI -> Local Daemon -> Check Mode -> Sync Flush -> Forward via
SSH Tunnel -> Remote Daemon -> Proxy responses back

Also includes Phase 2 fixes:
- Fix get_sync_session method name in handlers
- Fix truncate_str test assertion
- Clean up unused imports
Add remote_name field to CoastInstance to track which remote an instance
is running on. This enables routing exec and logs requests to the correct
remote daemon based on instance location.

Key changes:
- Add remote_name: Option<String> to CoastInstance struct
- Add DB migration for remote_name column in instances table
- Add get_instance_remote_route() to look up instance's remote location
- Add forward_to_remote() for non-streaming requests (exec, logs)
- Add forward_logs_streaming_to_remote() for streaming logs
- Modify handle_connection to route exec/logs based on instance location
- Update forward_run_to_remote to create shadow instance records locally
  with remote_name set, enabling future exec/logs routing
- Fix all test files to include remote_name: None field

Phase 4 routes based on instance location (remote_name field), unlike
Phase 3 which routes based on project mode.
@VAIBHAVSING VAIBHAVSING merged commit d6bf7a8 into feat/remote-coasts-phase0 Mar 31, 2026
1 check passed
@VAIBHAVSING VAIBHAVSING deleted the feat/remote-coast-phase2 branch March 31, 2026 20:11
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.

1 participant