More screenshots

    Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseOpenClawOpenClaw+21 more

    Repair Temporary File & Cleanup Failures

    1

    Repair Temporary File & Cleanup Failures is a bounded ToolForge Labs workflow.

    $8.99

    Secure checkout via Stripe

    30-day refund guarantee

    Converts to your local currency at checkout

    Security scanned
    Repair Temporary File & Cleanup Failures

    Repair Temporary File & Cleanup Failures

    Example session with this skill installed

    Our Python background worker is leaving thousands of .tmp files in /tmp after it crashes, eventually hitting disk quotas. It uses a simple open() and doesn't clean up on SIGTERM. Help.

    • Read your context and instructions
    • Compiled the repair temporary file

    I have analyzed the lifecycle failure in your background worker. The primary issue is the lack of a formal cleanup contract and the absence of atomic publication, which leads to orphaned files when the process receives a SIGTERM or crashes during a write operation.

    Temporary File Lifecycle Repair

    The following implementation uses a context manager to ensure cleanup and an atomic write-then-rename pattern to prevent partial data corruption.

    import os
    import tempfile
    import logging
    from contextlib import contextmanager
    from pathlib import Path
    
    logger = logging.getLogger(__name__)
    
    @contextmanager
    def atomic_write_path(target_path, dir=None):
        """
        Ensures a file is written completely or not at all.
        Handles cleanup of the temporary file even on exceptions or crashes.
        """
        target_path = Path(target_path)
        # Create temp file in the same filesystem as target for atomic rename
        fd, temp_path = tempfile.mkstemp(
            dir=dir or target_path.parent, 
            prefix=f".{target_path.name}-",
            suffix=".tmp"
        )
        try:
            os.close(fd) # Close handle so we can use standard file IO
            yield Path(temp_path)
            
            # Ensure data is flushed to disk before renaming
            with open(temp_path, 'rb+') as f:
                f.flush()
                os.fsync(f.fileno())
                
            os.replace(temp_path, target_path)
        except Exception as e:
            logger.error(f"Failed to write {target_path}: {e}")
            raise
        finally:
            # Final safety cleanup if rename didn't happen
            if os.path.exists(temp_path):
                try:
                    os.unlink(temp_path)
                except OSError:
                    pass
    
    # Usage in your worker
    def process_data(data, output_file):
        with atomic_write_path(output_file) as tmp:
            with open(tmp, 'w') as f:
                f.write(data)
    
    InvariantImplementation DetailBenefit
    Cleanupfinally block with os.unlinkPrevents disk quota exhaustion on SIGTERM/Exceptions.
    Atomicityos.replaceEnsures the target file is never in a partially-written state.
    Durabilityos.fsyncProtects against data loss during system power failure.
    Securitytempfile.mkstempUses safe permissions (0600) and prevents naming collisions.

    Next steps

    1. Integrate the atomic_write_path utility into your main processing loop.
    2. Register a signal handler for SIGTERM to allow the context manager's finally block to execute.
    3. Verify that your /tmp directory and the target directory reside on the same mount point to ensure os.replace is atomic.

    Connects securely to your tools. The creator never sees your data.

    What you get

    Fix resource leaks in processes that fail to clean up temporary directories.Implement atomic file replacement to prevent data corruption during crashes.Secure temporary file creation against symlink races and permission exploits.Resolve cross-platform pathing issues between Windows and Unix environments.

    About this skill

    Repair Temporary File & Cleanup Failures is a bounded ToolForge Labs workflow. Repair temporary-file lifecycle failures across secure creation, naming, permissions, atomic replacement, cancellation, crashes, concurrent workers, cleanup, disk pressure, and cross-platform behavior. Works from repositories or partial helper/log evidence. Produces bounded repairs and deterministic tests while preserving sandbox and data-handling rules. It works from a full repository or partial evidence such as snippets, logs, configuration, traces, tickets, and architecture notes. The skill preserves existing product and security policy, separates verified facts from assumptions, avoids invented execution claims, and produces concrete repair or review steps with focused deterministic validation or traceable evidence.

    How to install

    Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.

    ~30 seconds
    1. 1

      Download the ZIP

      Free skills download straight away. Paid skills unlock right after purchase.

    2. 2

      Unzip into your skills folder

      Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.

    3. 3

      Ask your agent to use it

      Restart the agent if it was already running. It picks the skill up automatically - no config needed.

    Skills folder by agent

    Click the path to copy it. Create the folder if it does not exist yet.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean 21 days ago

    • Passed all security checks, Safe to install

    Listed21 days ago

    What's inside

    Frequently Asked Questions