Skip to content

Stream CR-only progress ticks in run() instead of buffering them into one message - #2731

Merged
tom mortensen (limetech) merged 3 commits into
unraid:masterfrom
junkerderprovinz:fix/plugin-install-progress-cr-buffering
Sep 20, 2026
Merged

tom mortensen (limetech) merged 3 commits into
unraid:masterfrom
junkerderprovinz:fix/plugin-install-progress-cr-buffering

Conversation

@junkerderprovinz

@junkerderprovinz Junker der Provinz (junkerderprovinz) commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the plugin-install progress garbling reported on the Unraid forum, confirmed by Jorge (@jorgeb).

The bug

emhttp/plugins/dynamix.plugin.manager/scripts/plugin's run() read subprocess output with fgets(), which only splits on \n. A command whose output uses \r-only progress ticks (no \n between them, the classic in-place progress bar) gets every tick buffered into one fgets() read that doesn't return until an actual \n shows up or the process exits. That single, already-clumped blob then goes out as one nchan message. The client's per-message \r handling in renderMessage() operates on whole received messages, but cannot separate progress updates inside an already-clumped message. Reproduced live: a real install produced a single 3486-character message with 41 embedded \r.

The fix

Ports the pattern this repo already uses correctly in the sibling script multiplugin: read one character at a time with fgetc() and flush on \r or \n, so each tick becomes its own message.

 function run($command) {
   $run = popen($command,'r');
-  while (!feof($run)) write(fgets($run));
+  $line = '';
+  while (!feof($run)) {
+    $char = fgetc($run);
+    if ($char === false) break;
+    $line .= $char;
+    if (in_array($char,["\r","\n"])) {write($line); $line = '';}
+  }
+  if ($line !== '') write($line);
   return pclose($run);
 }

The browser renderer also removes the final character only when it is a newline. This preserves unterminated output and a literal 0, which previously reached the client but were truncated during rendering. The carriage-return replacement branch and multiplugin are unchanged.

Two small, deliberate differences from multiplugin's version, both strictly better and both verified against real output:

  • An explicit $char === false break on end-of-stream, instead of relying on fgets-style implicit end-of-stream handling. This also means a stream that errors without ever setting EOF can't spin the loop forever, which the old code was theoretically exposed to.
  • A trailing if ($line !== '') write($line) after the loop, so output with no final terminator (or output that's just the literal string "0") still reaches the client. multiplugin's own !empty($line) guard would drop a bare "0", since empty("0") is true in PHP; this uses !== '' instead.

Testing

Emitted bytes are unchanged in every case tested (only the message boundaries differ): \r-only progress ticks, normal \n-terminated lines, a mix of both, output with no trailing terminator, a bare "0" with no terminator, and no output at all. Verified against the five call sites of run() in this file (pre_hooks, post_hooks, and the three run variants) that none of them depend on the old message granularity, only on the return value. php -l passes.

One pre-existing property, unchanged by this PR and already present in multiplugin: a stream that mixes \n-only lines with later \r\n-terminated lines can lose one line at the transition, because the client's renderer treats a \r-terminated message as "replace the previous line." Not introduced here, and unlikely on the Linux run-scripts this path executes (wget/curl-style progress is \r-only, not CRLF).

Renderer follow-up validation

On Unraid 7.4.0-beta.1.3 with the original PR plugin plus the one-line renderer change, a real browser install showed live download progress, separate normal lines, the complete unterminated message, and literal 0. A deliberate exit-7 fixture still displayed Error and the command failure. Six focused checks against the extracted renderer passed: unterminated tail, zero, LF lines, spaces, blank lines, and repeated CR updates.

The rebuilt PR plugin version 2026.09.16.2354 was installed cleanly on Unraid 7.4.0-beta.1.3 after removing the temporary renderer edit. After a browser reload, the real download fixture displayed the complete trailing message and literal 0; the exit-7 fixture still displayed Error correctly. Installed renderer and reader hashes matched the tested sources, and all eight reader contract checks passed again. Build and CodeRabbit checks passed for head c4d48c8.

During a plugin install or update the download progress line clumps into
one very long line instead of updating in place. A captured example was a
single 3486 character message holding 41 carriage returns and one trailing
line feed.

Root cause is in run(): the subprocess pipe was read with fgets(), which
only breaks on LF. A command that emits classic CR-only progress ticks
therefore keeps filling the same fgets() read until a LF finally arrives
(or EOF), and the whole progress sequence leaves run() as one message.
The receiving side splits on CR per received message, so once the ticks
are already glued together inside a single message it can no longer
render them in place.

Read the pipe character by character and flush on CR or LF, so every tick
is passed on as its own message. 'multiplugin' in the same directory
already reads its child output this way and is the reference for the
pattern. Two details are handled beyond that reference: a final chunk
without a terminator is still flushed before returning, and fgetc()
returning false at end of stream ends the loop explicitly rather than
relying on the silent false to string cast.

Return value (pclose) and the emitted bytes are unchanged; only the
message boundaries differ. Ordinary LF-only output is unaffected.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: be8098cf-0fcd-4062-8cd0-70950300a30d

📥 Commits

Reviewing files that changed from the base of the PR and between 85aefb0 and c4d48c8.

📒 Files selected for processing (1)
  • emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

run() now processes command output character by character and flushes it on carriage returns or newlines. The renderer strips only a trailing newline from plugin log data.

Changes

Plugin output handling

Layer / File(s) Summary
Character-based output flushing
emhttp/plugins/dynamix.plugin.manager/scripts/plugin, emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php
run() emits buffered output at carriage-return and newline boundaries, then flushes remaining output at end of stream. renderMessage strips a trailing newline only when one is present.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: elibosley

Merge Risk: ⚪ Minimal · up to c4d48

The change preserves live plugin progress updates and replay behavior without an identified regression.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: streaming carriage-return-only progress updates in run() instead of buffering them.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit watched the output stream,
As carriage returns made updates gleam.
Newlines stayed neatly trimmed,
And unfinished text was never dimmed.
“Hop!” said Bun, “the logs now beam!”

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2026.09.16.2354
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-2731/webgui-pr-2731.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates
  • Post-merge behavior: This preview stays available after merge until preview storage expires or it is manually cleaned up

📝 Modified Files:

Click to expand file list
emhttp/plugins/dynamix.plugin.manager/scripts/plugin
emhttp/plugins/dynamix/include/DefaultPageLayout/BodyInlineJS.php

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-2731, or run:

plugin remove webgui-pr-2731

🤖 This comment is automatically generated and will be updated with each new push to this PR.

@unraid-bot Unraid Bot (unraid-bot) added QA Passed QA passed (auto-managed by notification-worker) 7.4.0 Approved for release 7.4.0 (auto-managed by notification-worker) labels Sep 17, 2026
@ljm42

ljm42 commented Sep 17, 2026

Copy link
Copy Markdown
Member

This is a great fix, thanks!

@limetech
tom mortensen (limetech) merged commit a167c21 into unraid:master Sep 20, 2026
1 check passed
@unraid-bot Unraid Bot (unraid-bot) removed the 7.4.0 Approved for release 7.4.0 (auto-managed by notification-worker) label Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA Passed QA passed (auto-managed by notification-worker)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants