Repository navigation
feat(core): experimental blob API backed by SQLite - #67016
rekram1-node wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Looks sound. I ran the core blob-store tests and the server video-generate tests (all pass). I also called the routes directly through the server:
- With the flag off, list and create return 403.
- A 3 MB upload goes to disk, and Range reads return the correct bytes from both the on-disk file and the SQLite-stored copy.
- An upload with an HTML content-type is served as a
text/plaindownload withnosniffand the sandbox CSP. PATCHmovestime.updatedforward, and deleting twice gives 204 then 404.
I couldn't run the type checks in this environment: the typecheck scripts call bun check, which this Bun doesn't have.
Public API impact (all experimental):
- Changed, breaking:
GET /api/experimental/blob/:idnow returns{ data: Blob.Info }. The bytes moved toGET /api/experimental/blob/:blobID/content, with the same Range, ETag and 304 support. Anyone fetching the old URL for bytes has to add/content. - Added:
GET /api/experimental/blob?sessionID=(experimental.blob.list),POST /api/experimental/blob?name=&sessionID=(experimental.blob.create),PATCH /api/experimental/blob/:blobID(experimental.blob.update),DELETE /api/experimental/blob/:blobID(experimental.blob.remove), and the config flagexperimental.blob_catalog. - Widened:
Blob.InfogainssessionID,name,metadata,width,height,durationMsandtime. The generated TS, Rust and Luau clients change to match. - Behaviour change: blobs no longer expire after 7 days. Blobs written by the old store have no row, so they can't be read through the API any more, as the description notes.
No blocking concerns.
There was a problem hiding this comment.
The new commits look good:
- List order: blobs are now listed newest first by
time_created, withidonly breaking ties. Blobs created in the same millisecond still come out newest first. - Index: the session index now matches that order.
- Generated files: the OpenAPI spec and generated clients were regenerated after the routes moved earlier in the group.
I re-ran the core blob-store tests and the server video-generate tests, and they pass. The public API is the same as in my last review; only the order of operations in the generated files changed. No new concerns.
There was a problem hiding this comment.
The new commit only updates the operation counts in the cli-rs plugin test: 195 operations, with the raw-body blob.create upload added to the ones plugins can't call. client-samples.json now has 195 entries, which matches. I couldn't run the Rust test here because cargo isn't installed. The public API is unchanged since my last review, and I have no new concerns.
There was a problem hiding this comment.
The metadata limit change is consistent: the constant, the route description, the API docs page and the test all move to 100 KB. The server video-generate test passes, including the 400 for metadata over the limit.
Public API: PATCH /api/experimental/blob/:blobID now accepts up to 100 KB of metadata instead of 4 KB. That's backwards compatible.
One side effect, not blocking: list returns every blob's metadata and has no pagination yet, so one response can now carry up to 100 KB per blob. Worth remembering when the cursor is added.
71d8a49 to
bc1779c
Compare
There was a problem hiding this comment.
The PR was rebased onto newer dev. The blob commits carried over without content changes, and the new chore(cli-rs) commit only regenerates the Rust client and compat.js to pick up the 503 responses that dev added to the fs and pty routes. After the rebase, the core blob-store tests and the server video-generate and workerd tests pass. The public API is the same as in my last review, and I have no new concerns.
There was a problem hiding this comment.
The new commit works as described. On a real server, the migration gave an old-style blob file a row and it read back as video/mp4, while a stray .part file was skipped. Paging with cursors moved through four blobs in pages of 2, 2 and 0, and a garbage cursor answered 400. The core blob-store, server video-generate and httpapi-codegen tests pass.
Public API changes (all experimental):
GET /api/experimental/blobnow takeslimitandcursorand returns{ data, cursor: { previous, next } }instead of{ data }. It can answer 400 for a bad cursor. This breaks callers that only read{ data }and expect every blob in one page.POST /api/experimental/blobreturns 404 for a session that doesn't exist, and 400 when the upload breaks off mid-body.GET /blob/:blobIDandGET /blob/:blobID/contentnow return 403 unlessexperimental.blob_catalogis on. Outside callers of the video API need the flag to read video bytes.- The Effect client gains
blob.createandblob.content.
One concern, inline: a single old file that can't be opened stops the migration, and with it server startup.
| const names = yield* Effect.promise(() => readdir(directory).catch(() => [] as string[])) | ||
| yield* Effect.forEach(names.filter(isID), (id) => | ||
| Effect.acquireUseRelease( | ||
| Effect.promise(() => open(path.join(directory, id))), |
There was a problem hiding this comment.
Effect.promise turns a failed open or stat into a defect. That fails the whole migration transaction, and the server then won't start. All it takes is one file in <data>/blobs that can't be read (permissions, or something deleting it during the scan). These files are only best-effort recoveries of expiring videos, so it would be safer to log and skip a file that can't be read than to block startup. For example, use Effect.tryPromise and Effect.catch, then log a warning for each file.
There was a problem hiding this comment.
Fixed in e40aae5: each file is read inside its own Effect.catchCause, so a file that can't be read logs a warning and is skipped. The test now includes a directory named like a blob.
There was a problem hiding this comment.
Looks good. In e40aae5 the Effect.catchCause wraps the whole acquireUseRelease for each file (20261128193337_blob_catalog.ts:79-81). If an open, stat or read fails, or probe hits a defect, the migration logs a warning, skips that file and keeps going. The upgrade test passes: I ran bun test test/blob-store.test.ts and got 3 pass.
Two small notes, neither blocking:
- On Linux,
open()on a directory works and the failure comes from the firstread(EISDIR). So the new test covers a failed read, not a failedopen. The same catch handles both, so that's fine. - The catch also covers the
INSERT OR IGNORE, so a database error on one row would be logged and skipped rather than aborting the upgrade. SQLite only undoes that one failed statement, not the transaction, so this is consistent with "best effort", and I think that's the right call.
I didn't change anything in the checkout.
There was a problem hiding this comment.
Thread 1 is fixed: if the migration can't read an old blob file, it now logs a warning and skips it, so one bad file no longer stops the server from starting. The updated migration test, which adds a directory named like a blob, passes. The public API is the same as in my last review, and I have no new concerns.
There was a problem hiding this comment.
Thread 1 was already fixed by the previous commit: if the migration can't read an old blob file, it logs a warning and skips it.
The new commit works as described. A WAV and a FLAC stored through the blob store each came back as type: "audio" with the right durationMs, and the core blob-store and server video-generate tests pass.
Public API change (experimental): Blob.Info is now a union on type (image, video, audio, file). The flat width and height fields become size: { width, height } on images and videos, and durationMs now appears only on videos and audio. Anyone reading the old flat fields has to switch, including readers of the video API's blobs list. The OpenAPI spec and generated clients are regenerated to match.
No new concerns.
There was a problem hiding this comment.
Thread 1 stays fixed: the migration still logs and skips an old blob file it can't read.
The new commit removes the header parsing; a blob's type is still sniffed from its first 64 bytes. The core blob-store and server video-generate tests pass.
Public API: since my last review, size and durationMs are never filled in for now. They were already optional, so this is backwards compatible, and the Blob.Info union shape is unchanged. No new concerns.
26743f0 to
af870fc
Compare
There was a problem hiding this comment.
Thread 1 stays fixed: the migration still logs and skips an old blob file it can't read.
The latest push is a rebase onto current dev with the commits squashed into one. Comparing the PR's changes file by file, only openapi.json and the generated Rust client differ, and those differences come from dev itself (the fs and pty 503 responses already merged there, and the machine-list description dev changed). The core blob-store and server video-generate tests pass. The public API is the same as in my last review, and I have no new concerns.
1aee650 to
a1ae97c
Compare
There was a problem hiding this comment.
Thread 1 stays fixed: the migration still logs and skips an old blob file it can't read.
This push is a rebase onto newer dev. The only code change is that the blob_catalog migration is now typed DatabaseMigration.Imperative, the type dev now uses for migrations that run code. openapi.json and compat.js were regenerated, and the spec check (generate-openapi.ts --check) passes. The core blob-store and server video-generate tests pass. The public API is the same as in my last review, and I have no new concerns.
a1ae97c to
a06600f
Compare
There was a problem hiding this comment.
Thread 1 stays fixed: the migration still logs and skips an old blob file it can't read.
This push only rebases the PR onto one new dev commit (#67251), which pins @effect/platform-node-shared. The PR's own changes are byte-for-byte the same. The core blob-store and server video-generate tests pass after bun install. The public API is the same as in my last review, and I have no new concerns.
Adds an experimental blob API: upload, list by session, read, edit name and metadata, delete.
BlobStorenow uses two SQLite tables instead of loose files that are deleted after a week. Generated videos already go through it, and nothing deletes a blob any more exceptDELETE.Plan and decisions: https://share.opncd.ai/BTqfjUQuu5Zq. This is part A of that plan. Making video and image generation label their blobs, and letting
readaccept blob IDs, comes next.Size
GitHub reports about +5.4k / −2.8k, but most of that is one generated file.
packages/protocol/openapi.jsonis about 6.1k of the changed lines in GitHub's diff, which aligns repetitive JSON badly. Withgit diff --diff-algorithm=histogram, its real change is +853 / −13: three blob paths replacing the old one, nine newBlob.*schemas, and the flag in the config schema. The hand-written change is about 750 lines of code plus about 230 of tests. Everything else is regenerated clients, the database snapshot and API docs, all markedlinguist-generated.Routes
All of them are under
/api/experimental/, follow the session and artifact groups, and return 403 unlessexperimental.blob_catalogis on:GET/blob?sessionID=&limit=&cursor=experimental.blob.list→{ data, cursor: { previous, next } }POST/blob?name=&sessionID=(raw body)experimental.blob.create→{ data: Blob.Info }GET/blob/:blobIDexperimental.blob.get→{ data: Blob.Info }GET/blob/:blobID/contentexperimental.blob.content→ bytesPATCH/blob/:blobID{ name?, metadata? }experimental.blob.update→{ data: Blob.Info }DELETE/blob/:blobIDexperimental.blob.removeBreaking (experimental) change:
No client in this repo fetched the old route. The video tool reads the store directly, so the flag doesn't affect it. Outside callers of the experimental video API need the flag to read the bytes.
Blob.Infois a union ontype, taken from the MIME type, so each kind carries only the facts it can have:The table stays flat (nullable
width,height,duration_mscolumns), and only the API shape is a union. This PR doesn't fillsizeordurationMsyet: reading them from file headers is a follow-up, done when Kit'sblobAPI is removed. Until then they're always missing.How it works
blob_v2:id,session_id?,mime,bytes,name?,width?,height?,duration_ms?,metadata?(JSON), timestamps. Index on(session_id, time_created) where session_id is not null.blob_data:(blob_id, seq, data)holding blobs of 1 MB or less, of any type. It cascades on delete.list: newest first bytime_created, withidonly breaking ties. An ID's 48-bit clock wraps about every 795 days (next on 2028-10-17), so IDs alone don't sort by age. Pages work likesession.list: 50 by default, with an opaque cursor that carries its filter.session_id: a label only, with no foreign key. Deleting a session keeps its blobs, which stay listable by its ID.createreturns 404 for a session that doesn't exist.metadata: belongs to the client.PATCHreplaces it, as S3 does, and the handler rejects more than 100 KB of JSON with a 400. That keeps a page oflistfrom growing without bound.create: a raw handler, so the body streams into the store and itscontent-typeis only a hint. An upload that breaks off mid-body answers 400 rather than logging a server error.machinesflag is, because blobs aren't tied to a project.Migrating the old store
Before this PR,
BlobStorekept each video as a loose file in<data>/blobs/with no row, and video job records point at them by ID. Theblob_catalogmigration gives each existing file a row, with its type sniffed from the file, its byte size, andtime_createdset to its modification time, so videos generated before the upgrade stay readable.Effect client
Raw uploads were left out of the Effect client because the generator cast their request to a type that also allows the raw-response mode, so
.datadidn't typecheck. The other generator path already pinsresponseMode: "decoded-only". This applies the same fix inpackages/httpapi-codegen, andblob.createandblob.contentare now in the Effect client.fs.writeand the other raw routes are left as they are.Trade-offs
create, the same asfs.write: the plugin runtimes don't send raw bodies.Verification
packages/core/test/blob-store.test.ts: inline versus on-disk split, sniffed type over the hint, range reads, paging forward and back, a missing file reading as missing, delete, a failed write leaving nothing behind, and the migration adopting an old file while skipping a non-blob file.packages/server/test/video-generate.test.ts: video job →/contentwith Range, ETag and 304, thenDELETE; upload to a real session → 404 for an unknown session → list with cursor →PATCHmetadata → 400 over 100 KB; and 403 on list, get and content with the flag off.packages/httpapi-codegenandpackages/clienttests pass, as does the cli-rs operation count test.bun run checkpasses.Added by the opencode bot (AI-generated).
Public API: replaces GET /api/experimental/blob/:id bytes with /blob/:blobID (info) + /blob/:blobID/content (bytes), adds paged blob list/create/update/delete behind experimental.blob_catalog, and makes Blob.Info a union on type (breaking for experimental routes only)