Skip to content

Summarizer port: coerce the provider budget to a non-negative integer #16

Closed

Description

@SutuSebastian

Parent

#15

What to build

Every completion request that leaves the core summarizer port asks the provider for a whole, non-negative number of tokens, whatever the caller computed. A leaf target that is half of an odd calibrated chunk budget, a heal target, a tiled chunk target and any future producer all arrive at the provider as integers, so a provider that validates the field strictly accepts the call instead of rejecting it and falling to the deterministic truncate.

The coercion belongs at the request boundary, not at the division sites: half a chunk is the intended target, and the provider contract is what needs enforcing. Round to nearest, clamp to at least one, and coerce a non-finite value to that same floor. The reasoning headroom is already an integer and keeps its current placement.

Acceptance criteria

  • A request built from a fractional budget carries an integer maxTokens at the host double, for both a reasoning and a non-reasoning model
  • A request built from a zero, negative, NaN or infinite budget carries the floor of one, plus headroom where it applies
  • A strict host double that rejects a non-integer budget, the way the provider in the report does, fails against the current code and passes after the change (red first)
  • An integer budget produces the same request as before the change, so existing exact-value assertions keep their meaning
  • No change to the ladder, the quality tiers, the metric row shapes or any config surface
  • vp check, bun run test, bun run typecheck and bun run pack pass

Blocked by

None (can start immediately).

Activity

  1. pullfrog commented on Nov 6, 2026

    @pullfrog

    Enrichment for #16 — no duplicate found, ready with a plan.

    Duplicates checked: #15 is the parent report (fractional max_tokens → 422 → truncate fallback), not a duplicate. #18 is the sibling changeset ticket for this same fix, not a duplicate. No other issue matches summarizer / provider / budget / maxTokens / coerce.

    Related context: #15 (parent) holds the wire evidence (540× floating point 5543.5, expected u32 on the direct DeepSeek route, 24.5% of summaries at level 3) and the one-seam decision. #18 is blocked on this ticket and should describe the shipped behavior afterward.

    Plan (seam: requestOf in packages/core/src/llm.ts:435-444, the single builder every adapter and heal path reaches):

    1. Add a small coerceBudget helper next to requestOf: non-finite → 1, else Math.max(1, Math.round(budget)). Apply it to the caller-supplied maxTokens before adding REASONING_HEADROOM (headroom at packages/core/src/llm.ts:28 is already an integer and stays after coercion). Leave the division sites in packages/core/src/compaction-engine.ts:324,416 (leafChunkBudget / 2) untouched.
    2. Red-first test in packages/core/test/llm.test.ts (prior art lines 88-102, doubles in test/support/fake-host.ts): a strict host double that throws on non-integer maxTokens. Drive makeLlm with budgets 1447.5, 0, -3, NaN, Infinity for both a reasoning and a non-reasoning model; assert integer maxTokens on the wire and floor-of-one plus headroom where applicable. Confirm it fails before the fix.
    3. Keep exact-value assertions meaningful: integer budgets produce byte-identical requests as before. No ladder, quality-tier, metric-row, or config-surface changes.
    4. Gates: vp check, bun run test, bun run typecheck, bun run pack.

    Pullfrog  | Implement a fix ➔ | View workflow run | via Pullfrog | Using muse-spark-1.3-contributor | 𝕏

  2. SutuSebastian commented on Nov 6, 2026

    @SutuSebastian
    ContributorAuthor

    Done in 0c70748 on main, not pushed yet.

    The coercion is a providerBudget helper used only inside the request builder: finite values round to nearest and never below one, non-finite values take the same floor, and the reasoning headroom is added after. Neither adapter changes, because both reach this seam.

    Coverage: a strict host double that rejects a non-integer budget with the provider's 422 wording, plus a boundary table across reasoning and non-reasoning models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentSpec or ticket ready for an agent to pick up

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions