Skip to content

The de-hardcode guard was blind to floats — and something was already through it (#124/#441) - #2342

Merged
joelteply merged 2 commits into
canaryfrom
fix/dehardcode-guard-float-ratios
Aug 21, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/dehardcode-guard-float-ratios

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Two commits, one theme: magic numbers I wrote, and the guard that should have stopped me.

1. Remove comparable_at + its invented 2.0 (#441)

Landed and removed same day. Three defects: the constant was invented; the method had zero production callers; and each of three seed rows carried a comment promising "consumers get comparable_at() == false" — asserting a reader that was never written, the same lying-receipt class as #151/#357.

Architecturally wrong too: whether two operating points are comparable is a consumer's judgement against the lease/handle it holds — not a rule a data struct asserts for every caller. measured_at_window stays: recording what a number describes is provenance; judging it is not the struct's job.

2. Close the hole that let it through (#124)

The guard fires on const NAME: <int> = <literal> when NAME says WINDOW/CONTEXT/TOKEN/…. Its type list stopped at the integers, so WINDOW_COMPARABILITY_FACTOR: f64 = 2.0 matched the name rule, was a bare literal, and sailed through on the type alone. A guard that an f64 annotation defeats teaches one lesson: type your magic number as a float.

Now covers f32/f64, with a digit-led single-decimal-point literal test (1.5 matches; A.b/1..2 don't).

Positive control — it caught a real one on the first run, not mine:

recall_faculty.rs:70 — const RECALL_WINDOW_FRACTION: f32 = 0.10

10% of every citizen's served window, spent on recall, invented and never derived. Fixed the way the guard's own message prescribes: ContextBudget::recall_tokens() over RECALL_DENOM, so it scales with the served window instead of being a 4k-shaped slice a 1M-context model inherits.

MIN_RECALL_TOKENS untouched — it carries a real context-budget-exempt: receipt (only ever raises a budget, never caps one).

cargo check --tests 0; guard + context_budget + recall suites 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply and others added 2 commits August 20, 2026 19:41
…culative interface, zero callers (#441)

Landed and removed the same day. Three defects in one small addition:

1. MAGIC CONSTANT. `WINDOW_COMPARABILITY_FACTOR: f64 = 2.0` was invented.
   Nothing derives it. The doc rationalised 2x after the fact.

2. ZERO PRODUCTION CALLERS. `comparable_at()` was never called anywhere in
   the tree. A predicate built for consumers that do not exist.

3. A LYING COMMENT, which is the worst of the three. Each of the three seed
   rows carried "consumers get `comparable_at() == false` rather than a
   silent assumption" — asserting a reader that was never written. Same
   class as #151/#357, authored while fixing that class.

ARCHITECTURALLY it was also the wrong shape (Joel): whether two operating
points are comparable is a CONSUMER's judgement, made against the lease/handle
it already holds. It is not a rule a data struct asserts for every caller in
the tree. We have consumer/handle interfaces for this; I bolted on a bespoke
free predicate instead of using them.

`measured_at_window` STAYS. It is provenance — it says what the number
describes, and its absence caused a real live mis-attribution. A field that
records a fact is not the same as a predicate that judges one.

cargo check 0.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…hing was already through it (#124)

THE HOLE. The guard fires on `const NAME: <int> = <literal>` when NAME says
WINDOW/CONTEXT/CTX/TOKEN/PROMPT/CHARS. Its type list stopped at the integers,
so ANY window-relative constant typed `f32`/`f64` walked straight past it.
Found the hard way: `WINDOW_COMPARABILITY_FACTOR: f64 = 2.0` (mine, #2339)
matched the name rule, WAS a bare literal, and sailed through on the type.
A guard against invented numbers that a float annotation defeats teaches
exactly one lesson — type your magic number as a float.

A ratio over the window is as much a fresh guess as a count of its tokens.
Now caught the same way: f32/f64 added, and the literal detector accepts a
decimal point (one only, digit-led, so `1.5` matches and `A.b`/`1..2` do not).

WHAT IT CAUGHT ON THE FIRST RUN — not mine, and pre-existing:

    recall_faculty.rs:70 — const RECALL_WINDOW_FRACTION: f32 = 0.10

10% of every citizen's served window, spent on recall, invented and never
derived. Exactly the shape the guard exists to stop, sitting inside the guard's
blind spot. That is the positive control: the hole was real and occupied.

THE FIX is the one the guard's own failure message prescribes — express it as
a fraction on ContextBudget, where it SCALES with the served window instead of
being a 4k-shaped slice a 1M-context model inherits. `ContextBudget::
recall_tokens()` over `RECALL_DENOM`; recall_faculty derives from it via the
existing `from_window` constructor and no longer owns a float.

MIN_RECALL_TOKENS stays as-is — it carries a real `context-budget-exempt:`
receipt saying it only ever RAISES a budget, never caps one.

cargo check --tests 0; context_budget + recall suites 0 (read by exit code).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply merged commit 5a8fc40 into canary Aug 21, 2026
5 checks passed
@joelteply
joelteply deleted the fix/dehardcode-guard-float-ratios branch August 21, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant