Repository navigation
Write a clip's title without holding the edit lock - #180
Conversation
The review page held the job's edit lock (and the folder's) while the AI backend answered, so Keep/Drop on other clips waited 2 s and got 409. write_clip_copy is now draft_clip_copy (reads the range and transcript, asks the backend, writes nothing) and save_clip_copy (re-reads manifest.json under the lock and saves, or refuses if the clip's range changed meanwhile). The endpoint drafts first and only locks to save.
A21-devs
left a comment
There was a problem hiding this comment.
Checked:
- The range check compares file, start and end from a fresh read under the lock. A layout-only re-render keeps all three and the title stays valid, which is right, since the title doesn't depend on the layout.
- A superseded job: the draft happens before
begin_edit, so the backend is asked and then the save gets the usual 409 "a newer run replaced these clips". That wastes one AI call in a rare case. Fine. - Two title requests for the same clip can't overlap from the page, because the button is disabled while one runs (index.html 423).
write_clip_copykeeps its signature, and the old pipeline tests pass unchanged.
One real problem with the save's wait budget, inline.
| # and saving checks the clip's range didn't change in between. | ||
| draft = self._draft_copy(st, manifest, int(number), backend, model) | ||
| action = partial(save_clip_copy, manifest, draft, log=st.add_log) | ||
| wait = KEEP_WAIT # saving takes milliseconds, like a keep |
There was a problem hiding this comment.
The save takes milliseconds, but the lock it waits for may not be free: a Re-render or layout change of another clip holds it for the whole ffmpeg run (7-8 s per 20 s clip in the run from the description, longer for longer clips). If the AI answers during one, the save waits KEEP_WAIT = 2 s, gets 409 "busy", and the title the user waited 15-30 s for (and may have paid for) is thrown away. Before this PR the request was refused before asking the backend, so nothing was lost. The budget here should cover a re-render, e.g. a separate SAVE_WAIT of a minute. The request thread is already parked for the AI call anyway.
|
Fixed in 9720c52. Saving a title now has its own Verified:
|
A21-devs
left a comment
There was a problem hiding this comment.
Second pass over 9720c52. Fixed: the title save now waits SAVE_WAIT (60 s). I checked where the budget starts. deadline = time.monotonic() + wait is computed after _draft_copy returns, so the 60 s count from when the answer arrives, not from the request, and a slow backend doesn't eat into it. The same deadline covers begin_edit and the cross-process editing() lock, which is what the new test holds. Keep/Drop still use KEEP_WAIT. Nothing else changed. Clean.
The save used KEEP_WAIT (2 s), so an answer that arrived during another clip's re-render was thrown away with a 409.
Closes #112.
What
"Write title" on the review page ran
write_clip_copyinsidebegin_edit+editing(), so the job's edit lock and the folder's lock were held for the whole AI call. Meanwhile Keep/Drop on any other clip waitedKEEP_WAITand got 409, and Re-render got 409 right away.pipeline.draft_clip_copy(manifest, n, backend, model)does the validation, reads the clip's range and transcript, and asks the backend. It writes nothing and returns aCopyDraft(n, file, start, end, post).pipeline.save_clip_copy(manifest, draft)re-reads manifest.json, and if the clip still has the same file and range it savescopy, writes<clip>.txtand the manifest. If the clip was trimmed or re-rendered in between, it raisesValueError("clip N changed while its title was being written, write it again")and saves nothing. A title for 10-15 s shouldn't land on a clip that's now 10-18 s.write_clip_copyis draft + save, same signature and behavior as before, for anything that calls it directly.no title:log line, 500 otherwise), then takes the locks only forsave_clip_copy. The save uses theKEEP_WAITbudget like a keep, since it takes milliseconds.The MCP server doesn't write titles for single clips, so it isn't touched.
Testing
uv run ruff check src tests,uv run mypy,uv run pytest -q tests/test_server.py tests/test_write_title.py tests/test_mcp_server.py: 159 passed.New tests in
tests/test_write_title.py:pipeline.editing) while its title is written, and the title request gets 400 with the "changed while" message and saves nothingReal run of the repro from the issue:
clipwright servewithCLIPWRIGHT_OPENAI_URLpointing at a local stub that sleeps 15 s before answering. Job on a 240 s synthetic video (TTS speech over Roblox gameplay, whisper on), 2 clips. While "Write title" ran on clip 1, I sent Keep and then Drop on clip 2:The .txt next to the clip had the stub's title, description and hashtag.