2026.9.28.1: interface update_packages reports its progress, and nothing but NDJSON reaches stdout - #625
Merged
Conversation
…erface mode `interface update_packages` reported no progress at all for an index refresh, and when the refresh rebuilt a stale index cache it let a downloaded pkgindex-build.lua's raw terminal text (carriage returns, ANSI clear-to-end-of-line) straight onto stdout, breaking the NDJSON stream the protocol requires there. The text comes from libxpkg's plain-Lua build sandbox: run_pkgindex_build executes the index repo's own pkgindex-build.lua with the real io library, and that script's self-refreshing progress line writes directly to the process's real stdout, bypassing every abstraction xlings routes through platform::is_tui_mode(). It is data the index repo ships, not code this repository owns, so the fix is at the boundary rather than in that script. platform::StdoutCapture redirects the real fd 1 into a pipe for the duration of a capability's execution and delivers whatever is written there line by line; interface::run() installs it around every capability, converting a recognisable "[i/n] ..." step into a progress event and routing anything else to stderr. The NDJSON writer itself is decoupled from fd 1 (InterfaceSession now writes through a duplicate taken before any capture starts), so the protocol's own output is never captured along with what this exists to catch. Because the guard sits around capability execution rather than around one call site, install_packages benefits the same way when its own first-run index rebuild hits the same script. cmd_update also reports two new progress phases -- index_sync (one event per repository, i/n within its group) and index_rebuild (from the captured scan) -- and reuses install_packages' own download_progress data event shape for an index artifact download's byte progress, so a client renders both the same way. Adds interface_update_packages_progress_test.sh (E2E-122): builds an offline index fixture whose own pkgindex-build.lua reproduces the exact defect shape, asserts every stdout line parses as JSON, and asserts at least one progress event fires. Confirmed it fails against the released 2026.9.27.1 binary before this change and passes after.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
xlings interface update_packagesnow reports its work as NDJSON events. No capability run throughxlings interfacewrites anything but NDJSON to stdout. The interface protocol becomes 1.2, which is additive, and the version becomes 2026.9.28.1.What was wrong
Measured with xlings 2026.9.27.1:
xlings interface update_packages --args '{}'emitted onlyheartbeatevents and the finalresult. A refresh of several seconds therefore gave a client nothing to show.[1/7] awesome::xim.lua\x1b[Kappeared on stdout. The text comes from thepkgindex-build.luascript that ships inside an index repository: libxpkg'srun_pkgindex_buildruns it with the realiolibrary, and itsprogress()writes to fd 1 directly. The protocol forbids this output, and it reachedinstall_packagesas well, which rebuilds the cache on first use.Change
platform::StdoutCapture. It redirects fd 1 into a pipe for the duration of one capability's execution.InterfaceSessionwrites NDJSON through a duplicate of fd 1 taken before any capture, so the protocol's own output cannot be captured. A captured[i/n] <message>line becomes aprogressevent with phaseindex_rebuild; any other captured line goes to stderr. The capture wraps every capability, so the protection does not depend on the one script.cmd_updateprogress. It emits aprogressevent with phaseindex_syncfor each repository it syncs,i/nwithin its group. It emits adownload_progressdata event with the samefiles[]shape asinstall_packageswhile an index artifact downloads with known bytes. The callbacks are optional parameters ofsync_all_repos,sync_one_repoandfetch_index_artifact, so no other caller changes.docs/spec/interface-ndjson-v1.mdgains the stdout rule (§5), the phases ofupdate_packages(§6.1.1), thedownload_progressshape (§6.3.2), and version 1.2.Consumer
mcpp (mcpp-community/mcpp#727) moves its index refresh from the bare
xlings updateto this interface, and renders the events with the same bar it uses for installs. Without these events it shows only its status line.Tests
tests/e2e/interface_update_packages_progress_test.sh(E2E-122) builds an offline index fixture whose ownpkgindex-build.luareproduces the stray output. It asserts that every stdout line parses as JSON and that at least oneprogressevent is emitted. It fails with the released 2026.9.27.1 and passes with this branch.mcpp test(58 unit tests, including the 26InterfaceProtocoltests),interface_multi_repo_error_visibility_test.sh,tui_output_contract_test.sh(including the S6 glyph rule),update_package_test.sh,self_update_failure_test.sh,index_artifact_update_test.shandcustom_index_artifact_test.sh.StdoutCapturebranch (_pipe,_dup2,_read) is exercised by this PR's Windows CI.