Skip to content

πŸ™Œ OpenHands: AI-Driven Development

ALL-677 fix(frontend) Truncate long CMD outputs to prevent UI freezing (#4785)

sp.wacke5d7735d75c2
diff --git a/frontend/src/services/observations.ts b/frontend/src/services/observations.ts
index 3ce2b6dbed..011c20c737 100644
--- a/frontend/src/services/observations.ts
+++ b/frontend/src/services/observations.ts
@@ -9,10 +9,18 @@ import { addAssistantMessage } from "#/state/chatSlice";
export function handleObservationMessage(message: ObservationMessage) {
switch (message.observation) {
- case ObservationType.RUN:
+ case ObservationType.RUN: {
if (message.extras.hidden) break;
- store.dispatch(appendOutput(message.content));
+ let { content } = message;
+
+ if (content.length > 5000) {
+ const head = content.slice(0, 5000);
+ content = `${head}\r\n\n... (truncated ${message.content.length - 5000} characters) ...`;
+ }
+
+ store.dispatch(appendOutput(content));
break;
+ }
case ObservationType.RUN_IPYTHON:
// FIXME: render this as markdown
store.dispatch(appendJupyterOutput(message.content));