Skip to content

Cancelled video-to-software request leaks the scaffold temp directory #1253

Description

@groupthinking

Problem

Once ProjectCodeGenerator moved its scaffolding filesystem work off the event loop (#1250 / #1251), the off-loop hops introduced await (cancellation) points that did not exist when the writes ran inline. A POST /api/v1/video-to-software request that is cancelled or fails mid-scaffold can now leave a uvai_project_* temporary directory that no caller receives or removes.

asyncio.to_thread cannot interrupt a worker thread once it has started, so a cancellation delivered while a scaffolding hop runs raises CancelledError in the coroutine while the thread keeps writing to disk. generate_project never returns the directory path, so nothing cleans it up.

There are two leak windows:

  1. mkdtemp window — cancellation delivered while tempfile.mkdtemp runs; the directory is created but its path is never assigned into a cleanup scope.
  2. write-plan window — cancellation delivered while _apply_write_plan runs; the scaffold is partially/fully written and abandoned.

Acceptance criteria

  • A request cancelled or failed at any point after the scaffold directory is created removes that directory before propagating.
  • Off-loop hops wait for their worker to settle before propagating cancellation, so cleanup never races a live writer.
  • Regression tests cover both windows (cancel during mkdtemp, cancel during _apply_write_plan, and failure during the write plan).
  • Happy-path generated output is unchanged (byte-for-byte equality preserved from perf: batch project scaffolding disk writes off the event loop #1251).

Fix

Tracked in PR #1252 on branch claude/determined-maxwell-9t5kou.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions