fix: delete coglet-managed output files after upload#3096
Open
anish-sahoo wants to merge 1 commit into
Open
Conversation
Coglet creates output files (IOBase writes, oversized JSON spills) in
/tmp/coglet/predictions/{id}/outputs/ but never deletes them. This can
cause stale-output bugs where models return outputs from previous
predictions if an overwrite fails (issue #1434).
Add a managed bool field to the FileOutput IPC protocol message so
the orchestrator knows which files are safe to delete (coglet-created)
vs user-authored Path outputs (returned by reference, must not be
deleted). The orchestrator deletes managed files immediately after
reading their bytes into memory. A backstop remove_dir_all in
remove_prediction cleans up the entire prediction directory to catch
files from aborted uploads or cancelled predictions.
Closes #1434
Contributor
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Coglet creates output files (IOBase writes, oversized JSON spills) in
/tmp/coglet/predictions/{id}/outputs/but never deletes them after upload or base64 encoding. This can cause stale-output bugs where models return outputs from previous predictions if an overwrite fails.Closes #1434.
Real-life examples
1. Fixed-path output with silent overwrite failure
A model writes its output to a fixed temp path (e.g.
/tmp/output.png) and returns thatPath. On a subsequent prediction, the image generation step hits an OOM or CUDA error that is caught by a try/except, but the model still returns the same path. Since the previous prediction's file was never cleaned up, the orchestrator reads and uploads the stale image — the user receives output from the previous prediction without any error.2. Partial failure in multi-output models
A model generates multiple output files and returns them as a list of
Pathobjects. If one of the file writes fails (e.g. disk full, permission error on a specific subdirectory), the model may still return all paths. The orchestrator uploads the stale file from the previous prediction for the failed write, producing a mixed output: some files from the current run, some from the previous run.3. Disk exhaustion from accumulated outputs
In high-throughput deployments, output files accumulate in
/tmp/coglet/predictions/across hundreds of predictions. Large outputs (video files, high-res images) can fill the container's tmpfs, causing subsequent predictions to fail withNo space left on deviceerrors. This is a slow-burn operational issue that degrades reliability over time until the container is restarted.4. Cancelled prediction leaves orphaned files
When a prediction is cancelled (e.g. client disconnects), in-flight upload tasks are aborted and their output files are left on disk. These orphans accumulate over the container's lifetime and are never cleaned up, contributing to the disk exhaustion problem above.
Solution
Add a
managed: boolfield to theFileOutputIPC protocol message so the orchestrator knows which files are safe to delete (coglet-created) vs user-authored Path outputs (returned by reference, must not be deleted).remove_predictionnow doesremove_dir_allon the prediction directory to catch files from aborted uploads or cancelled predictionsmanaged: false, never deletedFiles changed
crates/coglet/src/bridge/protocol.rs— addedmanaged: boolfield with#[serde(default)]; 3 snapshot testscrates/coglet/src/worker.rs—send_file_outputgainsmanagedparam;write_file_outputandbuild_output_messagesettruecrates/coglet-python/src/predictor.rs— PathLike call sites passfalsecrates/coglet/src/orchestrator.rs— deletes managed files afterstd::fs::readcrates/coglet/src/service.rs—prediction_dir_forhelper;remove_dir_allbackstop inremove_prediction; 2 testsValidation
mise run test:rust— 220/220 passmise run lint:rust— clippy cleanmise run fmt:rust— formatting clean