GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(core): durable video jobs by rekram1-node · Pull Request #64546 · anomalyco/opencode

feat(core): durable video jobs #64546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
rekram1-node merged 4 commits into dev from video-durable
Nov 18, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(core): durable video jobs #64546

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
4 commits
Select commit Hold shift + click to select a range
144478d
feat(core): keep video job records in kv so jobs survive a restart
rekram1-node Nov 18, 2026
086ea34
feat(core): lease video jobs so servers sharing a database don't poll…
rekram1-node Nov 18, 2026
6a05754
fix(core): read a video job again after taking over its lease
rekram1-node Nov 18, 2026
a4e6dc0
feat(core): keep blobs until removed and write them in place
rekram1-node Nov 18, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 packages/client/src/promise/generated/types.ts
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

46 changes: 11 additions & 35 deletions 46 packages/core/src/blob-store.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { BlobStore } from "@opencode/schema/blob-store"
import { makeGlobalNode } from "@opencode/util/effect/app-node"
import { FSUtil } from "@opencode/util/fs-util"
import { Global } from "@opencode/util/global"
import { Context, Duration, Effect, Layer, Option, Schedule, Schema, Stream } from "effect"
import { FileRetention } from "./file-retention.js"
import { Context, Effect, Layer, Schema, Stream } from "effect"

export const ID = BlobStore.ID
export type ID = BlobStore.ID
Expand All @@ -22,7 +21,6 @@ export class UnavailableError extends Schema.TaggedError<UnavailableError>()("Bl
message: Schema.String,
}) {}

export const RETENTION = Duration.days(7)
/** Blobs are files named by their ID, with no extension; their type is read from their first bytes. */
export const DIRECTORY = "blobs"

Expand All @@ -32,18 +30,15 @@ export interface Content extends Info {
}

export interface Interface {
/** Stores the stream as the blob `id`, replacing any earlier one. The file appears only once it's whole. */
readonly write: <E>(id: ID, stream: Stream.Stream<Uint8Array, E>) => Effect.Effect<Info, E | UnavailableError>
/** Stores the stream as a new blob, flushed to disk before it returns. A failed write leaves no blob. */
readonly write: <E>(stream: Stream.Stream<Uint8Array, E>) => Effect.Effect<Info, E | UnavailableError>
readonly read: (id: ID) => Effect.Effect<Content, NotFoundError>
readonly remove: (id: ID) => Effect.Effect<void>
}

export class Service extends Context.Service<Service, Interface>()("@opencode/BlobStore") {}

/**
* Files under `<data>/blobs/`, deleted 7 days after they're written, at startup and hourly. Nothing tracks who uses a
* blob, so a caller that keeps one longer copies it.
*/
/** Files under `<data>/blobs/`, kept until something removes them. */
Comment thread

@opencodejr opencodejr Bot Nov 18, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nothing calls remove except the failure paths in write and download, and there's no delete route yet. Every generated video, the extra copy written after a crash, and any partial file from an interrupted write now stay on disk for good. The video: record is deleted 24 hours after the job finishes; after that nothing in the server links a blob to its job, so a delete route added later couldn't clean up existing files by job. Could some sweep stay until the delete route lands, for example blobs not referenced by any live record and older than a cutoff?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
const layer = Layer.effect(
Service,
Effect.gen(function* () {
Expand All @@ -55,7 +50,6 @@ const layer = Layer.effect(
const read = Effect.fn("BlobStore.read")(function* (id: ID) {
const missing = new NotFoundError({ id, message: `Blob not found: ${id}` })
const info = yield* fs.stat(file(id)).pipe(Effect.mapError(() => missing))
const written = Option.getOrUndefined(info.mtime)?.getTime() ?? 0
const head = yield* fs.stream(file(id), { bytesToRead: 64 }).pipe(
Stream.runCollect,
Effect.mapError(() => missing),
Expand All @@ -65,46 +59,28 @@ const layer = Layer.effect(
path: file(id),
mime: Media.detectMediaType(Buffer.concat([...head])) ?? "application/octet-stream",
bytes: Number(info.size),
expiresAt: written + Duration.toMillis(RETENTION),
}
})

// Written to `<id>.part`, synced, then renamed, so a stored blob is always whole.
const write = <E>(id: ID, stream: Stream.Stream<Uint8Array, E>) =>
const remove = (id: ID) => fs.remove(file(id), { force: true }).pipe(Effect.ignore)

const write = <E>(stream: Stream.Stream<Uint8Array, E>) =>
Effect.gen(function* () {
const part = `${file(id)}.part`
const id = ID.create()
const unavailable = (cause: unknown) =>
new UnavailableError({ message: `Could not store blob ${id}: ${String(cause)}` })
yield* fs.makeDirectory(directory, { recursive: true }).pipe(Effect.mapError(unavailable))
yield* Effect.scoped(
Effect.gen(function* () {
const handle = yield* fs.open(part, { flag: "w", mode: 0o600 }).pipe(Effect.mapError(unavailable))
const handle = yield* fs.open(file(id), { flag: "w", mode: 0o600 }).pipe(Effect.mapError(unavailable))
yield* stream.pipe(Stream.runForEach((chunk) => handle.writeAll(chunk).pipe(Effect.mapError(unavailable))))
yield* handle.sync.pipe(Effect.mapError(unavailable))
}),
).pipe(Effect.onError(() => fs.remove(part, { force: true }).pipe(Effect.ignore)))
yield* fs.rename(part, file(id)).pipe(Effect.mapError(unavailable))
).pipe(Effect.onError(() => remove(id)))
const stored = yield* read(id).pipe(Effect.mapError(unavailable))
return { id, mime: stored.mime, bytes: stored.bytes, expiresAt: stored.expiresAt } satisfies Info
return { id, mime: stored.mime, bytes: stored.bytes } satisfies Info
}).pipe(Effect.withSpan("BlobStore.write"))

const remove = (id: ID) => fs.remove(file(id), { force: true }).pipe(Effect.ignore)

// Blobs and leftover `.part` files are deleted once older than the retention.
yield* fs.readDirectory(directory).pipe(
Effect.orElseSucceed((): string[] => []),
Effect.flatMap((entries) =>
FileRetention.cleanup(
fs,
entries.filter((entry) => entry.startsWith("video_")).map((entry) => path.join(directory, entry)),
RETENTION,
),
),
Effect.ignoreCause({ log: "Error", message: "Blob cleanup failed" }),
Effect.repeat(Schedule.spaced(Duration.hours(1))),
Effect.forkScoped,
)

return Service.of({ write, read, remove })
}),
)
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.