From 9776376cb6240c77ec934283e078324adf61f08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 6 Nov 2026 14:15:08 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20MCP:=20export=5Fqueue=20pause,=20st?= =?UTF-8?q?art=20and=20status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MCP.md | 3 +- crates/mcp/src/help.rs | 3 +- crates/mcp/src/main.rs | 5 +- crates/mcp/src/server.rs | 3 + crates/mcp/src/tools/export.rs | 123 +++++++++++++++++++++++++++++++-- 5 files changed, 128 insertions(+), 9 deletions(-) diff --git a/MCP.md b/MCP.md index b8c7266..82dfeee 100644 --- a/MCP.md +++ b/MCP.md @@ -412,7 +412,8 @@ Piper's stderr is reported on failure. | `proxies` | action (`status`, the default, `make`, `cancel` or `delete`), source (`src:`, a list or `"all"`) | the editing copies (proxies) of sources. `status` shows each source's state (ready, making with its percent, off, not needed for a sound or still, or why a stand-in failed). `make` starts one in the background and turns that film's switch back on; a film that plays at speed on this machine needs none, and says so. `cancel` stops one being made and leaves the film off, as the Proxies switch on a library row does. `delete` removes the stand-in and keeps the film off. With `auto_proxies` on, each `media_import` starts its stand-ins the same way | | `speech_model` | download (false), model (`tiny`, `base` or `small`; default `base`), cancel (false) | the speech model that `transcript`, `find_words` and `auto_captions` run on: no argument shows which models are installed and the download in progress. `download: true` fetches a model in the background (the GUI's Download model fetches `base`); `cancel: true` stops it and keeps the files fetched so far. Nothing is downloaded unless `download` is true | | `export_status` | job, out | a queued job (`export_start {queue:true}`) reads `waiting` with the number of exports ahead of it; progress, elapsed, ETA, encoder, outcome of one job; while a stabilised clip is measured before it can encode, the line and `stage`/`stage_progress` name that stage (`Measuring shake`) with its own percent; `out` reports a file this session did not start; omitted, every export so far, with its size when done (decimal: 12,139,083 bytes is 12.1 MB) and the integrated loudness (LUFS) and true peak of the written file (`integrated_lufs`, `true_peak_dbtp`, measured once from the file with the `loudness` measurement), or its error when failed. When a job finishes, a peak over the format's ceiling gets a warning line: -1 dBTP for lossless (wav, flac), -2 dBTP for lossy (the rest, since encoding can overshoot the mix) | -| `export_cancel` | job, all | cancels a running job; a waiting (queued) job is removed from the queue and never starts. `all: true` cancels every unfinished export at once (the queued ones and the running one), as the export queue's Cancel all does. The queue's Pause and Start are not offered here: the MCP queue starts each job as the one before it ends, with no pause state to reach | +| `export_cancel` | job, all | cancels a running job; a waiting (queued) job is removed from the queue and never starts. `all: true` cancels every unfinished export at once (the queued ones and the running one), as the export queue's Cancel all does. | +| `export_queue` | action (`pause`, `start` or `status`, the default) | `pause` stops the queue after the running export: the running one finishes, and the queued exports (`export_start {queue:true}`) stay waiting. `start` lifts the pause and starts the next queued export now if nothing is running. `status` says whether the queue is paused, the running export and the queued ones in order. A pause holds only queued exports; a direct export (no `queue`) starts at once. `export_status` names a paused queue | | `render_preview` | range (`"all"`, the default, or `{from, to}`), cancel, clear | `clear: true` deletes every render file in the cache (finished or half written) and says how many went, as File > Delete render files does; refused while a render is running. Pre-renders a stretch of the timeline at preview size into the render cache, so playback over it reads finished frames instead of compositing them (heavy sections: stacked effects, titles over video, colour, speed, multicam). One render at a time, in the background; `project_status` shows the progress and the cached ranges. A render is keyed by a hash of everything that changes its pixels (the clips overlapping it and their neighbours, their sources, titles, captions, tone, rate), so an edit inside a cached range drops it and playback composes live there again. `cancel: true` stops the running render and removes its partial file. The sound is not rendered; the live mix always plays | `format` is one of `mp4`, `av1`, `av1-mp4`, `hevc`, `hevc-mp4`, `webm`, `wav`, diff --git a/crates/mcp/src/help.rs b/crates/mcp/src/help.rs index 1493054..3878fef 100644 --- a/crates/mcp/src/help.rs +++ b/crates/mcp/src/help.rs @@ -42,7 +42,7 @@ const GROUPS: &[(&str, &[&str])] = &[ ("scan", &["scenes", "stabilize_status", "track", "track_status"]), ("hear", &["levels", "silence", "cut_silence", "loudness", "normalize", "clean_voice"]), ("edit", &["edit", "sequence", "multicam_create", "multicam_flatten", "effect", "undo", "redo", "checkpoint", "restore", "checkpoints"]), - ("export", &["export_start", "export_presets", "export_status", "export_cancel", "export_captions", "render_preview"]), + ("export", &["export_start", "export_presets", "export_status", "export_cancel", "export_queue", "export_captions", "render_preview"]), ("listen", &["transcript", "find_words", "auto_captions", "speech_model"]), ("captions", &["captions"]), ("speak", &["voices", "voiceover"]), @@ -261,6 +261,7 @@ EXPORT The export keeps running while you do other things. If the client closes the server's input, the server waits for running exports to finish before it exits. A stop signal (SIGTERM or SIGINT) cancels them and deletes their partial files. Poll export_status until it finishes; export_cancel {job} stops one. export_status reports progress, ETA, the encoder and the outcome; a done export reports its file size. Queue: export_start {queue:true} lines an export up. It keeps its own copy of the timeline as it is at that moment (later edits do not change it) and starts when every earlier export has finished, one encode at a time, with no polling needed; export_status shows it as `waiting` with the number of exports ahead. export_cancel {job} on a waiting job removes it from the queue. Without queue the export starts at once, beside any others. + export_queue {action:\"pause\"} pauses the queue: the running export finishes, and the queued ones stay waiting until export_queue {action:\"start\"}, which lifts the pause and starts the next one now if nothing is running. export_queue {action:\"status\"} (the default) says whether the queue is paused, the running export and the queued ones in order. A pause holds only queued exports; a direct export starts at once. export_status says when the queue is paused. Render preview: render_preview {range?} pre-renders a stretch (default: the whole timeline) so playback over the heavy parts of a cut reads finished frames instead of compositing them. It runs in the background; project_status shows the progress and the cached ranges. An edit inside a cached range drops that render. render_preview {cancel:true} stops it. export_status {out} for a file this session did not write reports whether it is there, its size and its time; the progress of a job from an earlier session is not known. diff --git a/crates/mcp/src/main.rs b/crates/mcp/src/main.rs index 5f9c57a..4cedfb6 100644 --- a/crates/mcp/src/main.rs +++ b/crates/mcp/src/main.rs @@ -144,7 +144,9 @@ fn wait_for_exports(server: &mut server::Server) { .filter(|(_, j)| tools::export::job_running(j)) .map(|(i, j)| (i + 1, j.progress())) .collect(); - if running.is_empty() { + // A paused queue starts nothing, so once only held exports remain the wait is over. + let held = server.queue_paused && server.jobs.iter().all(|j| !tools::export::job_running(j) || j.waiting()); + if running.is_empty() || held { // Nothing else can read this outcome back, so it goes to stderr once: a failure // always (the client is gone and a missing file would otherwise be silent), a // success only under EDITH_DEBUG. @@ -154,6 +156,7 @@ fn wait_for_exports(server: &mut server::Server) { Some(Ok(())) if debug => eprintln!("export job:{} finished: {} ({:.0?} after start)", i + 1, job.out.display(), job.started.elapsed()), Some(Ok(())) => {} Some(Err(e)) => eprintln!("export job:{} failed: {}: {e}", i + 1, job.out.display()), + None if job.waiting() => eprintln!("export job:{} was queued and never started (the queue was paused): {}", i + 1, job.out.display()), None => eprintln!("export job:{} ended without a result: {}", i + 1, job.out.display()), } } diff --git a/crates/mcp/src/server.rs b/crates/mcp/src/server.rs index 2158902..8e1fa2a 100644 --- a/crates/mcp/src/server.rs +++ b/crates/mcp/src/server.rs @@ -39,6 +39,9 @@ pub struct Server { /// the history did not survive the open. Cleared wherever a new edit lands. pub history_lost_on_open: bool, pub jobs: Vec, + /// Set by `export_queue {action:"pause"}`: a queued export does not start while it is set, so + /// the running one finishes and the rest wait for `export_queue {action:"start"}`. + pub queue_paused: bool, /// Editing copies (proxies) being made or settled, one per source (`proxies`). pub proxy_runs: Vec, /// The speech model download running or finished (`speech_model`). diff --git a/crates/mcp/src/tools/export.rs b/crates/mcp/src/tools/export.rs index 37f58ef..0d39cad 100644 --- a/crates/mcp/src/tools/export.rs +++ b/crates/mcp/src/tools/export.rs @@ -58,9 +58,99 @@ pub fn tools() -> Vec { schema: cancel_schema, run: export_cancel, }, + Tool { + name: "export_queue", + description: "Pause or start the export queue (export_start {queue:true}). pause: the running export finishes, and the queued ones stay queued until start. start: lifts the pause and starts the next queued export now, if nothing is running. status: whether the queue is paused, the running export and the queued ones in order. A direct export (no queue) is not held by a pause.", + schema: queue_schema, + run: export_queue, + }, ] } +fn queue_schema() -> Value { + json!({ + "type": "object", + "properties": { + "action": { + "type": "string", + "enum": ["pause", "start", "status"], + "description": "pause: queued exports stay queued after the running one ends. start: lifts the pause and starts the next queued export now if nothing is running. status (the default): whether the queue is paused, the running export and the queued ones in order." + } + }, + "additionalProperties": false + }) +} + +/// The running job's index: one with a worker that has not finished (a waiting job has none). +fn running_index(srv: &Server) -> Option { + srv.jobs.iter().position(|j| j.handle.is_some() && job_running(j)) +} + +/// `export_queue`: pauses the queue, lifts the pause, or reports the queue's state. +fn export_queue(srv: &mut Server, args: &Value) -> Reply { + let action = opt_str(args, "action").unwrap_or("status"); + let queued_list = |srv: &Server| -> String { + let waiting: Vec = srv.jobs.iter().enumerate().filter(|(_, j)| j.waiting()).map(|(i, _)| format!("job:{}", i + 1)).collect(); + if waiting.is_empty() { "none".to_string() } else { waiting.join(", ") } + }; + match action { + "pause" => { + let was = srv.queue_paused; + srv.queue_paused = true; + let head = if was { "queue already paused" } else { "queue paused" }; + let running = running_index(srv).map_or("no export is running".to_string(), |i| format!("job:{} keeps running and finishes", i + 1)); + Reply::ok(format!( + "{head}: {running}; queued exports wait ({}) until export_queue {{action:\"start\"}}", + queued_list(srv) + )) + .with(json!({ "action": "pause", "paused": true, "queued": queued_list(srv) })) + } + "start" => { + let was = srv.queue_paused; + srv.queue_paused = false; + let next = srv.jobs.iter().position(|j| j.waiting()); + advance(srv); + let started = next.is_some_and(|i| !srv.jobs[i].waiting()); + let mut text = if was { "queue started".to_string() } else { "queue was not paused".to_string() }; + match (started, running_index(srv), next) { + (true, _, Some(i)) => text.push_str(&format!(": job:{} started now", i + 1)), + (false, Some(r), Some(i)) => text.push_str(&format!(": job:{} is still running, and job:{} starts when it finishes", r + 1, i + 1)), + _ => text.push_str(": nothing is waiting"), + } + Reply::ok(text).with(json!({ "action": "start", "paused": false, "running": running_index(srv).map(|i| i + 1), "queued": queued_list(srv) })) + } + "status" => { + let running = running_index(srv).map(|i| { + let n = i + 1; + let pct = f64::from(srv.jobs[i].progress()).clamp(0.0, 1.0) * 100.0; + format!("job:{n} running {pct:.0}% → {}", srv.jobs[i].out.display()) + }); + let queued: Vec = srv + .jobs + .iter() + .enumerate() + .filter(|(_, j)| j.waiting()) + .enumerate() + .map(|(k, (i, j))| format!("{}. job:{} waiting → {}", k + 1, i + 1, j.out.display())) + .collect(); + let state = if srv.queue_paused { "paused" } else { "running" }; + let mut lines = vec![format!("queue {state}; {} queued", queued.len())]; + lines.push(format!("running: {}", running.unwrap_or_else(|| "none".to_string()))); + if queued.is_empty() { + lines.push("queued: none".to_string()); + } else { + lines.push("queued, in order:".to_string()); + lines.extend(queued); + } + if srv.queue_paused { + lines.push("The queue is paused: queued exports do not start until export_queue {action:\"start\"}.".to_string()); + } + Reply::ok(lines.join("\n")).with(json!({ "action": "status", "paused": srv.queue_paused, "queued": queued_list(srv), "running": running_index(srv).map(|i| i + 1) })) + } + other => Reply::err(format!("export_queue action `{other}` is not one of pause, start, status")), + } +} + fn presets_schema() -> Value { json!({ "type": "object", "properties": {} }) } @@ -1666,7 +1756,9 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { // timeline and starts when they are done (`advance`). With nothing ahead it starts now. let queued = opt_bool(args, "queue").unwrap_or(false); let ahead = srv.jobs.iter().position(job_running).map(|i| i + 1); - let (handle, pending) = if queued && ahead.is_some() { + // A paused queue holds a queued export even with nothing ahead of it. + let paused = srv.queue_paused; + let (handle, pending) = if queued && (ahead.is_some() || paused) { let frames = settings.range.map_or(project.media_frames(), |(a, b)| b.min(project.media_frames()).saturating_sub(a)); let length_secs = f64::from(frames) / meta.frame_rate; (None, Some(Box::new(Pending { project, meta, settings: settings.clone(), sample_rate, length_secs }))) @@ -1705,7 +1797,9 @@ fn export_start(srv: &mut Server, args: &Value) -> Reply { let preset_note = preset.map_or_else(String::new, |p| format!("; preset {}", p.id)); let verb = if waiting { "queued" } else { "started" }; let mut text = format!("job:{job} {verb} → {} ({when}); {words}{captions}{tone_note}{size_note}{fit_note}{preset_note}{loudness_note}", out.display()); - if waiting { + if waiting && paused { + text.push_str("\nWaiting: the export queue is paused, so this one starts only when export_queue {action:\"start\"} is sent, from the timeline as it is now (later edits do not change it). export_status shows the queue; export_cancel with its job removes it."); + } else if waiting { text.push_str(&format!( "\nWaiting: it starts when job:{} and every export queued before it have finished, from the timeline as it is now (later edits do not change it). export_status shows it as waiting; export_cancel with its job removes it.", ahead.unwrap_or(1) @@ -1838,12 +1932,13 @@ pub fn job_running(job: &Job) -> bool { /// Moves the queue on: a waiting job whose cancel arrived is settled by `Job::cancel`; when no /// worker is running, the first waiting job starts from its own copy of the timeline. One encode -/// at a time. Called on every server tick, so a queue drains with no client polling. +/// at a time. A paused queue (`export_queue {action:"pause"}`) starts nothing new. Called on every +/// server tick, so a queue drains with no client polling. pub fn advance(srv: &mut Server) { for job in srv.jobs.iter_mut() { settle(job); } - if srv.jobs.iter().any(|j| j.handle.is_some() && job_running(j)) { + if srv.queue_paused || srv.jobs.iter().any(|j| j.handle.is_some() && job_running(j)) { return; } if let Some(job) = srv.jobs.iter_mut().find(|j| j.outcome.is_none() && j.waiting()) @@ -1874,7 +1969,7 @@ fn export_status(srv: &mut Server, args: &Value) -> Reply { None => Reply::ok(unknown_out_text(&anchored)).with(json!({"jobs": [], "finished": 0})), }; } - if srv.jobs.is_empty() && args.get("job").is_none() { + if srv.jobs.is_empty() && args.get("job").is_none() && !srv.queue_paused { return Reply::ok( "no exports in this session — export_start makes one. An export from an earlier session is not tracked here: pass out (its file path) to see whether its file is there", ) @@ -1922,6 +2017,9 @@ fn export_status(srv: &mut Server, args: &Value) -> Reply { if args.get("job").is_none() { let unfinished = srv.jobs.len() - finished_total; lines.push(format!("exports: {unfinished} unfinished, {finished_total} finished")); + if srv.queue_paused { + lines.push("queue paused: queued exports wait until export_queue {action:\"start\"}".to_string()); + } } for i in ids { let job = &srv.jobs[i]; @@ -1977,6 +2075,7 @@ fn export_status(srv: &mut Server, args: &Value) -> Reply { let eta_text = eta.map_or_else(|| "unknown".to_string(), clock_secs); let ahead = srv.jobs[..i].iter().filter(|j| j.outcome.is_none()).count(); let line = match job.stage() { + _ if job.waiting() && srv.queue_paused => format!("job:{n} waiting (queue paused) · {ahead} export{} ahead → {out}", if ahead == 1 { "" } else { "s" }), _ if job.waiting() => format!("job:{n} waiting · {ahead} export{} ahead → {out}", if ahead == 1 { "" } else { "s" }), // A stage before the encode has its own percent; the encode's ETA // means nothing yet. @@ -2036,7 +2135,7 @@ fn export_status(srv: &mut Server, args: &Value) -> Reply { if lines.is_empty() { lines.push("no exports to show".to_string()); } - Reply::ok(lines.join("\n")).with(json!({ "jobs": rows, "finished": finished_total })) + Reply::ok(lines.join("\n")).with(json!({ "jobs": rows, "finished": finished_total, "queue_paused": srv.queue_paused })) } /// The true-peak ceiling the advice names: -2 dBTP for a lossy file, whose encoder can add about a @@ -3155,6 +3254,18 @@ mod tests { } } + /// Pause sets the flag and status says so; start lifts it, with nothing waiting to start. + #[test] + fn queue_pause_and_start_set_the_flag_and_say_so() { + let mut srv = Server::new(); + let paused = export_queue(&mut srv, &json!({"action": "pause"})); + assert!(!paused.is_error && srv.queue_paused, "{}", paused.text); + let status = export_queue(&mut srv, &json!({"action": "status"})); + assert!(status.text.contains("queue paused") && status.text.contains("queued: none"), "{}", status.text); + let started = export_queue(&mut srv, &json!({"action": "start"})); + assert!(!srv.queue_paused && started.text.contains("nothing is waiting"), "{}", started.text); + } + /// A waiting job cancelled by number never starts and writes nothing; the queue moves past it. #[test] fn a_waiting_job_can_be_cancelled_and_never_starts() {