Repository navigation
feat(policy): make the list reduction legible, and boundable - #36
Merged
Merged
Conversation
Roadmap Horizon 1 item 3, which finishes that horizon.
fold has always answered "context bloat" structurally: per-principal policy
filtering means a caller's tools/list is the subset they may invoke, computed
at egress with no model in the loop. Two things were missing. The reduction was
invisible — nothing said a caller received 12 tools out of 400 — and it was
unbounded, so a large enough federation still handed an agent more context than
anyone had chosen.
fold_list_items_total{method,stage} counts offered, served, and capped. All
three, because a served count without its denominator says nothing about the
reduction it is supposed to demonstrate.
policy.rules[].maxItems bounds what one rule may make visible in a response.
Three properties are deliberate and tested:
It is a bound, not a curation. Items past the cap are dropped in merge order,
because fold has no notion of which tools matter and acquiring one would be the
semantic tool selection the roadmap declines — it would put a ranking model on
the egress path. The order is stable for a snapshot; that it is arbitrary is
documented rather than dressed up.
Truncation is announced three ways: the result's _meta, the audit event's
itemsCapped, and the metric. A cap that silently removed capability would be
worse than no cap, because an agent would simply stop being able to do things
with nothing anywhere saying why.
It bounds visibility, not authority. A name withheld from a list is still
callable if policy allows it, and a test asserts exactly that. The alternative
turns the list path into a second, weaker policy engine and quietly redefines
what fold's invisibility-plus-denial pair means.
All four list methods share one filter rather than four copies of the same
loop, so the guarantee cannot drift per surface. It consults the decision the
filtering already made: BenchmarkFederatedListTools is unchanged at 83
allocs/op and 21,866 B/op, byte for byte with the documented baseline, and the
latency gate reads 180us.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Roadmap Horizon 1 item 3 — which finishes that horizon.
fold has always answered "context bloat" structurally: per-principal policy filtering means a caller's
tools/listis the subset they may invoke, computed at egress with no model in the loop. Two things were missing — the reduction was invisible (nothing said a caller got 12 tools out of 400), and it was unbounded.The metric
fold_list_items_total{method,stage}counts offered, served, and capped. All three, because a served count without its denominator says nothing about the reduction it's meant to demonstrate.served/offeredis the ratio; the dashboard shows it as "Context reduction".The cap, and three deliberate properties
policy.rules[].maxItemsbounds what one rule may make visible in a response._meta["run.fold/truncated"], the audit event'sitemsCapped, and the metric. A cap that silently removed capability would be worse than no cap: an agent would just stop being able to do things, with nothing anywhere saying why.TestCappedToolIsStillCallableasserts it. Otherwise the list path becomes a second, weaker policy engine and quietly redefines what fold's invisibility-plus-denial pair means.Cost
All four list methods share one filter rather than four copies of the same loop, so the guarantee can't drift per surface, and it consults the decision the filtering already made.
Allocations are byte-identical to the documented baseline (21,866 B / 83 allocs); timings within noise of 25.2 µs / 44.9 µs. Latency gate 180 µs.
make checkgreen, lint 0 issues.🤖 Generated with Claude Code