Skip to content

feat(primitives): staged uploads, discard, adoption, the files/<patchId>/<objectId> key layout and its sweep #409

Closed

Description

@allisonmahmood

Part of #384. Implements spec §10's staged uploads and key layout; decisions composition point 8, the reference CRM (discard, the new-layout sweep), limits (staged upload bounds).

What to build

  • Staging, a shell exception on the server-only client: patchy.files.stage(bytes, { contentType }) has the shell write an unreferenced object and returns a single-use Upload bound to viewer, consuming patch and loaded version. Bytes never enter the isolate on upload. Staging is unlogged transport.
  • Adoption: t.upload() in action arguments; ctx.files.<store>.put(name, bytes | Upload) in actions only, into a store the loaded version defines. The action sees Patchy's measured size (authoritative) and the claimed content type (not proof) before adopting. Adoption is a pointer write with no copy, logged as the existing file write. An object id is never adoption authority; only the Upload is.
  • Discard: patchy.files.discard(upload) removes a stage early under the same binding. Adoption and discard both take the stage row under lock, so whichever commits first wins; a consumed or discarded stage answers not_found.
  • The key layout: object keys become files/<patchId>/<objectId>. Nothing is deployed, so nothing migrates; the company-database inventory gains the staged-object and adoption state as an idempotent upgrade.
  • The sweep for the new layout: an object is swept only when no store references it and no live stage holds it, and adoption cannot race the sweep. Unadopted stages are swept after 1 h, after which adoption is refused.
  • Bounds: 20 MiB per stage; 16 stages and 100 MiB outstanding per viewer per patch; 1 GiB per company.
  • Put then mutation is not atomic: if the follow-up mutation fails the adopted file remains, and the skill says the patch must present that partial outcome. "A content type is a claim."

Admitted at merge

Tier 2 uploads.

Done when

A stage adopted twice is refused the second time; discard racing adoption leaves exactly one outcome; an hour-old stage is swept and its adoption refused; the sweep never removes an adopted or live-staged object; the bounds refuse the 17th stage.

Surfaces

The wire (docs/API.md), the Primitives glossary (Staged upload), ADR-0010 (the third shell exception), docs/product.md § Files, the patchy-files and patchy-server skills.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:primitivesready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions