fix(auth): make writes visible to reads while credentials are injected - #2104
Open
yuyang27 wants to merge 1 commit into
Open
fix(auth): make writes visible to reads while credentials are injected#2104yuyang27 wants to merge 1 commit into
yuyang27 wants to merge 1 commit into
Conversation
`Auth.all()` returns the injected snapshot (or the `MIMOCODE_AUTH_CONTENT` fallback) and never consults the file when one is present, but `set`/`remove` only wrote the file. So while either channel is active, a write landed on disk and every later read in that process kept returning the pre-write state: an OAuth token refresh, a key rotation or a logout looked like it succeeded and changed nothing until the process restarted. The env channel had this defect before `inject` existed — a refresh inside a workspace child was invisible to that same child. A mutation through this service is authoritative, so the snapshot now moves with the write. It is updated only *after* the write lands: moving it first would leave the in-memory credentials ahead of the file on a failed write, and the next process would silently run on the old ones. An embedding host that re-injects from the file on its own schedule converges on the same content. Tests: `set`/`remove` visible to later reads with `inject` active, the same for the env channel, and a failed write leaving the snapshot untouched (flip-verified — moving the update before the write turns that one red).
Contributor
Author
|
@MiMoHardFather 麻烦review下 |
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.
Auth.all()returns the injected snapshot (or theMIMOCODE_AUTH_CONTENTfallback) and never consults the file when one is present, butset/removeonly wrote the file. So while either channel is active, a write landed on disk and every later read in that process kept returning the pre-write state: an OAuth token refresh, a key rotation or a logout looked like it succeeded and changed nothing until the process restarted.The env channel had this defect before
injectexisted — a refresh inside a workspace child was invisible to that same child.A mutation through this service is authoritative, so the snapshot now moves with the write. It is updated only after the write lands: moving it first would leave the in-memory credentials ahead of the file on a failed write, and the next process would silently run on the old ones. An embedding host that re-injects from the file on its own schedule converges on the same content.
Tests:
set/removevisible to later reads withinjectactive, the same for the env channel, and a failed write leaving the snapshot untouched (flip-verified — moving the update before the write turns that one red).Issue / context (if applicable)
Type of change
Bug fix / New feature / Refactor / Documentation — keep the ones that apply and delete the rest.
What does this PR do?
Briefly describe the problem, what changed, and why this approach works.
How did you verify your code works?
What did you test, and how can a reviewer reproduce the result?
Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist