fix(nhis): skip the last-logged update on read-only storages - #158
Merged
Merged
Conversation
The NHI token exchange called updateLogged unconditionally, while the password path guards it with `if (!storage.readonly)` in confirmLog. Under file storage that made the exchange fail outright: FileStorage.updateLogged throws `Method not implemented.` SYNCHRONOUSLY — it is not async — so the `.catch()` on the returned promise never attached and the throw propagated as a 500. The effect was that an NHI could not obtain a session at all under file storage, even though everything else on that path works: getUser is a read FileStorage implements, and it carries an `nhi` field through verbatim. This was the only thing standing between a file-storage deployment and a working exchange. Fixed by applying the same readonly guard the login path already uses, so the two call sites agree. Two unit tests pin it: that the storage declares itself readonly (the flag callers must branch on), and that updateLogged throws synchronously — the second is what makes a `.catch()` insufficient, so if it ever becomes an async rejection the test fails and the guard can be removed. Found while giving the data-fair/agents dev stack fixture NHIs so its autonomous agents could complete a real token exchange in dev rather than only in staging. Co-Authored-By: Claude Opus 5 (1M context) <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.
The NHI token exchange no longer calls
updateLoggedwhen the global storage is read-only. This is the samereadonlyguard the password login path already uses inconfirmLog.Why: with file or LDAP storage, an NHI could not get a session at all.
FileStorage.updateLoggedandLdapStorage.updateLoggedthrowMethod not implemented.synchronously, so the.catch()on the returned promise never attached and the exchange failed with a 500. Found while seeding dev NHIs for the data-fair/agents stack.Two unit tests in
file-storage.unit.spec.tspin that the storage declares itselfreadonlyand thatupdateLoggedthrows synchronously.