Skip to content

Commit 939fc1b

Browse files
author
SentienceDEV
committed
fix step_end issue for failed run
1 parent 6f30a79 commit 939fc1b

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

sentience/agent_runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def assert_done(
583583
True if task is complete (assertion passed), False otherwise
584584
"""
585585
# Convenience wrapper for assert_ with required=True
586-
ok = self.assert_(predicate, label=label, required=True)
586+
ok = self.assertTrue(predicate, label=label, required=True)
587587
if ok:
588588
self._task_done = True
589589
self._task_done_label = label

sentience/trace_event_builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ def build_step_end_event(
116116
pre_data["elements"] = pre_elements
117117

118118
# Build verify data with assertions if provided
119-
final_verify_data = verify_data.copy()
119+
# Handle None verify_data for failed steps
120+
final_verify_data = verify_data.copy() if verify_data else {}
120121
if assertions:
121122
# Ensure signals dict exists
122123
if "signals" not in final_verify_data:

tests/test_trace_event_builder.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,3 +273,50 @@ def test_build_step_end_event_empty_elements():
273273
# Should have elements field but it's empty
274274
assert "elements" in result["pre"]
275275
assert len(result["pre"]["elements"]) == 0
276+
277+
278+
def test_build_step_end_event_with_none_verify_data():
279+
"""Test step_end event building when verify_data is None (failed steps).
280+
281+
This test ensures that failed steps can emit step_end events even when
282+
verify_data is None, which happens when a step fails before verification.
283+
"""
284+
llm_data = {
285+
"response_text": "click(123)",
286+
"response_hash": "sha256:abc123",
287+
"usage": {"prompt_tokens": 100, "completion_tokens": 10, "total_tokens": 110},
288+
}
289+
290+
exec_data = {
291+
"success": False,
292+
"action": "error",
293+
"outcome": "Element not found",
294+
"duration_ms": 500,
295+
}
296+
297+
# verify_data is None for failed steps
298+
result = TraceEventBuilder.build_step_end_event(
299+
step_id="step-1",
300+
step_index=1,
301+
goal="Click the button",
302+
attempt=2,
303+
pre_url="http://example.com/page1",
304+
post_url="http://example.com/page1",
305+
snapshot_digest="sha256:digest123",
306+
llm_data=llm_data,
307+
exec_data=exec_data,
308+
verify_data=None, # None for failed steps
309+
)
310+
311+
# Verify basic structure
312+
assert result["v"] == 1
313+
assert result["step_id"] == "step-1"
314+
assert result["step_index"] == 1
315+
assert result["attempt"] == 2
316+
317+
# Verify exec shows failure
318+
assert result["exec"]["success"] is False
319+
assert result["exec"]["action"] == "error"
320+
321+
# Verify should be empty dict when verify_data is None
322+
assert result["verify"] == {}

0 commit comments

Comments
 (0)