Skip to content

fix: expose unavailable provider budget diagnostics safely - #59

Merged
Brian Krabach (bkrabach) merged 2 commits into
mainfrom
lane/gcr-loop
Sep 16, 2026
Merged

Brian Krabach (bkrabach) merged 2 commits into
mainfrom
lane/gcr-loop

Conversation

@bkrabach

@bkrabach Brian Krabach (bkrabach) commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

What changed

  • Emits safe orchestrator:provider_budget unavailable outcomes when an invoked provider-budget path cannot produce a usable native count.
  • Keeps the initial compatibility fallback, post-concrete fail-closed behavior, malformed-budget rejection, cancellation propagation, and behavior for providers without the optional counting capability unchanged.
  • Makes unavailable diagnostic-hook failures best effort without logging exception tracebacks that could carry request data.

Why

A missing native count should be observable without fabricating numeric measurements or changing compaction policy.

Compatibility

orchestrator:provider_budget can now emit result: "unavailable". These payloads omit fields such as estimated_input_tokens, input_limit_tokens, and context_token_budget; consumers must branch on result and treat those numeric fields as optional.

Known diagnostic-label nuance: an allow_unproven recovery probe after a server-overflow path can be reported as initial_fallback with attempt > 0. This is diagnostic labeling only; policy and recovery behavior are unchanged.

No dependency changes or breaking changes are intended beyond the additive diagnostic outcome above.

Validation

  • Offline loop suite: 366 passed, with 1 existing OpenAI-dependent module skipped.
  • Executed command: pytest -q -p no:cacheprovider -m 'not live' tests, in an isolated environment with Python 3.12.3 and Core 1.6.1.
  • Seven coupled integration checks passed, and changed-file Ruff checks reported no diagnostics.
  • Synthetic request fixtures exercised the unavailable, malformed, cancellation, initial-fallback, and post-concrete-failure paths.

Joint live validation with Gemini #50 and the existing Context implementation preserved native measured-compaction behavior in both streaming modes: 879,659 native input tokens reduced to 443,422, below the effective 499,600 target. The next ordinary request remained at 443,643 native tokens (nonstreaming) and 443,642 (streaming).

The SDK prompt counts matched three of four comparisons exactly. Nonstreaming next-request SDK usage was 443,945, a 302-token (0.0681%) difference within the predeclared 1% tolerance. The final run's 10 count requests and four generations all returned HTTP 200, with no unavailable/estimate fallback. Normalized payload parity, required instructions, final five tool pairs and durable removal of the oldest full tool body were verified.

Live scope was the Gemini Developer API, gemini-3.8-flash, SDK 2.23.0, synthetic history and declared tools with mode NONE; it does not establish endurance or live post-compaction tool-execution coverage. Earlier harness failures are separate from this final successful run.

Independent read-only review found no ship blockers. The initial commits' unexecuted-test notes describe creation time; the final candidate was subsequently validated as above.

Emit orchestrator:provider_budget with result="unavailable" whenever an
invoked request-budget path yields no usable native count, so a session
that silently fell back to estimate-based compaction is visible.

Why: a live run produced zero orchestrator:provider_budget events while
check_request_budget and count_measured_request returned None silently.

Scope: diagnostic only. The initial compatibility fallback, the
post-concrete fail-closed error, malformed-decision rejection, return
types, policy target, compaction stages, retries and the success event
schema are unchanged. A provider that never advertised request_budget
keeps its historical silent path. Emits are best-effort and never
swallow cancellation.

Verified: source-only lane -- AST parse, compileall, git diff --check.
Test suites not executed here; the manager runs them in the DTU.
Breaking changes: none.

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 20aac7a 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