Skip to content

fix(loop): drive compaction from full request counts - #58

Merged
Brian Krabach (bkrabach) merged 3 commits into
mainfrom
fix/measured-compaction-from-provider-counts
Sep 16, 2026
Merged

Brian Krabach (bkrabach) merged 3 commits into
mainfrom
fix/measured-compaction-from-provider-counts

Conversation

@bkrabach

Copy link
Copy Markdown
Collaborator

Summary

This final Loop change lets measured compaction use a provider's native request count when both optional contracts are available: context.measured_request_view and request_budget:provider_count.

  • It freezes request overlays, tools, and factory output once per request; Context receives that frozen request plan while finding a fitting retained view.
  • Context returns the exact counted ChatRequest, and Loop commits the selected retention transaction immediately before dispatch before sending that same object.
  • Provider-count pressure uses the existing provider budget, with 80% trigger / 50% target behavior and at most nine count attempts.
  • The measured path preserves cancellation rollback and the existing input hard guard. Its one-shot strict-400 recovery begins from the measured base view; a recovered or uncounted stream leaves foreground usage stale rather than inventing a count.
  • Foreground usage keeps Context-owned recorder ownership across turns, including zero-cache responses and helper activity between or during turns.

Compatibility

This is additive. The measured path is used only when both Context and the selected provider advertise their optional capabilities. Existing request-budget preflight, estimate-based retention, request overlays, required-content protection, and canonical context behavior remain unchanged otherwise.

There are no new configuration defaults, provider-specific imports or calibration, dependency changes, or breaking public API changes.

Validation

  • Candidate suite: 357 passed, with 1 optional Context-collection skip.
  • Focused runtime coverage: 83 tests, including measured dispatch, strict-400 recovery, cancellation/rollback, finalization, exact request identity, and stream accounting.
  • Cross-module validation against the producer changes passed all 15 joint checks; the SDK boundary was exercised with synthetic full-request projections and byte-identity assertions, not a claim of native-token accuracy or performance.
  • No live provider calls were used.

Release sequence

  1. The upstream producer changes are already merged and green: Context #43 (main CI) and Anthropic #122 (main CI).
  2. This is the final consumer change. Its PR CI installs the released amplifier-core==1.5.2 and is the remaining public validation gate.
  3. No merge or auto-merge is requested by this PR publication step; subsequent after-green gating remains separate.

Generated with Amplifier

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
Generated with Amplifier

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
Generated with Amplifier

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
@bkrabach
Brian Krabach (bkrabach) merged commit 2d8ff2b into main Sep 16, 2026
5 checks passed
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.

2 participants