Uploads: replace a file in place, and say which file each version is

Merged
JE
4mo ago
+4556-201

Absorbs basecamp/bc3#12555 and #12565. Closes #649. Closes the write side of spec/api-gaps/upload-new-version.md, open since 2026-07-22, and unblocks basecamp-cli#404.

The write

POST /uploads/{id}/versions.json replaces an upload's file in place. The recording keeps its id, its URL and its comments; the previous file becomes a past version. CreateUpload cannot do this — it mints a new recording with a new id and a new URL, so every published link rots on each release.

CreateUploadVersion models attachable_sgid, base_name, description, notify and subscriptions.

notify and subscriptions are documented contracts as of #12565, not guesses. Subscribers#notify_param defaults to "custom", so an audience arrives through two doors: notify naming a mode, or a bare subscriptions array taken as custom. The plan for this work assumed neither was caller-selectable; reading the concern showed the second door is live and that bc3's own web tests already rely on it. visible_to_clients is deliberately absent — #12565 removed it from the endpoint's reachable surface, because it never set the recording's visibility, only widened the notification audience, and could announce a client-invisible file to a project's clients.

The read — this is the half that fixes #649

ListUploadVersionsOutput declared uploads: UploadList. The endpoint returns events: 11 of Upload's 14 @required members are absent from every response. That typed lie is why the CLI's versions command and the MCP server's list_upload_versions render blank fields — the SDK was decoding an event payload into a struct whose required fields it does not carry.

It now returns UploadVersion / UploadVersionFile, built from _version.json.jbuilder over recordings/events/_event.json.jbuilder rather than from the Upload shape it was pretending to be. New shapes rather than EventList plus a member, for the reason bc3's own commit gives for using a purpose-built partial: widening the shared one "would leak upload fields onto todo, message, and card events". Recorded in SPEC §10 as the second worked example of One Renderer, One Schema.

The 507, which turned out to be four operations wide and then six

StorageLimitError declares the 507 ensure_account_can_upload_files has always been able to raise. That guard fronts four modelled operations, so all four take it — absorbing the contract for the new one alone would leave three declaring a status they can return and don't model.

The larger find is the classification. SPEC §6 had no 507 step, so a 507 fell through status >= 500 and surfaced as api_error with retryable: true — a plan limit no retry can satisfy, reported as a transient server error. §6 now maps 507 to limit_exceeded, non-retryable, ordered ahead of the 5xx catch-all, with exit code 10 in all six SDKs.

That also fixes ProjectLimitError, which #679 added days ago. Five SDKs carried tests pinning the old behaviour, each commented "No SDK gives 507 a named class". Python's went further and recorded a genuine cross-SDK divergence — its fallback arm produced retryable=False while the other five marked every unclassified 5xx retryable, "asserted here as-is rather than fixed in passing". All six now agree on False, and False is what the spec says rather than an accident of which arm caught the status.

Nothing retried a 507 in practice — no retryOn list names it — so this changes what the caller is told, not what the client does.

Breaking

Two entries in MIGRATING.md. The ListUploadVersions retype is compiler-silent in Ruby, Python and Kotlin: the type does not change, only which keys are actually present. Go's UpdateUploadRequest.Description → *string the compiler does catch.

BaseName stays a plain string on both request types, and says why in its doc comment: Upload#base_name= guards on new_base_name.present?, so "" and absent are the same server write and there is no third state a pointer could express.

Verification

make passes clean. 250 operations.

Every new assertion was run against un-fixed code first:

  • TestUpdateUploadRequest_DescriptionIsTriState → Description: the clear spelling must reach the wire
  • TestUploadVersionFromGenerated_DetailsSurvives → a present but empty details object must survive as non-nil
  • the conformance 507 case → TypeScript reported expected 'api_error' to be 'limit_exceeded'

conformance/tests/uploads_write.json — 7 cases, all six runners green. Named for the surface, not the operation, because it has to cover both writes: UpdateUpload lands on the same serialized ActionText attribute and had its presence semantics pinned nowhere. The uploads surface had zero requestBodyAbsent assertions before this; each rides with a requestBody presence assertion in the same case, since a requestBodyAbsent alone is satisfied by an empty body.

The shared fixture is built from the renderer, and its mock bodies come from spec/fixtures/uploads/get.json — Swift's strict decoder rejected hand-rolled ones for missing bucket, which is a better outcome than passing.

Notes for review

  • Rebased onto #679 mid-flight. That repin already contained #12555, so this range is one commit (#12565), and the registry: waivers #679 parked for these routes are deleted here — absorption is what removes them. Three gap entries this branch wrote were dropped as duplicates of #679's better ones.
  • One finding no gate could catch, already fixed upstream: #9471 added resource :authorization to bc3's routes, so the out_of_scope waiver's "served from Launchpad" justification had decayed. #679's bc5-authorization-document-shape.md covers it, and splits the OAuth work more carefully than this branch had.
  • New gap registered: upload-create-subscriptions.md. CreateUploadInput has always declared a subscriptions member that UploadsController#create never reads — the same class of lie as #649, in the structure next to it. Not fixed here; removing an input member is breaking and belongs in a change whose title says so.
  • The Go reflection guard TestUpdateUploadRequest_HasNoFileReplacementField stays. bc3 chose a dedicated route rather than widening the PUT, so it now pins a design choice rather than a missing feature.

Still open

  • basecamp/bc-api#433 — the public docs mirror is two PRs behind (#12555 and #12565).
  • The live-account canary in upload-new-version.md, and basecamp-cli#404's command.

Summary by cubic

Adds CreateUploadVersion to replace an upload’s file in place and retypes versions reads to return UploadVersion with the file each event recorded. Also reclassifies HTTP 507 to non‑retryable limit_exceeded across SDKs and sweeps docs to the correct 250‑operation count.

  • New Features

    • POST /uploads/{id}/versions.json via CreateUploadVersion; models attachable_sgid, base_name, description, notify, subscriptions.
    • Description is presence‑aware: omit carries forward, "" clears, value sets.
    • Versions list returns UploadVersion with upload details and current. current is positional and exactly one per non‑empty response; it does not mean “the file the upload’s download_url serves” after a metadata‑only update.
  • Migration

    • Type change: listVersions now returns UploadVersion (not Upload) in TypeScript, Swift, and Kotlin; update callers. Ruby/Python decode unchanged at runtime.
    • New error code: 507 is limit_exceeded (exit code 10), non‑retryable. Update exhaustive handling in TypeScript, Swift, Kotlin, and Python; applies to eight ops: CreateUpload, CreateUploadVersion, CreateDocument, CreateCloudFile, CreateProject, UnarchiveProject, CreateWebhook, UpdateWebhook.
    • TypeScript: UploadVersion and CreateVersionUploadRequest are exported from index.ts; update imports if used.
    • Go: UpdateUploadRequest.Description is now *string; 507 maps to limit_exceeded on generated and raw HTTP paths.
    • Selecting past versions: filter for upload.current === false; do not filter on action === "blob_changed".
    • Docs/counts sweep: repo updated to 250 operations (83 idempotent, 167 non‑idempotent); 42 POSTs are attempted exactly once.