Skip to content

bug(platform): /files/reject-blob deletes the bytes of an upload a task already attached #4104

Closed

Description

@yannickmonney

Summary

POST /api/app/files/reject-blob deletes the stored bytes of an upload that a task already lists as an attachment. Afterwards the task still shows the file, /files/urls answers url: null for it, and per #4085 every run start for that task fails as input_missing.

The cause is in the reclaim lane:

Reach is low. The shipped UI registers every upload before attaching it, and registration consumes the intent, so the UI-shaped flow is protected (case P1 below). It takes a session-API client that attaches a POST /files/upload ref to a task without registering it, then reclaims that same ref within the 2-hour intent TTL. The consequence, once reached, is permanent loss of the attachment's bytes.

Source and environment

  • Source: origin/main b7d1c1d7ef1b6755fad8a75da122159d8d3a6138 (fix: name budget-rule keys, explain empty chat replies, land docs labels #4012). The reclaim lane and the task door are unchanged since fix(platform): keep task attachment bytes alive and name a gone one #4085 (1f0009cc3).
  • Local native stack, owned by the TALE-358 local-qa occurrence 2026-10-03 00:15 Zurich, run 820db997-15c0-43a4-a678-23bd1714628f:
    • Database: PostgreSQL 16.15 (PGDG bookworm) with pg_search 0.22.6, pgvector 0.8.6 and pg_cron 1.6.7, initialized like tale-db, on 127.0.0.1:55370.
    • App: bun scripts/dev.ts (backend 127.0.0.1:3656, Vite localhost:3651), with egress to a dead proxy.
    • Object store: a local S3 test double on 127.0.0.1:59070 that logs every request, so each DELETE the backend sends is visible.
    • Data: synthetic users and organization proof-b1-murjho5n.

Impact

A task attachment's bytes are deleted while the task keeps listing the file. Nothing warns, the bytes can't be recovered, and the task can't run until someone re-uploads the file. This is the same user-visible end state that #4085 fixed for the file-delete, trash-purge and sweep lanes.

The same rule also covers the other lanes that bind without consuming, the document multi-bind and outbound mail attachments (#3191). Those weren't exercised here; see Limits.

Root cause

All references are to services/platform at b7d1c1d7e.

  1. The task door binds without consuming the intent. assertOwnedTaskAttachments (backend/domains/tasks/service.ts:1239-1257) calls firstForeignUpload → ownsUploadedBlob (backend/domains/files/upload-intents.ts:146-169). That stamps bound_at_ms and leaves consumed_at_ms NULL.
  2. The reclaim lane then treats the open intent as never bound. deleteRejectedUploadBlob (backend/domains/files/service.ts:846-872):
    • looks only for an app.file_metadata row;
    • calls consumeUploadIntent (upload-intents.ts:113-131), which matches any unconsumed, unexpired intent of the caller whatever bound_at_ms says;
    • then deletes the object.
  3. The sibling lanes honour the rules this one skips:
    • sweepUploadIntents (upload-intents.ts:200-) never reclaims a ref with bound_at_ms set;
    • deleteFile (files/service.ts:685-700) keeps bytes while taskHoldsBlobRef is true.

Deterministic reproduction

The probe is scripts/b1-reject-blob.ts, retained in the TALE-358 evidence archive TALE-358-local-qa-r20261003T0015-evidence.tar.gz together with its log, the S3 double's request log and the database readback. Every case runs as one synthetic owner (plus a synthetic member for C2), through the session doors under /api/app.

Case Steps reject-blob answer S3 DELETEs Bytes after
C1 control POST files/upload, then reject deleted: true 1 gone (expected)
C2 refusal owner uploads; a member rejects that ref deleted: false 0 kept
C3 refusal UI lane: blob-upload → PUT → files/register, then reject deleted: false 0 kept
P1 UI-shaped UI lane upload, POST tasks with it as an attachment, then reject deleted: false 0 kept
C4 #4085 predicate UI lane upload, attach to a task, DELETE files/:fileId 200 0 kept (the task holds the ref)
P2 defect POST files/upload, POST tasks with it as an attachment (the task lists it), then reject deleted: true 1 gone; the task still lists it; POST files/urls → url: null

Readback after P2: P2's app.upload_intents row has bound_at_ms set, by the task bind, and consumed_at_ms set, by the reject.

Expected

The rejected-upload reclaim deletes only bytes that nothing holds. A ref that a task, a document or an outbound message bound or vouched for answers deleted: false, and its bytes stay.

Observed

P2: {"deleted": true}. The backend sent DELETE /tale358-r0015/proof-b1-murjho5n/2b8e419f-… to the store (logged with existed: true), while app.tasks.attachments still lists s3:proof-b1-murjho5n/2b8e419f-….

Acceptance checks

  1. The reclaim refuses held refs. deleteRejectedUploadBlob refuses when the caller's intent carries bound_at_ms, or any holder check is true. At minimum that is taskHoldsBlobRef, app.documents.file_ref and app.file_metadata, the same checks deleteFile uses. Preferably there is one shared rule, so the next holder can't be missed again.
  2. A regression case for P2 passes (upload → task attach → reject → deleted: false, bytes kept). C1, C2 and C3 keep their current results. Use the real-Postgres backend:integration lane next to fix(platform): keep task attachment bytes alive and name a gone one #4085's task-holder lanes, with an object store, so a DELETE would be observed.
  3. Optional: consume or close the intent at the task bind, so a later reclaim can't match it. If that's the chosen fix, document how it interacts with the non-consuming multi-bind lanes (fix(platform): close eight low-severity reliability leaks and races #3191).
  4. Out of scope: the user-erasure lane's documented behaviour (fix(platform): keep task attachment bytes alive and name a gone one #4085 "Out of scope").

Limits

  • Object store: a local S3 test double that ignores authentication, not MinIO. It shows the DELETEs the backend sends; the server-side code path is the real one.
  • Database differences from tale-db:
    • PostgreSQL 16.15 on bookworm, while tale-db builds FROM postgres:16-trixie;
    • pgvector 0.8.6, while the image has 0.8.1;
    • no pg_ivm, which Tale doesn't use.
  • Not exercised: the outbound mail and document multi-bind lanes. They share the non-consuming proof, but documents also register a file row, which C3 shows is honoured.
  • No reachable UI path: P1 shows the shipped UI flow is protected, and REST v1 carries no task attachments (backend/rest/error-codes.test.ts:221).

Activity

  1. yannickmonney commented on Oct 3, 2026

    @yannickmonney
    ContributorAuthor

    Source triage at 358f69107e3725e7e1e30f0c9e0eaf3a2410da74 confirms the reported reclaim gap remains. This is an independent source read, not another reproduction.

    For the repair, preserve the legitimate callers: registerUpload also uses consumeUploadIntent, while ownsUploadedBlob deliberately supports non-consuming multi-bind and consumed-but-unexpired intents. A blanket bound_at_ms IS NULL condition on the shared registration consumer would change that contract; keep the unbound-only requirement specific to reclamation and reuse the existing holder predicate.

    Also state the bind/reclaim ordering guarantee explicitly. The ownership stamp currently ignores consumed_at_ms, so merely checking the stamp once before deletion does not by itself prove that a later bind cannot win. That is a source-derived concurrency concern, not an independently reproduced second finding. Cover the chosen boundary with the real-Postgres regression/control lane, or clearly record the remaining limit; no production experiment is requested.

    The fleet manager has been asked to prioritize deduplicated intake for this issue. Root is not starting a competing implementation.

  2. yannickmonney commented on Oct 3, 2026

    @yannickmonney
    ContributorAuthor

    QA recheck after #4109, on main 3b23bd2cb (TALE-358 local-qa, run bab9f790-2159-4a21-88a7-4b46daffdf28; the reporter's own reproduction, replayed natively; I didn't write #4109).

    Setup: the same doors and S3 test double as the original report, with its own PostgreSQL :55372, the app on :3671/:3676 and synthetic data. Every DELETE the backend sends is logged.

    Case Original (b7d1c1d7e) Now (3b23bd2cb)
    P2: files/upload → task attach → reject-blob deleted: true, 1 DELETE, bytes gone deleted: false, 0 DELETEs, bytes kept; the task still lists the ref
    C1 unbound / C2 foreign / C3 registered / P1 UI lane / C4 deleteFile on a task-held ref true / false / false / false / kept unchanged
    C5: a reclaimed upload, then task attach — 403 TASK_ATTACHMENT_NOT_OWNED
    P3: API bind, the task drops the attachment, then reject-blob — the task door released the bytes (1 DELETE); the reject answers false

    Verdict: the original reproduction no longer reproduces, and the nearby controls hold.

    Correction to this issue's evidence: POST files/urls answers url: null for P2's ref even with its bytes present. It resolves file rows only (files/routes.ts:500-508), and an API-shaped upload has none. So that line was not evidence of the deletion. The S3 DELETE and the HEAD 404 were.

    Same class, one more lane: the product image release still keeps its own holder copy, the source follow-up agent #2 raised on TALE-487. It is confirmed natively in #4110.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugservice: platform

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions