Skip to content

Surface truncation instead of silently compacting a partial log window#9

Open
NGHINAI wants to merge 1 commit into
codag-megalith:mainfrom
NGHINAI:feat/truncation-notice
Open

Surface truncation instead of silently compacting a partial log window#9
NGHINAI wants to merge 1 commit into
codag-megalith:mainfrom
NGHINAI:feat/truncation-notice

Conversation

@NGHINAI

@NGHINAI NGHINAI commented Jun 10, 2026

Copy link
Copy Markdown

Implements the minimal fix from #7. All input paths cap collection at 20k lines and kill the child at the cap, keeping the oldest lines and dropping the newest — and nothing in the output said so. For incident debugging that's the wrong slice to keep silently: the incident is usually in the recent lines, and a confident "N→M tok" summary over a partial window reads as full coverage.

This PR makes the behavior honest everywhere it bites:

  • exec.Collect now reports cap-hits (Streamed.HitLimit()); readLines / readNonEmptyLines detect a dropped non-empty line past their caps (trailing blanks don't count).
  • CLI: stderr warning before compaction, for both the line cap and the 90s collection timeout. It prints even with --quiet — coverage is correctness, not chrome — and stays off stdout so pipes/agents get clean output. Happy to gate it on --quiet instead if you prefer.
  • MCP: the tools append [codag] note: input truncated at 20000 lines — the oldest 20000 were compacted and the newest dropped. Narrow the log window (e.g. --since, --tail, --limit) and rerun for full coverage. (and an equivalent note for the 90s timeout), so an agent can react instead of trusting a partial compact.

Demo: codag wrap -- sh -c 'seq 1 25000'

The keep-newest ring-buffer alternative from #7 is deliberately left out — it changes the latency profile (child runs to completion instead of dying at the cap), so it deserves its own discussion. This makes current behavior visible first.

All input paths cap collection at 20k lines and kill the child when the
cap is hit, keeping the oldest lines and dropping the newest — but
nothing in the output said so. An agent (or user) debugging an incident
saw a confident compaction summary computed over a slice that often
excludes the incident itself, since recent lines are the ones that
matter and file reads put them at the end.

Closes the visibility half of codag-megalith#7:

- exec.Collect now reports whether the line cap cut the stream short
  (Streamed.HitLimit), and readLines/readNonEmptyLines detect a dropped
  non-empty line past their caps.
- CLI wrap prints a stderr warning (even with --quiet — coverage is
  correctness, not chrome) for both the line cap and the 90s collection
  timeout, before the compaction starts.
- MCP tools append a "[codag] note: ..." to the returned text for both
  cases, telling the agent to narrow the window (--since/--tail) and
  rerun.

The keep-newest ring-buffer alternative from codag-megalith#7 is left as a follow-up
since it changes the latency profile; this makes the current behavior
honest first.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant