You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(api-tox): v2.2.0 Phase 1.1 — auto-rollback on error regression (#34)
* feat(api-tox): v2.2.0 Phase 1.1 — auto-rollback on error regression
First feature of the v2.2.0→v3.0 reliability phase (see
docs/ROADMAP.md). Wraps each LLM tool batch with a baseline-and-diff
check against td_get_errors plus a TD ui.undo.startBlock so the
whole batch is one undo entry. If the batch introduces new critical
errors (compile-style: Python syntax, expression-parse, GLSL
compile, Script DAT load), ui.undo.undo() rolls it back atomically
and a hint is appended to the last tool_result so the LLM sees the
regression on its next API call.
Pure-read batches skip the wrap (saves two td_get_errors calls);
batches containing td_exec_python / td_emergency_stabilize /
td_patch_apply stand down because their side effects aren't
undo-reversible (half-rolling-back is worse than not rolling back).
Disable via env var TDPILOT_DISABLE_AUTO_ROLLBACK=1. No version
bump — Phase 1 ships as v2.2.0 when the whole phase is in.
Implementation:
- NEW td_component/tdpilot_api_rollback.py — pure-Python predicate
(is_critical_error), diff (diff_errors), batch classifier
(batch_should_be_guarded), and the AutoRollbackGuard context
manager. Two cook-thread handlers (handle_auto_rollback_begin /
handle_auto_rollback_end) registered in TOOL_TO_HANDLER but NOT
in TOOL_SCHEMAS — the LLM never sees them as callable tools.
- tdpilot_api_agent.py — new rollback_guard_factory ctor kwarg;
_loop wraps the per-batch for-loop with the guard. Hint goes into
the last tool_result's content (preserves the alternating
user/assistant constraint) and also surfaces via on_text for the
chat UI.
- tdpilot_api_runtime.py — _build_rollback_guard_factory reads
TDPILOT_DISABLE_AUTO_ROLLBACK and returns None when disabled, in
which case Agent._loop is a literal no-op around the guard.
- tdpilot_api_schema_map.py — INTERNAL_ONLY_TOOL_NAMES frozenset
registered next to TOOL_TO_HANDLER; the schema-vs-handler parity
pin tests in test_tdpilot_api_batch.py + test_tdpilot_api_tracing.py
subtract this set so the parity invariant stays meaningful.
- tdpilot_api_extension.py — registers tdpilot_api_rollback as a
handler module so the dispatcher finds the two internal handlers.
- build_tdpilot_api_tox.py — adds tdpilot_api_rollback to
_SOURCE_FILES (auto-rolls into _API_TOX_SOURCE_FILES via the
derivation in lines 1-50ish).
Tests:
- 60 new tests in tests/test_tdpilot_api_rollback.py covering the
predicate (20+ pattern cases), diff, batch classifier, env-var
gate, the guard's state machine (with a recorded mock dispatcher
covering clean / regression / baseline-failure / undo-block-failure
/ exception-mid-batch / exec_python-standdown paths), the hint
formatter, and the internal handlers' outside-TD failure mode.
- Two pre-existing parity-pin tests updated to honour the
INTERNAL_ONLY_TOOL_NAMES exclusion.
Local sweep:
- pytest: 1760 passed (1700 prior + 60 new).
- ruff format / check: clean.
- check_versions: in sync at v2.1.5 (no bump on this PR).
- check_tox_freshness (MCP server tox): fresh — that tox not touched.
- check_tox_api_freshness (chat-pipe tox): EXPECTED FAIL until the
user rebuilds the .tox inside TouchDesigner. See the rebuild
recipe in AGENTS.md / feedback_td_tox_rebuild_recipe.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore: rebuild tdpilot_API.tox for v2.2.0 Phase 1.1 (auto-rollback)
* ci(api-tox): sync SOURCE_FILES list to include tdpilot_api_rollback.py
Paired-list maintenance: build_tdpilot_api_tox.py:_API_TOX_SOURCE_FILES
and scripts/check_tox_api_freshness.py:SOURCE_FILES must contain the
same paths — the build script writes the hash, the check script
verifies it. Adding tdpilot_api_rollback.py to one but not the other
produced a stable mismatch (built hash a9a4..., check-computed
hash da67...) even on a freshly-rebuilt .tox.
This is a known footgun (the comment on line 28-32 of the check
script flags it explicitly); future Phase 1+ features adding new
source files will hit the same trap until both lists are
consolidated behind a single source of truth.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments