Repository navigation
fix(tenantctx): expire cached user context by CLI version and age - #610
Merged
Merged
Conversation
|
👋 ejacquier, thanks for creating this pull request! To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team. Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks! |
tarcisiozf
previously approved these changes
Oct 6, 2026
- logout uses tenantctx.ClearContext instead of inline removal - cache tests use testutil.IsolateCLIHome so Windows runs don't touch the real ~/.cre - replace fakeJWT with testjwt helper; tighten doc comments Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stamp each context.yaml entry with cli_version and fetched_at; bearer users refetch when the version differs or the entry is older than 24h, falling back to the cached copy if the refetch fails. This replaces deleting the cache on token refresh and after cre update, which raced with concurrent cre processes, never ran on Windows or for non-`cre update` installs, and discarded valid caches on every refresh. Temp files are now unique per write so concurrent refreshes don't clash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anirudhwarrier
approved these changes
Oct 8, 2026
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 DEVSVCS-6566: for bearer-token users the tenants cache (
~/.cre/context.yaml) was only refreshed oncre login, so new environments or server-side tenant config changes stayed hidden until a manual re-login.Each cached environment entry is now stamped with
cli_versionandfetched_at. On commands that load user context, bearer users refetch when:cre update, Homebrew, install script, manual download, Windows), orcontextTTL), orAPI-key users are unchanged (always fetch). If a bearer refetch fails (e.g. offline), the stale cached copy is used, preserving today's behaviour.
An earlier iteration of this PR deleted the cache on token refresh and after
cre update. That was replaced because it raced with concurrentcreprocesses (one process deletingcontext.yamlbetween another's existence check and read), never ran on Windows or for non-cre updateinstalls, and discarded a valid cache on every token refresh.Changes
internal/tenantctx:EnvironmentContextgainsFetchedAt/CLIVersion(omitempty);FetchAndWriteContextstamps them;EnsureContextusesisFreshinstead of an existence check and falls back to the cache on fetch failure.writeContextFileuses a unique temp file per write so concurrent refreshes can't clobber each other.ClearContext()added.cmd/root.go: setstenantctx.CLIVersion = version.Version(direct import would create acmd/version→runtime→tenantctxcycle).cmd/logout: usestenantctx.ClearContext()instead of inline removal.Breaking Changes
context.yamlformat changed incompatibly — no: two optional fields added; older CLIs ignore them, and pre-existing files are refetched onceTesting Verification
internal/tenantctx/tenantctx_test.go:TestFetchAndWriteContext_StampsVersionAndTimeTestEnsureContext_BearerRefetchesStaleCache(expired / different CLI version / pre-stamp file)TestEnsureContext_BearerFallsBackToStaleCacheOnFetchErrorTestClearContext_RemovesFile,TestClearContext_MissingFilego test ./... -short -skip '<make test-quick skip list>'— all packages pass.golangci-lint runon changed packages — 0 issues.go build ./...andgo veton changed packages — clean.🤖 Generated with Claude Code