Skip to content

Automate browser based workflows with AI

perf(record): single exfiltration transport + None-tolerant dedup (#7004)

Cindy Licfb3922705dd
diff --git a/skyvern/forge/sdk/routes/streaming/channels/exfiltration.py b/skyvern/forge/sdk/routes/streaming/channels/exfiltration.py
index 3f3e339f3..76737a4cf 100644
--- a/skyvern/forge/sdk/routes/streaming/channels/exfiltration.py
+++ b/skyvern/forge/sdk/routes/streaming/channels/exfiltration.py
@@ -188,12 +188,26 @@ class ExfiltrationChannel(CdpChannel):
_CONSOLE_FINGERPRINT_VOLATILE_KEYS: t.ClassVar[frozenset[str]] = frozenset({"timestamp"})
def _console_fingerprint(self, event_data: dict[str, t.Any]) -> str:
- stable = {k: v for k, v in event_data.items() if k not in self._CONSOLE_FINGERPRINT_VOLATILE_KEYS}
+ # Drop None values (recursively) as well as volatile keys: the binding,
+ # Playwright-console, and raw-CDP transports materialize the same event
+ # with None-vs-absent differences (JSON.stringify drops undefined keys;
+ # the binding serializes them to null), which otherwise defeats dedup.
+ stable = self._strip_none(
+ {k: v for k, v in event_data.items() if k not in self._CONSOLE_FINGERPRINT_VOLATILE_KEYS}
+ )
try:
return json.dumps(stable, sort_keys=True, separators=(",", ":"))
except TypeError:
return json.dumps(stable, sort_keys=True, separators=(",", ":"), default=str)
+ @classmethod
+ def _strip_none(cls, value: t.Any) -> t.Any:
+ if isinstance(value, dict):
+ return {k: cls._strip_none(v) for k, v in value.items() if v is not None}
+ if isinstance(value, list):
+ return [cls._strip_none(item) for item in value]
+ return value
+
def _should_emit_console_event(self, event_data: dict[str, t.Any]) -> bool:
fingerprint = self._console_fingerprint(event_data)
diff --git a/skyvern/forge/sdk/routes/streaming/channels/js/exfiltrate.js b/skyvern/forge/sdk/routes/streaming/channels/js/exfiltrate.js
index 5e5fe5496..f63957c21 100644
--- a/skyvern/forge/sdk/routes/streaming/channels/js/exfiltrate.js
+++ b/skyvern/forge/sdk/routes/streaming/channels/js/exfiltrate.js
@@ -221,13 +221,18 @@
const binding =
typeof bindingName === "string" ? window[bindingName] : null;
+ // Single transport: prefer the CDP binding; console.log is only the
+ // fallback when the binding is absent. Sending through both delivered
+ // every event 2-3x (the console paths also cost json_value CDP
+ // round-trips per event, queueing seconds of latency under load).
if (typeof binding === "function") {
Promise.resolve(binding(eventData)).catch((err) => {
console.log("[SYS] exfiltration: binding transport failed.", err);
+ console.log("[EXFIL]", JSON.stringify(eventData));
});
+ } else {
+ console.log("[EXFIL]", JSON.stringify(eventData));
}
-
- console.log("[EXFIL]", JSON.stringify(eventData));
},
true,
);
diff --git a/tests/unit/forge/sdk/routes/streaming/test_exfiltration_channel.py b/tests/unit/forge/sdk/routes/streaming/test_exfiltration_channel.py
index 1a8891a32..daf6c40f2 100644
--- a/tests/unit/forge/sdk/routes/streaming/test_exfiltration_channel.py
+++ b/tests/unit/forge/sdk/routes/streaming/test_exfiltration_channel.py
@@ -334,6 +334,39 @@ class TestExfiltrationChannelEvents:
on_event.assert_called_once()
+ def test_fingerprint_treats_none_and_absent_keys_as_equal(self) -> None:
+ # The binding transport serializes JS undefined to None while the console
+ # transports drop those keys entirely (JSON.stringify). Both shapes must
+ # dedup as one event or every interaction is delivered 2-3x.
+ channel, _ = _make_channel()
+ via_binding = {
+ **_make_event_data(),
+ "inputValue": None,
+ "mousePosition": {"xa": 10, "ya": 20, "xp": None, "yp": None},
+ }
+ via_console = {
+ **_make_event_data(),
+ "mousePosition": {"xa": 10, "ya": 20},
+ }
+
+ assert channel._console_fingerprint(via_binding) == channel._console_fingerprint(via_console)
+
+ def test_should_emit_console_event_dedupes_none_vs_absent_duplicates(self) -> None:
+ channel, _ = _make_channel()
+ via_binding = {**_make_event_data(), "inputValue": None}
+ via_console = _make_event_data()
+
+ assert channel._should_emit_console_event(via_binding) is True
+ assert channel._should_emit_console_event(via_console) is False
+
+ def test_should_emit_console_event_keeps_distinct_values_over_none(self) -> None:
+ channel, _ = _make_channel()
+ first = {**_make_event_data(), "inputValue": None}
+ distinct = {**_make_event_data(), "inputValue": "hello"}
+
+ assert channel._should_emit_console_event(first) is True
+ assert channel._should_emit_console_event(distinct) is True
+
class TestNavigationReExfiltration:
@pytest.mark.asyncio