fix(audit): kb.audit with tail=0 returns the entire log instead of nothing - #644
Merged
plind-junior merged 2 commits intoJul 30, 2026
Merged
Conversation
kai392
force-pushed
the
fix/critical-issue-zero-tail-returns-all
branch
from
July 30, 2026 15:21
e0b326b to
de2b59d
Compare
`kb.audit` windowed with `events[-tail:]`. that reads as "the last n" and is wrong at the boundary: `-0` is `0`, so `tail=0` slices from the start and returns every event the viewer can see — the opposite of the bound asked for. a negative tail is worse, dropping that many off the front and returning the rest. `tail` is caller-supplied on all three surfaces — the mcp tool signature, the jsonl `params.tail`, and the cli `--tail` — and the expression was copy-pasted into each, which is the surface drift CLAUDE.md warns about. so the clamp lands once in `audit.tail_events` and all three call it. `retrieval_events.read_events` had the same `[-limit:]` boundary, guarded by `limit >= 0` which lets zero through. fixed alongside, since it is the same defect rather than a second concern.
There was a problem hiding this comment.
Pull request overview
Fixes a boundary-condition bug where kb.audit with tail=0 (or negative) could widen the result window and return the entire visible audit log, by centralizing the tail-window logic and applying the same guard to retrieval event log reads.
Changes:
- Introduce
audit.tail_events()to ensure non-positivetailreturns an empty list (never widens the window). - Update MCP (
server.py), JSONL (jsonl_server.py), and CLI (cli.py)kb.auditsurfaces to delegate tail-windowing toaudit.tail_events(). - Add regression tests for
tail<=0behavior and updateretrieval_events.read_events(limit=...)to avoid the same[-0:]widening; document the fix inCHANGELOG.md.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_jsonl_server.py | Adds a JSONL-surface regression test asserting kb.audit with tail=0 returns no events. |
| tests/test_audit.py | Adds unit tests pinning audit.tail_events behavior for positive and non-positive tails and ensuring “newest N” selection. |
| src/vouch/server.py | Switches MCP kb_audit to use audit.tail_events instead of events[-tail:]. |
| src/vouch/retrieval_events.py | Prevents limit=0 (and other non-positive limits) from returning the whole retrieval-events log via [-0:]. |
| src/vouch/jsonl_server.py | Switches JSONL kb.audit handler to use audit.tail_events instead of events[-tail:]. |
| src/vouch/cli.py | Switches CLI vouch audit to use audit_mod.tail_events instead of events[-tail:]. |
| src/vouch/audit.py | Adds tail_events(events, tail) helper implementing the non-widening tail window semantics. |
| CHANGELOG.md | Records the user-visible behavior change for kb.audit tail=0 and the related retrieval-events limit fix. |
plind-junior
enabled auto-merge
July 30, 2026 18:56
Contributor
|
diff coverage: 100% — every python line this PR changes under |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
the
kb.audittail window moves intoaudit.tail_events, which returnsnothing for a non-positive tail, and the three surfaces call it instead of
each slicing for themselves.
retrieval_events.read_eventsgets the sameguard at its own
[-limit:].Why
the window was
events[-tail:]. that reads as "the last n" and is wrong atthe boundary —
-0is0, so a zero tail slices from the start and returnsthe entire visible log, the opposite of the bound the caller asked for. a
negative tail is worse: it drops that many events off the front and returns
everything after.
on
testwith five events in the log:tailis caller-supplied on every surface —kb_audit(tail: int = 50)in themcp tool,
int(p.get("tail", 50))in the jsonl handler,--tailon the cli —so this is reachable input, not an internal invariant. asking for a bounded
window and getting an unbounded dump of the audit log is the wrong direction
for a read the scoping layer exists to keep narrow.
the expression was copy-pasted into all three handlers, which is the surface
drift CLAUDE.md calls the most common contributor mistake, and the same shape
kb.searchwas consolidated for in #476. so the clamp lands once and thethree call it rather than being patched three times.
retrieval_events.read_eventscarried the identical[-limit:]with alimit >= 0guard that lets zero through. it is the same defect rather than asecond concern, so it is fixed here; say the word if you would rather it were
split out.
What might break
nothing on disk, no method signature or response-shape change. a positive
tail behaves exactly as before —
tail_events(events, 2)is still the lasttwo. the only behaviour change is at the boundary:
tail<=0now yields anempty list where it previously yielded the whole log (or all-but-n). anyone
who was passing
0to mean "everything" was relying on a bug, andkb.audithas no documented spelling for that.
VEP
not a surface change — no vep.
Tests
make checkpasses locally (lint + mypy + pytest)New / changed behaviour has a test
CHANGELOG.mdupdated under## [Unreleased]tests/test_audit.py::test_tail_events_never_widens_the_window—parametrised over
3, 1, 99, 0, -1, so the positive cases pin the existingbehaviour and the boundary cases pin the fix.
tests/test_audit.py::test_tail_events_keeps_the_newest— the window is thenewest end, not the oldest.
tests/test_jsonl_server.py::test_jsonl_audit_zero_tail_returns_no_events—the same assertion through
handle_request, so it fails on the previouscode at the surface rather than only against the new helper.
validation run:
no ui files touched, so no screenshots.