[codex] Recover ACP runtime errors from snapshots#296
Draft
ijry wants to merge 1 commit into
Draft
Conversation
Author
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
This PR makes ACP runtime errors recoverable from the live session snapshot. The main user-visible case is a client that was offline or outside the replay window when the server emitted an
AcpEvent::Error, such as:Before this change, a live web client could show that error because it received the realtime event, while MCode/mobile or any reconnecting client could miss it and hydrate from a snapshot with no error detail.
Root Cause
SessionStatealready captured the latestAcpEvent::Errorinlast_error, butSessionState::to_snapshot()intentionally omitted it. That made the error delivery path realtime-only:AcpEvent::Errorand updatedConnectionState.error.LiveSessionSnapshot.last_error, so clients that missed the realtime event had no durable source for the latest ACP runtime failure.This is why a CodeG web session could show the spend-limit 403 under the input box, but an MCode/mobile client could show nothing or incomplete state after reconnect.
Changes
SessionState.last_erroras optionalLiveSessionSnapshot.last_error.serde(default, skip_serializing_if = "Option::is_none"), so normal snapshots omit it and older clients can ignore it.last_errorwhen a new prompt entersPrompting, matching the existing frontend live reducer behavior where a new prompt clears the visible error scope.SessionLastErrorandLiveSessionSnapshot.last_error.last_error.messageintoSnapshotPatch.lastError.ConnectionState.errorfrom fresh snapshots; for stale snapshots, only fill the error if the current live state does not already have a newer error.SnapshotPatchshape.Compatibility / Client Guidance
The new field is optional and omitted when absent:
Native iOS/Android/MCode clients should treat
last_error?.messageas the snapshot recovery value for the same UI surface that currently consumes realtime ACP error events. The field is not an event replay replacement; it is the latest unresolved runtime error that lets a reconnecting client recover what it missed.Clients should also preserve their realtime ordering rules: if a local state already observed a newer realtime error, an older/stale snapshot should not overwrite it.
Validation
cargo test --no-default-features --features test-utils --lib snapshot_carries_last_error_and_clears_on_next_promptpnpm test src/lib/snapshot-denormalize.test.ts src/contexts/acp-connections-context.test.tsxpnpm exec eslint src/lib/snapshot-denormalize.ts src/lib/snapshot-denormalize.test.ts src/contexts/acp-connections-context.tsx src/contexts/acp-connections-context.test.tsx src/lib/types.tsgit diff --checkNote: the default
cargo test --features test-utilspath on Windows attempted to build the Tauri desktop target and failed before tests because../outstatic assets were not present. The shared/server-side targeted command above avoids the desktop build-script asset requirement and exercises this ACP snapshot logic directly.