fix: improve AI corrective prompt clarity and add global next_node_id validation

- Rewrote CORRECTIVE_PROMPT_TEMPLATE to clearly distinguish option→child
  vs action→sibling next_node_id semantics with concrete examples
- Added global check in ai_tree_validator that action next_node_ids
  actually reference existing nodes in the tree (was silently unchecked)
- Added max_tokens truncation warning to branch_detail logger
- Added test for action next_node_id referencing nonexistent node

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-23 23:45:39 -05:00
parent 6a76e61792
commit fe43f5cb46
3 changed files with 33 additions and 2 deletions

View File

@@ -124,6 +124,13 @@ class TestReferenceIntegrity:
errors = validate_generated_tree(tree)
assert any("non-existent child" in e for e in errors)
def test_action_next_node_id_references_nonexistent_node(self):
"""Action next_node_id pointing to a node that doesn't exist anywhere in the tree."""
tree = _make_valid_tree()
tree["children"][1]["next_node_id"] = "ghost-node"
errors = validate_generated_tree(tree)
assert any("ghost-node" in e for e in errors)
def test_duplicate_option_ids(self):
tree = _make_valid_tree()
tree["options"][0]["id"] = "same"