fix: keep compacted request views stable across requests - #41
Merged
Merged
Conversation
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>
Brian Krabach (bkrabach)
added a commit
to microsoft/amplifier-module-loop-streaming
that referenced
this pull request
Sep 15, 2026
## 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix repeated context reduction after a provider-directed rebuild. Previously, an ordinary request below the normal compaction threshold could return the full canonical history instead of applying the existing sticky reductions. A provider guard could then treat that restored content as new growth and request another reduction.
hard_fit=Falseargument tocontext.request_retention. When enabled, target the effective forced budget without applying the ordinarytarget_usagefraction again. Ordinary explicittoken_budgetbehavior remains unchanged.Preserved behavior
Required human messages, retained persisted reminders, the protected tool-result floor, atomic tool pairing, safe tail-notice placement, and irreducible-content errors remain protected. This does not change Core, dependencies, CI, user configuration, provider implementation, or advertised model limits.
Validation
Recorded against this exact candidate in an isolated DTU with Core 1.6.1:
These are deterministic offline mechanism tests, not live-vendor requests, model-quality or cache-performance measurements, or proof of a native context-window ceiling. The downstream loop companion will be published after this producer change is merged.
Changed files
amplifier_module_context_simple/__init__.pytests/test_request_retention.pytests/test_sticky_compaction_and_tail_notice.pyREADME.md