Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(run) Fix live / streaming / flushing of output #493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 21, 2025

Conversation

tony
Copy link
Member

@tony tony commented Jun 21, 2025

Follow up to #485.

Live updates were broken, e.g. flushing of output during git clone

Summary by Sourcery

Fix live streaming and flushing of subprocess output in run.py by switching to byte-mode I/O, preserving carriage returns for progress updates, and decoding output via a console-encoding fallback.

Bug Fixes:

  • Restore live updating and flushing of progress output by reading raw bytes (text=False) to preserve carriage-return behavior
  • Prevent Unicode errors during decoding by adding a console_to_str helper that tries the console’s encoding and falls back to UTF-8

Enhancements:

  • Consolidate stdout/stderr line reading into byte streams trimmed and decoded with console_to_str

Live updates were broken, e.g. flushing of output during `git clone`
Copy link

sourcery-ai bot commented Jun 21, 2025

Reviewer's Guide

This PR restores live output streaming by switching subprocess pipes to bytes mode, decoding output with a new utility to preserve carriage returns, and refactoring how stderr and stdout are read and decoded.

Class diagram for ProgressCallbackProtocol and process function changes

classDiagram
    class ProgressCallbackProtocol {
        +__call__(output: str, timestamp: datetime.datetime) -> None
    }
    class process {
        +console_to_str(s: bytes) -> str
    }
Loading

File-Level Changes

Change Details Files
Add console_to_str utility for robust byte decoding
  • Introduce console_to_str to decode bytes using sys.stdout.encoding with UTF-8 fallback
  • Handle AttributeError for non-bytes inputs
src/libvcs/_internal/run.py
Switch subprocess pipes to bytes mode
  • Set Popen(text=False) to preserve carriage returns in progress updates
  • Remove encoding=text handling in favor of manual decoding
src/libvcs/_internal/run.py
Update progress callback to handle decoded strings
  • Change ProgressCallbackProtocol to accept str output
  • Use console_to_str when reading stderr chunks for live updates
src/libvcs/_internal/run.py
Refactor final stdout/stderr aggregation with proper decoding
  • Read stdout/stderr as bytes, strip and join into a single bytes object
  • Decode the combined bytes via console_to_str to produce the final output string
src/libvcs/_internal/run.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

codecov bot commented Jun 21, 2025

Codecov Report

Attention: Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.

Project coverage is 54.05%. Comparing base (fdf8992) to head (4e8241b).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
src/libvcs/_internal/run.py 64.70% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #493      +/-   ##
==========================================
- Coverage   54.09%   54.05%   -0.04%     
==========================================
  Files          40       40              
  Lines        3627     3637      +10     
  Branches      793      794       +1     
==========================================
+ Hits         1962     1966       +4     
- Misses       1314     1319       +5     
- Partials      351      352       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @tony - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/libvcs/_internal/run.py:25` </location>
<code_context>

 logger = logging.getLogger(__name__)

+console_encoding = sys.stdout.encoding
+
+
</code_context>

<issue_to_address>
sys.stdout.encoding may be None in some environments.

If console_encoding is None, provide a fallback like 'utf-8' to avoid potential TypeError when decoding.
</issue_to_address>

### Comment 2
<location> `src/libvcs/_internal/run.py:228` </location>
<code_context>

         if callback and callable(callback) and proc.stderr is not None:
-            line = str(proc.stderr.read(128))
+            line = console_to_str(proc.stderr.read(128))
             if line:
                 callback(output=line, timestamp=datetime.datetime.now())
</code_context>

<issue_to_address>
Reading fixed-size chunks may split multibyte characters.

This approach can cause decode errors or corrupted output. Buffer the data and decode only complete lines, or use an incremental decoder to handle multibyte characters correctly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/libvcs/_internal/run.py Show resolved Hide resolved
src/libvcs/_internal/run.py Show resolved Hide resolved
@tony tony merged commit 18d72cb into master Jun 21, 2025
8 checks passed
@tony tony deleted the sync-progress-flushes-fix branch June 21, 2025 18:28
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.