Skip to main content

Module logs

Module logs 

Source
Expand description

log_compaction transform (canonical id "log_compaction", v1.0.0).

Mode: lossy-with-evidence. Ships behind --experimental until the fidelity gate (roadmap.md F-016) is green for this transform; see crate::modes::ALL_ENTRIES.

Collapses runs of three or more adjacent identical lines into three output lines: the first occurrence, an evidence marker [repeated Nx] recording exactly how many copies were dropped, and the last occurrence. This preserves enough evidence to tell a reader “this line repeated N times here” without paying the token cost of every copy.

Deliberate behavioral contract (see port_spec in eval/transforms/log_compaction.py and roadmap.md F-012):

  • Threshold is 3, not 2. Runs of exactly one or exactly two adjacent identical lines are left completely untouched — no marker, every line kept. Only a run of three or more collapses to the three-line evidence form above, regardless of how long the run actually is ([repeated 2000x] is still just three output lines).
  • Adjacent-only. Only consecutive identical lines count as a run. Non-adjacent duplicates (e.g. [A, B, A]) are never collapsed, even though A appears twice overall. This is a documented, tested limitation, not a bug — interleaved log deduplication is explicitly out of scope for this transform.
  • Relative line ordering is always preserved.
  • Empty input produces empty output; a single-line input is returned unchanged.
  • Timestamp removal is opt-in only (default off, via remove_timestamps: bool). When off, two lines that differ only by timestamp are distinct strings and are never collapsed. When on, a recognized leading timestamp is stripped from every line before comparison, and the stripped form is what appears in the output — the timestamp is genuinely removed from surviving lines, not just ignored for comparison purposes.

Timestamp patterns run on Rust’s regex crate, whose matching engine is provably linear-time in the length of the input (no catastrophic backtracking) — see deny.toml at the workspace root.

Constants§

TRANSFORM_ID
Canonical transform id, as registered with the pipeline.
TRANSFORM_VERSION
Semantic version of this transform’s output behavior.

Functions§

compact
Compacts a log by collapsing runs of three or more adjacent identical lines into first-occurrence / [repeated Nx] / last-occurrence (three output lines total, regardless of run length). See the module-level doc comment for the full behavioral contract, including the adjacent-only limitation and the >=3 threshold.