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

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 18, 2026 •
edited by opencodejr Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Issue for this PR

Prepares #63666 (the agent's video tool).

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Video jobs now survive a server restart. Until now, running and failed jobs lived only in memory: a restart lost them, and a running job's videos were never collected. Each job now has a record in the kv table, and the server resumes polling running jobs when it starts.

The video ID is still the only handle. The provider's job ID (remote) stays inside the video service.

Record, key video:<videoID>, decoded with a schema on read:

{ status: "submitting" | "running" | "completed" | "error",
  model, location, created,
  remote?,          // running
  blobs?,           // completed: blob IDs
  reason?, error?,  // error
  finished? }       // completed, error

Lifecycle:

start     write submitting -> provider accepts -> write running (remote) -> return { id, status: "running" }
          provider rejects -> remove the record, return the error
done      save each video as a new blob -> write completed (blobs, finished)
          any download fails -> remove the blobs saved so far -> write error
startup   running    -> poll again until 2 h after created (already past: error "unknown")
          submitting -> error "unknown": never resubmitted, it's paid and not idempotent
hourly    remove records 24 h after finished (or 26 h after created if they never finished)

get reads the record. For a completed job it reads each blob, drops the ones that no longer exist, and returns not found if none remain. Memory holds only the polling fibers.

start takes an optional location, stored on the record and used for every later provider call, including after a restart. The HTTP route still uses the server's base configuration; the agent tool will pass the session's location.

API differences (/api/experimental/generate/video):

  • Blob IDs are generic again: blob_ + 26 characters, instead of <videoID>_<n>.
  • GET /generate/video/:id returns running, failed and completed jobs after a restart, and 404 from 24 hours after the job finished.
  • Blobs are kept until removed: no more 7-day cleanup, and Blob.Info drops expiresAt. They're written straight to blob_… and flushed to disk (no .part file); a failed write deletes its file. The blob route's cache lifetime goes from 7 days to a year, since a blob ID never changes content.

Servers sharing a database (the background service plus opencode serve) never poll the same job. A job has a lease in kv (video-lease:<id> = { owner, until }), taken with a conditional write the same way automation elects its scheduler:

owner     renews every 30 s (until = now + 1 min); stops the job if the lease was taken
every server, at startup and every minute
          unfinished job whose lease expired → claim it → poll it (or fail an interrupted submission)

So when a server dies, another one that's still running picks up its jobs within about 1–2 minutes, instead of waiting for a restart.

Still behind the video_generate flag.

Known limits, accepted for now:

  • After a hard crash, the restarted server waits for the old lease to expire (up to a minute) before it resumes a job.
  • If the server crashes between saving a blob and updating the record, the next start downloads the videos again and the first blob stays on disk. A crash mid-download can also leave a partial file that no job references. Nothing removes blobs yet; a delete endpoint comes later.

How did you verify your code works?

  • packages/core/test/video-generation.test.ts (one test): a job with two videos completes with two blob_ IDs; a fresh layer on the same data dir and database still reads it; a job running when the first process stops completes in the next one; a submitting record becomes an error on startup; records are gone 25 hours later (TestClock). Passed with --rerun-each 10.
  • packages/server/test/video-generate.test.ts updated for blob_ IDs and reading the job back after a restart.
  • bun typecheck in core, server, schema and protocol; bun run check at the root.
  • Live, against xAI (grok-imagine-video-1.5-lite): two jobs started, server stopped mid-generation, restarted; both completed and their blobs stream as H.264 MP4. Then two servers on one data dir: started a job on A, killed A with SIGKILL; B claimed the expired lease and completed the job about two minutes later.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Public API: experimental video API: Blob.ID changes from video_<id>_<n> to blob_…, Blob.Info.expiresAt is removed, blob cache lifetime goes from 7 days to 1 year, and video jobs survive restarts

Sorry, something went wrong.

Uh oh!

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

All reactions
@rekram1-node
feat(core): keep video job records in kv so jobs survive a restart
144478d
opencodejr[bot]
opencodejr Bot reviewed Nov 18, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

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.

I found no blocking problems; there's one small inline comment.

I ran the new core test 10 times in a row (--rerun-each 10) and all runs passed; it restarts the service on the same data dir and database with a fake provider. The server video tests also pass, and core and server type-check with tsc -b. I couldn't run a real video job end to end because there are no provider credentials.

Public API (experimental, behind video_generate):

  • Blob.ID changes from video_<id>_<n> to blob_ + 26 characters. Blob IDs from v2.3.1 no longer pass validation, so GET /api/experimental/blob/:id rejects them with 400.
  • GET /api/experimental/generate/video/:id now returns running and failed jobs after a restart, and 404 from 24 h after the job finished.
  • VideoGeneration.start (core) gains an optional { location }.
  • OpenAPI changes only in descriptions and the Blob.ID pattern.

This isn't backwards compatible for anyone holding old blob IDs, which seems fine for an experimental API.

The only concern is the blob cleanup in blob-store.ts: blob files written by v2.3.1 are no longer swept (see the inline comment).

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread packages/core/src/blob-store.ts Outdated
FileRetention.cleanup(
fs,
entries.filter((entry) => entry.startsWith("video_")).map((entry) => path.join(directory, entry)),
entries.filter((entry) => entry.startsWith("blob_")).map((entry) => path.join(directory, entry)),

@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.

v2.3.1 already shipped video_<id>_<n> blob files (behind the flag). With the cleanup now matching only blob_, those files stay on disk forever after upgrading. Should the sweep also match the old video_ prefix, at least for one retention period?

Sorry, something went wrong.

Uh oh!

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

All reactions
opencodejr[bot]
opencodejr Bot reviewed Nov 18, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

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.

The earlier point is fixed: blob cleanup now also sweeps video_ files left by v2.3.1. The core video test and the core type-check pass. The new commit doesn't change the public API, and I have no new concerns.

Sorry, something went wrong.

Uh oh!

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

All reactions
@rekram1-node
rekram1-node force-pushed the video-durable branch from 65bfd14 to 144478d Compare November 18, 2026 00:22
opencodejr[bot]
opencodejr Bot reviewed Nov 18, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

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.

The latest push moves the branch back to 144478dee and drops 65bfd14ec. That commit had added the video_ prefix to the blob cleanup, so v2.3.1 blob files are left on disk again and the earlier thread on blob-store.ts is still open. Nothing else changed since that first review: the rest of the code is unchanged and the public API impact is the same.

Sorry, something went wrong.

Uh oh!

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

All reactions
@rekram1-node
feat(core): lease video jobs so servers sharing a database don't poll…
086ea34
… the same one
opencodejr[bot]
opencodejr Bot reviewed Nov 18, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

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.

The lease approach works: a server that shuts down cleanly releases its leases, a crashed server's leases expire after a minute, and the takeover loop picks those jobs up. The tests and the core type-check pass. Two-server takeover isn't tested; I checked it by reading the code.

One concern: when another server takes over a job, it acts on a record it read before claiming the lease, so it can overwrite a job that just finished (inline comment).

The new commit doesn't change the public API. The video-lease:<id> kv keys are internal.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread packages/core/src/video-generation.ts
const job = Option.getOrUndefined(decode(row.value))
if (!id || !job || (job.status !== "running" && job.status !== "submitting")) return
if (yield* FiberMap.has(fibers, id)) return
if (!(yield* claim(id))) return

@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.

job comes from the rows snapshot, which was read before claim. Suppose the owning server finishes the job (finish, then release) between that scan and this claim. The claim then succeeds, and this server acts on a stale record:

  • If the stale status is running, settle runs again. It downloads the videos a second time and replaces the completed record's blob IDs; the first set of blobs is orphaned.
  • If the stale status is submitting, this server overwrites a completed job with the error "server stopped while submitting".

Re-reading and decoding PREFIX + id after a successful claim, and releasing if it's no longer unfinished, would close the gap.

Sorry, something went wrong.

Uh oh!

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

All reactions
@rekram1-node
fix(core): read a video job again after taking over its lease
6a05754
opencodejr[bot]
opencodejr Bot reviewed Nov 18, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

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.

The stale-record race in the takeover loop is fixed: after claiming a lease, the server reads the job again and releases the lease if the job already finished. The core video test passed 5 times out of 5, and the core type-check passes. This commit doesn't change the public API, and I have no new concerns.

Sorry, something went wrong.

Uh oh!

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

All reactions
@github-actions github-actions Bot mentioned this pull request Nov 18, 2026
📊 AI CLI 工具社区动态日报 2026-11-18 litang9/big_model_radar#721
Open
@rekram1-node
feat(core): keep blobs until removed and write them in place
a4e6dc0
opencodejr[bot]
opencodejr Bot reviewed Nov 18, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

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.

Blobs are now kept until removed, and the change works as described. The core and server video tests pass, core and server type-check, and the OpenAPI spec and generated client types match the schema.

Public API (experimental, behind video_generate):

  • Blob.Info.expiresAt is removed (OpenAPI and @opencode/client BlobInfo). Clients that read it break.
  • GET /api/experimental/blob/:id cache-control goes from max-age=604800 (7 days) to max-age=31536000 (a year).
  • The route descriptions drop the 7-day retention promise.

The earlier thread about old video_ blob files stays open: this commit stops all blob cleanup instead of sweeping them.

One concern: with no cleanup and no delete route yet, the blobs directory only grows (inline comment).

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread packages/core/src/blob-store.ts
* 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. */

@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
@rekram1-node
rekram1-node merged commit 1950fb8 into dev Nov 18, 2026
15 checks passed

Uh oh!

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

@rekram1-node
rekram1-node deleted the video-durable branch November 18, 2026 03:07
@rekram1-node rekram1-node mentioned this pull request Nov 18, 2026
feat(core): add an experimental video generation tool #63666
Merged
3 of 6 tasks
@Edo771977 Edo771977 mentioned this pull request Nov 18, 2026
chore: merge upstream/dev into the fork Edo771977/opencode#92
Merged
@BrewTestBot BrewTestBot mentioned this pull request Nov 23, 2026
opencode 2.4.0 Homebrew/homebrew-core#327368
Merged
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
opencode 2.4.0 amrkmn/homebrew-tap#1251
Closed
1 task
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
feat: opencode release v2.4.0 sprisa/opencode-server#95
Merged
@scottames-github-bot scottames-github-bot Bot mentioned this pull request Nov 27, 2026
chore(deps): update ⬆️ mise-packages scottames/dots#1181
Merged
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

1 participant

@rekram1-node
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.