šŸ” Code Extractor

function check_gpt_in_folder

Maturity: 46

Diagnostic function that checks the status, metadata, and contents of a specific 'gpt_in' folder in the reMarkable cloud storage system, providing detailed analysis of folder structure and potential sync issues.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/check_gpt_in_folder.py
Lines:
13 - 163
Complexity:
complex

Purpose

This function performs a comprehensive diagnostic check of a hardcoded 'gpt_in' folder (UUID: 99c6551f-2855-44cf-a4e4-c9c586558f42) in the reMarkable cloud sync system. It retrieves and analyzes the folder's entry in the root document schema, fetches the folder's own document schema, examines metadata (name, parent, type, deletion status), and checks for expected documents within the folder. The function is designed for debugging folder visibility and sync issues between reMarkable devices and applications.

Source Code

def check_gpt_in_folder():
    """Check the gpt_in folder status and metadata"""
    
    # Load auth session
    auth = RemarkableAuth()
    session = auth.get_authenticated_session()
    
    if not session:
        print("āŒ Failed to authenticate")
        return False
    
    print("šŸ“ Checking gpt_in Folder Status")
    print("=" * 50)
    
    gpt_in_uuid = "99c6551f-2855-44cf-a4e4-c9c586558f42"
    
    try:
        # Step 1: Get current root.docSchema
        root_response = session.get("https://eu.tectonic.remarkable.com/sync/v4/root")
        root_response.raise_for_status()
        root_data = root_response.json()
        
        root_content_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{root_data['hash']}")
        root_content_response.raise_for_status()  
        root_content = root_content_response.text
        
        # Step 2: Find gpt_in folder entry
        print(f"\nšŸ“‹ Step 1: Finding gpt_in folder in root.docSchema...")
        
        gpt_in_entry = None
        gpt_in_hash = None
        
        for line in root_content.strip().split('\n')[1:]:  # Skip version
            if gpt_in_uuid in line:
                gpt_in_entry = line
                parts = line.split(':')
                if len(parts) >= 5:
                    gpt_in_hash = parts[0]
                    folder_type = parts[3]
                    folder_size = parts[4]
                break
        
        if not gpt_in_entry:
            print(f"āŒ gpt_in folder NOT found in root.docSchema")
            return False
        
        print(f"āœ… Found gpt_in folder entry: {gpt_in_entry}")
        print(f"āœ… Folder hash: {gpt_in_hash}")
        print(f"āœ… Folder type: {folder_type} (should be 2 for collection)")
        print(f"āœ… Folder size: {folder_size}")
        
        # Step 3: Get folder's docSchema
        print(f"\nšŸ“„ Step 2: Fetching gpt_in folder's docSchema...")
        folder_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{gpt_in_hash}")
        folder_response.raise_for_status()
        folder_content = folder_response.text
        
        print(f"āœ… gpt_in folder docSchema size: {len(folder_content)} bytes")
        print(f"šŸ“„ gpt_in folder docSchema content:")
        
        folder_lines = folder_content.strip().split('\n')
        for i, line in enumerate(folder_lines):
            print(f"   {i}: {line}")
        
        # Step 4: Get folder metadata
        print(f"\nšŸ“ Step 3: Getting gpt_in folder metadata...")
        
        folder_metadata_hash = None
        for line in folder_lines[1:]:  # Skip version
            if ':' in line and '.metadata' in line:
                parts = line.split(':')
                if len(parts) >= 5:
                    folder_metadata_hash = parts[0]
                    break
        
        if not folder_metadata_hash:
            print(f"āŒ gpt_in folder metadata not found")
            return False
        
        print(f"āœ… gpt_in metadata hash: {folder_metadata_hash}")
        
        # Fetch folder metadata
        folder_metadata_response = session.get(f"https://eu.tectonic.remarkable.com/sync/v3/files/{folder_metadata_hash}")
        folder_metadata_response.raise_for_status()
        folder_metadata = json.loads(folder_metadata_response.text)
        
        print(f"\nšŸ“Š GPT_IN FOLDER METADATA:")
        print(f"   Folder Name: {folder_metadata.get('visibleName', 'N/A')}")
        print(f"   Parent UUID: {folder_metadata.get('parent', 'N/A')}")
        print(f"   Parent Display: {'(root)' if folder_metadata.get('parent', '') == '' else folder_metadata.get('parent', 'N/A')}")
        print(f"   Folder Type: {folder_metadata.get('type', 'N/A')}")
        print(f"   Last Modified: {folder_metadata.get('lastModified', 'N/A')}")
        print(f"   Deleted: {folder_metadata.get('deleted', 'N/A')}")
        
        print(f"\nšŸ“„ FULL FOLDER METADATA JSON:")
        print(json.dumps(folder_metadata, indent=2))
        
        # Step 5: Check if our document should be visible in this folder
        print(f"\nšŸ” Step 4: Checking folder contents...")
        
        # Look for documents that should be in this folder
        our_doc_uuid = "206f5df3-07c2-4341-8afd-2b7362aefa91"
        documents_in_folder = []
        
        for line in root_content.strip().split('\n')[1:]:  # Skip version
            if ':' in line:
                parts = line.split(':')
                if len(parts) >= 5:
                    doc_uuid = parts[2]
                    doc_type = parts[3]
                    
                    # Check if this is a document (type 4) that might be in our folder
                    if doc_type == '4':  # Document type
                        # We need to check each document's metadata to see if it's in our folder
                        # For now, just note our target document
                        if doc_uuid == our_doc_uuid:
                            documents_in_folder.append(f"āœ… Our document: {doc_uuid}")
        
        print(f"šŸ“Š Documents that should appear in gpt_in folder:")
        for doc in documents_in_folder:
            print(f"   {doc}")
        
        # Step 6: Analysis
        print(f"\nšŸ” ANALYSIS:")
        if folder_metadata.get('deleted', False):
            print(f"āŒ gpt_in folder is marked as DELETED")
        else:
            print(f"āœ… gpt_in folder is NOT deleted")
        
        if folder_metadata.get('parent', '') == '':
            print(f"āœ… gpt_in folder is in ROOT (correct)")
        else:
            print(f"āŒ gpt_in folder is NOT in root: {folder_metadata.get('parent', 'N/A')}")
        
        if folder_metadata.get('type') == 'CollectionType':
            print(f"āœ… gpt_in folder type is CollectionType (correct)")
        else:
            print(f"āŒ gpt_in folder type is wrong: {folder_metadata.get('type', 'N/A')}")
        
        print(f"\nšŸ’” POTENTIAL ISSUES:")
        print(f"   • Document is correctly assigned to gpt_in folder")
        print(f"   • gpt_in folder exists and appears valid")
        print(f"   • This might be a client sync timing issue")
        print(f"   • Try refreshing/resyncing the desktop app and device")
        print(f"   • Web app may be caching old folder view")
        
        return True
        
    except Exception as e:
        print(f"āŒ Check failed: {e}")
        return False

Return Value

Returns a boolean value: True if the folder check completes successfully and the folder is found with valid structure, False if authentication fails, the folder is not found, or an exception occurs during the check process. The function primarily outputs diagnostic information to stdout rather than returning detailed data.

Dependencies

  • json
  • requests
  • auth

Required Imports

import json
import requests
from auth import RemarkableAuth

Usage Example

# Ensure auth.py module is available with RemarkableAuth class
# from auth import RemarkableAuth

# Call the function to check gpt_in folder status
result = check_gpt_in_folder()

if result:
    print("Folder check completed successfully")
else:
    print("Folder check failed or folder not found")

# The function will print detailed diagnostic information including:
# - Folder existence in root schema
# - Folder hash and type
# - Folder metadata (name, parent, modification date)
# - Documents within the folder
# - Analysis of potential issues

Best Practices

  • This function contains hardcoded UUIDs (gpt_in folder and document) - consider parameterizing these for reusability
  • The function makes multiple sequential API calls which could be optimized or made concurrent
  • Error handling uses a broad try-except block - consider more granular exception handling for different failure modes
  • The function has side effects (prints to stdout) - consider returning structured data instead for better testability
  • API endpoint URLs are hardcoded to 'eu.tectonic.remarkable.com' - consider making region configurable
  • The function assumes specific API response formats - ensure API version compatibility
  • Authentication session should be validated before making multiple API calls
  • Consider adding rate limiting or retry logic for API calls to handle transient failures

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v85 85.3% similar

    Diagnostic function that debugs visibility issues with the 'gpt_in' folder in a reMarkable tablet's file system by analyzing folder metadata, document contents, and sync status.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/debug_gpt_in_folder.py
  • function verify_document_status 73.0% similar

    Verifies the current status and metadata of a specific test document in the reMarkable cloud sync system by querying the sync API endpoints and analyzing the document's location and properties.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/verify_document_status.py
  • class FolderDebugger 73.0% similar

    A debugging utility class for analyzing and troubleshooting folder structure and visibility issues in the reMarkable cloud sync system.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/debug_gpt_in_folder.py
  • function test_remarkable_discovery 71.9% similar

    Asynchronous test function that verifies reMarkable cloud folder discovery functionality by initializing a RemarkableCloudWatcher and attempting to locate the 'gpt_out' folder.

    From: /tf/active/vicechatdev/e-ink-llm/test_mixed_mode.py
  • function main_v86 64.7% similar

    A test function that attempts to move a specific document (identified by UUID) from trash to a 'gpt_in' folder on a reMarkable device using the DocumentMover class.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_move_from_trash.py
← Back to Browse