[Bug]: agy session gets trapped in Terminal mode on tui -> chat switch due to checkpoint mismatches [ao_high_water] when turn 1 contains handoff or settings wrappers
What went wrong?
In Agent Orchestrator v0.15.3, switching an agy (Antigravity) session from Chat UI to Terminal (chat -> tui) and then switching back to Chat UI (tui -> chat) deterministically fails with TARGET_HISTORY_UNSETTLED (checkpoint mismatches [ao_high_water]: context deadline exceeded), even when agy ACP session/load completes in ~1.3s.
Unlike slow-provider timeout cases (such as #7697), session_load succeeds immediately here (stage=session_load outcome=ok), and every poll iteration during the 45s settle window deterministically rejects the replayed history due to a text normalization mismatch:
-
Wrapper injection on the initial
agyturn:- When a session switches in-place to
agyviaPOST /api/v1/sessions/{id}/provider-switch(or starts a newagysession with initial model configuration), the first prompt stored inagy's native conversation database (antigravity-acp/conversations/<uuid>.db) wraps the user prompt with:<USER_REQUEST> ... </USER_REQUEST>Standing instructions from Agent Orchestrator... <ao_standing_instructions>...</ao_standing_instructions><ao-handoff-request switch-id="...">...</ao-handoff-request>(onprovider-switch)- Queued message JSON envelope (when delivered via
ao send/ automation) <USER_SETTINGS_CHANGE> The user has changed the model to ... </USER_SETTINGS_CHANGE>
- Meanwhile, Orchestrator's
conversation_messagestable stores only the bare user message text with an emptyprovider_item_id("").
- When a session switches in-place to
-
Incomplete wrapper stripping during
tui -> chatreplay (acp.historicalUserContent):- On
tui -> chat,BridgeConversationToACPbridges the conversation back andsession/loadreplays the native history. captureAOHighWaterselects the highest-sequence user message (highWater["message.user.completed"]). Becauseprovider_item_idis empty for that user message,nativeHistoryCheckpoint.mismatchesfalls back todomain.NativeCheckpointTextMatches(aoText, replayedText).acp.historicalUserContentonly strips the standing-instructions block; it does not strip<ao-handoff-request>...</ao-handoff-request>, queued batch envelopes, or<USER_REQUEST>/<USER_SETTINGS_CHANGE>tags persisted byagy.NativeCheckpointTextMatchestherefore returnsfalseon every poll until the deadline expires with:switch interface <session>: resume chat: wait for settled native conversation history: chat conversation history is not settled: checkpoint mismatches [ao_high_water]: context deadline exceeded
- On
-
Session is permanently trapped in
tuimode with no official API escape hatch:- Sending additional turns inside Terminal (
tui) does not advanceconversation_messagesin Orchestrator's DB, sohighWater["message.user.completed"]remains pinned to the wrapped turn. - Retrying
POST /api/v1/sessions/{id}/interface-transitionwith"historyPolicy": "provider_history"is rejected with HTTP409(PROVIDER_HISTORY_RECOVERY_UNAVAILABLE) becauseChatHistoryMismatchOnlyUntrustedTextonly admitsuntrusted_user_textanduntrusted_assistant_text, notao_high_water. POST /api/v1/sessions/{id}/provider-switchrequiresmode == "chat"(requireChatSession), so it cannot be used fromtuimode either.
- Sending additional turns inside Terminal (
Steps to reproduce
- Start a Chat UI session (for example on
codex), run a few turns, and switch it in-place toagyviaprovider-switch(or start anagyChat session with model configuration changes on turn 1), then complete 1 turn onagy. - Switch the session from Chat UI to Terminal (
chat -> tui). - Switch the session back from Terminal to Chat UI (
tui -> chat). - Observe
ACP start stage ... stage=session_load outcome=okin ~1.3s, followed ~45s later byInterface switch failed: ... checkpoint mismatches [ao_high_water]: context deadline exceeded.
Expected behavior
acp.historicalUserContent(oragyacphistory normalization /NativeCheckpointTextMatches) should strip<ao-handoff-request>blocks, queued delivery envelopes, andagy-injected<USER_REQUEST>/<USER_SETTINGS_CHANGE>wrappers when matching replayed user messages againstao_high_water(or persist a stableprovider_item_idfor user turns).- If an
ao_high_watertext mismatch still occurs due to provider-side prompt wrapping, allow explicit user-confirmed recovery back to Chat UI instead of leaving the session permanently stuck intuimode.
Version
0.15.3
This is a bug report. Check that nobody has claimed it, comment to claim it, and open a PR with Fixes #8677.
See the contributing guide. Think the classification is wrong? Tell us on Discord.
I'd like to work on this. historicalUserContent only strips the <ao-standing-instructions> form, but agyacp sends its standing instructions as the <ao_standing_instructions> lead-sentence block, which Antigravity replays joined to the first prompt. So that message never matches AO's record and the switch times out on ao_high_water. I have a small fix with a unit test that strips that form too; I'll leave the <USER_REQUEST> wrapper part out unless someone can confirm agy replays it.