Skip to content

feat(context): compact measured requests and isolate foreground usage - #43

Merged
Brian Krabach (bkrabach) merged 4 commits into
mainfrom
fix/provider-counted-request-views
Sep 16, 2026
Merged

Brian Krabach (bkrabach) merged 4 commits into
mainfrom
fix/provider-counted-request-views

Conversation

@bkrabach

Copy link
Copy Markdown
Collaborator

Summary

Adds the optional context.measured_request_view capability to context-simple when token_meter: "actual" is enabled. It lets a compatible orchestrator count the complete provider-facing request and preserve the exact counted envelope for dispatch.

Behavior and compatibility

  • Context provides a single notice-inclusive candidate snapshot; the orchestrator owns its overlays and the provider-count callback.
  • Provider input counts drive the existing configured trigger and target across no more than the existing eight legal compaction rungs. Protected floors are reported honestly, and a known hard-limit oversize fails closed.
  • Missing or malformed soft measurement safely rolls back to the original counted view or the legacy actual-meter path; staged sticky decisions use a cancellation-aware transaction and commit predicate immediately before dispatch.
  • Required system, developer, human/reminder, protected-tool, and tool-pair boundaries remain protected. Compaction notices remain qualitative rather than presenting local estimates as provider token totals.
  • Foreground-usage ownership is persistent: after the claimant records scoped foreground usage, the broad generic response hook remains observational, including between requests.
  • The capability is optional and negotiated. Older callers and non-participating orchestrators retain their prior paths. No new user configuration, Core/dependency/SDK, or CI changes are included. Breaking changes: none.

Validation

  • Offline exact-archive validation with released Core 1.6.1: Context suite 209 passed, 1 existing expected xfail; no live count or model calls.
  • Focused coverage: 33 new measured-view cases and 19 existing hard-fit cases passed. Eleven shared R2 regression cases were confirmed failing before commit 36688f52c803958037b53715fddf1fca2e7c9ba1, without fixture errors.
  • Exact-candidate coupled validation: 15 passed using Loop a9544aa70f16e3dca38596c56963fac2c072c7ec and Anthropic 421e4506d91b7814c9653f4376d3a24bfbf5b444 (10 measured-path, 2 strict-400, 3 finalization/import), with SDK-boundary mocks. The oracle was synthetic canonical-JSON UTF-8 projection bytes, not native-token-accuracy, live-provider, performance, or quality evidence.

Release sequence

Context may merge independently of the Anthropic producer. The Loop consumer follows only after both producers are merged and their exact main CI is green; its publication happens afterward. This PR includes no host rollout, merge, auto-merge, review bypass, or administrative action.

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>
Generated with Amplifier

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