@@ -143,6 +143,25 @@ def _compute_hash(self, text: str) -> str:
143143 """Compute SHA256 hash of text."""
144144 return hashlib .sha256 (text .encode ("utf-8" )).hexdigest ()
145145
146+ def _best_effort_post_snapshot_digest (self , goal : str ) -> str | None :
147+ """
148+ Best-effort post-action snapshot digest for tracing.
149+ """
150+ try :
151+ snap_opts = SnapshotOptions (
152+ limit = min (10 , self .default_snapshot_limit ),
153+ goal = f"{ goal } (post)" ,
154+ )
155+ snap_opts .screenshot = False
156+ snap_opts .show_overlay = self .config .show_overlay if self .config else None
157+ post_snap = snapshot (self .browser , snap_opts )
158+ if post_snap .status != "success" :
159+ return None
160+ digest_input = f"{ post_snap .url } { post_snap .timestamp } "
161+ return f"sha256:{ self ._compute_hash (digest_input )} "
162+ except Exception :
163+ return None
164+
146165 def _get_element_bbox (self , element_id : int | None , snap : Snapshot ) -> dict [str , float ] | None :
147166 """Get bounding box for an element from snapshot."""
148167 if element_id is None :
@@ -513,6 +532,10 @@ def act( # noqa: C901
513532 snapshot_event_data = TraceEventBuilder .build_snapshot_event (snap_with_diff )
514533 pre_elements = snapshot_event_data .get ("elements" , [])
515534
535+ post_snapshot_digest = (
536+ self ._best_effort_post_snapshot_digest (goal ) if self .tracer else None
537+ )
538+
516539 # Build complete step_end event
517540 step_end_data = TraceEventBuilder .build_step_end_event (
518541 step_id = step_id ,
@@ -522,6 +545,7 @@ def act( # noqa: C901
522545 pre_url = pre_url ,
523546 post_url = post_url ,
524547 snapshot_digest = snapshot_digest ,
548+ post_snapshot_digest = post_snapshot_digest ,
525549 llm_data = llm_data ,
526550 exec_data = exec_data ,
527551 verify_data = verify_data ,
@@ -601,6 +625,7 @@ def act( # noqa: C901
601625 pre_url = _step_pre_url ,
602626 post_url = post_url ,
603627 snapshot_digest = snapshot_digest ,
628+ post_snapshot_digest = None ,
604629 llm_data = llm_data ,
605630 exec_data = exec_data ,
606631 verify_data = None ,
@@ -1155,6 +1180,10 @@ async def act( # noqa: C901
11551180 snapshot_event_data = TraceEventBuilder .build_snapshot_event (snap_with_diff )
11561181 pre_elements = snapshot_event_data .get ("elements" , [])
11571182
1183+ post_snapshot_digest = (
1184+ self ._best_effort_post_snapshot_digest (goal ) if self .tracer else None
1185+ )
1186+
11581187 # Build complete step_end event
11591188 step_end_data = TraceEventBuilder .build_step_end_event (
11601189 step_id = step_id ,
@@ -1164,6 +1193,7 @@ async def act( # noqa: C901
11641193 pre_url = pre_url ,
11651194 post_url = post_url ,
11661195 snapshot_digest = snapshot_digest ,
1196+ post_snapshot_digest = post_snapshot_digest ,
11671197 llm_data = llm_data ,
11681198 exec_data = exec_data ,
11691199 verify_data = verify_data ,
@@ -1243,6 +1273,7 @@ async def act( # noqa: C901
12431273 pre_url = _step_pre_url ,
12441274 post_url = post_url ,
12451275 snapshot_digest = snapshot_digest ,
1276+ post_snapshot_digest = None ,
12461277 llm_data = llm_data ,
12471278 exec_data = exec_data ,
12481279 verify_data = None ,
0 commit comments