OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

[Bug]: A rejected add-skill request leaves the materialized shared upload behind

Open Kiko0301 opened this issue 2 weeks ago • 0 comments

A rejected add-skill request leaves the materialized shared upload behind

Bug Description

POST /api/v1/skills (OpenViking/server/routers/resources.py, add_skill) consumes a temporary upload before the request is validated:

if request.temp_file_id:
    store = TempUploadStore.build(http_request.app.state.config)
    resolved = await store.resolve_for_consume(request.temp_file_id, _ctx)
    data = resolved.local_path
    ...
async def _add():
    try:
        return await install_skills(...)
    finally:
        if resolved:
            await resolved.cleanup()

execution = await run_operation(
    operation="resources.add_skill",
    telemetry=request.telemetry,
    fn=_add,
)

For a shared upload, resolve_for_consume() copies the stored content into a new OS temporary file (ov_shared_upload_*, bounded only by temp_upload.shared_max_size_bytes) and relies on resolved.cleanup() to remove that copy. run_operation() validates the telemetry request in run_with_telemetry() before calling fn; an unsupported telemetry option raises InvalidArgumentError (400). _add() never runs, so its finally never runs and the materialized copy is left behind.

The shared upload itself can be consumed repeatedly, so a client can repeat this request on demand and fill the server's temporary directory. The other upload-consuming entry points already keep resolution inside a try/finally (resource_ingest.ingest_temp_upload, skill_ingest.ingest_temp_upload_skill); add_skill is the outlier because it moved the resolution outside the operation.

Steps to Reproduce

  1. Upload a file with upload_mode=shared: POST /api/v1/resources/temp_upload and keep the returned temp_file_id.
  2. Call POST /api/v1/skills with {"temp_file_id": "<id>", "telemetry": {"unsupported": true}} (any telemetry option the server does not support).
  3. The request is rejected with 400.
  4. Inspect the server's temporary directory: a leftover ov_shared_upload_* copy of the upload remains. Repeating step 2 with the same shared upload id accumulates one copy per request.

Expected Behavior

A request rejected during validation leaves no materialized upload copy behind.

Actual Behavior

Every rejected request leaks one temporary copy of the shared upload, and because shared uploads are reusable the leak is repeatable on demand.

Environment

  • OS: Windows 11
  • OpenViking version/commit: main @ b2031597

Additional Context

Fix submitted as PR #7639: temporary-upload resolution and the values derived from it move inside _add(), so the upload is materialized only after telemetry validation succeeds and the existing try/finally always cleans it up. A regression test uses a fake upload store that materializes a file and asserts that a rejected request calls neither resolve_for_consume() nor install_skills() and leaves no temporary file.

Kiko0301 avatar Nov 14 '26 09:11 Kiko0301