fix(license): recover from stale tokens and cached licenses without manual logout#394
Draft
skyrpex wants to merge 1 commit into
Draft
fix(license): recover from stale tokens and cached licenses without manual logout#394skyrpex wants to merge 1 commit into
skyrpex wants to merge 1 commit into
Conversation
…anual logout A rejected token or a stale cached license.json previously required a manual `lstk logout` before the next start could succeed (DEVX-658). - Definitive license rejections (HTTP 400/401/403) now delete the cached license.json, and interactive starts offer an in-place re-login (auth.Relogin) followed by one retried start with the fresh token. Non-interactive starts emit an actionable ErrorEvent instead of a raw stderr error. - Non-definitive license server responses (5xx outages, 407 from corporate proxies) no longer block the start; the pre-flight degrades and the emulator validates the license at startup, like transport failures already did. - When the container exits with a license failure while a cached license.json that this run did not refresh was mounted (pre-flight skipped, e.g. image already local), the cache is dropped, re-validated against the license server, and the start is retried once. Fixes DEVX-658 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Fixes DEVX-658: after buying/upgrading a license,
lstkcould keep failing license validation until the user ranlstk logoutby hand. The CLI now identifies why the license check failed and recovers on its own where possible.The four behaviors
1. Rejected token → offer re-login and retry (interactive)
When the license server definitively rejects the token (HTTP 400/401/403) — e.g. the stored token predates a license purchase —
lstknow asks:Pressing ENTER drops the old token, runs the normal browser login, and retries the start once with the fresh token. This replaces the manual
lstk logout && lstk logindance.2. Rejected token → actionable error (non-interactive)
Same rejection in CI / piped mode can't open a browser, so
lstkprints a structured error telling the user exactly what to do (lstk logout && lstk login, or set a validLOCALSTACK_AUTH_TOKEN) instead of a raw error string on stderr. In both modes the rejection also deletes the cachedlicense.json, since the server just told us it's no good.3. License server outages no longer block the start
A 5xx from the license server or a 407 from a corporate proxy is not a verdict on the license — but it used to fail the start. These now degrade the same way an unreachable server already did: skip the pre-flight with a warning and let the emulator validate the license itself once it starts. Only real rejections (400/401/403) stay fatal.
4. Stale cached license → refresh and retry automatically
The pre-flight is skipped when the image is already local (offline support), which means a previously cached
license.jsongets mounted as-is. If that cache predates a plan change, the emulator exits with a license error on every run — the exact "stuck after upgrade" report.lstknow detects the license failure in the container logs, drops the stale cache, re-fetches the license (forced, even though the image is local), and retries the start once:No retry loop: if the license was freshly fetched this run, a startup license failure is a real verdict and surfaces as before.
Implementation notes
isDefinitiveLicenseRejection(400/401/403) gates fatal vs. degrade invalidateLicense; resolves the "known limitation" comment about 5xx/407.auth.Relogin= delete stored token + cached license + rerun login flow.startWithLicenseRetryowns the mount + start + stale-cache retry;licenseStartupErrorclassifies license-related container exits from the buffered startup logs.StartOptions.AuthOptionsthreadsauth.WithBrowserOpenerinto the internally builtauth.Authso tests never open real browser tabs.Testing
startWithLicenseRetry),Relogin.TestLicenseRejectionOffersReloginAndRetriesdrives the full interactive PTY flow (rejection → prompt → ENTER → login → retried start against Docker); existing license failure tests updated for the new structured error output.Fixes DEVX-658
🤖 Generated with Claude Code