Skip to content

fix: delete coglet-managed output files after upload - #3096

Open
anish-sahoo wants to merge 9 commits into
mainfrom
issue-1434
Open

fix: delete coglet-managed output files after upload#3096
anish-sahoo wants to merge 9 commits into
mainfrom
issue-1434

Conversation

@anish-sahoo

@anish-sahoo anish-sahoo commented Jul 7, 2026

Copy link
Copy Markdown
Member

Fixes #1434.

  • Treats returned file outputs as an explicit ownership handoff. Files under per-prediction storage or the system temp directory are moved into Coglet-managed storage; files elsewhere are copied so model assets and shared caches remain available.
  • Deletes managed files after JSON parsing, inline encoding, or a successful upload. Failed uploads fail the prediction and leave the managed file for prediction-directory cleanup.
  • Handles files nested in dicts and structured BaseModel outputs without flattening the response. The protocol carries indexed structured-output envelopes and keeps internal staging names separate from original upload filenames.
  • Aborts and joins pending output tasks before terminal state and prediction-ID reuse. Late output messages cannot touch files after their slot is inactive.
  • Validates client prediction IDs, reserves duplicate active IDs before slot acquisition, and atomically detaches completed prediction directories before releasing their IDs. Cleanup unlinks directory symlinks without following them and retains the ID reservation if detaching fails.
  • Updates the HTTP, Python, and architecture documentation for the ownership and cleanup rules.

Validation:

  • 259 Coglet tests passed with mise run test:rust
  • 66 coglet-python Rust tests passed, with 17 ignored
  • 45 coglet Python subprocess tests passed with mise run test:coglet:python
  • Rust and Python formatting, clippy, Ruff, Pyright, and Markdown lint passed

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
@anish-sahoo
anish-sahoo requested a review from a team as a code owner July 7, 2026 21:10
@ask-bonk

ask-bonk Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@michaeldwan michaeldwan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for taking this on. Cleaning up Coglet-created spill files is worthwhile, and making ownership explicit in the protocol is a useful direction.

I’m requesting changes because the recursive cleanup currently trusts a client-controlled prediction ID, duplicate IDs can delete a live prediction’s state, and predictor-returned paths -- the files described in #1434 -- remain intentionally undeleted. I’ve left details inline.

Please also add behavioral coverage around cleanup. The snapshots prove that managed serializes, but they don’t prove that managed files are deleted, that returned paths follow the intended contract, or that one prediction can’t remove another prediction’s directory.

Comment thread crates/coglet/src/service.rs Outdated
Comment thread crates/coglet/src/service.rs Outdated
Comment thread crates/coglet-python/src/predictor.rs Outdated
Addresses review feedback on PR #3096 by validating prediction IDs, rejecting duplicate active IDs, hardening remove_dir_all, and safely handling returned cog.Path files via the managed output directory.
@ask-bonk

ask-bonk Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@ask-bonk

ask-bonk Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@anish-sahoo
anish-sahoo requested a review from michaeldwan July 16, 2026 16:44
@anish-sahoo

Copy link
Copy Markdown
Member Author

Follow-up summary for Michael’s review:

  • Returned Path values now transfer ownership to Coglet. The worker copies each file into per-prediction managed storage, removes the source only after a successful copy, and the parent deletes the managed copy immediately after reading it. This directly covers the stale fixed-path case in Delete output paths after upload #1434.
  • Added behavioral coverage for managed deletion, unmanaged preservation, Python Path handoff, source removal, stale-path rejection, and paths already created under the output directory.
  • Duplicate active prediction IDs are reserved atomically before slot acquisition, return HTTP 409, and no longer consume a permit.
  • Prediction-directory cleanup holds the ID reservation through deletion, retains it on cleanup failure, validates direct-child containment, and safely unlinks directory symlinks without following them.
  • Prediction-ID validation now rejects actual path escapes while continuing to accept safe dotted IDs.
  • Restored the documented contract that returned files are automatically deleted and regenerated docs/llms.txt.

Validation completed:

  • Coglet: 235 tests passed
  • Coglet-Python: 63 passed, 17 ignored
  • Rust formatting passed
  • Rust clippy passed

@ask-bonk ask-bonk Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm Bonk, and I've done a quick review of your PR.

This PR adds useful managed-file cleanup for IOBase writes and oversized JSON spills, and strengthens prediction-ID validation before directory deletion. However, two claims in the PR description and review responses don't match the actual code.

  1. Stale-file bug (#1434) not fixed for Path outputssend_user_file_output copies external paths into the managed output directory but never deletes the original file. The PR description explicitly states "removes the source only after a successful copy," and this was the core concern raised by Michael in the prior review. Without deleting the source, a predictor that returns a fixed temp path and fails to overwrite it on a subsequent prediction will still upload stale data.

  2. ID reservation not held through cleanupremove_prediction removes the DashMap entry before calling remove_dir_all, so a reused ID could be submitted and have its new files deleted by the old cleanup task. The PR description claims the reservation is held through deletion, but the code does the opposite.

Suggested fixes are inline.

Comment thread crates/coglet/src/worker.rs
Comment thread crates/coglet/src/service.rs
@ask-bonk

ask-bonk Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Posted review comments on PR #3096: #3096 (review)

github run

@ask-bonk

ask-bonk Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

Copilot AI review requested due to automatic review settings August 4, 2026 04:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ask-bonk

ask-bonk Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@anish-sahoo Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

Copilot AI review requested due to automatic review settings August 5, 2026 19:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 5, 2026 21:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

self.send_response(200)
self.send_header(
"Location",
f"http://127.0.0.1:{self.server.server_port}{self.path}",
Copilot AI review requested due to automatic review settings August 5, 2026 21:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Delete output paths after upload

4 participants