Repository navigation
fix(plugin): hand a Python plugin its inputs on stdin, never on disk - #2587
Merged
Merged
Conversation
A Python plugin read its inputs (the entries, options and config) from a temp directory preopened as /work, removed when the plugin ended. A Ctrl-C stops rledger at once, so the directory, holding a serialized copy of the ledger, stayed in $TMPDIR. The inputs now go to the guest on its stdin from memory (length-prefixed sections, then the entries line by line), the script runs as `python -c`, and the guest sees only /lib. There is nothing on disk to clean up. Tracebacks still show the plugin's source lines (registered in linecache) under the plugin's own name instead of /work/plugin.py. Closes #2551 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
The entries arrive on the guest's stdin since the previous commit, so a plugin reading sys.stdin at import (an input() left in) took them and the plugin ran on none, which would delete the ledger's entries. The runner now holds the entries stream privately and sys.stdin is empty, as it was before. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Member
Author
Review loop
The loop converged at round 2. The required checks ( |
…gint # Conflicts: # CHANGELOG.md
robcohen
added a commit
that referenced
this pull request
Oct 11, 2026
…rance-rounding CHANGELOG: main's file plus this PR's entries. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
This was referenced Oct 11, 2026
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.
What
A Python plugin's inputs (entries, options, config, the compat layer and the plugin's source) now reach the CPython-WASI guest on its stdin, from memory, instead of as files in a temp directory preopened as
/work. The script runs aspython -c; the guest's only preopen is/lib(the standard library, read-only).stdin carries four length-prefixed sections (compat layer, plugin source, options JSON, invocation JSON), then the entries as JSON lines to EOF, which
load_entriesstill reads one line at a time.Why
rledgerexits at once on Ctrl-C (SIGINT), so the work directory, which held a serialized copy of the ledger, stayed in$TMPDIR. The issue preferred removing the on-disk copy over racing a signal handler, and wasmtime-wasi'sMemoryInputPipesupports that directly. Nothing is written to disk now, so there is nothing to clean up.Tracebacks still show the plugin's source lines: the sources are registered in
linecacheunder the plugin's own name (e.g.File "bad.py", line 1), where they used to read/work/plugin.py.How tested
python_plugin_leaves_nothing_on_disk_after_sigint(Linux): startsrledger checkon a ledger whose Python plugin sleeps, waits for the guest thread (rledger-python-pluginin/proc/<pid>/task), sends SIGINT, asserts rledger died of the signal and$TMPDIRis empty. Fails without the fix (left in $TMPDIR after Ctrl-C: [".../.tmpCbekx0"]), passes with it. It replacespython_plugin_work_dir_is_private, which tested the 0700 mode of the directory that no longer exists.python_plugin_isolationnow expectslistable=['/lib'](it listed/worktoo); the open-files cap case opens/lib/os.py.cargo test -p rustledger-plugin --all-features,cargo test -p rustledger --all-featureswithRLEDGER_REQUIRE_PYTHON_WASI=1 RLEDGER_REQUIRE_WASM32=1: all pass.python_plugins_back_to_back_after_a_timeout(a 2-second budget) failed once locally while four other builds loaded the machine, and passed in an isolated run. It failed the same way on an unrelated branch under the same load.-D warnings) and fmt clean. The release-config clippy (--no-default-features --features mimalloc,ag-rledger --all-targets) fails onwasm_plugins_dirbeing unused incli_commands_test.rs. That is on main already, not from this PR, and the docs: release binaries do not include plugin runtimes #2541 PR fixes it.Closes #2551
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr