fix: self-heal stale auth token on translate instead of failing#33
Conversation
A purged/invalid token in chrome.storage.sync made every translation fail with "User not found" (and other token-dependent calls 412) until a full reload. Requests now detect auth-shaped failures, recover the session, and retry once. - isAuthError: detect token failures from the response body (the client discards the HTTP status). Patterns are grounded in the actual modular-rest server output, including the swallowed "Precondition Failed" body for invalid/expired/wrong-signature tokens. - withAuthRetry: reusable wrapper that recovers + retries once on an auth error; wired into TranslateService's three function/run calls. - recoverSession: tears a dead registered session down system-wide via logout() (profile/isLogin/analytics reset + broadcast) then re-auths anonymous; anonymous sessions just re-auth (contained). - single-flight recovery: concurrent failures share ONE loginAnonymous instead of each minting and stranding an anonymous user. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Automated PR ReviewPrimary Task: fix: self-heal stale auth token on translate instead of failing Task alignment✅ Core fix — ✅ Anonymous-login refactor — ✅ Registered-user downgrade path — ✅ Thundering-herd prevention — Two single-flight guards are in place: ✅ Circular-import avoidance — ✅ Commit messages✅ Prior review follow-up(No prior reviews.) Convention check✅ New file ✅ Comments follow the project convention: multi-line JSDoc explaining the why (auth-error detection rationale, the Koa/modular-rest body format, the single-flight guarantee, the late-binding motivation) — exactly what CLAUDE.md encourages. ✅ ✅ No new bundle entries, no CSS/DOM, no manifest changes required. One minor observation (no change needed): VerdictAPPROVE — The implementation is well-designed, thoroughly tested (25+ new unit/integration tests across 3 files), and follows all project conventions. The refactoring of the existing anonymous-login flow is a meaningful correctness improvement, not just scope creep. Generated by Claude Code |
|
🎉 This PR is included in version 1.14.1-dev.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 1.14.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
🏷️ PR Title:
fix: self-heal stale auth token on translate instead of failing
📋 Summary
This PR introduces a fix that enables the system to automatically recover from a stale authentication token during translation requests rather than failing immediately. This improves the robustness and user experience of the translation feature.
🔗 Related Tasks
#6ef3766 - fix: self-heal stale auth token on translate instead of failing
📝 Additional Details
The change ensures that when an expired or invalid auth token is detected during a translate operation, the token is refreshed internally and the translation is retried, minimizing errors and interruptions.
📜 Commit List
6ef3766 fix: self-heal stale auth token on translate instead of failing