Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:0xsline OpenChatCut Atomic File Delivery

From Leeroopedia
Knowledge Sources
Domains Reliability, File_System
Last Updated 2026-10-22 14:00 GMT

Overview

Atomic file delivery using temp-file-then-rename with lease-based concurrency control to prevent concurrent writes to the same export target.

Description

OpenChatCut's export destination plugin writes exported files atomically: the file is first written to a temporary path, then renamed to the final destination. A lease mechanism (`leasedTargets` set) prevents two concurrent exports from writing to the same target path. If the target is already leased, a 409 Conflict error is returned (retryable). The lease is released after the write completes or fails. File names are validated against reserved Windows names, trailing dots/spaces, and sanitization rules.

Usage

Use this heuristic when delivering exported video files to user-specified directories. Apply it whenever concurrent export operations might target the same file path, or when a partially-written file must never be visible to the user. Also use it to handle export failure cleanup — the temp file is deleted if the rename fails.

The Insight (Rule of Thumb)

  • Action: Acquire a lease on the target path, write to a temp file, then `rename()` atomically to the final path. Release the lease in a finally block.
  • Value: Max export file size = 100 GiB. Lease conflict = HTTP 409 (retryable). Temp file cleaned up on failure.
  • Trade-off: Lease prevents parallel writes to the same path; concurrent exports to different paths are unaffected.
  • Compatibility: Filename validation rejects reserved Windows names (CON, PRN, etc.), trailing dots/spaces, non-sanitized characters, and names > 240 UTF-8 bytes.

Reasoning

File rename is atomic on POSIX filesystems and NTFS — either the old file or the new file is visible, never a partial write. The lease set prevents a race where two exports finish simultaneously and both try to rename to the same target, which would cause one to overwrite the other's output. The 409 Conflict status is retryable so the client can wait and retry. The temp file is cleaned up on failure to avoid orphaned partial files consuming disk space.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment