Skip to content

fix(runtime): refresh fallback policy before turn start - #272

Merged
OmarB97 merged 1 commit into
mainfrom
fix/live-fallback-policy-refresh-telemetry-20260713
Jul 13, 2026
Merged

fix(runtime): refresh fallback policy before turn start#272
OmarB97 merged 1 commit into
mainfrom
fix/live-fallback-policy-refresh-telemetry-20260713

Conversation

@OmarB97

@OmarB97 OmarB97 commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Refresh cached desktop/TUI fallback policy inside the active profile context and publish session.info before message.start or any model request.

Live evidence

The installed desktop profile was changed from fallback_policy: any to local-only while its cached agent remained alive. The next turn enforced the refreshed policy inside run_conversation, but the desktop footer still displayed Fallback any throughout the request, leaving operator telemetry unable to prove that cloud substitution was blocked.

Change

  • refresh the cached agent fallback policy after per-session model sync and inside the session profile override
  • emit the effective policy before the UI enters the running state
  • retain the existing in-loop refresh as the enforcement backstop

Verification

  • scripts/run_tests.sh tests/run_agent/test_provider_fallback.py tests/tui_gateway/test_turn_outcomes.py tests/tui_gateway/test_fallback_policy_refresh.py -q — 59 passed
  • focused profile/order test — policy refresh occurs after profile override, then session.info, then message.start, then request
  • Ruff, py_compile, and git diff --check pass

Risk and rollback

The preflight performs one additional read-only config refresh per desktop/TUI turn and emits one extra session snapshot. Revert 58dcc02 to restore the prior event order.

Signed-off-by: Omar B <omar@kostudios.io>
@OmarB97
OmarB97 merged commit 6ba7777 into main Jul 13, 2026
21 of 31 checks passed
OmarB97 added a commit that referenced this pull request Jul 20, 2026
Signed-off-by: Omar B <omar@kostudios.io>
Co-authored-by: Omar B <omar@kostudios.io>
OmarB97 added a commit that referenced this pull request Aug 2, 2026
…#291)

PRs #269 and #272 added fallback-policy plumbing to the shared turn
prologue (`_refresh_fallback_policy`, `_emit_pending_fallback_notice`)
and structured status emission to the fallback activation path
(`_emit_fallback_status`, which reads `self.status_callback` directly).

Three test files build agents that deliberately bypass `__init__` —
either `AIAgent.__new__(AIAgent)` or a hand-rolled `_FakeAgent` — and
were never updated with the new attributes, so they raise
AttributeError as soon as the prologue or fallback path runs. This is
test-side only: `agent_init.py` sets `status_callback` unconditionally
during real construction, so no shipped code path is affected.

In `test_compressor_fallback_update.py` the breakage was masked: the
missing `status_callback` raised inside `try_activate_fallback`, whose
`except` swallowed it, logged "Failed to activate fallback", and
recursed through the rest of the chain before failing on the terminal
status emit.

Stubs match the convention already used by tests/agent/test_turn_context.py.

Co-authored-by: Omar Baradei <omar@kostudios.io>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant