#3814·headroom

LogCompressor silently drops middle FAILED lines from pytest's short test summary

Author: asq-sheriffCreated Sep 27, 2026Updated Sep 28, 2026

LogCompressor silently drops middle FAILED lines from pytest's short test summary

What happens

With a pytest log containing 16 or more FAILED lines in the short test summary info section, LogCompressor keeps only 15 of them: the first 12 and the last 3. The FAILED lines in between are removed, and the only trace left is an aggregate count in the omission marker. Nothing in the output names which tests were dropped.

Test failure lines are not interchangeable log lines. Each one names a distinct test, and the short-summary block is the canonical machine-readable list of what failed. An agent reading the compressed output sees a plausible, complete-looking list of failures and has no way to discover that a named test is missing from it.

This is the same shape as #2586 (dropped line read as evidence of absence, agent acted on it) and #3099 (compression encoding a false fact, "materially worse than truncation: truncation is visible and an agent knows to re-run").

Reproduction

Self-contained, no pytest run needed:

python
from headroom.transforms.log_compressor import LogCompressor, LogCompressorConfig

def pytest_log(n_failed: int, n_progress: int = 40) -> str:
    lines = ["============================= test session starts =============================",
             "collected 400 items", ""]
    for i in range(n_progress):
        lines.append("tests/test_module_%02d.py ...................................  [ %2d%%]" % (i, i * 2))
    lines.append("=================================== FAILURES ==================================")
    ids = [f"tests/t.py::test_case{i:02d}" for i in range(1, n_failed + 1)]
    for nid in ids:
        lines += ["_" * 20 + f" {nid.split('::')[-1]} " + "_" * 20, "",
                  ">       assert result == expected",
                  "E       AssertionError: mismatch", "",
                  "tests/t.py:42: AssertionError"]
    lines.append("=========================== short test summary info ===========================")
    lines += [f"FAILED {nid} - AssertionError: mismatch" for nid in ids]
    lines.append(f"=============== {n_failed} failed, 380 passed in 41.02s ==============")
    return "\n".join(lines)

for n in (15, 16, 20):
    out = LogCompressor(LogCompressorConfig()).compress(pytest_log(n)).compressed
    kept = [int(l.split("test_case")[1][:2]) for l in out.splitlines()
            if l.startswith("FAILED") and "test_case" in l]
    missing = [i for i in range(1, n + 1) if i not in kept]
    marker = next((l.strip() for l in out.splitlines() if "omitted" in l), "(none)")
    print(f"{n} FAILED in -> {len(kept)} kept, missing {missing}")
    print(f"    marker: {marker}")

Output on 0.39.1:

15 FAILED in -> 15 kept, missing []
    marker: [120 lines omitted: 16 FAIL, 1 INFO]
16 FAILED in -> 15 kept, missing [13]
    marker: [127 lines omitted: 17 FAIL, 1 INFO]
20 FAILED in -> 15 kept, missing [13, 14, 15, 16, 17]
    marker: [155 lines omitted: 21 FAIL, 1 INFO]

At 20 failures, test_case13 through test_case17 are gone. The marker reports a FAIL count but never names them, and the count it reports does not match the number of FAILED lines actually present, so the two cannot be reconciled from the output alone.

Notes from narrowing it down

  • The retained count is max_errors + 5: the first max_errors + 2 and the last 3. max_errors=5 keeps 10, the default max_errors=10 keeps 15, max_errors=40 keeps all 20.
  • keep_summary_lines=False changes nothing here, so FAILED lines inside the short test summary info section are not being treated as summary lines. Given that flag's name and purpose, that looks like the actual defect: these lines are in the summary block and are one line each.
  • Selection keeps first and last and fills the remainder in ascending line order (select_with_first_last). Because every FAIL line carries the same score, the fill is positional, so what gets dropped is always the middle band rather than the least informative lines.
  • Reproduced through the published headroom-ai 0.39.1 wheel, which routes compress() to the Rust implementation, so this is not specific to the Python mirror.

Suggested fix

Two options, smallest first:

  1. Name the omitted tests in the marker. Keep the cap, but list the dropped node ids, e.g. [5 FAILED omitted: tests/t.py::test_case13, ... test_case17]. Node ids are short, so this costs very little and makes the loss recoverable without a headroom_retrieve round trip.
  2. Exempt short-summary FAILED/ERROR lines from max_errors. Treat them as summary lines under keep_summary_lines. One line per failed test is the highest-value content in a test log, and the tracebacks above them (already collapsed by max_stack_traces and stack_trace_max_lines) are where the real savings are.

Option 2 changes default retention, so if that counts as a behaviour change I am happy to do option 1 instead, or whichever you prefer.

Environment

  • headroom-ai 0.39.1 (PyPI wheel)
  • Python 3.13.15, macOS, arm64
  • Default LogCompressorConfig()

Source: headroomlabs-ai/headroom