Fix session history after UDS login by binding identity on all ws stream upgrades.

Gateway Remote stream mux starts async session.follow after the sync message
listener returns; without patching every ws copy and awaiting identity, ACL
saw an empty ALS and failed history load as gateway/internal.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-08 19:43:09 +08:00
parent 9a93e9c8ce
commit ba60368f39
2 changed files with 86 additions and 24 deletions

View file

@ -33,6 +33,17 @@ export function runWithUserContext(userContext, fn) {
return userContextStorage.run(userContext, fn)
}
/**
* Persist ALS for the rest of this async execution chain.
* Needed for Gateway Remote stream mux: message handlers are sync but start
* async `pump()` work that continues after the listener returns (so als.run
* alone would exit before session.follow runs).
* @param {object|null|undefined} userContext
*/
export function enterUserContext(userContext) {
userContextStorage.enterWith(userContext ?? null)
}
/**
* Decorator/helper for injecting user context into request handlers
* @param {Function} handler - Request handler function