Skip to content

feat(policy): make the list reduction legible, and boundable - #36

Merged
blakebauman merged 1 commit into
mainfrom
feat/toolset-shaping
Aug 11, 2026
Merged

blakebauman merged 1 commit into
mainfrom
feat/toolset-shaping

Conversation

@blakebauman

Copy link
Copy Markdown
Member

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 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/offered is the ratio; the dashboard shows it as "Context reduction".

The cap, and three deliberate properties

policy.rules[].maxItems bounds what one rule may make visible in a response.

  1. A bound, not a curation. Items past the cap are dropped in merge order. 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's arbitrary is documented rather than dressed up as smart.
  2. Truncation is announced three ways — _meta["run.fold/truncated"], the audit event's itemsCapped, 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.
  3. It bounds visibility, not authority. A name withheld from a list is still callable if policy allows it — TestCappedToolIsStillCallable asserts 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.

BenchmarkFederatedListTools/up20_tools50          25,815 ns/op   21,870 B/op   83 allocs/op
BenchmarkFederatedListTools/up20_tools50_policy   44,442 ns/op   21,866 B/op   83 allocs/op

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 check green, lint 0 issues.

🤖 Generated with Claude Code

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]>
@blakebauman
blakebauman merged commit 7471f3c into main Aug 11, 2026
6 checks passed
@blakebauman
blakebauman deleted the feat/toolset-shaping branch August 11, 2026 13:53
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