Skip to content

Live output: cache the tail per requested byte limit — v0.10.8 - #176

Merged
jamesabel merged 4 commits into
jamesabel:masterfrom
JingHao-Leon:fix/live-output-cache-max-bytes
Oct 20, 2026
Merged

jamesabel merged 4 commits into
jamesabel:masterfrom
JingHao-Leon:fix/live-output-cache-max-bytes

Conversation

@JingHao-Leon

@JingHao-Leon JingHao-Leon commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

What was broken

read_live_output() could return text that did not match the max_bytes limit it was called with. The decoded-text cache was keyed by the log file's path alone, but the text it stores is the tail of that file, so the cached value also depends on the byte limit. The first read of a given log file therefore fixed the length of the text that every later read of that file received:

  • a read asking for a large limit could be answered with a much shorter tail, prefixed with a spurious ...[truncated]... marker even when nothing had to be elided;
  • a read asking for a small limit could be answered with more bytes than the limit permits.

In the running app the Table tab and the Live Output pane read the same log file with the 65536-byte default, while resolve_test_output() asks for 10,000,000 bytes — so whichever of them ran first decided how much output the others saw.

Root cause

src/pytest_fly/pytest_runner/live_output.py:22 declared the module-level cache as _read_cache: dict[Path, tuple[int, int, str]] = {} — keyed by path only. The entry was looked up at src/pytest_fly/pytest_runner/live_output.py:52 and stored at src/pytest_fly/pytest_runner/live_output.py:66, and neither the key nor the stored value took max_bytes into account — even though the stored string is the tail read at src/pytest_fly/pytest_runner/live_output.py:57-59, and so is a function of max_bytes as well as of the file's contents.

The change

  • src/pytest_fly/pytest_runner/live_output.py — the cache is now keyed by (path, max_bytes), so each byte limit gets its own cached tail. The cached value keeps its (size, mtime_ns, text) shape; only the key changed.
  • tests/test_live_output.py — two regression tests, one for each direction (a large limit after a small one, and a small limit after a large one). The existing cache test now addresses the cache by its new key.
  • pyproject.toml — version bump to 0.10.7.

How this was verified

Regression tests against the unmodified live_output.py:

$ pytest tests/test_live_output.py
FAILED tests/test_live_output.py::test_read_live_output_cache_respects_max_bytes
FAILED tests/test_live_output.py::test_read_live_output_cache_does_not_return_more_than_max_bytes
========================= 2 failed, 9 passed in 0.20s ==========================

The same tests with the fix applied:

$ pytest tests/test_live_output.py
============================== 11 passed in 0.17s ==============================

Full suite, unmodified master baseline versus this branch:

$ pytest tests -q
master baseline:  519 passed, 4 skipped in 162.01s
this branch:       523 passed, 4 skipped in 163.87s

The +4 is accounted for: +2 are the new regression tests, and +2 are tests/tests_many/test_many_000.py and test_many_001.py — the session fixture make_many_tests creates that directory during the first run (after collection, so those two files are not collected in that run) and they are collected from the second run onwards.

Lint and format are clean:

$ ruff check src tests
All checks passed!
$ ruff format --check src tests
161 files already formatted

Coverage of the changed module is unchanged; the only uncovered lines in src/pytest_fly/pytest_runner/live_output.py are the two pre-existing except OSError: pass branches in clear_live_output (lines 82-83 and 86-87), which this change does not touch.

The above was run locally on macOS (Python 3.13.9, PySide6 6.11.0) with the suite headless, using QT_QPA_PLATFORM=offscreen as CI does. The change itself is pure Python and platform-independent.

CI status

The main workflow for this branch did run — run 39335619684, conclusion: failure. Its jobs are:

  • test (3.14) → failure
  • test (3.15) → cancelled
  • test (3.12) → cancelled

main.yml builds a matrix over ['3.12', '3.14', '3.15'] and does not set fail-fast: false, so the default fail-fast applies: the 3.12 and 3.15 jobs were cancelled once the 3.14 job failed, rather than running to completion.

The 3.14 job log ends with the suite passing and the process then dying:

================== 521 passed, 4 skipped in 133.12s (0:02:13) ==================
##[error]Process completed with exit code 139.

Exit code 139 is 128 + SIGSEGV, so no test failed — the interpreter crashed during shutdown (Qt/PySide6 teardown) after the test session had already finished.

That crash is pre-existing on the base commit and is not caused by this change. This PR's base is bfa652b1c6b0db810844daa42d40da754e7bcc1c, which is the current master head of this repository. The main workflow on that same commit — run 36520991752 (event: push, head_branch: master, run_attempt: 2) — also concludes failure, with the same signature: test (3.14) fails while 3.12/3.15 are cancelled, and its log ends with

================== 519 passed, 4 skipped in 139.38s (0:02:19) ==================
##[error]Process completed with exit code 139.

The only difference between the two runs is the test count: 519 on the base commit versus 521 here — exactly the two regression tests added by this PR. The failing job, the exit code and the timing are identical.

So the workflow is not waiting for a maintainer approval: it ran, and the failure reproduces on the unmodified base commit.
Fixes #175

This change was prepared with the assistance of an AI coding agent.

The decoded live-output cache is keyed by the file's (size, mtime_ns) only, but
the text it holds is the *tail* of the file and therefore depends on max_bytes.
A read with one byte limit can be served the tail computed for a different one.

Adds two regression tests that fail on the current implementation:
  - a large-limit read after a small-limit read must not reuse the small tail
  - a small-limit read after a large-limit read must not return more than the limit
The decoded live-output cache was keyed by the log file's path alone, but the
text it stores is the *tail* of that file, so the cached value also depends on
the max_bytes limit the read was made with. The first call for a given file
therefore fixed the length of the text every later call received.

This is reachable in the app: the Table tab and the Live Output pane read the
same log file with the 65536-byte default, while resolve_test_output() asks
for 10,000,000 bytes. Whichever ran first decided how much output the others
saw -- a read could return far fewer bytes than requested (with a spurious
"...[truncated]..." marker) or far more than requested.

Key the cache by (path, max_bytes) so each limit gets its own cached tail.

Also bumps the version to 0.10.7.
@jamesabel jamesabel changed the title Live output: cache the tail per requested byte limit — v0.10.7 Live output: cache the tail per requested byte limit — v0.10.8 Oct 20, 2026
@codecov-commenter

codecov-commenter commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.70%. Comparing base (08f9dac) to head (2f230e4).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #176   +/-   ##
=======================================
  Coverage   85.70%   85.70%           
=======================================
  Files          74       74           
  Lines        6450     6451    +1     
=======================================
+ Hits         5528     5529    +1     
  Misses        922      922           

☔ View full report in Codecov by Harness.
📢 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.

@jamesabel
jamesabel merged commit 31df28e into jamesabel:master Oct 20, 2026
3 checks passed
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.

read_live_output() can return more or fewer bytes than the requested max_bytes

3 participants