Skip to content

fix(api): a session refused over its Stream app's keys is answered with the refusal, not a 500 - #2354

Merged
Nash0x7E2 merged 1 commit into
mainfrom
fix/api-refusal-keys-message
Nov 24, 2026
Merged

Nash0x7E2 merged 1 commit into
mainfrom
fix/api-refusal-keys-message

Conversation

@thesyncim

Copy link
Copy Markdown
Member

Problem
#2295 refused a session on a deployment whose Stream app keys Stream rejects with its own sentence. A fork reached that refusal through refusedRequest, and so did an app-mode create whose own app rejects its keys. #2295 relied on refusedRequest answering any error as a 400 with the error's text. #2248, already on #2295's branch, had changed that: an error refusedRequest does not recognise is now a 500 "something went wrong". These paths never answered correctly on main. Their tests in SelfHostedSessionsSuite and AppModeSessionsSuite could not run until #2341 fixed the package's compile, so integration (api) fails on every PR.

Fix

  • refusedRequest (money.go) answers ErrNoStreamKeys and ErrStreamKeysRejected through unkeptAnswer, as not_configured. Create, fork, resume, voice and the socket now give this refusal the same code and status.
  • In app mode, unkeptIn (session/stream_keys.go) maps Stream's 401 for an app's own keys to a new ErrAppStreamKeysRejected. That error is a caller mistake, answered as invalid_request in our own words. It names no deployment variable and none of Stream's text. Before, the raw StreamError went through as a 500.
  • Create and fork log Stream's answer as create did before (logUnkept). A resume answers correctly but does not log the cause.

Tests

  • TestAForkOnKeysStreamRefusesNamesTheKeysWithNothingOfStreams caught a fork answered as a 500. It now also asserts not_configured. It failed on main with 500 "something went wrong".
  • TestAPersistedTextSessionIntoAnAppRefusingItsKeysIsNotTheDeploymentsToFix caught an app's refused keys answered as a 500. It failed on main with a 500. It now also asserts invalid_request and our sentence, and that Stream's "api_key not valid" stays out of the body. Without that last check, putting back the old catch-all invalidRequest(err.Error()) would pass.
  • TestInAppModeTheAppIsTheCustomers (unit) now expects ErrAppStreamKeysRejected without STREAM_API_KEY, where it expected nil.
  • Both suites passed 3 times with -count=3. Five mutants were each killed: no unkept case in refusedRequest, the app-mode branch returning nil, the app refusal answered not_configured, the old catch-all, and the app refusal dropped from callerMistakes.

…th the refusal

A fork, a resume and an app-mode create on a Stream app whose keys Stream refuses answered
a 500 saying only that something went wrong. refusedRequest now answers the deployment's
refusal as not_configured on every path, and an app's own refused keys are a refusal of
their own, answered as invalid_request without the deployment's variables.
@thesyncim thesyncim added the data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review label Nov 24, 2026
func (s *Server) logUnkept(customerID string, err error) {
if found, ok := errors.AsType[*session.UnkeptError](err); ok {
s.logger.Warn("a session that is not incognito has no Stream app to be kept in",
"customer", customerID, "error", err, "cause", found.Cause)

@thesyncim thesyncim left a comment •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — the app-mode/deployment-mode split and moving unkeptAnswer into refusedRequest are clean.

Just need to clear the CodeQL alert on session_create.go:89 (false positive since UnkeptError.Error() is a static string, but it's failing CI).

@Nash0x7E2
Nash0x7E2 merged commit 6251dc8 into main Nov 24, 2026
12 of 14 checks passed
@Nash0x7E2
Nash0x7E2 deleted the fix/api-refusal-keys-message branch November 24, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data-layer-review: ready Data layer review fix: passed automated review, merges cleanly, ready for a human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants