Skip to content

jobs: remove a job's directory when it ends with nothing written - #167

Open
smfworks wants to merge 1 commit into
jayleaton:mainfrom
smfworks:upstream/empty-job-dirs
Open

smfworks wants to merge 1 commit into
jayleaton:mainfrom
smfworks:upstream/empty-job-dirs

Conversation

@smfworks

Copy link
Copy Markdown
Contributor

Independent; based on main.

Problem

Every request gets <data>/jobs/<id> before it runs. A request refused or failed before its tool wrote anything (503 insufficient_memory, an invalid image request, a cancel) left an empty directory. It stayed until the job expired, and across a restart until it was older than keep_outputs_s. One day of agent use on a workstation left 47 empty job directories (39 chat, 7 image, 1 video) out of 453.

Change

  • Job.dropIfEmpty removes the job's directory only if it is empty (rmdir). It runs when a job ends failed or cancelled (finish, finishCancelled) and when the API abandons a job it could not set up.
  • A directory with saved inputs or partial output stays, for expire as before. Completed jobs are untouched.
  • The start-up sweep also removes empty job directories of any age. It runs before any job exists, so they belong to no job.

Tests

  • jobs.zig: a refused job's directory goes, and a second call is harmless. A job with a saved input keeps its directory. sweep drops an empty directory and leaves one with a file.
  • scheduler.zig: a job whose generate fails, and a cancelled one, leave no directory. This test fails without the change.
  • zig build test-unit passes; zig fmt --check is clean.

Every request gets <data>/jobs/<id>, created before it runs. A request
refused or failed before the tool wrote anything (insufficient_memory, an
invalid image request, a cancel) left an empty directory until the job
expired, and across a restart until it was past keep_outputs_s. On a
Strix Halo box a day of agent use left 47 empty directories (39 chat, 7
image, 1 video) among 453.

A job that ends failed or cancelled now removes its directory when it is
empty (rmdir: one with saved inputs or partial outputs stays for expire).
The start-up sweep also removes empty directories whatever their age; it
runs before any job exists, so they belong to no job.

@jayleaton jayleaton left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The deletion paths only use server-generated job IDs or entries listed under the open jobs directory, so there's no path-traversal risk. Normal cleanup works for a worker's 400 and for a queue-full 503. Still needed:

  1. Blocking: src/api/routes.zig:693 and src/sched/scheduler.zig:1279 and :1303. Terminal status becomes visible before dropIfEmpty uses the job. With zero retention, expiry on another lane can free the job and its path before cleanup finishes. Please finish cleanup before publishing terminal status, and keep the job alive through completion signalling and active readers. Please add a finalization-vs-expiry test.
  2. Blocking: src/sched/jobs.zig:147. Startup checks that a fresh directory is empty and later calls deleteTree on it, so a file created in between is deleted even though it's inside the retention window. Please use the atomic deleteDir for fresh directories and keep deleteTree for expired ones. Please add a test where a fresh directory gains a file before cleanup.
  3. Blocking: src/sched/scheduler.zig:1974. The new test conflicts with #156's test at the end of the file. Please rebase and keep both tests.
  4. Nit: src/serve.zig:91. The startup log says every removal is age-based. Please update it to cover fresh empty directories.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants