fix: gate _last_seed mutation to dynamic modes

- random_seed_generator.py: only update the shared _last_seed counter for
  random/increment/decrement modes. fixed mode must be side-effect-free so
  interleaved fixed reads do not clobber the counter used by other
  AdvancedSeedGenerator nodes in the same workflow.
- tests: add regression coverage for the new gating (fixed leaves _last_seed
  alone; random and increment write through). Rewrite reset_state test to
  set state directly instead of relying on the removed fixed side effect.
- pyproject.toml: rewrite description to drop the stale
  "cross-library synchronization" claim (feature removed in 2.3.0).
- README: replace the unrealistic "ComfyUI Python console" reset advice
  with three actionable options (restart, random-then-increment, and
  reset_state for scripts).
This commit is contained in:
limbicnation
2026-05-10 19:47:38 +02:00
parent 89f84f0b68
commit 20d5149d02
4 changed files with 32 additions and 8 deletions
+4 -2
View File
@@ -100,8 +100,10 @@ The `_last_seed` counter is **class-level** — shared across every instance of
- Check the ComfyUI console for import errors.
**Increment/decrement counter is "wrong"**
- The counter is shared across all instances of this node in the workflow. See *State scope* above.
- To reset to `0`, call `AdvancedSeedGenerator.reset_state()` from the ComfyUI Python console.
- The counter is shared across every instance of this node in the workflow. See *State scope* above.
- The simplest reset is to restart ComfyUI — `_last_seed` lives in process memory only.
- If you need a known starting point without restarting, switch to `random` mode for one execution; the next `increment` will start from that random value plus one.
- For scripts/tests, `AdvancedSeedGenerator.reset_state()` zeroes the counter directly.
## 🤝 Contributing
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "randomseedgenerator"
description = "Advanced seed generator for ComfyUI with multiple modes, state persistence, and cross-library synchronization"
description = "Minimal ComfyUI seed generator with fixed, random, increment, and decrement modes. Zero dependencies."
version = "2.3.0"
license = {file = "LICENSE"}
dependencies = []
+4 -1
View File
@@ -76,7 +76,10 @@ class AdvancedSeedGenerator:
else:
raise ValueError(f"Unknown mode: {mode!r}")
self.__class__._last_seed = result
# Only dynamic modes update the shared counter; fixed must be side-effect-free
# so users can interleave fixed reads without disturbing increment/decrement state.
if mode in ("random", "increment", "decrement"):
self.__class__._last_seed = result
logger.debug("Generated seed %d (mode=%s)", result, mode)
return (result,)
+23 -4
View File
@@ -39,9 +39,28 @@ def test_fixed_returns_input_seed(gen):
assert gen.generate_seed("fixed", 42) == (42,)
def test_fixed_updates_last_seed(gen):
gen.generate_seed("fixed", 12345)
assert AdvancedSeedGenerator._last_seed == 12345
def test_fixed_does_not_mutate_last_seed(gen):
"""Regression: fixed mode must not touch the shared increment/decrement counter.
Before this guard, calling `fixed` clobbered `_last_seed`, which silently
altered other AdvancedSeedGenerator nodes running increment/decrement in the
same workflow.
"""
AdvancedSeedGenerator._last_seed = 500
assert gen.generate_seed("fixed", 12345) == (12345,)
assert AdvancedSeedGenerator._last_seed == 500
def test_random_updates_last_seed(gen):
AdvancedSeedGenerator._last_seed = 0
(result,) = gen.generate_seed("random", 0)
assert AdvancedSeedGenerator._last_seed == result
def test_increment_updates_last_seed(gen):
AdvancedSeedGenerator._last_seed = 100
gen.generate_seed("increment", 0)
assert AdvancedSeedGenerator._last_seed == 101
def test_random_within_bounds(gen):
@@ -98,7 +117,7 @@ def test_is_changed_fixed_returns_stable_key():
def test_reset_state_clears_last_seed(gen):
gen.generate_seed("fixed", 7777)
AdvancedSeedGenerator._last_seed = 7777
assert AdvancedSeedGenerator._last_seed == 7777
AdvancedSeedGenerator.reset_state()
assert AdvancedSeedGenerator._last_seed == 0