Skip to content

Scaffolding failure leaves an orphaned project directory #1254

Description

@groupthinking

Problem

ProjectCodeGenerator.generate_project creates a temporary project directory and
hands the path back to its caller. If scaffolding raises, the handler logs and
re-raises without removing the directory, so the path is never returned and the
directory has no owner.

Aspect Detail
File src/youtube_extension/backend/code_generator.py
Directory created tempfile.mkdtemp(prefix="uvai_project_")
Handler except Exception as e: logger.error(...); raise (L276-278)
Missing No removal of the directory the function created
Age Pre-existing; predates #1250 / #1251

The caller at backend/services/video_processing_service.py:380 reads
generation_result["project_path"] at L390, so it never learns the path when the
call raises. There is no rmtree anywhere in that module.

Reachability evidence

POST /api/v1/video-to-software        router.py:778   (mounted main.py:192)
  -> process_video_to_software        video_processing_service.py:317
  -> code_generator.generate_project  video_processing_service.py:380

Same endpoint verified in #1239 and #1250.

Scope note

This is deliberately not fixed in #1251. That PR restores cancellation
atomicity after moving scaffolding writes onto worker threads, and it covers the
CancelledError path only. The generic-exception leak is older, is not caused by
that change, and touching the shared handler risks altering existing failure
expectations. Splitting it keeps the perf change reviewable.

Acceptance criteria

  • A scaffolding failure removes the directory generate_project created.
  • The original exception still propagates unchanged; cleanup never masks it.
  • Cleanup runs off the event loop and drains any worker still writing, matching
    the _run_to_completion / _discard_project_dir helpers added in perf: batch project scaffolding disk writes off the event loop #1251.
  • A regression test forces a real failure (no mocks on the mechanism under test)
    and asserts no uvai_project_* directory survives.

Proposed fix

Reuse the helpers introduced in #1251: on the exception path, await _discard_project_dir(project_path) before re-raising, guarded so a cleanup
failure cannot replace the original exception.

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