Skip to content

Retry hosted summary auth and wait out CloudSync drain - #7275

Merged
ComputelessComputer merged 4 commits into
mainfrom
fix/pro-summary-auth-drain
Sep 3, 2026
Merged

Retry hosted summary auth and wait out CloudSync drain#7275
ComputelessComputer merged 4 commits into
mainfrom
fix/pro-summary-auth-drain

Conversation

@ComputelessComputer

@ComputelessComputer ComputelessComputer commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Stable logs showed Pro summary hitting 401 invalid_token, then failing persist with cloudsync_activity_drain_timeout after re-login. Hosted LLM fetch now refreshes on 401, and enhance/chat drain waits 15s for in-flight witness repair instead of 2s.


Note

High Risk
Changes authentication admission semantics, session commit timing, and CloudSync queue interaction—areas that affect sign-in, multi-window auth, and hosted API access.

Overview
Addresses production issues where hosted summary calls failed with 401 invalid_token and summary/chat persistence hit cloudsync_activity_drain_timeout after re-login.

Hosted LLM auth: createAuthFetch now resolves tokens asynchronously, retries once on 401 after refreshAccessToken, and Anarlog-hosted models use getSessionForRequest / refreshSession so requests pick up rotated credentials without rebuilding the transport.

Desktop auth / CloudSync admission: Local account binding returns claimed | mismatch | superseded instead of a boolean, so a superseded bind is not treated as admission and a completed bind still reports mismatch if the DB belongs to another account. The auth provider keeps a committed session ref for headers, admits accounts with a 15s timeout and retries, finishes admission in the background when stalled, and fast-paths TOKEN_REFRESHED for already-admitted users so token updates do not sit behind a jammed CloudSync handshake queue.

Native CloudSync: Non-capture local writes (enhance, chat, etc.) wait up to 15s for activity drain (capture stays at 2s), reducing premature drain timeouts during long witness/repair work.

Reviewed by Cursor Bugbot for commit b223474. Bugbot is set up for automated code reviews on this repo. Configure here.

@netlify

netlify Bot commented Sep 3, 2026

Copy link
Copy Markdown

Deploy Preview for anarlog canceled.

Name Link
🔨 Latest commit b223474
🔍 Latest deploy log https://app.netlify.com/projects/anarlog/deploys/6a991fe6580975000840cb5c

Stable logs showed Pro summary hitting 401 invalid_token, then failing persist with cloudsync_activity_drain_timeout after re-login. Hosted LLM fetch now refreshes on 401, and enhance/chat drain waits 15s for in-flight witness repair instead of 2s.
A refreshed token for the already-admitted account is committed the moment the SDK emits it; it no longer queues behind earlier auth transitions, re-runs local account admission, or waits for the CloudSync handshake. Unadmitted sessions still fail closed, and admission that stalls behind the plugin queue preserves the local session after 15s and finishes admission late (rejecting a mismatch if it turns out to be another account). getHeaders and getSessionForRequest sign with the committed session ref so long-lived closures never send a stale token.
Comment thread apps/desktop/src/auth/context.tsx
Comment thread apps/desktop/src/auth/context.tsx
…ction

Late admission now runs the same tail as immediate admission: re-persist the session when storage was cleared since the event was enqueued and restart the SDK refresh ticker, and the ticker is also restarted as soon as a stalled session is preserved. rejectAuthChange revokes admission up front so a token that arrives during sign-out or account-mismatch cleanup re-runs admission instead of cancelling the rejection and keeping the account signed in.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1a9fb11. Configure here.

Comment thread apps/desktop/src/auth/context.tsx
bindCloudsyncAccountForAuth now reports claimed, mismatch, or superseded instead of collapsing "a newer CloudSync generation preempted me" into true. A bind that actually ran keeps its real answer even if CloudSync moved on, so a concurrent window-focus refresh can no longer mask a mismatch. The auth provider retries a superseded bind up to three times and otherwise keeps the session visible but unadmitted, in both the immediate and the late-admission path.
@ComputelessComputer
ComputelessComputer merged commit 43c3a2e into main Sep 3, 2026
21 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.

1 participant