Skip to content

fix: request hard-fit context rebuilds and expose budget telemetry - #53

Merged
Brian Krabach (bkrabach) merged 3 commits into
mainfrom
lane/sb-loop-fixture-a7ec
Sep 15, 2026
Merged

Brian Krabach (bkrabach) merged 3 commits into
mainfrom
lane/sb-loop-fixture-a7ec

Conversation

@bkrabach

Copy link
Copy Markdown
Collaborator

Summary

Use the context manager's optional hard-fit capability for provider-directed rebuilds, and make provider-budget decisions discoverable by logging hooks.

  • Request hard_fit=True only when a provider preflight asks for a rebuild, in both ordinary generation and finalization paths.
  • Detect keyword-compatible retention callables without catching and retrying implementation-raised TypeError. Old retention signatures and generic contexts keep their existing call shape.
  • Declare orchestrator:provider_budget in the module's observability.events contribution.
  • Add regressions for compatibility, event discovery, and repeated real-module requests after a forced rebuild.

The at-most-one rebuild rule, second preflight, final provider payload guard, required-content retention, tool pairing, and safe notice placement remain intact. No Core, provider implementation, dependency, CI, user configuration, or model-window metadata changes.

Dependency

The context producer change is merged: microsoft/amplifier-module-context-simple#41

Its exact merge commit passed main-branch CI before this downstream publication. Older contexts remain supported through the legacy fallback, with the second preflight still enforcing the provider budget.

Validation

Recorded against this exact candidate in an isolated DTU:

  • Loop full suite with Core 1.6.1: 306 passed.
  • Focused budget, real-module runtime, and retention tests: 40 passed, including the non-skipped test_hard_fit_stays_compacted_across_real_openai_dispatches.
  • Real context manager, streaming loop, and OpenAI adapter with an in-memory SDK: one provider-forced rebuild followed by four ordinary requests. All five dispatched payloads retained the required human messages, reminder, and current tool result without resurrecting removed history. Canonical history remained intact; impossible protected input was rejected locally.
  • Ruff passed for the implementation and all three changed Python test files.
  • Separate Python 3.12 control matching the existing Core 1.5.2 / Foundation lock setup: 305 passed, 1 skipped. That skip is the optional cross-module test because sibling modules are not installed in the per-repo control; it executed successfully in the joint DTU run above.
  • An unchanged real-Anthropic-adapter control produced identical assembled request parameters in the baseline and candidate, using an in-memory SDK.

The regression fixture uses generated supplementary Han characters so its character estimate remains below ordinary compaction's threshold while its serialized UTF-8 size triggers the real provider preflight. It does not replace the budget calculation or weaken the test assertions.

These are deterministic offline mechanism tests, not real-vendor requests, task-quality or cache-performance measurements, proof of a native context ceiling, or a claim that the whole Python CI matrix ran in the DTU.

Changed files

  • amplifier_module_loop_streaming/__init__.py
  • tests/test_provider_budget_guard.py
  • tests/test_provider_budget_context_simple_runtime.py
  • tests/test_request_retention.py
  • README.md

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 c93d980 into main Sep 15, 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