Skip to content

fix(uploads): store upload bytes per version - #31

Open
TheGreatAxios wants to merge 11 commits into
cl-9068-artifacts-remove-skill-draft-web_site-handling-and-mailfrom
cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns
Open

TheGreatAxios wants to merge 11 commits into
cl-9068-artifacts-remove-skill-draft-web_site-handling-and-mailfrom
cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns

Conversation

@TheGreatAxios

@TheGreatAxios TheGreatAxios commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • artifact_version.source records each version's content reference and size. GET /artifacts/:id/download?version=N and GET /artifacts/:id/versions/:version return that version's file; omitting version serves the latest.
  • POST /artifacts/:id/versions with a multipart file (and optional expectedVersion) revises an upload with new bytes through the ContentStore and upload policy (reviseFileArtifact). The bytes are stored only after the row is locked and expectedVersion holds, so a 409 writes no blob. More than one file field is refused. The title carries forward.
  • Migration 0004_version_source backfills every existing version from its artifact, so 0.1.0 uploads download as version 1.
  • createWorkflowArtifactRoutes(deps) replaces mountWorkflowArtifacts(app, opts): the run-scoped routes are a sub-app factory like createArtifactRoutes. MountWorkflowArtifactsOpts is renamed CreateWorkflowArtifactRoutesDeps.
  • On upgrade from 0.1.0, 0002 grants create on artifact:* in the host's grant table to every principal that has already created an artifact in its tenant, before it drops the 0.1.0 ledger. It runs only while the ledger exists, so a later revoke sticks. New principals need the grant.
  • The real-Postgres suites move to e2e/, with the shared harness in e2e/helpers.ts and e2e/fixtures.ts. bun run test runs src/, bun run test:e2e runs e2e/, and test:coverage runs both.
  • The README follows the Corbits README standard (hub module). CONTRIBUTING adds the rule that a backfill must be cheap once it has run.
  • The find-by-title recency test no longer ties on timestamps.
  • Release 0.2.0: the version is bumped, and the CHANGELOG is one dated 0.2.0 section with every breaking change, including no rollback to 0.1.0 after the ledger drop and the Node 24 floor.
  • Stacked on refactor!: remove skill-draft, web_site handling and mail attachments #30; top of the stack.

Verification

  • bun install --frozen-lockfile, bun run build, bun run typecheck: pass.
  • bun run test:coverage against local Postgres (ALLOW_DESTRUCTIVE_ARTIFACT_TESTS=1): 292 pass, 0 fail, coverage floor met.
  • e2e/upgrade-from-0.1.0.test.ts upgrades a database written by the published 0.1.0: a 0.1.0 creator still gets 201 on create, a new principal gets 403, and re-running the migrations adds no grants.
  • e2e/file-round-trip.test.ts asserts each version's bytes and source, and that a stale expectedVersion revise leaves no file on disk.
  • Every README snippet typechecks against the built dist.

Closes CL-9336

@TheGreatAxios TheGreatAxios left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self-review: the review found that a file revise overwrote the title; this is fixed (title carries forward). Known and unchanged: multipart bodies are buffered before the size check, same as the upload route. The source merge reads the artifact before the lock; it is harmless today because nothing else rewrites source.

@TheGreatAxios
TheGreatAxios force-pushed the cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns branch from 0722cd6 to 7b1c38c Compare September 25, 2026 14:30
@TheGreatAxios
TheGreatAxios force-pushed the cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns branch 6 times, most recently from 336466d to 659191d Compare September 25, 2026 23:57
@TheGreatAxios
TheGreatAxios force-pushed the cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns branch 2 times, most recently from c47e831 to c3c62b1 Compare September 26, 2026 00:54
@TheGreatAxios
TheGreatAxios force-pushed the cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns branch from c3c62b1 to 0621cd7 Compare September 26, 2026 01:29
@TheGreatAxios TheGreatAxios changed the title Store upload bytes per version fix(uploads): store upload bytes per version Sep 26, 2026
Each artifact_version records its own source, so ?version=N downloads
that version's bytes. POST /artifacts/:id/versions accepts a multipart
file to revise an upload with new bytes. The 0004 migration backfills
existing versions from their artifact, so 0.1.0 uploads keep
downloading.
The version detail route now returns that version's source, not the
latest one's. A file revise stores its bytes only after the row is
locked and expectedVersion holds, and merges source from the locked
row, so a 409 leaves no orphaned blob. A revise with more than one file
field is refused.
The run-scoped routes become a sub-app factory like
createArtifactRoutes, so the host mounts them with app.route and their
bearer-token middleware no longer registers on the host app.
MountWorkflowArtifactsOpts is renamed CreateWorkflowArtifactRoutesDeps.
The seeds and the revise could share a millisecond, so the revised
artifact was not always strictly newer. Backdate the seeds first.
0.1.0 let any principal create; 0.2.0 requires create on artifact:*.
Before dropping the 0.1.0 ledger, 0002 grants it in the host's grant
table to every principal that already created an artifact in its
tenant, so existing users keep working and new principals need the
grant. It runs only while the ledger exists, so a later revoke sticks.
The Interchange section builds the database, grant store and
requireGrant from @intx/db, @intx/authz and @intx/hub-api instead of
declaring host placeholders, and the install line lists every
package the snippets import.
@TheGreatAxios
TheGreatAxios force-pushed the cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns branch from 0621cd7 to b458038 Compare September 26, 2026 01:37
@TheGreatAxios
TheGreatAxios added this pull request to stack #32 September 26, 2026 01:57
@TheGreatAxios
TheGreatAxios force-pushed the cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns branch from b458038 to 910afd3 Compare September 26, 2026 02:23
@TheGreatAxios
TheGreatAxios force-pushed the cl-9336-artifacts-store-upload-bytes-per-version-so-versionn-returns branch from 910afd3 to e64d794 Compare September 26, 2026 02:30
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.

1 participant