Skip to content

fix(runtime): preserve stdout and stderr streams on Python execution timeout - #720

Open
pei711 wants to merge 2 commits into
OpenBMB:mainfrom
pei711:fix/python-executor-timeout-streams
Open

pei711 wants to merge 2 commits into
OpenBMB:mainfrom
pei711:fix/python-executor-timeout-streams

Conversation

@pei711

@pei711 pei711 commented Nov 12, 2026

Copy link
Copy Markdown

Description

This PR fixes stream handling in PythonNodeExecutor when a script times out, ensuring stdout and stderr are properly decoded and preserved rather than swapped or discarded.

Problem

In runtime/node/executor/python_executor.py:

  1. When subprocess.TimeoutExpired is raised, _run_process mistakenly decoded exc.stdout into stderr, while hardcoding stdout="":
    except subprocess.TimeoutExpired as exc:
        return _ExecutionResult(
            success=False,
            stdout="",
            stderr=exc.stdout.decode(config.encoding, errors="replace") if exc.stdout else "",
            exit_code=None,
            error=f"Script did not finish within {config.timeout_seconds}s",
        )
    This swapped the streams, discarded any real diagnostics emitted to stderr before timeout, and completely dropped stdout.
  2. In _build_failure_message and _error_message, stdout was not forwarded or recorded in the failure message's metadata, preventing downstream nodes or users from inspecting partial output.

Fix

  • Decode exc.stdout (or fallback exc.output) into stdout, and exc.stderr into stderr.
  • Forward result.stdout in _build_failure_message and record metadata["stdout"] = stdout when present.
  • Added comprehensive unit tests in tests/test_python_executor_timeout.py verifying stream preservation, stream separation, and edge cases.

How Has This Been Tested?

  • Ran pytest tests/test_python_executor_timeout.py (3 passed in 4.30s).
  • Ran ruff check tests/test_python_executor_timeout.py (All checks passed).
  • Ran ruff format --check tests/test_python_executor_timeout.py (Clean).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T03:46:56.091163Z 8263be8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8263be8528

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if stderr:
metadata["stderr"] = stderr
if stdout:
metadata["stdout"] = stdout

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include partial stdout in the failure payload

When a script prints before timing out, this stores stdout only in metadata. Built-in downstream nodes consume Message.text_content() via NodeExecutor._inputs_to_text, and the normal workflow result is likewise derived from text content, so they receive only the timeout banner and stderr; the partial stdout is available only to callers that manually inspect metadata. Add stdout as a separate content section or otherwise expose it through the standard workflow output path.

Useful? React with 👍 / 👎.

@pei711

pei711 commented Nov 12, 2026

Copy link
Copy Markdown
Author

Addressed in commit 64acb0f: included partial stdout as a separate content section in the failure message payload when available, ensuring downstream workflow nodes can consume standard output from timed-out executions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant