Skip to content

fix(runner): restore caller stdout instead of raw sys.__stdout__#82

Merged
aadya940 merged 1 commit intomasterfrom
fix/runner-stdout-tee-preservation
Apr 28, 2026
Merged

fix(runner): restore caller stdout instead of raw sys.__stdout__#82
aadya940 merged 1 commit intomasterfrom
fix/runner-stdout-tee-preservation

Conversation

@aadya940
Copy link
Copy Markdown
Owner

Problem

When log_file_path is set on a verb, runner.run() installs its own _Tee over sys.stdout. The finally block then restores with:

sys.stdout = sys.__stdout__

sys.__stdout__ is the raw original stdout — not whatever the caller had installed. If the caller had replaced sys.stdout with their own tee (e.g. a workflow runner that logs all output to a file), this line silently destroys it. Every print() call after the verb returns goes to the void.

Symptom

In a workflow that tees sys.stdout to a log file and runs multiple orbit verbs in sequence, the log file is truncated after the first verb's completion banner. All subsequent node labels, status checks, and error tracebacks are swallowed silently. The run shows status=error in the DB with no visible cause.

Fix

Save sys.stdout before touching it, restore to that:

_prev_stdout = sys.stdout  # save caller's stdout (may be a workflow-level tee)
if self.log_file_path:
    ...
    sys.stdout = _Tee(sys.__stdout__, log_f)
...
finally:
    if log_f:
        sys.stdout = _prev_stdout  # restore caller's stdout, not raw __stdout__
        log_f.close()

Two-line change, no behaviour change when log_file_path is not set.

🤖 Generated with Claude Code

When log_file_path is set, runner.run() replaced sys.stdout with its
own _Tee. The finally block restored sys.stdout = sys.__stdout__ (the
raw original), which destroyed any outer tee the caller had installed
(e.g. a workflow-level tee that logs all output to a file).

Fix: save sys.stdout before the verb runs and restore to that instead
of sys.__stdout__, so any outer tee survives across verb calls.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 28, 2026 01:59
@aadya940 aadya940 merged commit 9ffa1dc into master Apr 28, 2026
2 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Agent.run()’s stdout restoration when log_file_path is enabled so Orbit doesn’t clobber a caller-provided sys.stdout (e.g., a workflow-level tee/capture) after the run completes.

Changes:

  • Capture the caller’s current sys.stdout before installing Orbit’s _Tee.
  • Restore sys.stdout back to the captured value in the finally block (instead of sys.__stdout__) when closing the log file.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants