(diag): log Realtime session-verify failure context

Temporary instrumentation to diagnose the 'Session is not valid.' failure
on appwrite-labs/cloud#3214's Realtime (dedicated) E2E. Emits:
  - project ID in scope
  - user ID from the session payload
  - whether the user document was found in the project DB
  - session count on the returned user document
  - session-secret prefix being verified
  - sessionVerify result

This will reveal whether the race is (a) user doc missing in project DB
(routing/provisioning issue) or (b) user doc found but sessions array
empty or mismatched (session write path issue). Revert once the root
cause is identified.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jake Barnby
2026-04-17 23:08:44 +12:00
co-authored by Claude Opus 4.7
parent 4da9873b83
commit 4e928ee08b
+15 -5
View File
@@ -939,11 +939,21 @@ $server->onMessage(function (int $connection, string $message) use ($server, $re
$proofForToken = new Token();
$proofForToken->setHash(new Sha());
if (
empty($user->getId()) // Check a document has been found in the DB
|| !$user->sessionVerify($store->getProperty('secret', ''), $proofForToken) // Validate user has valid login token
) {
// cookie not valid
$sessionSecret = $store->getProperty('secret', '');
$userFound = !empty($user->getId());
$sessionsInDoc = $userFound ? \count($user->getAttribute('sessions', [])) : 0;
$sessionVerified = $userFound && $user->sessionVerify($sessionSecret, $proofForToken);
if (!$userFound || !$sessionVerified) {
Console::warning(sprintf(
'[realtime-auth-diag] project=%s userId=%s userFound=%s sessions=%d secretPrefix=%s verified=%s',
$projectId ?? '(null)',
$userId,
$userFound ? 'yes' : 'no',
$sessionsInDoc,
\substr($sessionSecret, 0, 8),
$sessionVerified ? 'yes' : 'no'
));
throw new Exception(Exception::REALTIME_MESSAGE_FORMAT_INVALID, 'Session is not valid.');
}