Skip to content

Automate browser based workflows with AI

log: compact Action / ActionResult kwargs in structlog pipeline (#5739)

Shuchang Zhengb9237c5a5b40
diff --git a/skyvern/forge/__main__.py b/skyvern/forge/__main__.py
index 1066c278b..e6a9c4018 100644
--- a/skyvern/forge/__main__.py
+++ b/skyvern/forge/__main__.py
@@ -37,6 +37,7 @@ if __name__ == "__main__":
host="0.0.0.0",
port=port,
log_level="info",
+ access_log=False,
reload=reload,
reload_excludes=[
f"{temp_path_for_excludes}/**/*.py",
diff --git a/skyvern/forge/sdk/forge_log.py b/skyvern/forge/sdk/forge_log.py
index 93cc044a8..6cbadefff 100644
--- a/skyvern/forge/sdk/forge_log.py
+++ b/skyvern/forge/sdk/forge_log.py
@@ -119,6 +119,38 @@ def add_kv_pairs_to_msg(logger: logging.Logger, method_name: str, event_dict: Ev
return event_dict
+def compact_action_objects(logger: logging.Logger, method_name: str, event_dict: EventDict) -> EventDict:
+ """Compact verbose Action / ActionResult kwargs to a few key fields.
+
+ LOG.info(..., action=action, ...) was emitting ~3 KB per line because the
+ Action dataclass dumps 25+ attributes including LLM-generated reasoning /
+ intention / response strings. Full action data is persisted to the DB and
+ queryable there; logs only need enough to correlate.
+ """
+ action = event_dict.get("action")
+ if action is not None and not isinstance(action, (str, int, float, bool, dict, list, type(None))):
+ try:
+ event_dict["action"] = {
+ "id": getattr(action, "action_id", None),
+ "type": str(getattr(action, "action_type", type(action).__name__)),
+ "element_id": getattr(action, "element_id", None),
+ }
+ except Exception:
+ pass
+
+ action_result = event_dict.get("action_result")
+ if isinstance(action_result, list) and action_result:
+ try:
+ event_dict["action_result"] = {
+ "count": len(action_result),
+ "success": all(getattr(r, "success", False) for r in action_result),
+ }
+ except Exception:
+ pass
+
+ return event_dict
+
+
def skyvern_logs_processor(logger: logging.Logger, method_name: str, event_dict: EventDict) -> EventDict:
"""
A custom processor to add skyvern logs to the context
@@ -324,6 +356,7 @@ def setup_logger() -> None:
renderer = structlog.processors.JSONRenderer() if settings.JSON_LOGGING else CustomConsoleRenderer()
additional_processors = (
[
+ compact_action_objects,
structlog.processors.EventRenamer("msg"),
add_kv_pairs_to_msg,
structlog.processors.CallsiteParameterAdder(
@@ -338,6 +371,7 @@ def setup_logger() -> None:
]
if settings.JSON_LOGGING
else [
+ compact_action_objects,
structlog.processors.CallsiteParameterAdder(
{
structlog.processors.CallsiteParameter.FILENAME,
diff --git a/skyvern/webeye/actions/handler.py b/skyvern/webeye/actions/handler.py
index 285e258ff..9693f31dd 100644
--- a/skyvern/webeye/actions/handler.py
+++ b/skyvern/webeye/actions/handler.py
@@ -632,30 +632,10 @@ class ActionHandler:
action_type=action.action_type,
action_id=action.action_id,
status=action.status,
- source_action_id=action.source_action_id,
step_order=action.step_order,
action_order=action.action_order,
- confidence_float=action.confidence_float,
- description=action.description,
- reasoning=action.reasoning,
- intention=action.intention,
- response=action.response,
element_id=action.element_id,
errors=action.errors,
- file_name=action.file_name,
- file_url=action.file_url,
- download=action.download,
- download_triggered=action.download_triggered,
- is_upload_file_tag=action.is_upload_file_tag,
- text=action.text,
- input_or_select_context=action.input_or_select_context,
- option=action.option,
- is_checked=action.is_checked,
- verified=action.verified,
- click_context=action.click_context,
- totp_timing_info=action.totp_timing_info,
- has_mini_agent=action.has_mini_agent,
- skip_auto_complete_tab=action.skip_auto_complete_tab,
)
actions_result: list[ActionResult] = []
llm_caller = LLMCallerManager.get_llm_caller(task.task_id)
diff --git a/tests/unit/test_forge_log_compaction.py b/tests/unit/test_forge_log_compaction.py
new file mode 100644
index 000000000..abfd5a8de
--- /dev/null
+++ b/tests/unit/test_forge_log_compaction.py
@@ -0,0 +1,55 @@
+from skyvern.forge.sdk.forge_log import compact_action_objects
+
+
+class _FakeAction:
+ def __init__(self, action_id: str = "act_1", action_type: str = "click", element_id: str = "AAA") -> None:
+ self.action_id = action_id
+ self.action_type = action_type
+ self.element_id = element_id
+ self.reasoning = "x" * 5000
+ self.intention = "y" * 5000
+ self.response = "z" * 5000
+
+
+class _FakeResult:
+ def __init__(self, success: bool) -> None:
+ self.success = success
+
+
+def test_compact_action_replaces_object_with_three_keys() -> None:
+ event = {"event": "Handling action", "action": _FakeAction()}
+ result = compact_action_objects(None, "info", event) # type: ignore[arg-type]
+ assert result["action"] == {"id": "act_1", "type": "click", "element_id": "AAA"}
+
+
+def test_compact_action_leaves_primitive_untouched() -> None:
+ event = {"event": "msg", "action": "literal-string"}
+ result = compact_action_objects(None, "info", event) # type: ignore[arg-type]
+ assert result["action"] == "literal-string"
+
+
+def test_compact_action_handles_missing_attrs_defensively() -> None:
+ class _Bare:
+ pass
+
+ event = {"event": "msg", "action": _Bare()}
+ result = compact_action_objects(None, "info", event) # type: ignore[arg-type]
+ assert result["action"] == {"id": None, "type": "_Bare", "element_id": None}
+
+
+def test_compact_action_result_summarizes_list() -> None:
+ event = {"event": "Action succeeded", "action_result": [_FakeResult(True), _FakeResult(True)]}
+ result = compact_action_objects(None, "info", event) # type: ignore[arg-type]
+ assert result["action_result"] == {"count": 2, "success": True}
+
+
+def test_compact_action_result_flags_partial_failure() -> None:
+ event = {"event": "Action failed", "action_result": [_FakeResult(True), _FakeResult(False)]}
+ result = compact_action_objects(None, "info", event) # type: ignore[arg-type]
+ assert result["action_result"] == {"count": 2, "success": False}
+
+
+def test_compact_action_passthrough_when_keys_absent() -> None:
+ event = {"event": "msg", "step_order": 0}
+ result = compact_action_objects(None, "info", event) # type: ignore[arg-type]
+ assert result == event