Skip to content

bug: silent fallback to full — a compressed ctx_read that returns the whole file says nothing #1587

Description

@yvgude

Reported by a user running 3.9.20 (official build, path jail active, doctor green).

Symptom

Outside the project root, ctx_read(mode="signatures") returned the full file
with no indication that no compression had happened. From the caller's side a
lossy summary and a verbatim full read are indistinguishable — you pay full-file
tokens believing you asked for a summary. Same session: ctx_delta reported
"no cached version for diff" immediately after a successful mode=full read.

"A silent fallback to full is the bad failure mode — you pay full tokens
believing you asked for a summary."

Root cause

cap_to_raw (tools/ctx_read/core_logic.rs) enforces the #361 anti-inflation
invariant: if the framed/compressed output is larger than the raw file, the raw
file is returned instead. It returned it bare — no mode label, no note. The
same is true of raw_fallback in render.rs (the monotonic guard).

For a verbatim request (full, raw, lines:N-M) that is correct and silent
is right. For a request that asked for a summary (signatures, map,
aggressive, entropy, task, reference) silence is a lie by omission.

Fix (implemented)

A size-gated honesty banner:

[lean-ctx] no compression applied (mode=signatures): output was not smaller
than the file — returning full content (N tok)

Tests: cap_to_raw_labels_silent_fallback_for_compressed_request,
cap_to_raw_stays_silent_for_verbatim_full_request,
cap_to_raw_notice_never_breaks_the_361_cap.

Still open

The exact trigger for the out-of-root case was not reproduced end to end; a
/tmp vs /private/tmp path-normalization mismatch in the cache key is the
leading hypothesis and would also explain the ctx_delta "no cached version"
right after a successful read. Tracked separately if it recurs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcostgain / metering / savings ledgermcpMCP server / toolspriority: highImportant — schedule soonstatus: integratedFix merged to main but NOT yet in a tagged release

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions