GeezerVison is showing github.com — feat(core): add an experimental video generation tool by rekram1-node · Pull Request #63666 · anomalyco/opencode
Conversation
rekram1-node
commented
Nov 13, 2026
•
edited by opencodejr
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
No issue. Builds on durable video jobs from #64546.
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
Agents can generate videos. A new experimental_video_generate tool starts a job on the server's video service, returns right away, and copies the finished videos into the workspace. The agent is then woken with a notice that lists every saved file. The video ID is the only handle the tool keeps: it never sees the provider's job ID.
tool call (foreground, seconds)
pick model → check aspect, permissions → read local inputs
VideoGeneration.start(input, { location: session's Location }) → { id: video_…, status: "running" }
a rejected request fails the call here
background Job, row recovery = { kind: "video", sessionID, path, videoID }
VideoGeneration.wait(videoID) completed { blobs } | error
copy each blob → cat.mp4, cat-1.mp4, … through Environment.files
notice <video id=… state=…> "Saved 2 videos: /x/cat.mp4, /x/cat-1.mp4" → the agent wakes up
cancelling the Job → VideoGeneration.cancel(videoID)
server restart
the video service has already resumed polling the job itself (here or in another server sharing the database)
the tool's running Job row → wait(videoID) → copy → notice, without submitting again
session's Location gone → reported as lost
VideoGeneration gains two calls and stays free of sessions and the job table:
VideoGeneration
- start(request: VideoRequest, { location? })
+ start(input: Generate.VideoInput, { location? }) the HTTP handler converts its inline files with Generate.videoInput
get(id)
+ wait(id) → completed | error re-reads the kv record; awaits the local poller when this server holds it
+ cancel(id) record → error "cancelled", stop local polling, ask the provider (best effort)
Generate.video
+ cancel(model, remote)
One server polls, like the automation scheduler. The per-job lease from #64546 becomes a single leader lease (video-leader in kv, same claim SQL as automation:leader):
any server submits the jobs it receives, answers get / wait / cancel / blob reads
the record is written once the provider accepted the job
every 5 s each server: drop records 24 h after they finished
if any job is running, try for the lease (60 s); the holder checks each running job once
and downloads finished ones; a lost or failed claim stops its checks
A new job gets its first status check within 5 s, whichever server took it. If the leader dies, another server takes over every running job once its lease expires (~1 min); a leader that shuts down cleanly releases it at once.
The final write is one conditional update that only applies while the record is still running, so a poller never overwrites a cancelled job; it drops the blobs it downloaded instead.
Several videos: some models return more than one per job. The first goes to path, the rest next to it as cat-1.mp4, cat-2.mp4, …. With no path, the first goes to <tmp>/videos/<sessionID>/<videoID>.mp4.
Other changes: Job.Kind gains video (job list, idle hook, subagent reports, goals, opencode run exit), the models tool accepts type: "video", and the plugin SessionIdleBackground type gains a video member.
Trade-offs:
- Copy: each video is streamed from its blob into the workspace in 4 MiB chunks (
Environment.files.write then append), so a video is never held in memory.
- Inputs: local files are read whole and sent inline, up to 100 MiB each, with no limit on how many references; the provider rejects what it can't take.
- Extra files: the edit approval covers
path. cat-1.mp4 and later are written next to it without their own prompt, because a restarted server can't ask.
- Wait:
wait re-reads the record every 5 s instead of being notified, so it works the same whichever server polls the job.
Default model: experimental.video_generate also takes { "model": "xai/grok-imagine-video" }, like image_generate. An object turns the flag on. Without it, or when that model isn't available, the tool picks the newest video model from the chat's provider, then the newest overall.
Feature flag: video_generate, now covering both the HTTP API and the tool.
How did you verify your code works?
tool-video-generate.test.ts: a job returning two videos saves kite.mp4 and kite-1.mp4, and the notice lists both.
video-generation.test.ts: wait resolves when the job completes; cancel marks a running job cancelled and reaches the provider; wait on an unknown ID fails.
session-execution.test.ts: a running video Job row survives a restart, waits on its video ID, copies the video and delivers the notice.
bun run check passes at the root; the related core suites and server generate tests pass.
- Live against xAI (
grok-imagine-video-1.5-lite) with two servers on one data dir: a job submitted on the follower was polled by the leader (only the leader opened provider connections besides the submit) and both servers returned the same blob; then the leader was killed with SIGKILL mid-job, the follower won the lease 60 s later and completed the job. Re-run after simplifying the loop: a job submitted on one server and read on the other completed, then after stopping one server (it released the lease) the other took over and completed a new job.
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: adds the video job kind, the experimental_video_generate tool, the plugin SessionIdleBackground video member and an object form of experimental.video_generate ({ model }); the flag now also enables the tool (backwards compatible)
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 change looks sound. I couldn't run it end to end because it needs a real xAI video provider and the updated models.dev catalog, so I read the diff, focusing on restart recovery, cancellation and polling. The tests for the new tool, restart recovery, models, the ai media entrypoints and the server pass, and tsc -b in packages/core is clean. Transient status errors are covered by the media route's read retries, and catalog entries that still name protocols/xai-video load as having no package, so the tool stays hidden until models.dev#13540 lands, as described.
Public API impact. Everything here is an addition and backwards compatible:
Job.Kind gains "video", and the Job.Info union gains Job.Video (client JobVideo). Clients that switch over every job kind will see a new kind.
Model.Type gains "video", and model.list types accepts it.
- New
video_generate feature flag in config.
- The plugin type
SessionIdleBackground gains a video member.
- New tool
experimental_video_generate, and the models tool accepts type: "video".
- New
@opencode/ai/providers/xai/videos export, and videoModel is exported from @opencode/ai/providers/xai.
- The models.dev request now asks for
type=chat,decision,image,video.
No blocking concerns.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 new commit regenerates packages/protocol/openapi.json. check:generated confirms it matches the schema, and the protocol tests pass. The spec now includes the video_generate flag, "video" in Job.Kind and Model.Type, and Job.Video in the Job.Info union. These are additions, all backwards compatible and already covered by the earlier API impact. Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Nov 13, 2026
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.
This push is a rebase onto current dev. git range-diff shows only conflict resolutions against the video providers that landed there: the xAI case moves into the existing video entrypoint test list, the variant test's videos regex comes from dev, and subagent-completion uses dev's STILL_RUNNING constant. The core and ai tests, the core type check and the OpenAPI check:generated all pass. The public API impact is unchanged from earlier, all backwards-compatible additions. Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
This push moves the xAI video entrypoint out to #63707 and folds the OpenAPI regeneration into the main commit. git range-diff shows nothing else changed. The core tests, the core type check and check:generated pass. The public API impact is as before without the @opencode/ai/providers/xai/videos export: the video job kind (Job.Video in Job.Info), the video model type, the video_generate flag, the experimental_video_generate tool and the plugin SessionIdleBackground video member. All are backwards-compatible additions. Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 new commit doesn't work on the current base: it saves the provider job ID and passes that plain string to ai.video.status/result/cancel, but on dev every video protocol still decodes a token object ({ id }, { taskID }, { requestID }…). I checked against the OpenRouter video model with a mocked HTTP response. The token object returns queued, and the plain ID fails with openrouter-video cannot resume a generation from this token (Expected object). Without #63714 (still open), every job would fail on its first status read after the paid submit, and restart recovery would fail too. The tool and restart tests mock Generate, and the token parameter is typed unknown, so neither the tests nor the type check catch it. The rebase onto newer dev (feature flag list conflict) is fine. The core tests, the core type check and check:generated pass.
Public API impact is the same as before, all backwards-compatible additions. The video recovery record now stores providerJobID instead of token, which is internal and unreleased.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
notificationID: SessionMessage.ID.create(),
|
|
|
sessionID: context.sessionID,
|
|
|
model: ref,
|
|
|
providerJobID: job.id,
|
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.
On the current dev, ai.video.status/result/cancel still decode the protocol's token object ({ id }, { taskID }, { requestID }…), not the bare job ID. With a mocked OpenRouter response, ai.video.status(model, "job_1") fails with openrouter-video cannot resume a generation from this token (Expected object), while { id: "job_1" } works. Every job would fail on its first status read after the paid submit, so this doesn't work without #63714. Either land this after #63714, or keep storing the token until then.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Right, I had that wrong. This depends on #63714 and should merge after it; the description now says so.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
opencodejr[bot] reacted with eyes emoji
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.
Sounds right. #63714 is still open. Once it lands, status/result/cancel take job.id: string for all five protocols on dev (xAI, OpenRouter, Seedance, MiniMax, Google Omni). That matches what this PR sends to generate.video.start and stores as providerJobID for resuming after a restart, so this PR needs no code changes. I'd add one check after rebasing: run the video tool tests against the ai package that includes #63714, because anything in this PR that still reads job.token will fail typecheck there.
Two things to watch:
I only read #63714's description. I didn't rerun anything this turn and didn't change the checkout.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
My earlier point about passing the plain job ID is resolved: #63714 is now on dev, and with a mocked OpenRouter response ai.video.status(model, "job_1") returns queued on the new base. The new commits only rename the stored field to generationID and add video to the job.list kind filter description. The core tests, the core type check and check:generated pass. Public API impact is unchanged from earlier, all backwards-compatible additions. Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
My earlier point about passing the plain job ID was addressed last round by #63714 landing on dev. The new commit adapts the tool to #63721: start/end are typed as Media.ImageAsset and built with Media.image, so URLs of unknown type still reach the provider. The core tests, the core type check and check:generated pass. Public API impact is unchanged, all backwards-compatible additions. Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
rekram1-node
changed the title
feat(core): add an experimental video generation tool with resumable jobs
feat(core): add an experimental video generation tool on the server video service
Nov 16, 2026
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 rework onto VideoGeneration looks sound, and my earlier point about the plain provider job ID is settled. resume, wait and cancel work together after a restart: an already-tracked or already-stored job isn't polled again, and wait reads the stored blobs. A running tool job is re-tracked in the session's Location or reported as lost. The create route still returns only { id, status }. I couldn't run it end to end without a video provider. The core and server tests pass, and so do tsc -b in core and server and check:generated.
Public API impact, all additions and backwards compatible:
Job.Kind gains video, and Job.Info gains Job.Video.
- New tool
experimental_video_generate, and the models tool accepts type: "video".
- The plugin type
SessionIdleBackground gains a video member.
- The
video_generate flag now enables the tool as well as the HTTP API.
Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 new commit only trims tests, keeping one tool test plus the service and restart tests. Production code is unchanged since the last review, and the remaining tests and the core type check pass. My earlier job-ID point was already settled now that dev accepts plain IDs. Public API impact is unchanged, all backwards-compatible additions. Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
rekram1-node
changed the title
feat(core): add an experimental video generation tool on the server video service
feat(core): add an experimental video generation tool
Nov 18, 2026
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 rework on top of #64546's durable video jobs looks sound, and my earlier job-ID thread no longer applies: the tool keeps only the video ID and never sees the provider's job ID. wait works whichever server polls the job, cancel stops the local poller and is re-checked before a poller downloads or writes its final state, and a restarted server just waits on the same video ID again without submitting it twice. The create route's response is unchanged. I couldn't run it end to end without a video provider. The core and server tests, tsc -b in core and server, and check:generated pass.
Public API impact, all additions and backwards compatible:
Job.Kind gains video, and Job.Info gains Job.Video.
- New tool
experimental_video_generate, and the models tool accepts type: "video".
- The plugin type
SessionIdleBackground gains a video member.
- The
video_generate flag now enables the tool as well as the HTTP API.
Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 only new commit is a wording change: the agent's start message names the video model only when the tool picked it. The output's model field is unchanged, and the tool test passes. My earlier job-ID thread no longer applies, since the tool keeps only the video ID. Public API impact is unchanged, all backwards-compatible additions. Nothing new to raise.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 new commit only rewrites the comments in routes.ts on why the blob store and video service start with the server. Nothing runs differently. The input-size thread is still open. Public API impact is unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Both remaining points from my last review are fixed. A failed leader claim stops this server's checks inside the single 5-second loop, and the submitting state is gone because the record is written once the provider accepts the job. The final write is now a conditional update, which also closes the cancel/overwrite window. The input-size thread is still open.
One new problem: tool-video-generate.test.ts now fails every time with bun's 5-second timeout (details inline). The service, restart and server tests, tsc -b in core and check:generated pass. Public API impact: only the description of the video unknown error reason changes. Otherwise unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
})
|
|
|
yield* tick.pipe(
|
|
|
Effect.ignoreCause({ log: "Error", message: "Video job check failed" }),
|
|
|
Effect.repeat(Schedule.spaced(INTERVAL)),
|
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.
With one 5-second loop, a new job gets its first status check only on the next pass, and wait (line 261) now always sleeps 5 seconds between reads. So even a job the provider finishes instantly takes about 5–10 seconds. tool-video-generate.test.ts runs on real time (it.live) and now fails every time with bun's default 5-second timeout. It passes with --timeout 30000, in 5.6 seconds. Running a first check right after submission, or driving time in that test with a test clock, would fix the test and also make short jobs finish faster.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 new commit only rewords the restart notice for a running video job whose project folder is gone, which matches the case that produces it. The tool test from thread 5 still times out at 5 seconds, and the input-size thread is still open. Public API impact is unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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 new commit lets experimental.video_generate take { model } as the default video model. An object turns the flag on, and the tool falls back to its automatic pick when that model isn't available, matching image_generate. The new flag test, the core type check and check:generated pass. The tool test from thread 5 still times out at 5 seconds, and the input-size thread is still open.
Public API impact: the config schema's experimental.video_generate now accepts boolean | { model?: string }. This is an addition, and existing boolean configs keep working.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
…st conversion to Generate
… 30 minutes on a submission
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.
This push is a rebase onto newer dev with no new changes: the flag code no longer references opt-in-only flags, which dev removed, and the rule that an object setting turns the flag on is unchanged. The flag and service tests, the core type check and check:generated pass. The tool test from thread 5 still times out at 5 seconds, and the input-size thread is still open. Public API impact is unchanged.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
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.
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.
|