mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 01:39:51 +08:00
* fix(math_animator): make the code-repair deadline configurable The render-fix loop's overall repair timeout was fixed at 180s: run_render built CodeRetryManager without passing repair_timeout_seconds, so the knob existed on the manager but was unreachable from settings. A long reasoning model repairing a book animation was cancelled mid-edit at that ceiling with no way to raise it (#2767). Lift the deadline into a runtime setting capabilities.math_animator.repair_timeout in main.yaml, read once in run_render through a get_math_animator_params getter that shares the UI's coerce/clamp path. The single read site covers all three callers (math_animator capability, visualize Manim route, book AnimationGenerator), and an in-flight render keeps the value it started with. The apply branch only persists when the key is present, so saving unrelated animation settings does not shadow the loop's default (#1316 shape). Clarify both repair-timeout errors to name the stage, the effective seconds, and that this is a local deadline rather than a provider connection failure. Backend only; the Settings-form field is left to a follow-up and failure-stage diagnostics/artifact retention to #2768. * fix(config): keep repair timeout default out of settings saves The Settings page PUTs the full GET DTO, so exposing the runtime default caused unrelated saves to persist repair_timeout=180. Omit it until explicitly configured, cover the full round trip, and soften the timeout diagnostic. --------- Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>
132 lines
4.6 KiB
Python
132 lines
4.6 KiB
Python
"""The animation code-repair deadline must be reachable from runtime settings.
|
|
|
|
``MathAnimatorPipeline.run_render`` built ``CodeRetryManager`` without passing a
|
|
configured ``repair_timeout_seconds``, so the loop always fell back to the
|
|
hardcoded 180s overall deadline. A long reasoning model repairing a book
|
|
animation was cancelled mid-edit with no setting anywhere that moved it (#2767).
|
|
|
|
These tests pin the seam that fixes it: the knob lives in main.yaml under
|
|
``capabilities.math_animator.repair_timeout``, round-trips through the settings
|
|
page, and is read back through the same coerce path the pipeline uses.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from deeptutor.services.config import capabilities_settings as module
|
|
from deeptutor.services.config.capabilities_settings import get_math_animator_params
|
|
from deeptutor.utils.config_manager import ConfigManager
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _reset_config_manager_singleton():
|
|
ConfigManager.reset_for_tests()
|
|
yield
|
|
ConfigManager.reset_for_tests()
|
|
|
|
|
|
def _settings_root(
|
|
tmp_path: Path, agents_content: dict[str, Any], main_content: dict[str, Any] | None = None
|
|
) -> Path:
|
|
settings_dir = tmp_path / "data" / "user" / "settings"
|
|
settings_dir.mkdir(parents=True, exist_ok=True)
|
|
(settings_dir / "agents.yaml").write_text(yaml.dump(agents_content), encoding="utf-8")
|
|
if main_content is not None:
|
|
(settings_dir / "main.yaml").write_text(yaml.dump(main_content), encoding="utf-8")
|
|
# Seed the singleton so ``ConfigManager()`` inside the module reads tmp, not
|
|
# the real repo root. Must happen before any code constructs ConfigManager().
|
|
ConfigManager(project_root=tmp_path)
|
|
return tmp_path
|
|
|
|
|
|
def test_repair_timeout_default_matches_the_previously_hardcoded_deadline(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""An install that never touched this keeps exactly the old 180s behaviour."""
|
|
monkeypatch.setattr(module, "PROJECT_ROOT", _settings_root(tmp_path, {"capabilities": {}}))
|
|
|
|
assert get_math_animator_params() == {"repair_timeout": 180}
|
|
assert "repair_timeout" not in module.capabilities_settings_dict()["math_animator"]
|
|
|
|
|
|
def test_repair_timeout_is_overridable_from_main_yaml(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
module,
|
|
"PROJECT_ROOT",
|
|
_settings_root(
|
|
tmp_path,
|
|
{"capabilities": {}},
|
|
{"capabilities": {"math_animator": {"repair_timeout": 600}}},
|
|
),
|
|
)
|
|
|
|
assert get_math_animator_params() == {"repair_timeout": 600}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("raw", "expected"),
|
|
[(0, 1), (-5, 1), (999_999, 3600), ("junk", 180), (None, 180)],
|
|
)
|
|
def test_repair_timeout_is_clamped_to_a_sane_range(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, raw: Any, expected: int
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
module,
|
|
"PROJECT_ROOT",
|
|
_settings_root(
|
|
tmp_path,
|
|
{"capabilities": {}},
|
|
{"capabilities": {"math_animator": {"repair_timeout": raw}}},
|
|
),
|
|
)
|
|
|
|
assert get_math_animator_params()["repair_timeout"] == expected
|
|
|
|
|
|
def test_configured_repair_timeout_round_trips_through_the_settings_page(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
monkeypatch.setattr(
|
|
module,
|
|
"PROJECT_ROOT",
|
|
_settings_root(
|
|
tmp_path,
|
|
{"capabilities": {}},
|
|
{"capabilities": {"math_animator": {"repair_timeout": 320}}},
|
|
),
|
|
)
|
|
|
|
payload = module.capabilities_settings_dict()
|
|
assert payload["math_animator"]["repair_timeout"] == 320
|
|
assert payload["math_animator"]["temperature"] == 0.2
|
|
assert payload["math_animator"]["max_tokens"] == 16834
|
|
|
|
payload["visualize"]["max_tokens"] = 32000
|
|
module.save_capabilities_settings(payload)
|
|
|
|
assert get_math_animator_params()["repair_timeout"] == 320
|
|
main_cfg = ConfigManager().load_config()
|
|
assert main_cfg["capabilities"]["math_animator"]["repair_timeout"] == 320
|
|
|
|
|
|
def test_saving_another_capability_does_not_shadow_the_repair_deadline(
|
|
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
|
) -> None:
|
|
"""The real Settings page GETs the full DTO and PUTs it back verbatim."""
|
|
monkeypatch.setattr(module, "PROJECT_ROOT", _settings_root(tmp_path, {"capabilities": {}}))
|
|
|
|
payload = module.capabilities_settings_dict()
|
|
payload["visualize"]["max_tokens"] = 32000
|
|
module.save_capabilities_settings(payload)
|
|
|
|
main_cfg = ConfigManager().load_config()
|
|
assert "math_animator" not in main_cfg.get("capabilities", {})
|
|
assert get_math_animator_params()["repair_timeout"] == 180
|