Skip to content

fix(auth): make writes visible to reads while credentials are injected - #2104

Open
yuyang27 wants to merge 1 commit into
XiaomiMiMo:mainfrom
yuyang27:fix/auth-inject-mutation-semantics
Open

fix(auth): make writes visible to reads while credentials are injected#2104
yuyang27 wants to merge 1 commit into
XiaomiMiMo:mainfrom
yuyang27:fix/auth-inject-mutation-semantics

Conversation

@yuyang27

Copy link
Copy Markdown
Contributor

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).

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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

`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).
@yuyang27

Copy link
Copy Markdown
Contributor Author

@MiMoHardFather 麻烦review下

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