You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(sdk): add skipAccumulation option to ExecutionHandlers to prevent OOM
When streaming handlers are provided for long-running executions, the SDK
unconditionally accumulates every stdout/stderr message in memory, causing
OOM for executions with large output volumes.
Add `skipAccumulation` (default false) to ExecutionHandlers across all SDK
languages. When enabled, messages are delivered to handler callbacks without
being appended to ExecutionLogs, allowing constant-memory streaming.
Closesopensandbox-group#981
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/domain/models/execd/executions/ExecutionModels.kt
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -216,6 +216,12 @@ class ExecutionHandlers private constructor(
216
216
* Called when code execution starts.
217
217
*/
218
218
valonInit:OutputHandler<ExecutionInit>? = null,
219
+
/**
220
+
* When true, stdout/stderr messages are only delivered to handlers without
221
+
* being accumulated in [ExecutionLogs]. Use this for long-running executions
222
+
* to prevent unbounded memory growth.
223
+
*/
224
+
valskipAccumulation:Boolean = false,
219
225
) {
220
226
companionobject {
221
227
@JvmStatic
@@ -229,6 +235,7 @@ class ExecutionHandlers private constructor(
Copy file name to clipboardExpand all lines: sdks/sandbox/kotlin/sandbox/src/main/kotlin/com/alibaba/opensandbox/sandbox/infrastructure/adapters/converter/ExecutionEventDispatcher.kt
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,9 @@ class ExecutionEventDispatcher(
62
62
) {
63
63
val stdoutText = eventNode.text ?:""
64
64
val stdoutMessage =OutputMessage(stdoutText, timestamp, false)
65
-
execution.logs.addStdout(stdoutMessage)
65
+
if (handlers?.skipAccumulation !=true) {
66
+
execution.logs.addStdout(stdoutMessage)
67
+
}
66
68
handlers?.onStdout?.handle(stdoutMessage)
67
69
}
68
70
@@ -72,7 +74,9 @@ class ExecutionEventDispatcher(
72
74
) {
73
75
val stderrText = eventNode.text ?:""
74
76
val stderrMessage =OutputMessage(stderrText, timestamp, true)
0 commit comments