fix(v3.8): restore review continuation and prefix resume

This commit is contained in:
ukr8b3g-cmyk
2026-09-08 14:42:07 +00:00
parent 20be744b3f
commit aa35de4244
8 changed files with 1939 additions and 1575 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ jobs:
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
python -m pip install --index-url https://download.pytorch.org/whl/cpu torch python -m pip install --index-url https://download.pytorch.org/whl/cpu torch
python -m pip install -r requirements.txt numpy safetensors pytest psutil python -m pip install -r requirements.txt numpy safetensors pytest psutil opencv-python-headless Pillow
- name: Compile Python - name: Compile Python
run: python -m compileall -q . run: python -m compileall -q .
- name: Run tests - name: Run tests
+5 -5
View File
@@ -1,6 +1,6 @@
dca65fb1393e67f59c6f81f9411e3e745eb8f1097e9a2adf7ffc6f4e3901ca9f __init__.py dca65fb1393e67f59c6f81f9411e3e745eb8f1097e9a2adf7ffc6f4e3901ca9f __init__.py
3e7a1ec3380be2a222c8a3e9b8a6bb184d3a760478957f48186438f15235bdba branch_provenance.py 3e7a1ec3380be2a222c8a3e9b8a6bb184d3a760478957f48186438f15235bdba branch_provenance.py
4f6feeb2f63a9285b0e76fb2e2618058c7d7c279af1632e1a6ccabcc9ec9a45a .github/workflows/tests.yml 8296f0afc7be47171e439c02fb2988cfeb0df904acbe3fc4f507f426d709157e .github/workflows/tests.yml
0a2f69d4cec89d440f5d5aa1ec68a7c9a741382d313f80dcddf96d13f70b3e68 .gitignore 0a2f69d4cec89d440f5d5aa1ec68a7c9a741382d313f80dcddf96d13f70b3e68 .gitignore
e0d0093229dd4719e97e1ee2c0cf935f6692f323f97af49a6361fd9ffac8a3d2 AGENTS.md e0d0093229dd4719e97e1ee2c0cf935f6692f323f97af49a6361fd9ffac8a3d2 AGENTS.md
2794b4f4831e5ec9a38b6cb3049736c16d800708057349e80e1a921c90d16a2e CHANGELOG.md 2794b4f4831e5ec9a38b6cb3049736c16d800708057349e80e1a921c90d16a2e CHANGELOG.md
@@ -87,12 +87,12 @@ b470819f16fc179654dc1600721a63f0a5a14e777f4c004d574b499da6886ba5 public_api.py
96f98d727b72d6aefd431061572e187c303365a3e5b4d20cbb2bcf030aa30112 pyproject.toml 96f98d727b72d6aefd431061572e187c303365a3e5b4d20cbb2bcf030aa30112 pyproject.toml
94fdc2d545b2d4077a4d70229fd22ba3ccac21d49d1097d2873f76d04e9a3c7a pytest.ini 94fdc2d545b2d4077a4d70229fd22ba3ccac21d49d1097d2873f76d04e9a3c7a pytest.ini
88aa955161d04d14ebd8d90d6cb6c6206097160a671eb4d1bfe9b3e76ebc6c13 README_JA.md 88aa955161d04d14ebd8d90d6cb6c6206097160a671eb4d1bfe9b3e76ebc6c13 README_JA.md
1f8a6e1a4441ac2fd7a07ddbdfea923ed1da9f3100db49dca729e141de92f4af README.md 9d9fa5ec9db29e2fb52e3c5ed26df02c9c0c2ba39608294f7c62057237830908 README.md
44127adcfa30ee84bff9cd4b2d0c695355209550e76982d374122008728aa5bc reference_audio.py 44127adcfa30ee84bff9cd4b2d0c695355209550e76982d374122008728aa5bc reference_audio.py
5cb9bfd6810d3a93a637451980a4cc5c1436e5b84cfd1c7a111cd192e876351b reference_video.py 5cb9bfd6810d3a93a637451980a4cc5c1436e5b84cfd1c7a111cd192e876351b reference_video.py
131bdfbb7a7173c9e7826859c0e648bfb69bd18bf20fa5528c0e18a63f888b26 reference.py 131bdfbb7a7173c9e7826859c0e648bfb69bd18bf20fa5528c0e18a63f888b26 reference.py
467edb2c188d024c2392aafe7423b3f835e16b10f570da76e2f7dda8a962c1c5 requirements.txt 467edb2c188d024c2392aafe7423b3f835e16b10f570da76e2f7dda8a962c1c5 requirements.txt
a65d657466491aba8b2d1004e87071cee2819869813e646789df736a3ccf479e run_storage.py 2ceba1091dad4fa66da7299e8320ff0a8a6dccb948fc918e3101b40f6d8b03f6 run_storage.py
6056de6c0a5322a8a51ba5a114538dca2ef67788cd1afba10fedd483b95f6afa state_io.py 6056de6c0a5322a8a51ba5a114538dca2ef67788cd1afba10fedd483b95f6afa state_io.py
3a359a0467725cc292ccb4c86cf0c3d30bb6a114d01f5345792b09ea3d45441d state.py 3a359a0467725cc292ccb4c86cf0c3d30bb6a114d01f5345792b09ea3d45441d state.py
43ec4023dc06c941e5d7a04db4b8a89fb58d744ceb986f6eb9bf534d4fdcb87b temporal.py 43ec4023dc06c941e5d7a04db4b8a89fb58d744ceb986f6eb9bf534d4fdcb87b temporal.py
@@ -173,7 +173,7 @@ ee4dd8f6eb8114706b2625b4471b041a0ea66198f9f825c63e913c896ed87530 tests/test_v38
72a0e3cb334049b66dd36f52c826931067c242fa63557933fd667138b38d6e8d tests/test_v38_review_control.py 72a0e3cb334049b66dd36f52c826931067c242fa63557933fd667138b38d6e8d tests/test_v38_review_control.py
83301839f08d275f5648d7782b6d96795e14b1ce79d722e83e57190fe52fb4aa tests/test_v38_review_execution_cap.py 83301839f08d275f5648d7782b6d96795e14b1ce79d722e83e57190fe52fb4aa tests/test_v38_review_execution_cap.py
2fec519540e18c55682884647db9fa1c90902da7be3d62261f2801a5c5724a96 tests/test_v38_review_run_storage.py 2fec519540e18c55682884647db9fa1c90902da7be3d62261f2801a5c5724a96 tests/test_v38_review_run_storage.py
b228d1a596ade2c3b3495fdf97177e798cec4be774d6ff02d5c6294e09140866 tests/test_v38_review_ui.py dfa174feed4b14d819d1c9f36381e5650e97da6d0e59de441895955dd107ff5f tests/test_v38_review_ui.py
75697036f361a9b8ea74f69b15e408670f686c8c0e8a6c1d48fe059cc837d12a tests/test_v38_selective_second_pass_node.py 75697036f361a9b8ea74f69b15e408670f686c8c0e8a6c1d48fe059cc837d12a tests/test_v38_selective_second_pass_node.py
8026a241301dfc4de518649305458a538ef17a0b1567b113877a2af377738528 tests/test_v38_temporal_window_refine.py 8026a241301dfc4de518649305458a538ef17a0b1567b113877a2af377738528 tests/test_v38_temporal_window_refine.py
0dbe8a5f71c92f3523942343b40787104c8b96781461ba3ba82934a6bdbe5834 THIRD_PARTY_NOTICES.md 0dbe8a5f71c92f3523942343b40787104c8b96781461ba3ba82934a6bdbe5834 THIRD_PARTY_NOTICES.md
@@ -241,7 +241,7 @@ c2883272b05a9a9146b5c6cf614ddae8a3e6893cd910902023aae61360195289 web/easy_bypas
9db0aa94f634578a962d5db49e5c70356040a59df968e3a2e531b327a623081f web/easy_load_image.js 9db0aa94f634578a962d5db49e5c70356040a59df968e3a2e531b327a623081f web/easy_load_image.js
873efcbd15c2d9fa10c9d5fc51a796ad3a18c0c6acceecf499c4b956aa845c6c web/easy_load_video.js 873efcbd15c2d9fa10c9d5fc51a796ad3a18c0c6acceecf499c4b956aa845c6c web/easy_load_video.js
0c68d13a1f8beb7431a32b471f8b0612c42fcc4bf72dd97611a025d158008662 web/easy_v38.js 0c68d13a1f8beb7431a32b471f8b0612c42fcc4bf72dd97611a025d158008662 web/easy_v38.js
549a8150bc926bf142758b1610e3730547d6abcfbcddb0b37ed8baaaf86b38cb web/project_id.js 613797b621f07813b7c13417766f6f87aab92eb4c049ddd692577b226f46a894 web/project_id.js
be0b8d39e5343680ebea815c3a4fb6ce7a32e065f30e43e013040a40f702cef3 .comfyignore be0b8d39e5343680ebea815c3a4fb6ce7a32e065f30e43e013040a40f702cef3 .comfyignore
1d2838cc47694609289ea15132872ad48e1b6c8274da4b7bf188dd3ebf066121 docs/V38_RELEASE_AND_MIGRATION.md 1d2838cc47694609289ea15132872ad48e1b6c8274da4b7bf188dd3ebf066121 docs/V38_RELEASE_AND_MIGRATION.md
69d0e95d4d8ed8414e9bfb9bbbcb6183efa6d27f27cc8c6dd2f84c9cc5ce3439 tests/test_v38_public_surface_cleanup.py 69d0e95d4d8ed8414e9bfb9bbbcb6183efa6d27f27cc8c6dd2f84c9cc5ce3439 tests/test_v38_public_surface_cleanup.py
+25 -13
View File
@@ -2,7 +2,7 @@
**Download workflow: [JSON](examples/workflows/MiniMax_H3_Continuum_V38.json) | [ZIP](examples/workflows/MiniMax_H3_Continuum_V38.zip)** — [Latest release](https://github.com/ukr8b3g-cmyk/ComfyUI-H3-Continuum/releases/latest) **Download workflow: [JSON](examples/workflows/MiniMax_H3_Continuum_V38.json) | [ZIP](examples/workflows/MiniMax_H3_Continuum_V38.zip)** — [Latest release](https://github.com/ukr8b3g-cmyk/ComfyUI-H3-Continuum/releases/latest)
⚠️ Hotfix in progress: We’re investigating reported issues with chunk continuation and Review Each Chunk mode in V3.8. A hotfix is being prepared. Thank you for your reports and patience—we’ll update this page when it’s ready. ✅ V3.8 hotfix applied on `main` — September 8, 2026: Review Each Chunk continuation, stale `Regenerate From` state, completed-sequence extension, and Render History queue handling have been repaired. Update with `git pull --ff-only origin main` (or ComfyUI Manager **Update**), restart ComfyUI, and hard-refresh the browser if the old UI remains. Existing saved Takes are preserved. Issue #13 remains a separate open long-continuation quality issue and is not part of this hotfix.
<img width="1536" height="1024" alt="exec-55ad0463-8655-409c-b9a6-49d1315cdd78" src="https://github.com/user-attachments/assets/063bb16b-5c25-44f8-9304-031995502b26" /> <img width="1536" height="1024" alt="exec-55ad0463-8655-409c-b9a6-49d1315cdd78" src="https://github.com/user-attachments/assets/063bb16b-5c25-44f8-9304-031995502b26" />
@@ -463,23 +463,35 @@ If you want a review pause instead, choose `Run = Review Each Chunk` in step 6.
#### 9. Add more chunks to a completed sequence #### 9. Add more chunks to a completed sequence
For a compatible saved run without a Last Image constraint, increasing the target can reuse completed chunks. This requires saved progress, not just an existing MP4 file. **You do not need Render History just to make a completed video longer.** For an ordinary extension, go back to the normal settings, increase the target `Chunks`, and Queue again. `Chunks` is the **final total number of chunks**, not the number you want to add next.
1. Keep the same Sampler/workflow and `Run Name (Optional Override)`. Do not create a new run identity. For the simplest and safest extension, keep the existing generation conditions unchanged: the same Sampler/workflow and run identity, `Base Seed`, `Control After Generate = fixed`, `Seconds per Chunk`, prompt, model/LoRA, media, dimensions, sampling schedule, Continuity, and Audio Continuity. Keep `Progress = On — Resume and Takes available` and `Regenerate From = Auto`.
2. Keep `Base Seed` unchanged and `Control After Generate = fixed`.
3. Keep `Progress = On — Resume and Takes available`, and keep the saved progress files available.
4. Keep `Seconds per Chunk` and the generation inputs unchanged.
5. Set `Regenerate From = Auto`.
6. Change **only the target count** in `Chunks`: for example, change `3` to `5` to add two chunks. Do not set it to `2`.
7. Choose `Run = Review Each Chunk` for one new review unit per Queue, or `Run = Generate Full Video` to finish all missing chunks.
8. Check `Total Length`, then click the top-right blue `Run` button and check the reuse report described below.
With compatible progress for three 5-second chunks, the new target is 25 seconds. Review mode should first produce Chunk 4 and a 20-second output; continuing again completes Chunk 5. Full-video mode should produce Chunks 4–5 and the 25-second output in one Queue. **Example: extend a completed 2 × 5-second sequence to 3 × 5 seconds**
**Do not assume append-only reuse with Last Image.** Extending a sequence changes where its final-image constraint belongs. The former last chunk, or a terminal pair, may need regeneration. Likewise, changing the model, prompt, media, dimensions, schedule, or continuation settings can invalidate saved progress. `Progress = On` enables compatibility checking; it does not force incompatible chunks to be reused. 1. Finish the original two chunks. The completed target is `Chunks = 2`, so the saved video is 10 seconds.
2. Click `Back to Settings`. You do **not** need to open `Render History`.
3. Change `Chunks` from `2` to `3`. `Total Length` changes from 10 seconds to 15 seconds.
4. Keep `Progress = On — Resume and Takes available` and `Regenerate From = Auto`. Keep the prompt and the existing generation inputs unchanged for this ordinary extension.
5. Use `Run = Review Each Chunk` if you want to review the new chunk, or `Run = Generate Full Video` if you want all currently missing chunks generated in one Queue.
6. Click the top-right blue `Run` button.
With compatible saved progress, the expected work is:
- Chunk 1 → reused; no new Sampling
- Chunk 2 → reused; no new Sampling
- Chunk 3 → newly generated
- final saved sequence → 3 chunks / 15 seconds
The same rule applies to a larger extension. For example, changing `Chunks` from `3` to `5` means the new target is five total chunks; it does **not** mean “add five.” Review mode first generates Chunk 4, then Chunk 5 on the next accepted continuation. Full-video mode generates the missing Chunks 4–5 in one Queue.
Switching `Generate Full Video` ↔ `Review Each Chunk` by itself does **not** mean restart from Chunk 1. A Chunk 1 restart happens only when you explicitly choose `Start again from Chunk 1`, explicitly set Advanced `Regenerate From = Chunk 1`, or the backend determines that the stored prefix is incompatible with the current generation contract.
`Render History` is for a different job: browsing stored Takes, selecting an older Take, or branching with `Continue From Here`. Normal append-style extension does not require History. `Previous Take` / `Next Take` only browse stored results; they do not generate a new chunk.
**Do not assume append-only reuse with Last Image.** Extending a sequence changes where its final-image constraint belongs. The former last chunk, or a terminal pair, may need regeneration. Likewise, changing the prompt or other generation-contract inputs can invalidate saved progress. `Progress = On` enables compatibility checking; it does not force incompatible chunks to be reused.
The extension path is covered by CPU compatibility tests, including two-to-three chunks and Last Image invalidation. It is not the same GPU test as the two-chunk review timing example below; arbitrary extensions and media combinations have not all been GPU-verified. The extension path is covered by CPU compatibility tests, including two-to-three chunks and Last Image invalidation. It is not the same GPU test as the two-chunk review timing example below; arbitrary extensions and media combinations have not all been GPU-verified.
#### 10. Understand continuation time and check reuse #### 10. Understand continuation time and check reuse
Continuing does not mean saving only the new segment. With compatible saved progress, the normal workflow: Continuing does not mean saving only the new segment. With compatible saved progress, the normal workflow:
+3 -3
View File
@@ -28,12 +28,12 @@ a4ce23167b83e8d72b86a802dfde4f4045828433c7c13aab799bd64831dc04a4 nodes.py
b470819f16fc179654dc1600721a63f0a5a14e777f4c004d574b499da6886ba5 public_api.py b470819f16fc179654dc1600721a63f0a5a14e777f4c004d574b499da6886ba5 public_api.py
96f98d727b72d6aefd431061572e187c303365a3e5b4d20cbb2bcf030aa30112 pyproject.toml 96f98d727b72d6aefd431061572e187c303365a3e5b4d20cbb2bcf030aa30112 pyproject.toml
88aa955161d04d14ebd8d90d6cb6c6206097160a671eb4d1bfe9b3e76ebc6c13 README_JA.md 88aa955161d04d14ebd8d90d6cb6c6206097160a671eb4d1bfe9b3e76ebc6c13 README_JA.md
1f8a6e1a4441ac2fd7a07ddbdfea923ed1da9f3100db49dca729e141de92f4af README.md 9d9fa5ec9db29e2fb52e3c5ed26df02c9c0c2ba39608294f7c62057237830908 README.md
44127adcfa30ee84bff9cd4b2d0c695355209550e76982d374122008728aa5bc reference_audio.py 44127adcfa30ee84bff9cd4b2d0c695355209550e76982d374122008728aa5bc reference_audio.py
5cb9bfd6810d3a93a637451980a4cc5c1436e5b84cfd1c7a111cd192e876351b reference_video.py 5cb9bfd6810d3a93a637451980a4cc5c1436e5b84cfd1c7a111cd192e876351b reference_video.py
131bdfbb7a7173c9e7826859c0e648bfb69bd18bf20fa5528c0e18a63f888b26 reference.py 131bdfbb7a7173c9e7826859c0e648bfb69bd18bf20fa5528c0e18a63f888b26 reference.py
467edb2c188d024c2392aafe7423b3f835e16b10f570da76e2f7dda8a962c1c5 requirements.txt 467edb2c188d024c2392aafe7423b3f835e16b10f570da76e2f7dda8a962c1c5 requirements.txt
a65d657466491aba8b2d1004e87071cee2819869813e646789df736a3ccf479e run_storage.py 2ceba1091dad4fa66da7299e8320ff0a8a6dccb948fc918e3101b40f6d8b03f6 run_storage.py
6056de6c0a5322a8a51ba5a114538dca2ef67788cd1afba10fedd483b95f6afa state_io.py 6056de6c0a5322a8a51ba5a114538dca2ef67788cd1afba10fedd483b95f6afa state_io.py
3a359a0467725cc292ccb4c86cf0c3d30bb6a114d01f5345792b09ea3d45441d state.py 3a359a0467725cc292ccb4c86cf0c3d30bb6a114d01f5345792b09ea3d45441d state.py
43ec4023dc06c941e5d7a04db4b8a89fb58d744ceb986f6eb9bf534d4fdcb87b temporal.py 43ec4023dc06c941e5d7a04db4b8a89fb58d744ceb986f6eb9bf534d4fdcb87b temporal.py
@@ -100,6 +100,6 @@ c2883272b05a9a9146b5c6cf614ddae8a3e6893cd910902023aae61360195289 web/easy_bypas
9db0aa94f634578a962d5db49e5c70356040a59df968e3a2e531b327a623081f web/easy_load_image.js 9db0aa94f634578a962d5db49e5c70356040a59df968e3a2e531b327a623081f web/easy_load_image.js
873efcbd15c2d9fa10c9d5fc51a796ad3a18c0c6acceecf499c4b956aa845c6c web/easy_load_video.js 873efcbd15c2d9fa10c9d5fc51a796ad3a18c0c6acceecf499c4b956aa845c6c web/easy_load_video.js
0c68d13a1f8beb7431a32b471f8b0612c42fcc4bf72dd97611a025d158008662 web/easy_v38.js 0c68d13a1f8beb7431a32b471f8b0612c42fcc4bf72dd97611a025d158008662 web/easy_v38.js
549a8150bc926bf142758b1610e3730547d6abcfbcddb0b37ed8baaaf86b38cb web/project_id.js 613797b621f07813b7c13417766f6f87aab92eb4c049ddd692577b226f46a894 web/project_id.js
0cf8d49bcb71b30437dc893f6218dc4cfb1cd244b647e4fbc2861dea2271a33a web/reference_audio_ui.js 0cf8d49bcb71b30437dc893f6218dc4cfb1cd244b647e4fbc2861dea2271a33a web/reference_audio_ui.js
83d28cc0cd549066962dc21ceae05d2b189fe22391b556887eab2cc1800e1e80 examples/workflows/MiniMax_H3_Continuum_V38.zip 83d28cc0cd549066962dc21ceae05d2b189fe22391b556887eab2cc1800e1e80 examples/workflows/MiniMax_H3_Continuum_V38.zip
+326 -62
View File
@@ -9,8 +9,8 @@ import marshal
import os import os
import re import re
import shutil import shutil
import socket
import time import time
import socket
import uuid import uuid
from datetime import datetime, timezone from datetime import datetime, timezone
from pathlib import Path from pathlib import Path
@@ -287,8 +287,7 @@ def _replace_json_atomically(temporary: Path, destination: Path) -> None:
winerror = getattr(exc, "winerror", None) winerror = getattr(exc, "winerror", None)
error_code = winerror if winerror is not None else exc.errno error_code = winerror if winerror is not None else exc.errno
transient = ( transient = (
os.name == "nt" error_code in _WINDOWS_REPLACE_RETRY_WINERRORS
and error_code in _WINDOWS_REPLACE_RETRY_WINERRORS
and delay is not None and delay is not None
) )
if transient: if transient:
@@ -1186,6 +1185,12 @@ class RunStorageController:
self.selected_take_revision: dict[str, Any] | None = None self.selected_take_revision: dict[str, Any] | None = None
self.pending_branch_cut: dict[str, Any] | None = None self.pending_branch_cut: dict[str, Any] | None = None
self.storage_revision_id_override = "" self.storage_revision_id_override = ""
# Lock-scoped metadata only. Never cache tensors or skip raw integrity checks.
self._manifest_snapshot = None
self._plan_import = None
self.io_metrics = {"manifest_scans": 0, "manifest_reads": 0,
"raw_loads": 0, "raw_bytes": 0,
"manifest_seconds": 0.0, "raw_seconds": 0.0}
def set_prompt_graph(self, prompt: Any, unique_id: Any) -> None: def set_prompt_graph(self, prompt: Any, unique_id: Any) -> None:
self.prompt_graph = prompt if isinstance(prompt, dict) else None self.prompt_graph = prompt if isinstance(prompt, dict) else None
@@ -1220,6 +1225,7 @@ class RunStorageController:
def __enter__(self) -> "RunStorageController": def __enter__(self) -> "RunStorageController":
self.lock.acquire() self.lock.acquire()
self._manifest_snapshot = None
self.context_token = _ACTIVE.set(self) self.context_token = _ACTIVE.set(self)
return self return self
@@ -1235,6 +1241,8 @@ class RunStorageController:
if self.context_token is not None: if self.context_token is not None:
_ACTIVE.reset(self.context_token) _ACTIVE.reset(self.context_token)
self.context_token = None self.context_token = None
self._manifest_snapshot = None
self._plan_import = None
self.lock.release() self.lock.release()
def _manifest_path(self) -> Path: def _manifest_path(self) -> Path:
@@ -1245,13 +1253,17 @@ class RunStorageController:
def _write_manifest(self) -> None: def _write_manifest(self) -> None:
if self.manifest is not None: if self.manifest is not None:
_write_json(self._manifest_path(), self.manifest) _write_json(self._manifest_path(), self.manifest)
self._manifest_snapshot = None
def _read_manifests(self) -> dict[str, dict[str, Any]]: def _read_manifests(self) -> dict[str, dict[str, Any]]:
if self.context_token is not None and self._manifest_snapshot is not None:
return self._manifest_snapshot
started = time.perf_counter()
manifests: dict[str, dict[str, Any]] = {} manifests: dict[str, dict[str, Any]] = {}
if not self.revisions_root.exists(): self.io_metrics["manifest_scans"] += 1
return manifests
for path in sorted(self.revisions_root.glob("*/manifest.json")): for path in sorted(self.revisions_root.glob("*/manifest.json")):
try: try:
self.io_metrics["manifest_reads"] += 1
value = _read_json(path) value = _read_json(path)
_manifest_sampling_identity(value) _manifest_sampling_identity(value)
revision_id = str(value.get("revision_id", "")) revision_id = str(value.get("revision_id", ""))
@@ -1260,6 +1272,9 @@ class RunStorageController:
manifests[revision_id] = value manifests[revision_id] = value
except Exception as exc: except Exception as exc:
self.notes.append(f"provenance manifest {path.parent.name} rejected: {exc}") self.notes.append(f"provenance manifest {path.parent.name} rejected: {exc}")
self.io_metrics["manifest_seconds"] += time.perf_counter() - started
if self.context_token is not None:
self._manifest_snapshot = manifests
return manifests return manifests
def _manifest_provenance_chain( def _manifest_provenance_chain(
@@ -1309,8 +1324,8 @@ class RunStorageController:
group=group, group=group,
variation_nonce=variation_nonce, variation_nonce=variation_nonce,
created_utc=str( created_utc=str(
source_manifest.get("updated_utc") source_manifest.get("created_utc")
or source_manifest.get("created_utc") or source_manifest.get("updated_utc")
or "" or ""
), ),
storage_revision_id=source_id, storage_revision_id=source_id,
@@ -1482,9 +1497,14 @@ class RunStorageController:
def _load_entry(self, record: dict[str, Any], prompt: str) -> dict[str, Any]: def _load_entry(self, record: dict[str, Any], prompt: str) -> dict[str, Any]:
source = str(record["storage_revision_id"]) source = str(record["storage_revision_id"])
filename = str(record["filename"]) filename = str(record["filename"])
if Path(filename).name != filename: if Path(filename).name != filename or any(c in filename for c in "/\\") or filename in {"", ".", ".."}:
raise RunStorageError("stored chunk filename is invalid") raise RunStorageError("stored chunk filename is invalid")
if source in {"", ".", ".."} or any(c in source for c in "/\\"):
raise RunStorageError("stored revision directory is invalid")
path = self.revisions_root / source / "chunks" / filename path = self.revisions_root / source / "chunks" / filename
if not path.resolve().is_relative_to(self.revisions_root.resolve()):
raise RunStorageError("stored chunk escapes the Run Storage directory")
started = time.perf_counter()
if path.stat().st_size != int(record["file_size"]): if path.stat().st_size != int(record["file_size"]):
raise RunStorageError(f"stored chunk size mismatch: {filename}") raise RunStorageError(f"stored chunk size mismatch: {filename}")
expected_sha256 = str(record.get("file_sha256", "")) expected_sha256 = str(record.get("file_sha256", ""))
@@ -1492,13 +1512,17 @@ class RunStorageController:
raise RunStorageError(f"stored chunk SHA-256 is missing: {filename}") raise RunStorageError(f"stored chunk SHA-256 is missing: {filename}")
if _file_sha256(path) != expected_sha256: if _file_sha256(path) != expected_sha256:
raise RunStorageError(f"stored chunk SHA-256 mismatch: {filename}") raise RunStorageError(f"stored chunk SHA-256 mismatch: {filename}")
self.io_metrics["raw_bytes"] += int(record["file_size"])
self.io_metrics["raw_loads"] += 1
with safe_open(str(path), framework="pt", device="cpu") as handle: with safe_open(str(path), framework="pt", device="cpu") as handle:
if set(handle.keys()) != {"audio", "video"}: if set(handle.keys()) != {"audio", "video"}:
raise RunStorageError(f"stored chunk tensors are invalid: {filename}") raise RunStorageError(f"stored chunk tensors are invalid: {filename}")
video, audio = handle.get_tensor("video"), handle.get_tensor("audio") video, audio = handle.get_tensor("video"), handle.get_tensor("audio")
entry = dict(record["entry"]) entry = dict(record["entry"])
entry.update(prompt=str(prompt), video=video, audio=audio, reused=False) entry.update(prompt=str(prompt), video=video, audio=audio, reused=False)
return validate_chunk_entry(entry) result = validate_chunk_entry(entry)
self.io_metrics["raw_seconds"] += time.perf_counter() - started
return result
def _valid_prefix( def _valid_prefix(
self, self,
@@ -1602,6 +1626,166 @@ class RunStorageController:
entries.append(entry) entries.append(entry)
return entries, records[:len(entries)] return entries, records[:len(entries)]
def _compatible_plan_prefix(
self, manifest: dict[str, Any], current_contract: dict[str, Any],
*, stop_before: int = 0,
) -> tuple[list[dict[str, Any]], list[dict[str, Any]]]:
"""Certify a prefix for import, not for cross-lineage Take selection.
Original provenance is validated first. Every reused physical group must
retain its topology and actual producing per-chunk contract. New plans
get their own raw copies below; no foreign lineage is spliced into a DAG.
"""
manifests = self._read_manifests()
source_contract = manifest.get("contract") or {}
_manifest_sampling_identity(manifest)
if _hash(source_contract.get("global")) != _hash(current_contract.get("global")):
return [], []
chain = self._manifest_provenance_chain(manifest, manifests)
records = list(manifest.get("chunks") or [])
allowed = {g.start: g for g in physical_groups(
chunks=int(current_contract["chunk_count"]),
terminal_merge_enabled=_terminal_merge_enabled(current_contract),
)}
accepted = []
requested_by_producer = {}
for revision in chain:
group = revision["group"]
expected = allowed.get(int(group["start"]))
if (expected is None or expected.as_metadata() != group
or (stop_before > 0 and expected.end >= stop_before)):
break
group_records = records[expected.start - 1:expected.end]
if len(group_records) != expected.end - expected.start + 1:
break
compatible = True
for position, record in zip(range(expected.start - 1, expected.end), group_records):
producer = manifests.get(str(record.get("storage_revision_id", "")))
if producer is None:
compatible = False
break
producing = producer.get("contract") or {}
hashes = producing.get("chunk_contract_hashes") or []
# Accepted earlier Takes can come from several nonce branches.
# Compare each producing contract against the new plan while
# preserving that producer's verified variation, not the latest
# branch's nonce for the entire ancestry.
producer_id = str(record["storage_revision_id"])
if producer_id not in requested_by_producer:
requested_by_producer[producer_id] = _apply_reroll_branch_contract(
current_contract,
boundary=int(producing.get("reroll_from_chunk", 0)),
requested_nonce=int(producing.get("effective_reroll_nonce", 0)),
effective_nonce=int(producing.get("effective_reroll_nonce", 0)),
)["chunk_contract_hashes"]
requested_hashes = requested_by_producer[producer_id]
producer_records = producer.get("chunks") or []
if (position >= len(hashes) or position >= len(requested_hashes)
or hashes[position] != requested_hashes[position]
or position >= len(producer_records)
or producer_records[position] != record):
compatible = False
break
if not compatible:
break
accepted.extend(group_records)
entries = []
# Only now load the certified prefix. A corrupt group never becomes reusable.
for position, record in enumerate(accepted):
item = self._load_entry(record, self.prompts[position])
if item["prompt_hash"] != current_contract["prompt_hashes"][position]:
raise RunStorageError("imported prefix prompt does not match its producing contract")
entries.append(item)
return entries, accepted
def _find_plan_import(
self, contract: dict[str, Any], *, stop_before: int = 0,
) -> dict[str, Any] | None:
"""Find a verified plan prefix, stopping before explicit regeneration."""
if stop_before == 1:
return None
manifests = self._read_manifests()
# A matching plan already owns its history. Do not reload an older plan
# merely because that older plan also supplies a compatible prefix.
if any((m.get("contract") or {}).get("nonce_lineage_sha256")
== contract.get("nonce_lineage_sha256") for m in manifests.values()):
return None
canonical_id = ""
try:
project = _read_json(self.run_root / "project.json")
canonical_id = str(project.get("canonical_storage_revision_id", ""))
selected = manifests.get(canonical_id) or {}
expected_chain = (selected.get("branch_provenance") or {}).get("active_chain")
if expected_chain is not None and project.get("canonical_chain") != expected_chain:
canonical_id = ""
except (OSError, ValueError, RunStorageError):
pass
ordered = sorted(manifests.values(), key=lambda m: (
str(m.get("revision_id", "")) == canonical_id,
int((m.get("branch_provenance") or {}).get("canonical_sequence", 0)),
str(m.get("updated_utc", "")), str(m.get("revision_id", "")),
), reverse=True)
for manifest in ordered:
source = manifest.get("contract") or {}
if (manifest.get("status") not in {"complete", "review_ready", "interrupted"}
or source.get("nonce_lineage_sha256") == contract.get("nonce_lineage_sha256")
or _hash(source.get("global")) != _hash(contract.get("global"))):
continue
# Preserve accepted variations when extending/editing a plan. Explicit
# regeneration still uses the existing nonce resolver, not this path.
boundary = int(source.get("reroll_from_chunk", 0))
nonce = int(source.get("effective_reroll_nonce", 0))
if boundary > int(contract["chunk_count"]):
boundary = nonce = 0
requested = _apply_reroll_branch_contract(
contract, boundary=boundary, requested_nonce=nonce, effective_nonce=nonce,
)
try:
entries, records = self._compatible_plan_prefix(
manifest, requested, stop_before=stop_before,
)
except (RunStorageError, ValueError, OSError) as exc:
self.notes.append(f"plan prefix {manifest.get('revision_id', '')} rejected: {exc}")
continue
if not entries:
continue
if boundary > len(entries):
boundary = nonce = 0
requested = _apply_reroll_branch_contract(
contract, boundary=0, requested_nonce=0, effective_nonce=0,
)
groups = physical_groups(chunks=int(contract["chunk_count"]),
terminal_merge_enabled=_terminal_merge_enabled(contract))
unit = next(g for g in groups if g.end == len(entries))
return {"revision_id": str(manifest["revision_id"]),
"status": "complete" if len(entries) == int(contract["chunk_count"]) else "review_ready",
"validated_prefix_count": len(entries), "review_unit": unit.as_metadata(),
"branch_regenerate_from": boundary, "effective_reroll_nonce": nonce,
"manifest": manifest, "entries": entries, "records": records,
"contract": requested, "updated_utc": str(manifest.get("updated_utc", ""))}
return None
def _adopt_plan_prefix(self, imported: dict[str, Any]) -> list[dict[str, Any]]:
"""Copy verified tensors into the new plan; keep every old revision intact."""
self.manifest["prefix_import"] = {
"version": 1, "source_revision_id": imported["revision_id"],
"source_contract_sha256": imported["manifest"]["contract_sha256"],
"records": [
{"sequence_index": position,
"storage_revision_id": original["storage_revision_id"],
"filename": original["filename"], "file_sha256": original["file_sha256"]}
for position, original in enumerate(imported["records"])
],
}
self._write_manifest()
records = []
for position, entry in enumerate(imported["entries"]):
self.commit_chunk(entry, position=position)
records.append(dict(self.manifest["chunks"][-1]))
self.generated_count = 0 # Copies are reused work, never new Sampling.
self.notes.append(f"Imported {len(records)} verified prefix chunks into the new plan; originals preserved")
return records
def _highest_lineage_nonce(self, lineage_sha256: str) -> int: def _highest_lineage_nonce(self, lineage_sha256: str) -> int:
highest = 0 highest = 0
for manifest in self._read_manifests().values(): for manifest in self._read_manifests().values():
@@ -1848,21 +2032,27 @@ class RunStorageController:
if not self.revisions_root.exists(): if not self.revisions_root.exists():
return None return None
compatible_lineage = str(contract.get("nonce_lineage_sha256", "")) compatible_lineage = str(contract.get("nonce_lineage_sha256", ""))
heads: list[dict[str, Any]] = []
mismatched_contracts: list[tuple[str, dict]] = [] mismatched_contracts: list[tuple[str, dict]] = []
paths = sorted( manifests = self._read_manifests()
self.revisions_root.glob("*/manifest.json"), canonical_id = ""
key=lambda path: path.parent.name,
)
for path in paths:
try: try:
manifest = _read_json(path) project = _read_json(self.run_root / "project.json")
except Exception as exc: canonical_id = str(project.get("canonical_storage_revision_id", ""))
self.notes.append(f"review head {path.parent.name} rejected: {exc}") selected = manifests.get(canonical_id) or {}
continue expected_chain = (selected.get("branch_provenance") or {}).get("active_chain")
if expected_chain is not None and project.get("canonical_chain") != expected_chain:
canonical_id = ""
except (OSError, ValueError, RunStorageError):
pass
ordered = sorted(manifests.items(), key=lambda item: (
item[0] == canonical_id,
int((item[1].get("contract") or {}).get("effective_reroll_nonce", 0)),
str(item[1].get("updated_utc", "")), item[0],
), reverse=True)
for revision_id, manifest in ordered:
stored_contract = manifest.get("contract") or {} stored_contract = manifest.get("contract") or {}
if str(stored_contract.get("nonce_lineage_sha256", "")) != compatible_lineage: if str(stored_contract.get("nonce_lineage_sha256", "")) != compatible_lineage:
mismatched_contracts.append((path.parent.name, stored_contract)) mismatched_contracts.append((revision_id, stored_contract))
continue continue
try: try:
head = self._validated_review_head( head = self._validated_review_head(
@@ -1870,7 +2060,7 @@ class RunStorageController:
current_contract=contract, current_contract=contract,
) )
except Exception as exc: except Exception as exc:
self.notes.append(f"review head {path.parent.name} rejected: {exc}") self.notes.append(f"review head {revision_id} rejected: {exc}")
continue continue
if smart_regenerate_only and not ( if smart_regenerate_only and not (
head["status"] == REVISION_STATUS_REVIEW_READY head["status"] == REVISION_STATUS_REVIEW_READY
@@ -1880,8 +2070,7 @@ class RunStorageController:
) )
): ):
continue continue
heads.append(head) return head
if not heads:
# Explain a missing head without changing which heads are reusable. # Explain a missing head without changing which heads are reusable.
# Evaluate only after lookup fails; successful runs are unaffected. # Evaluate only after lookup fails; successful runs are unaffected.
candidates = [] candidates = []
@@ -1899,33 +2088,6 @@ class RunStorageController:
detail += f"; {len(delta) - 12} more differing sections" detail += f"; {len(delta) - 12} more differing sections"
self.notes.append(f"review head {revision_id} incompatible: {detail}") self.notes.append(f"review head {revision_id} incompatible: {detail}")
return None return None
_, catalog, chains = self._provenance_catalog(
lineage_sha256=compatible_lineage,
)
canonical_storage_revision_id, _ = self._canonical_project_selection(
catalog=catalog,
chains=chains,
)
if canonical_storage_revision_id:
for head in heads:
if head["revision_id"] == canonical_storage_revision_id:
if smart_regenerate_only and not (
head["status"] == REVISION_STATUS_REVIEW_READY
or (
head["status"] == REVISION_STATUS_COMPLETE
and head["review_unit"] is not None
)
):
break
return head
return max(
heads,
key=lambda head: (
int(head["effective_reroll_nonce"]),
str(head["updated_utc"]),
str(head["revision_id"]),
),
)
def _resolve_review_contract( def _resolve_review_contract(
self, self,
@@ -1999,6 +2161,11 @@ class RunStorageController:
contract, contract,
smart_regenerate_only=smart_only, smart_regenerate_only=smart_only,
) )
if head is None and not smart_only and resume_safe:
self._plan_import = self._find_plan_import(
contract, stop_before=self.review_manual_regenerate_from,
)
head = self._plan_import
self.review_head = head self.review_head = head
self.inherited_review_unit = ( self.inherited_review_unit = (
None if head is None or head.get("review_unit") is None None if head is None or head.get("review_unit") is None
@@ -2064,6 +2231,70 @@ class RunStorageController:
self.review_execution = execution self.review_execution = execution
return resolved, effective_nonce, decision return resolved, effective_nonce, decision
def _reconcile_review_execution_with_reused_prefix(self, prefix_count: int) -> None:
"""Make ordinary Review continuation follow the prefix actually reused.
Run Storage candidate selection is the final authority for which saved
prefix survived integrity/contract validation. A stale or missed review
head must never make the Review controller expect Chunk 1 while the
sampler has already restored Chunk 1 and is about to generate Chunk 2.
Explicit regeneration and Take actions keep their resolved boundaries.
"""
execution = self.review_execution
if (
execution is None
or self.review_generation_mode != GENERATION_MODE_REVIEW
or self.review_action != REVIEW_ACTION_CONTINUE
or self.take_action != TAKE_ACTION_AUTOMATIC
or self.review_manual_regenerate_from
):
return
contract = self.contract or {}
chunks = int(contract.get("chunk_count", 0))
prefix = int(prefix_count)
if chunks <= 0 or prefix < 0 or prefix > chunks:
raise RunStorageError("reused review prefix is outside the configured chunk range")
status = (
None
if prefix == 0
else REVISION_STATUS_COMPLETE
if prefix == chunks
else REVISION_STATUS_REVIEW_READY
)
terminal_merge_enabled = _terminal_merge_enabled(contract)
resolved = resolve_review_execution(
generation_mode=GENERATION_MODE_REVIEW,
review_action=REVIEW_ACTION_CONTINUE,
configured_chunks=chunks,
validated_prefix_count=prefix,
terminal_merge_enabled=terminal_merge_enabled,
terminal_pair_start=(chunks - 1 if terminal_merge_enabled else None),
manual_regenerate_from=0,
run_storage_mode=RUN_STORAGE_SAVE_AUTO_RESUME,
latest_review_unit=None,
latest_revision_status=status,
latest_effective_nonce=int(self.effective_reroll_nonce),
latest_branch_regenerate_from=int(contract.get("reroll_from_chunk", 0)),
)
old_expected = (
execution.next_review_unit_start,
execution.next_review_unit_end,
execution.next_review_physical_group,
)
new_expected = (
resolved.next_review_unit_start,
resolved.next_review_unit_end,
resolved.next_review_physical_group,
)
if old_expected != new_expected or execution.projected_prefix_count != resolved.projected_prefix_count:
self.notes.append(
"Review continuation reconciled to validated saved prefix "
f"{prefix}/{chunks}: expected {old_expected} -> {new_expected}."
)
self.review_execution = resolved
def _resolve_effective_nonce( def _resolve_effective_nonce(
self, contract: dict[str, Any], *, requested_nonce: int, resume_safe: bool, self, contract: dict[str, Any], *, requested_nonce: int, resume_safe: bool,
) -> tuple[int, str]: ) -> tuple[int, str]:
@@ -2167,13 +2398,20 @@ class RunStorageController:
resume_safe=safe, resume_safe=safe,
) )
else: else:
if safe:
self._plan_import = self._find_plan_import(
contract, stop_before=int(reroll_from_chunk),
)
inherited_import = self._plan_import is not None and int(reroll_from_chunk) == 0
requested = (self._plan_import["effective_reroll_nonce"]
if inherited_import else int(reroll_nonce))
if inherited_import:
contract = self._plan_import["contract"]
effective_nonce, nonce_decision = self._resolve_effective_nonce( effective_nonce, nonce_decision = self._resolve_effective_nonce(
contract, requested_nonce=int(reroll_nonce), resume_safe=safe contract, requested_nonce=requested, resume_safe=safe,
) )
contract = _apply_nonce_contract( contract = _apply_nonce_contract(
contract, contract, requested_nonce=requested, effective_nonce=effective_nonce,
requested_nonce=int(reroll_nonce),
effective_nonce=effective_nonce,
) )
self.resume_safe = bool(safe) self.resume_safe = bool(safe)
self.effective_reroll_nonce = int(effective_nonce) self.effective_reroll_nonce = int(effective_nonce)
@@ -2185,6 +2423,14 @@ class RunStorageController:
self.disabled_reasons = reasons self.disabled_reasons = reasons
self.contract = contract self.contract = contract
sampling_revision_id, self.contract_sha256 = revision_identity(contract) sampling_revision_id, self.contract_sha256 = revision_identity(contract)
# A selected, shorter canonical Take is not interchangeable with an old
# longer revision having the same sampling inputs. Continue in its own
# storage revision when the contract is unchanged; preserve old Takes.
head_manifest = (self.review_head or {}).get("manifest")
if (not self.storage_revision_id_override and self._plan_import is None
and isinstance(head_manifest, dict)
and head_manifest.get("contract_sha256") == self.contract_sha256):
self.storage_revision_id_override = str(head_manifest["revision_id"])
self.revision_id = self.storage_revision_id_override or _storage_revision_identity( self.revision_id = self.storage_revision_id_override or _storage_revision_identity(
contract_sha256=self.contract_sha256, contract_sha256=self.contract_sha256,
take_action=TAKE_ACTION_AUTOMATIC, take_action=TAKE_ACTION_AUTOMATIC,
@@ -2207,18 +2453,26 @@ class RunStorageController:
hashes = list(contract["chunk_contract_hashes"]) hashes = list(contract["chunk_contract_hashes"])
best_entries: list[dict[str, Any]] = [] best_entries: list[dict[str, Any]] = []
best_records: list[dict[str, Any]] = [] best_records: list[dict[str, Any]] = []
if self.selected_take_revision is not None: if exact is not None:
self._plan_import = None
if self._plan_import is not None:
best_entries = list(self._plan_import["entries"])
best_records = [] # Populated with new-plan-owned copies after manifest creation.
elif self.selected_take_revision is not None:
best_entries = list(self.selected_take_revision["entries"]) best_entries = list(self.selected_take_revision["entries"])
best_records = list(self.selected_take_records) best_records = list(self.selected_take_records)
else: else:
candidates = [exact] if exact is not None and safe else [] candidates = [exact] if exact is not None and safe else []
if safe and exact is None and self.revisions_root.exists(): if safe and exact is None and self.revisions_root.exists():
for path in self.revisions_root.glob("*/manifest.json"): if isinstance(head_manifest, dict):
try: candidates.append(head_manifest)
candidates.append(_read_json(path)) else:
except Exception: candidates.extend(self._read_manifests().values())
continue candidates.sort(key=lambda m: (len(m.get("chunks") or []),
int((m.get("branch_provenance") or {}).get("canonical_sequence", 0))), reverse=True)
for candidate in candidates: for candidate in candidates:
if len(candidate.get("chunks") or []) <= len(best_entries):
continue
if int(candidate.get("run_storage_schema_version", -1)) not in RUN_STORAGE_READABLE_SCHEMA_VERSIONS: if int(candidate.get("run_storage_schema_version", -1)) not in RUN_STORAGE_READABLE_SCHEMA_VERSIONS:
continue continue
if ( if (
@@ -2242,6 +2496,7 @@ class RunStorageController:
if len(entries) > len(best_entries): if len(entries) > len(best_entries):
best_entries, best_records = entries, records best_entries, best_records = entries, records
self._reconcile_review_execution_with_reused_prefix(len(best_entries))
self.reused_count = len(best_entries) self.reused_count = len(best_entries)
now = _now() now = _now()
self.manifest = { self.manifest = {
@@ -2261,6 +2516,8 @@ class RunStorageController:
"chunks": best_records, "chunks": best_records,
"report_summary": (exact or {}).get("report_summary", ""), "report_summary": (exact or {}).get("report_summary", ""),
} }
if exact is not None and isinstance(exact.get("prefix_import"), dict):
self.manifest["prefix_import"] = dict(exact["prefix_import"])
if self.selected_take_chain: if self.selected_take_chain:
self.manifest["branch_provenance"] = { self.manifest["branch_provenance"] = {
"version": BRANCH_PROVENANCE_VERSION, "version": BRANCH_PROVENANCE_VERSION,
@@ -2281,6 +2538,9 @@ class RunStorageController:
effective_reroll_nonce=int(effective_nonce), effective_reroll_nonce=int(effective_nonce),
) )
self._write_manifest() self._write_manifest()
if self._plan_import is not None:
best_records = self._adopt_plan_prefix(self._plan_import)
self._plan_import = None
self._write_project() self._write_project()
if not best_entries: if not best_entries:
return None return None
@@ -2406,7 +2666,10 @@ class RunStorageController:
total = int((self.contract or {}).get("chunk_count", 0)) total = int((self.contract or {}).get("chunk_count", 0))
resume = self.reused_count + 1 if self.reused_count < total else "complete" resume = self.reused_count + 1 if self.reused_count < total else "complete"
policy = (" auto-resume disabled: " + "; ".join(self.disabled_reasons) + ".") if self.disabled_reasons else "" policy = (" auto-resume disabled: " + "; ".join(self.disabled_reasons) + ".") if self.disabled_reasons else ""
note = (" " + " ".join(self.notes)) if self.notes else "" shown_notes = self.notes if detailed else list(dict.fromkeys(self.notes))[:3]
note = (" " + " ".join(shown_notes)) if shown_notes else ""
if not detailed and len(self.notes) > len(shown_notes):
note += f" ({len(self.notes) - len(shown_notes)} additional diagnostics; enable Detailed Report.)"
basic = ( basic = (
f"Run Storage: {self.run_name} / revision {self.revision_id}; " f"Run Storage: {self.run_name} / revision {self.revision_id}; "
f"{self.reused_count} reused, {self.generated_count} generated, " f"{self.reused_count} reused, {self.generated_count} generated, "
@@ -2416,7 +2679,8 @@ class RunStorageController:
if not detailed or self.manifest is None: if not detailed or self.manifest is None:
return basic return basic
records = list(self.manifest.get("chunks") or []) records = list(self.manifest.get("chunks") or [])
lines = [basic, f"Run Storage path: {self.revision_root}"] lines = [basic, f"Run Storage path: {self.revision_root}",
"Run Storage I/O: " + _canonical(self.io_metrics)]
for record in records: for record in records:
lines.append( lines.append(
f"stored chunk {int(record['sequence_index']) + 1}: " f"stored chunk {int(record['sequence_index']) + 1}: "
+55 -29
View File
@@ -187,7 +187,7 @@ async function load(n,p) {project=p;await loadTakeHistory(n);n.__h3ContinuumIntu
prepareReviewQueueIntent(setup,inputs); prepareReviewQueueIntent(setup,inputs);
assert.equal(inputs.review_action,"Continue / Next"); assert.equal(inputs.review_action,"Continue / Next");
if(["complete","review_ready"].includes(oldStatus)){ if(["complete","review_ready"].includes(oldStatus)){
assert.equal(inputs.reroll_from_chunk,"Chunk 1","saved history starts a new review branch"); assert.equal(inputs.reroll_from_chunk,"Auto","mode switch preserves compatible continuation");
assert.equal(inputs.reroll_nonce,0); assert.equal(inputs.reroll_nonce,0);
assert.equal(inputs.take_group,0); assert.equal(inputs.take_group,0);
assert.equal(inputs.take_revision_id,""); assert.equal(inputs.take_revision_id,"");
@@ -195,7 +195,7 @@ async function load(n,p) {project=p;await loadTakeHistory(n);n.__h3ContinuumIntu
} }
await load(setup,old); await load(setup,old);
assert(visible(setup,"Chunks"),"Queue alone does not mean generation completed"); assert(visible(setup,"Chunks"),"Queue alone does not mean generation completed");
project=state("review_ready",{start:1,end:1,physical_group:1},"new-output"); project=state("review_ready",{start:2,end:2,physical_group:2},"new-output");
setup.onExecuted(); setup.onExecuted();
await new Promise(resolve=>setImmediate(resolve)); await new Promise(resolve=>setImmediate(resolve));
assert(buttons.every(name=>visible(setup,name)),"new queued result opens ordinary review"); assert(buttons.every(name=>visible(setup,name)),"new queued result opens ordinary review");
@@ -234,53 +234,79 @@ async function load(n,p) {project=p;await loadTakeHistory(n);n.__h3ContinuumIntu
// Frontend 1.49 contract: widget.beforeQueued runs before serializeValue; // Frontend 1.49 contract: widget.beforeQueued runs before serializeValue;
// legacy beforeQueuePrompt is not part of the real queue path. // legacy beforeQueuePrompt is not part of the real queue path.
const liveContract=makeNode();liveContract.id=312;app.graph._nodes=[liveContract]; const liveContract=makeNode();liveContract.id=312;app.graph._nodes=[liveContract];
w(liveContract,"chunks").value=4;
await load(liveContract,state("complete",{start:3,end:3,physical_group:3},"live-old-complete")); await load(liveContract,state("complete",{start:3,end:3,physical_group:3},"live-old-complete"));
w(liveContract,"Run").callback("Generate Full Video"); w(liveContract,"Run").callback("Generate Full Video");
w(liveContract,"Run").callback("Review Each Chunk"); w(liveContract,"Run").callback("Review Each Chunk");
for(const widget of liveContract.widgets)widget.beforeQueued?.({isPartialExecution:false}); for(const widget of liveContract.widgets)widget.beforeQueued?.({isPartialExecution:false});
const liveInputs=await serializedInputs(liveContract); const liveInputs=await serializedInputs(liveContract);
assert.equal(liveInputs.reroll_from_chunk,"Chunk 1"); assert.equal(liveInputs.reroll_from_chunk,"Auto","mode switch must not inject Chunk 1");
assert.equal(liveInputs.reroll_nonce,0); assert.equal(liveInputs.reroll_nonce,0);
assert.equal(liveInputs.take_group,0); assert.equal(liveInputs.take_group,0);
assert.equal(liveInputs.take_revision_id,""); assert.equal(liveInputs.take_revision_id,"");
assert.equal(liveInputs.take_action,"Automatic"); assert.equal(liveInputs.take_action,"Automatic");
assert.equal(liveInputs.review_action,"Continue / Next"); assert.equal(liveInputs.review_action,"Continue / Next");
assert.equal(w(liveContract,"reroll_from_chunk").value,"Auto","visible settings stay unchanged"); project=state("review_ready",{start:4,end:4,physical_group:4},"live-fresh-chunk-4");
project=state("review_ready",{start:1,end:1,physical_group:1},"live-fresh-chunk-1"); // Sampler V3.8 does not need to emit a node-specific `executed` UI event.
emit("executed",{node:"312",prompt_id:"live-prompt"});
emit("execution_success",{prompt_id:"live-prompt"}); emit("execution_success",{prompt_id:"live-prompt"});
await new Promise(resolve=>setTimeout(resolve,20)); await new Promise(resolve=>setTimeout(resolve,20));
assert(buttons.every(name=>visible(liveContract,name)),"real completion events open Chunk 1 review"); assert(buttons.every(name=>visible(liveContract,name)),"terminal readback opens the new review");
assert.match(w(liveContract,"Review Ready").value,/Chunk 1/); assert.match(w(liveContract,"Review Ready").value,/Chunk 4/);
// Acceptance lifecycle: 3 x 5 seconds must stop at every review boundary. // Acceptance lifecycle: extend a completed 3 x 5-second prefix to 5 x 5 seconds.
const flow=makeNode();w(flow,"chunks").value=3;w(flow,"chunk_seconds").value=5; const flow=makeNode();w(flow,"chunks").value=5;w(flow,"chunk_seconds").value=5;
await load(flow,state("complete",{start:3,end:3,physical_group:3},"old-complete-3x5")); await load(flow,state("complete",{start:3,end:3,physical_group:3},"old-complete-3x5"));
w(flow,"Run").callback("Generate Full Video"); w(flow,"Run").callback("Generate Full Video");
w(flow,"Run").callback("Review Each Chunk"); w(flow,"Run").callback("Review Each Chunk");
const chunk1Inputs={reroll_from_chunk:"Auto",reroll_nonce:0}; const chunk4Inputs={reroll_from_chunk:"Auto",reroll_nonce:0,
prepareReviewQueueIntent(flow,chunk1Inputs); take_group:9,take_revision_id:"stale",take_action:"Use This Take"};
assert.equal(chunk1Inputs.reroll_from_chunk,"Chunk 1"); prepareReviewQueueIntent(flow,chunk4Inputs);
project=state("review_ready",{start:1,end:1,physical_group:1},"fresh-chunk-1"); assert.equal(chunk4Inputs.reroll_from_chunk,"Auto","extension reuses the compatible prefix");
assert.equal(chunk4Inputs.take_group,0);
assert.equal(chunk4Inputs.take_revision_id,"");
assert.equal(chunk4Inputs.take_action,"Automatic");
project=state("review_ready",{start:4,end:4,physical_group:4},"fresh-chunk-4");
flow.onExecuted();await new Promise(resolve=>setImmediate(resolve)); flow.onExecuted();await new Promise(resolve=>setImmediate(resolve));
assert(buttons.every(name=>visible(flow,name)),"Chunk 1 opens the review screen"); assert(buttons.every(name=>visible(flow,name)),"Chunk 4 opens the review screen");
assert.match(w(flow,"Review Ready").value,/Chunk 1/); assert.match(w(flow,"Review Ready").value,/Chunk 4/);
w(flow,"Use it and continue").callback(); w(flow,"Use it and continue").callback();
const chunk2Inputs={reroll_from_chunk:"Auto",reroll_nonce:0}; const chunk5Inputs={reroll_from_chunk:"Auto",reroll_nonce:0};
prepareReviewQueueIntent(flow,chunk2Inputs); prepareReviewQueueIntent(flow,chunk5Inputs);
assert.equal(chunk2Inputs.reroll_from_chunk,"Auto","continuation does not restart Chunk 1"); assert.equal(chunk5Inputs.reroll_from_chunk,"Auto","continuation does not restart Chunk 1");
project=state("review_ready",{start:2,end:2,physical_group:2},"fresh-chunk-2"); project=state("complete",{start:5,end:5,physical_group:5},"fresh-chunk-5");
flow.onExecuted();await new Promise(resolve=>setImmediate(resolve)); flow.onExecuted();await new Promise(resolve=>setImmediate(resolve));
assert(buttons.every(name=>visible(flow,name)),"Chunk 2 opens the review screen"); assert(visible(flow,"Try this chunk again"),"Chunk 5 completion remains reviewable");
assert.match(w(flow,"Review Ready").value,/Chunk 2/);
w(flow,"Use it and continue").callback();
const chunk3Inputs={reroll_from_chunk:"Auto",reroll_nonce:0};
prepareReviewQueueIntent(flow,chunk3Inputs);
assert.equal(chunk3Inputs.reroll_from_chunk,"Auto");
project=state("complete",{start:3,end:3,physical_group:3},"fresh-chunk-3");
flow.onExecuted();await new Promise(resolve=>setImmediate(resolve));
assert(visible(flow,"Try this chunk again"),"Chunk 3 completion remains reviewable");
assert(!visible(flow,"Use it and continue")&&!visible(flow,"Use it and finish the rest")); assert(!visible(flow,"Use it and continue")&&!visible(flow,"Use it and finish the rest"));
assert.match(w(flow,"Review Ready").value,/Saved sequence is complete/); assert.match(w(flow,"Review Ready").value,/Saved sequence is complete/);
// Full mode also keeps Auto so the backend can reuse Chunks 1-3 and generate 4-5.
const fullExtend=makeNode();w(fullExtend,"chunks").value=5;
await load(fullExtend,state("complete",{start:3,end:3,physical_group:3},"full-old-3"));
w(fullExtend,"Run").callback("Generate Full Video");
const fullInputs={reroll_from_chunk:"Auto",reroll_nonce:0};prepareReviewQueueIntent(fullExtend,fullInputs);
assert.equal(fullInputs.generation_mode,"Full Run");
assert.equal(fullInputs.reroll_from_chunk,"Auto");
// Storage Off cannot submit a stale explicit regeneration boundary.
const storageOff=makeNode();
w(storageOff,"generation_mode").value="Full Run";
w(storageOff,"run_storage").value="Off";
w(storageOff,"reroll_from_chunk").value="Chunk 1";
w(storageOff,"reroll_nonce").value=7;
for(const widget of storageOff.widgets)widget.beforeQueued?.({isPartialExecution:false});
const offInputs=await serializedInputs(storageOff);
assert.equal(offInputs.reroll_from_chunk,"Auto");
assert.equal(offInputs.reroll_nonce,0);
assert.equal(w(storageOff,"reroll_from_chunk").value,"Auto","visible stale boundary is normalized");
// An explicit Advanced regeneration remains explicit while storage is enabled.
const explicit=makeNode();
w(explicit,"reroll_from_chunk").value="Chunk 1";
w(explicit,"reroll_from_chunk").callback?.("Chunk 1");
w(explicit,"Run").callback("Generate Full Video");
w(explicit,"Run").callback("Review Each Chunk");
for(const widget of explicit.widgets)widget.beforeQueued?.({isPartialExecution:false});
const explicitInputs=await serializedInputs(explicit);
assert.equal(explicitInputs.reroll_from_chunk,"Chunk 1","manual Advanced regeneration is preserved");
// Hotfix: stale saved review cannot offer/submit Retry after settings edits. // Hotfix: stale saved review cannot offer/submit Retry after settings edits.
const edited=makeNode();w(edited,"chunks").value=4; const edited=makeNode();w(edited,"chunks").value=4;
const originalProject=state("review_ready",{start:2,end:2,physical_group:2},"edit-base"); const originalProject=state("review_ready",{start:2,end:2,physical_group:2},"edit-base");
+1 -1
View File
@@ -1096,7 +1096,7 @@ def test_n2c_history_refresh_hooks_and_multiline_surface_are_present():
source = PROJECT_ID_JS.read_text(encoding="utf-8") source = PROJECT_ID_JS.read_text(encoding="utf-8")
assert '"Render History / Takes"' in source assert '"Render History / Takes"' in source
assert '{ multiline: true }' in source assert '{ multiline: true }' in source
assert "void loadTakeHistory(this);" in source assert "loadTakeHistory(this)" in source
assert "attachTakeHistoryReload(node);" in source assert "attachTakeHistoryReload(node);" in source
assert "node.__h3ContinuumTakeInitialLoad" in source assert "node.__h3ContinuumTakeInitialLoad" in source
assert 'const TAKE_TOGGLE_WIDGET = "Render History";' in source assert 'const TAKE_TOGGLE_WIDGET = "Render History";' in source
+160 -98
View File
@@ -434,18 +434,17 @@ function installReviewModeSetupQueueContract(node) {
const generationWidget = findWidget(node, GENERATION_MODE_WIDGET); const generationWidget = findWidget(node, GENERATION_MODE_WIDGET);
if (!generationWidget) return; if (!generationWidget) return;
// ComfyUI frontend 1.49 serializes API inputs through widget.serializeValue. // ComfyUI frontend 1.49 calls widget.beforeQueued before serializeValue.
// Keep the visible/saved settings intact while making the first Queue after // Mode selection is presentation/setup only: it must never inject a hidden
// Full Run -> Review Each Chunk an explicit, non-destructive Chunk 1 branch. // Chunk 1 restart. History selection is also cleared from a normal mode
const overrides = new Map([ // setup so Run Storage remains the authority for compatible prefix reuse.
const setupOverrides = new Map([
[REVIEW_ACTION_WIDGET, REVIEW_ACTION_CONTINUE], [REVIEW_ACTION_WIDGET, REVIEW_ACTION_CONTINUE],
[REGENERATE_WIDGET, "Chunk 1"],
[REROLL_NONCE_WIDGET, 0],
[TAKE_GROUP_WIDGET, 0], [TAKE_GROUP_WIDGET, 0],
[TAKE_REVISION_WIDGET, ""], [TAKE_REVISION_WIDGET, ""],
[TAKE_ACTION_WIDGET, TAKE_ACTION_AUTOMATIC], [TAKE_ACTION_WIDGET, TAKE_ACTION_AUTOMATIC],
]); ]);
for (const [name, value] of overrides) { for (const [name, value] of setupOverrides) {
const widget = findWidget(node, name); const widget = findWidget(node, name);
if (!widget || widget.__h3ContinuumModeSetupSerializeValue) continue; if (!widget || widget.__h3ContinuumModeSetupSerializeValue) continue;
const previous = widget.serializeValue; const previous = widget.serializeValue;
@@ -458,14 +457,60 @@ function installReviewModeSetupQueueContract(node) {
widget.__h3ContinuumModeSetupSerializeValue = true; widget.__h3ContinuumModeSetupSerializeValue = true;
} }
const regenerateWidget = findWidget(node, REGENERATE_WIDGET);
if (regenerateWidget && !regenerateWidget.__h3ContinuumSafeSerializeValue) {
const previous = regenerateWidget.serializeValue;
regenerateWidget.serializeValue = function(...args) {
if (findWidget(node, RUN_STORAGE_WIDGET)?.value !== "Save + Auto Resume") {
return "Auto";
}
if (
reviewModeSetupActive(node)
&& this.value === "Chunk 1"
&& !node.__h3ContinuumManualRegenerateIntent
&& !node.__h3ContinuumRestartSelected
) {
return "Auto";
}
return typeof previous === "function"
? previous.apply(this, args)
: this.value;
};
regenerateWidget.__h3ContinuumSafeSerializeValue = true;
}
const nonceWidget = findWidget(node, REROLL_NONCE_WIDGET);
if (nonceWidget && !nonceWidget.__h3ContinuumSafeSerializeValue) {
const previous = nonceWidget.serializeValue;
nonceWidget.serializeValue = function(...args) {
if (findWidget(node, RUN_STORAGE_WIDGET)?.value !== "Save + Auto Resume") {
return 0;
}
if (
reviewModeSetupActive(node)
&& regenerateWidget?.value === "Chunk 1"
&& !node.__h3ContinuumManualRegenerateIntent
&& !node.__h3ContinuumRestartSelected
) {
return 0;
}
return typeof previous === "function"
? previous.apply(this, args)
: this.value;
};
nonceWidget.__h3ContinuumSafeSerializeValue = true;
}
const previousBeforeQueued = generationWidget.beforeQueued; const previousBeforeQueued = generationWidget.beforeQueued;
generationWidget.beforeQueued = function(...args) { generationWidget.beforeQueued = function(...args) {
const result = previousBeforeQueued?.apply(this, args); const result = previousBeforeQueued?.apply(this, args);
normalizeRunStorageState(node);
if (reviewModeSetupActive(node)) { if (reviewModeSetupActive(node)) {
normalizeUnownedRestart(node);
const revision = canonicalStorageRevision(node.__h3ContinuumTakeProject);
node.__h3ContinuumModeSetupQueued = { node.__h3ContinuumModeSetupQueued = {
setup: node.__h3ContinuumModeSetup, setup: node.__h3ContinuumModeSetup,
runName: takeRunName(node), runName: takeRunName(node),
promptId: "", baselineRevision: String(revision?.revision_id || ""),
}; };
node.__h3ContinuumQueuedSettings = reviewSettingsSnapshot(node); node.__h3ContinuumQueuedSettings = reviewSettingsSnapshot(node);
node.__h3ContinuumQueuedSettingsRun = takeRunName(node); node.__h3ContinuumQueuedSettingsRun = takeRunName(node);
@@ -500,6 +545,39 @@ function setExistingWidgetValue(widget, value) {
widget.callback?.(value); widget.callback?.(value);
} }
function setRegenerateProgrammatically(node, value) {
const widget = findWidget(node, REGENERATE_WIDGET);
if (!widget || widget.value === value) {
if (value === "Auto" || value === 0 || value == null) {
delete node.__h3ContinuumManualRegenerateIntent;
}
return;
}
node.__h3ContinuumProgrammaticRegenerate = true;
try {
setExistingWidgetValue(widget, value);
} finally {
delete node.__h3ContinuumProgrammaticRegenerate;
}
if (value === "Auto" || value === 0 || value == null) {
delete node.__h3ContinuumManualRegenerateIntent;
}
}
function normalizeUnownedRestart(node) {
const widget = findWidget(node, REGENERATE_WIDGET);
if (
widget?.value === "Chunk 1"
&& !node.__h3ContinuumManualRegenerateIntent
&& !node.__h3ContinuumRestartSelected
) {
setRegenerateProgrammatically(node, "Auto");
setExistingWidgetValue(findWidget(node, REROLL_NONCE_WIDGET), 0);
return true;
}
return false;
}
function facadeProductionWidgets(node) { function facadeProductionWidgets(node) {
return node.widgets?.filter((widget) => widget[FACADE_TRANSIENT_WIDGET]) || []; return node.widgets?.filter((widget) => widget[FACADE_TRANSIENT_WIDGET]) || [];
} }
@@ -1096,12 +1174,15 @@ function configureIntuitiveV38Ux(node) {
onSet: (value, source) => { onSet: (value, source) => {
const reviewing = value === FACADE_GENERATE_REVIEW; const reviewing = value === FACADE_GENERATE_REVIEW;
if (reviewing && source.value !== GENERATION_MODE_REVIEW) { if (reviewing && source.value !== GENERATION_MODE_REVIEW) {
// Selecting a mode is setup, not selecting a saved review. // Selecting a mode is setup, not selecting a saved review and
// not a request to restart from Chunk 1.
node.__h3ContinuumModeSetup = {}; node.__h3ContinuumModeSetup = {};
delete node.__h3ContinuumModeSetupQueued; delete node.__h3ContinuumModeSetupQueued;
normalizeUnownedRestart(node);
} else if (!reviewing) { } else if (!reviewing) {
delete node.__h3ContinuumModeSetup; delete node.__h3ContinuumModeSetup;
delete node.__h3ContinuumModeSetupQueued; delete node.__h3ContinuumModeSetupQueued;
normalizeUnownedRestart(node);
} }
setExistingWidgetValue( setExistingWidgetValue(
source, source,
@@ -1134,6 +1215,8 @@ function configureIntuitiveV38Ux(node) {
const enabled = value === FACADE_SAVE_ON; const enabled = value === FACADE_SAVE_ON;
setExistingWidgetValue(source, enabled ? "Save + Auto Resume" : "Off"); setExistingWidgetValue(source, enabled ? "Save + Auto Resume" : "Off");
if (!enabled) { if (!enabled) {
setRegenerateProgrammatically(node, "Auto");
setExistingWidgetValue(findWidget(node, REROLL_NONCE_WIDGET), 0);
setExistingWidgetValue( setExistingWidgetValue(
findWidget(node, GENERATION_MODE_WIDGET), findWidget(node, GENERATION_MODE_WIDGET),
GENERATION_MODE_FULL_RUN, GENERATION_MODE_FULL_RUN,
@@ -1436,13 +1519,17 @@ function rememberReviewSettings(node, requestedSettings) {
delete node.__h3ContinuumQueuedSettingsRun; delete node.__h3ContinuumQueuedSettingsRun;
} }
function finishModeSetupAfterExecution(node, promptId = "") { function finishModeSetupAfterExecution(node) {
const queued = node.__h3ContinuumModeSetupQueued; const queued = node.__h3ContinuumModeSetupQueued;
const revision = canonicalStorageRevision(node.__h3ContinuumTakeProject);
const revisionId = String(revision?.revision_id || "");
if ( if (
!queued !queued
|| queued.setup !== node.__h3ContinuumModeSetup || queued.setup !== node.__h3ContinuumModeSetup
|| queued.runName !== takeRunName(node) || queued.runName !== takeRunName(node)
|| (promptId && queued.promptId !== promptId) || !revisionId
|| revisionId === String(queued.baselineRevision || "")
|| !["review_ready", "complete"].includes(revision?.status)
) { ) {
return false; return false;
} }
@@ -1453,26 +1540,6 @@ function finishModeSetupAfterExecution(node, promptId = "") {
return true; return true;
} }
function bindModeSetupPromptFromExecutedNode(event) {
const detail = event?.detail || event || {};
const promptId = String(detail.prompt_id || "");
const executedNodeId = String(detail.display_node || detail.node || "");
if (!promptId || !executedNodeId) return;
for (const node of app.graph?._nodes || []) {
const queued = node.__h3ContinuumModeSetupQueued;
if (
node.comfyClass !== V38_NODE_CLASS
|| String(node.id) !== executedNodeId
|| !queued
|| queued.setup !== node.__h3ContinuumModeSetup
|| queued.runName !== takeRunName(node)
) {
continue;
}
queued.promptId = promptId;
}
}
function selectProductionRestart(node) { function selectProductionRestart(node) {
clearTakeSelection(node); clearTakeSelection(node);
setExistingWidgetValue(findWidget(node, REVIEW_ACTION_WIDGET), REVIEW_ACTION_CONTINUE); setExistingWidgetValue(findWidget(node, REVIEW_ACTION_WIDGET), REVIEW_ACTION_CONTINUE);
@@ -1943,15 +2010,16 @@ async function loadTakeHistory(node) {
} }
function refreshV38TakeHistoryAfterExecution(event) { function refreshV38TakeHistoryAfterExecution(event) {
const promptId = String(event?.detail?.prompt_id || "");
for (const node of app.graph?._nodes || []) { for (const node of app.graph?._nodes || []) {
if (node.comfyClass !== V38_NODE_CLASS) continue; if (node.comfyClass !== V38_NODE_CLASS) continue;
if (event?.type === "execution_success" && promptId) {
finishModeSetupAfterExecution(node, promptId);
}
if (event?.type !== "execution_success") delete node.__h3ContinuumQueuedSettings; if (event?.type !== "execution_success") delete node.__h3ContinuumQueuedSettings;
// Terminal events only trigger authoritative Run Storage readback.
// Keep the existing 250 ms retry and release setup only after readback
// has had a chance to publish a newer review_ready/complete revision.
void loadTakeHistory(node); void loadTakeHistory(node);
setTimeout(() => finishModeSetupAfterExecution(node), 0);
setTimeout(() => void loadTakeHistory(node), 250); setTimeout(() => void loadTakeHistory(node), 250);
setTimeout(() => finishModeSetupAfterExecution(node), 500);
} }
} }
@@ -2152,8 +2220,7 @@ function configureProductionReviewUx(node) {
const previous = node.onExecuted; const previous = node.onExecuted;
node.onExecuted = function(...args) { node.onExecuted = function(...args) {
const result = previous?.apply(this, args); const result = previous?.apply(this, args);
finishModeSetupAfterExecution(this); void loadTakeHistory(this).then(() => finishModeSetupAfterExecution(this));
void loadTakeHistory(this);
return result; return result;
}; };
node.__h3ContinuumTakeExecutedRefresh = true; node.__h3ContinuumTakeExecutedRefresh = true;
@@ -2401,12 +2468,9 @@ function configureV38ViewProperty(node) {
function normalizeRunStorageState(node, apiInputs = null) { function normalizeRunStorageState(node, apiInputs = null) {
const storageWidget = findWidget(node, RUN_STORAGE_WIDGET); const storageWidget = findWidget(node, RUN_STORAGE_WIDGET);
const storageEnabled = storageWidget?.value === "Save + Auto Resume"; const storageEnabled = storageWidget?.value === "Save + Auto Resume";
if (storageEnabled) { if (storageEnabled) return true;
return true; setRegenerateProgrammatically(node, "Auto");
}
const regenerateWidget = findWidget(node, REGENERATE_WIDGET);
const nonceWidget = findWidget(node, REROLL_NONCE_WIDGET); const nonceWidget = findWidget(node, REROLL_NONCE_WIDGET);
if (regenerateWidget) regenerateWidget.value = "Auto";
if (nonceWidget) nonceWidget.value = 0; if (nonceWidget) nonceWidget.value = 0;
if (apiInputs) { if (apiInputs) {
apiInputs[REGENERATE_WIDGET] = "Auto"; apiInputs[REGENERATE_WIDGET] = "Auto";
@@ -2420,11 +2484,29 @@ function configureConditionalWidgets(node) {
const regenerateWidget = findWidget(node, REGENERATE_WIDGET); const regenerateWidget = findWidget(node, REGENERATE_WIDGET);
const nonceWidget = findWidget(node, REROLL_NONCE_WIDGET); const nonceWidget = findWidget(node, REROLL_NONCE_WIDGET);
const runNameWidget = findWidget(node, LEGACY_RUN_NAME_WIDGET); const runNameWidget = findWidget(node, LEGACY_RUN_NAME_WIDGET);
if (regenerateWidget && !regenerateWidget.__h3ContinuumManualIntentCallback) {
const previous = regenerateWidget.callback;
regenerateWidget.callback = function(value, ...args) {
const result = previous?.call(this, value, ...args);
if (!node.__h3ContinuumProgrammaticRegenerate) {
if (value === "Auto" || value === 0 || value == null) {
delete node.__h3ContinuumManualRegenerateIntent;
} else {
node.__h3ContinuumManualRegenerateIntent = true;
}
}
return result;
};
regenerateWidget.__h3ContinuumManualIntentCallback = true;
}
const refresh = () => { const refresh = () => {
const productionView = true; const productionView = true;
const storageEnabled = node.comfyClass === V38_NODE_CLASS const storageEnabled = node.comfyClass === V38_NODE_CLASS
? storageWidget?.value === "Save + Auto Resume" ? storageWidget?.value === "Save + Auto Resume"
: normalizeRunStorageState(node); : normalizeRunStorageState(node);
if (node.comfyClass === V38_NODE_CLASS && !storageEnabled) {
normalizeRunStorageState(node);
}
const explicitRegeneration = storageEnabled const explicitRegeneration = storageEnabled
&& regenerateWidget?.value !== "Auto" && regenerateWidget?.value !== "Auto"
&& Number.parseInt(String(regenerateWidget?.value).replace(/^Chunk\s+/, ""), 10) > 0; && Number.parseInt(String(regenerateWidget?.value).replace(/^Chunk\s+/, ""), 10) > 0;
@@ -2653,74 +2735,58 @@ function resetTakeActionAfterQueued(node) {
} }
function prepareReviewQueueIntent(node, apiInputs) { function prepareReviewQueueIntent(node, apiInputs) {
if (node.comfyClass !== V38_NODE_CLASS || !apiInputs) { if (node.comfyClass !== V38_NODE_CLASS || !apiInputs) return false;
return false;
}
const generationWidget = findWidget(node, GENERATION_MODE_WIDGET); const generationWidget = findWidget(node, GENERATION_MODE_WIDGET);
const actionWidget = findWidget(node, REVIEW_ACTION_WIDGET); const actionWidget = findWidget(node, REVIEW_ACTION_WIDGET);
if (!generationWidget || !actionWidget) { if (!generationWidget || !actionWidget) return false;
return false;
}
const generationMode = generationWidget.value; const generationMode = generationWidget.value;
const selectedAction = actionWidget.value;
const from = findWidget(node, REGENERATE_WIDGET)?.value;
const staleReview = node.__h3ContinuumReviewSettingsChanged?.() || false;
const modeSetup = Boolean(node.__h3ContinuumModeSetup); const modeSetup = Boolean(node.__h3ContinuumModeSetup);
const savedStatus = canonicalStorageRevision(node.__h3ContinuumTakeProject)?.status; const staleReview = node.__h3ContinuumReviewSettingsChanged?.() || false;
const savedReview = ["review_ready", "complete"].includes(savedStatus); const storageEnabled = findWidget(node, RUN_STORAGE_WIDGET)?.value === "Save + Auto Resume";
const hadFrom = Object.prototype.hasOwnProperty.call(apiInputs, REGENERATE_WIDGET);
const hadNonce = Object.prototype.hasOwnProperty.call(apiInputs, "reroll_nonce");
let from = hadFrom ? apiInputs[REGENERATE_WIDGET] : findWidget(node, REGENERATE_WIDGET)?.value ?? "Auto";
let nonce = hadNonce ? apiInputs.reroll_nonce : findWidget(node, "reroll_nonce")?.value ?? 0;
if (modeSetup && from === "Chunk 1" && !node.__h3ContinuumManualRegenerateIntent && !node.__h3ContinuumRestartSelected) {
from = "Auto"; nonce = 0;
setRegenerateProgrammatically(node, "Auto");
setExistingWidgetValue(findWidget(node, "reroll_nonce"), 0);
}
if (!storageEnabled) {
from = "Auto"; nonce = 0;
setRegenerateProgrammatically(node, "Auto");
setExistingWidgetValue(findWidget(node, "reroll_nonce"), 0);
}
if (hadFrom || modeSetup || !storageEnabled) apiInputs[REGENERATE_WIDGET] = from;
if (hadNonce || modeSetup || !storageEnabled) apiInputs.reroll_nonce = nonce;
const manualRegenerate = from && from !== "Auto" && from !== 0; const manualRegenerate = from && from !== "Auto" && from !== 0;
const selectedAction = actionWidget.value;
const submittedAction = generationMode === GENERATION_MODE_FULL_RUN || staleReview || manualRegenerate || modeSetup const submittedAction = generationMode === GENERATION_MODE_FULL_RUN || staleReview || manualRegenerate || modeSetup
? REVIEW_ACTION_CONTINUE ? REVIEW_ACTION_CONTINUE : selectedAction;
: selectedAction; apiInputs[GENERATION_MODE_WIDGET] = generationMode;
apiInputs[REVIEW_ACTION_WIDGET] = submittedAction;
if (staleReview || manualRegenerate || modeSetup) { if (staleReview || manualRegenerate || modeSetup) {
actionWidget.value = REVIEW_ACTION_CONTINUE; actionWidget.value = REVIEW_ACTION_CONTINUE;
delete node[REVIEW_UI_SELECTION]; delete node[REVIEW_UI_SELECTION];
} }
apiInputs[GENERATION_MODE_WIDGET] = generationMode; const takeDefaults = modeSetup || staleReview;
apiInputs[REVIEW_ACTION_WIDGET] = submittedAction; const takeAction = takeDefaults ? TAKE_ACTION_AUTOMATIC : findWidget(node, TAKE_ACTION_WIDGET)?.value || TAKE_ACTION_AUTOMATIC;
let takeAction = findWidget(node, TAKE_ACTION_WIDGET)?.value || TAKE_ACTION_AUTOMATIC; apiInputs[TAKE_GROUP_WIDGET] = takeDefaults ? 0 : Number(findWidget(node, TAKE_GROUP_WIDGET)?.value || 0);
apiInputs[TAKE_GROUP_WIDGET] = Number(findWidget(node, TAKE_GROUP_WIDGET)?.value || 0); apiInputs[TAKE_REVISION_WIDGET] = takeDefaults ? "" : String(findWidget(node, TAKE_REVISION_WIDGET)?.value || "");
apiInputs[TAKE_REVISION_WIDGET] = String(findWidget(node, TAKE_REVISION_WIDGET)?.value || "");
apiInputs[TAKE_ACTION_WIDGET] = takeAction; apiInputs[TAKE_ACTION_WIDGET] = takeAction;
if (generationMode === GENERATION_MODE_REVIEW && modeSetup) { if (generationMode === GENERATION_MODE_REVIEW && modeSetup) {
// Saved results are history, not the first result of a newly selected const revision = canonicalStorageRevision(node.__h3ContinuumTakeProject);
// Review Each Chunk run. Start a non-destructive branch at Chunk 1 in node.__h3ContinuumModeSetupQueued = {setup: node.__h3ContinuumModeSetup, runName: takeRunName(node), baselineRevision: String(revision?.revision_id || "")};
// the queued payload; keep the visible settings unchanged.
if (savedReview) {
apiInputs[REGENERATE_WIDGET] = "Chunk 1";
apiInputs[REROLL_NONCE_WIDGET] = 0;
apiInputs[TAKE_GROUP_WIDGET] = 0;
apiInputs[TAKE_REVISION_WIDGET] = "";
apiInputs[TAKE_ACTION_WIDGET] = TAKE_ACTION_AUTOMATIC;
takeAction = TAKE_ACTION_AUTOMATIC;
}
node.__h3ContinuumModeSetupQueued = {
setup: node.__h3ContinuumModeSetup,
runName: takeRunName(node),
};
} else { } else {
delete node.__h3ContinuumModeSetupQueued; delete node.__h3ContinuumModeSetupQueued;
} }
node.__h3ContinuumCaptureReviewSettings?.(); node.__h3ContinuumCaptureReviewSettings?.();
if (node.__h3ContinuumRestartSelected && from === "Chunk 1") { if (node.__h3ContinuumRestartSelected && from === "Chunk 1") node.__h3ContinuumRestartQueued = true;
node.__h3ContinuumRestartQueued = true; else { delete node.__h3ContinuumRestartSelected; delete node.__h3ContinuumRestartQueued; }
} else { if (generationMode === GENERATION_MODE_REVIEW && isOneShotReviewAction(submittedAction)) node[REVIEW_PENDING_ACTION] = submittedAction;
delete node.__h3ContinuumRestartSelected; else delete node[REVIEW_PENDING_ACTION];
delete node.__h3ContinuumRestartQueued; if (takeAction === TAKE_ACTION_USE || takeAction === TAKE_ACTION_CONTINUE) node[TAKE_PENDING_ACTION] = takeAction;
} else delete node[TAKE_PENDING_ACTION];
if (
generationMode === GENERATION_MODE_REVIEW
&& isOneShotReviewAction(submittedAction)
) {
node[REVIEW_PENDING_ACTION] = submittedAction;
} else {
delete node[REVIEW_PENDING_ACTION];
}
if (takeAction === TAKE_ACTION_USE || takeAction === TAKE_ACTION_CONTINUE) {
node[TAKE_PENDING_ACTION] = takeAction;
} else {
delete node[TAKE_PENDING_ACTION];
}
return true; return true;
} }
@@ -2867,10 +2933,6 @@ app.registerExtension({
name: "H3Continuum.ProjectId", name: "H3Continuum.ProjectId",
setup() { setup() {
app.api?.addEventListener?.(
"executed",
bindModeSetupPromptFromExecutedNode,
);
for (const eventName of [ for (const eventName of [
"execution_success", "execution_success",
"execution_error", "execution_error",