Skip to content

feat: thread checkpoints#740

Draft
ethanoroshiba wants to merge 6 commits into
mainfrom
eoroshiba/thread-checkpoint
Draft

feat: thread checkpoints#740
ethanoroshiba wants to merge 6 commits into
mainfrom
eoroshiba/thread-checkpoint

Conversation

@ethanoroshiba
Copy link
Copy Markdown

@ethanoroshiba ethanoroshiba commented Nov 5, 2025

Summary

This PR implements a thread checkpoint system that enables editing in conversations and working directory restoration.

Background

AI coding assistants need the ability to let users edit previous messages and re-run conversations from that point. However, as the AI makes changes to files during a conversation, simply editing an earlier message would create inconsistencies - the AI would be working with files in their current state, not the state they were in at that point in the conversation. This checkpoint system solves that problem by capturing filesystem state after each message and restoring it when needed.

Changes

Core Checkpoint Infrastructure

  • Database Schema: Added thread_checkpoint and checkpoint_file_snapshot tables for storing checkpoint metadata and file state
    • Diff-based storage: first snapshot stores full content, subsequent snapshots store efficient line-based diffs
    • Supports up to 100MB total directory size and 10MB individual file size limits
    • Automatic cleanup via CASCADE constraints when threads/messages are deleted
  • Checkpoint Creation: Implemented automatic checkpoint creation after each message completion
    • Captures all files in the configured working directory
    • Computes efficient diffs against previous checkpoints
    • Skips binary files and respects size limits
  • Checkpoint Restoration: Implemented restoration logic when editing messages
    • Reconstructs full file content from base snapshot + diffs
    • Returns base64-encoded file contents to client for restoration
    • Requires explicit user confirmation if files will be modified
    • Automatically deletes all messages after the edited message
    • Kicks off new LLM relay job to re-process from the edited message

API Changes

  • Added EditThreadMessage RPC endpoint for editing messages with checkpoint support
  • Added ConfigureThreadWorkingDirectory RPC endpoint to set up checkpoint tracking
  • Extended thread types with working_directory field
  • Added requires_confirmation and restorations fields to edit response for client-side restoration

CLI v2 Enhancements

  • Message Navigation: Added Ctrl+L keybinding to view and select messages in a thread
    • Arrow keys to navigate message list
    • Enter to edit selected message
    • Escape to return to chat view
  • Message Editing: Integrated full message editing flow
    • Opens textarea with original message content
    • Shows confirmation dialog if checkpoint restoration required
    • Displays number of files restored/deleted after edit
    • Automatically restores files in working directory
  • Automatic Working Directory Configuration: CLI now automatically configures the working directory for new and existing threads

Database Migrations

  • 20251105000000_create_thread_checkpoints.sql: Core checkpoint tables and indexes
  • 20251105000001_add_thread_working_directory.sql: Add working directory tracking to threads
  • 20251105204430_add_deleted_at_to_llm_message.sql: Soft delete support for messages

Authorization

  • Updated thread_message.yaml policy to allow editing of user messages

Testing

  • New system test
  • Manual testing with CLI v2

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