Repository navigation
fix(desktop): recover invalid connection context - #2963
jackie-cqz wants to merge 5 commits into
Conversation
hidb4ai
left a comment
There was a problem hiding this comment.
No confirmed correctness defect found in the recovery changes. Merge validation is still incomplete: the current CI preflight failed during Git checkout (TLS/HTTP2 fetch errors), so Desktop validation and the downstream checks were skipped. Please obtain passing checks for the current head and its merge result before merging; this checkout failure is not evidence of a code regression. Packaged Desktop acceptance also remains pending; renderer tests with mocked IPC and native loopback HTTP fixtures do not establish that acceptance.
The optional DesktopState.retryGeneration field expands the native IPC contract. There are no database or migration changes.
| <Button | ||
| size="sm" | ||
| variant="outline" | ||
| disabled={busy || contextPending} |
There was a problem hiding this comment.
[P2] Reset the busy flag on interruption
If a space switch starts while Home statistics are still loading and then fails during a transient outage, the statistics effect cleanup invalidates its ticket without clearing busy, leaving Retry read disabled even after the service returns. Reset the canceled read's busy state when entering interruption so the original space can be recovered.
knqiufan
left a comment
There was a problem hiding this comment.
Reviewed commit af56b235.
Requesting changes for 2 blocking P2 gaps in #2937 recovery (plus 2 small P3 feedback items):
- P2 (blocking): Preserve the verified service when
retry_connectionsucceeds on identity verification but the original Scope is revoked (session.rs, follow-up on #2963 (comment)). - P2 (blocking): Opening the scope picker in
desktop/ui/src/app/TopBar.tsx(ScopeMenu, around lines 348–360) callsdesktopApi.scopes(), which runs nativeidentity_unchangedand clearsactiveon deployment replacement. CurrentlyScopeMenuonly renders a dropdown error and never callsrefreshConnectionState, leaving stale Home scope/statistics on screen and preventing the user from ever clicking another space to triggeronSelectScoperecovery. (The test helperselectOtherSpaceinapp.test.tsx:367-376mockedscopesas succeeding, masking this native path.) Please reconcile global connection state whendesktopApi.scopes()fails. - P3 (non-blocking): Clear stale
nativeErrorafter a successfulRetry readrecovery (App.tsx), and optionally surface a brief error on permanentRetry readinvalidation (Overview.tsx, without duplicating PR#2960's Home service-selection UI).
| Err(error) => { | ||
| if !Self::retryable_interruption(error.code) { | ||
| inner.interrupted = None; | ||
| // Publish a new generation when the retry handle is retired. | ||
| self.invalidate(&mut inner)?; | ||
| } | ||
| return Err(error); | ||
| } |
There was a problem hiding this comment.
[P2] Keep the verified service active when the original Scope is revoked on retry (blocking)
Follow-up on #2963 (comment): after verify_identity confirms the deployment and principal are unchanged (line 417), if interrupted.api.scope(scope_id) returns Forbidden or NotFound, this branch calls self.invalidate(&mut inner)? and leaves active = None, dropping the verified service instead of allowing the user to pick another authorized Scope (inconsistent with check_expected at session.rs:785-797).
Required outcome: when identity verification succeeds but the original Scope returns Forbidden/NotFound, retire interrupted and restore active with scope: None (advancing generation) so the user can choose another authorized Scope on the verified service.
| .then(receiveState, async (error: unknown) => { | ||
| setNativeError(error); | ||
| await refreshConnectionState(receiveState); | ||
| }) |
There was a problem hiding this comment.
[P3] Clear stale switch error after Retry read recovers the connection (non-blocking)
When a scope switch triggers a transient interruption, setNativeError(error) stores the outage globally. After Retry read restores the original scope via onState(next) -> receiveState, nativeError is never cleared, so the outage banner and Manage connections link remain visible across all pages.
Required outcome: clear nativeError in receiveState when transitioning out of an interrupted state back to an active connection (while keeping nativeError intact when a target scope is denied without interrupting the current scope).
| await refreshConnectionState((next) => { | ||
| if (ticket !== request.current) return; | ||
| setBusy(false); | ||
| onState(next); | ||
| }); | ||
| }, |
There was a problem hiding this comment.
[P3] Keep a brief failure explanation visible when Retry read permanently invalidates the session (non-blocking)
When Retry read receives stale_context (e.g. deployment replaced), handleReadFailure stores the error in UsageDashboard local state and then onState(next) unmounts UsageDashboard in favor of FirstRunHome, discarding the error message so the user sees no reason why retry ended.
Required outcome: surface the permanent invalidation error via the existing app-level nativeError feedback (no need to add a Home service-selector UI here, as that is covered by PR #2960).
knqiufan
left a comment
There was a problem hiding this comment.
Reviewed commit 3b58fe0f. All earlier review items are resolved; requesting changes for two remaining P2 edge cases in the new recovery UI paths:
- P2:
Overviewshows "Choose a memory space" even whenactiveis unverified/unreachable andTopBarhides the space picker (including on startup restore with an offline saved server). - P2:
receiveStateonly clearsnativeErrorwhen recovering fromretryGeneration, leaving the stale invalidation banner pinned after reconnecting fromFirstRunHomevia Quick Connect.
| if (props.state.active && !props.state.active.scope) { | ||
| const zh = props.language === "zh"; | ||
| return ( | ||
| <PageFeedback | ||
| kind="empty" | ||
| title={zh ? "选择记忆空间" : "Choose a memory space"} | ||
| > | ||
| <p> | ||
| {zh | ||
| ? "请使用顶部的空间选择器继续。" | ||
| : "Use the space picker above to continue."} | ||
| </p> | ||
| </PageFeedback> | ||
| ); | ||
| } | ||
| if (!props.state.active && props.state.retryGeneration === undefined) | ||
| return <FirstRunHome {...props} />; |
There was a problem hiding this comment.
[P2] Only show "Choose a memory space" when the active service supports listing spaces
ConnectionManager::check_expected (session.rs:840-850) still sets active with scope: None when activate == true even if probing fails or compatibility is unverified (compatibility_verified: false, supported_operations: []). Both startup restore (App.tsx:320-323) and switching to an unreachable/incompatible service (App.tsx:446-452) reach this state. Because TopBar.tsx:84-86 hides the space picker whenever list_scopes is unsupported and active.scope is null, Home hides FirstRunHome and directs the user to a space picker that isn't rendered.
Please gate this branch on list_scopes support (matching TopBar.tsx:84-86), and fall back to FirstRunHome when there is no scope, no list_scopes support, and retryGeneration === undefined.
| if (next.active && previous?.retryGeneration !== undefined) { | ||
| setNativeError(null); | ||
| } else if ( | ||
| readError != null && | ||
| !next.active && | ||
| next.retryGeneration === undefined | ||
| ) { | ||
| setNativeError(readError); | ||
| } |
There was a problem hiding this comment.
[P2] Stale invalidation banner stays visible after reconnecting via Quick Connect
After permanent invalidation sets nativeError and returns Home to FirstRunHome, reconnecting via "Connect an existing service" calls receiveState(selected) with previous.active == null and previous.retryGeneration === undefined. Because line 230 only clears nativeError when previous?.retryGeneration !== undefined, the old invalidation error stays pinned above the newly connected workspace.
Please clear nativeError whenever a connection transitions from disconnected to active (if (next.active && !previous?.active)), which covers both retry recovery and Quick Connect while keeping target-scope errors on an active connection.

Which issue or RFC does this PR close?
Closes #2937.
Rationale for this change
When a Server is replaced at the same endpoint, the Desktop native layer invalidates the active connection. Home statistics, Retry read, and top-bar space selection could leave the renderer on the old space. The saved service then lacked an explicit activation action.
What changes are included in this PR?
Are there any user-facing changes?
Home and the space switcher discard stale context after permanent invalidation. A temporary interruption offers Retry read and restores the same space once the original Server is verified. A denied target scope leaves the current space available.
How was this change tested?
Local validation on macOS Apple Silicon, based on upstream master
667f77e8.vitest runpassed 92 frontend tests using mocked Desktop IPC.cargo test --locked --manifest-path desktop/src-tauri/Cargo.toml --test deployment_identitypassed 32 tests with loopback HTTP fixtures.cargo run --locked --manifest-path desktop/src-tauri/Cargo.toml --example export_ipc -- --check.cargo clippy --locked --manifest-path desktop/src-tauri/Cargo.toml --all-targets -- -D warningspassed on Rust 1.95.0.vite build, andgit diff --checkall passed. The repository hooks also passed withuv run --locked prek run -a.Packaged Desktop acceptance remains pending.
AI usage statement
OpenAI Codex (GPT-6) implemented the fix and regression tests, reviewed the diff, and ran local verification.