GitHub user dosubot[bot] added a comment to the discussion: localStorage misses 
last_async_event_id

<!-- Answer -->
I see the issue clearly now. Your logs show the **`async_channel_id` is 
changing between requests** - from `3dba366b-a70c-4ab8-9b86-7aaeb4159775` to 
`7e6ba64b-d2e7-4d8c-aff9-58e6ab88bd9f`. This is the core problem.

**Why `last_async_event_id` is never set:** The frontend [only calls 
`setLastId()` when it receives at least one 
event](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/src/middleware/asyncEvent.ts#L169-L183).
 Since `/async_event` returns empty `[]` (no events exist on the new channel), 
`processEvents()` is never called and localStorage never gets updated.

**Why events are empty:** Each time `async_channel_id` changes, you're polling 
a *brand new* Redis stream that has no events. The Celery workers wrote events 
to the old channel (`3dba366b...`), but your poll is hitting the new one 
(`7e6ba64b...`).

**The "Token reset" you're logging** happens because the [after-request handler 
detects a 
mismatch](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/async_events/async_query_manager.py#L167-L195)
 between the async-token cookie and session state. Looking at your logs:
- The async-token cookie likely contains the old channel_id from a previous 
request
- But the session (which you reworked to read from the token) shows the new 
channel_id
- This mismatch triggers regeneration

**The issue with your workaround:** You said "channel comes from token, because 
request doesn't have it at all". If the async-token cookie isn't being sent 
with `/async_event` requests, that's likely a **cookie domain or SameSite 
issue**. Check your browser DevTools → Network tab → click on the 
`/async_event` request → check if `Cookie: async-token=...` is in the Request 
Headers.

**To fix this:**
1. Ensure `GLOBAL_ASYNC_QUERIES_JWT_COOKIE_SAMESITE` is set to `"Lax"` or 
`"None"` (with `Secure=True` if `None`)
2. Ensure `GLOBAL_ASYNC_QUERIES_JWT_COOKIE_DOMAIN` matches your domain exactly
3. If using HTTP (not HTTPS), set `GLOBAL_ASYNC_QUERIES_JWT_COOKIE_SECURE = 
False`
4. Make sure your OAuth flow doesn't clear/recreate the Flask session after the 
async-token cookie is already set

The key is keeping the `async_channel_id` stable across all requests during a 
session - otherwise events get written to one channel but polled from another.


<!-- Dosu Comment Footer -->
*To reply, just mention [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/e67d6729-50f8-4e5c-8115-813e1aa94344?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/e67d6729-50f8-4e5c-8115-813e1aa94344?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/e67d6729-50f8-4e5c-8115-813e1aa94344?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/e67d6729-50f8-4e5c-8115-813e1aa94344?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/e67d6729-50f8-4e5c-8115-813e1aa94344?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/e67d6729-50f8-4e5c-8115-813e1aa94344?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/e67d6729-50f8-4e5c-8115-813e1aa94344?feedback_type=other)</sup>

[![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=I%20see%20the%20issue%20clearly%20now.%20Your%20logs%20show%20the%20%2A%2A%60async_channel_id%60%20is%20changing%20between%20requests%2A%2A%20-%20from%20%603dba366b-a70c-4ab8-9b86-7aaeb4159775%60%20to%20%607e6ba64b-d2e7-4d8c-aff9-58e6ab88bd9f%60.%20This%20is%20the%20core%20problem.%0A%0A%2A%2AWhy%20%60last_async_event_id%60%20is%20never%20set%3A%2A%2A%20The%20frontend%20%5Bonly%20calls%20%60setLastId%28%29%60%20when%20it%20receives%20at%20least%20one%20event%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset-frontend/src/middleware/asyncEvent.ts%23L169-L183%29.%20Since%20%60/async_event%60%20returns%20empty%20%60%5B%5D%60%20%28no%20events%20exist%20on%20the%20new%20channel%29%2C%20%60processEvents%28%29%60
 
%20is%20never%20called%20and%20localStorage%20never%20gets%20updated.%0A%0A%2A%2AWhy%20events%20are%20empty%3A%2A%2A%20Each%20time%20%60async_channel_id%60%20changes%2C%20you%27re%20polling%20a%20%2Abrand%20new%2A%20Redis%20stream%20that%20has%20no%20events.%20The%20Celery%20workers%20wrote%20events%20to%20the%20old%20channel%20%28%603dba366b...%60%29%2C%20but%20your%20poll%20is%20hitting%20the%20new%20one%20%28%607e6ba64b...%60%29.%0A%0A%2A%2AThe%20%22Token%20reset%22%20you%27re%20logging%2A%2A%20happens%20because%20the%20%5Bafter-request%20handler%20detects%20a%20mismatch%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/async_events/async_query_manager.py%23L167-L195%29%20between%20the%20async-token%20cookie%20and%20session%20state.%20Looking%20at%20your%20logs%3A%0A-%20The%20async-token%20cookie%20likely%20contains%20the%20old%20channel_id%20from%20a%20previous%20request%0A-%20But%20the%20session%20%28which%20you%20reworked%20to%20r
 
ead%20from%20the%20token%29%20shows%20the%20new%20channel_id%0A-%20This%20mismatch%20triggers%20regeneration%0A%0A%2A%2AThe%20issue%20with%20your%20workaround%3A%2A%2A%20You%20said%20%22channel%20comes%20from%20token%2C%20because%20request%20doesn%27t%20have%20it%20at%20all%22.%20If%20the%20async-token%20cookie%20isn%27t%20being%20sent%20with%20%60/async_event%60%20requests%2C%20that%27s%20likely%20a%20%2A%2Acookie%20domain%20or%20SameSite%20issue%2A%2A.%20Check%20your%20browser%20DevTools%20%E2%86%92%20Network%20tab%20%E2%86%92%20click%20on%20the%20%60/async_event%60%20request%20%E2%86%92%20check%20if%20%60Cookie%3A%20async-token%3D...%60%20is%20in%20the%20Request%20Headers.%0A%0A%2A%2ATo%20fix%20this%3A%2A%2A%0A1.%20Ensure%20%60GLOBAL_ASYNC_QUERIES_JWT_COOKIE_SAMESITE%60%20is%20set%20to%20%60%22Lax%22%60%20or%20%60%22None%22%60%20%28with%20%60Secure%3DTrue%60%20if%20%60None%60%29%0A2.%20Ensure%20%60GLOBAL_ASYNC_QUERIES_JWT_COOKIE_DOMAIN%60%20matches%20your%20domain%20exactly%0A3.%
 
20If%20using%20HTTP%20%28not%20HTTPS%29%2C%20set%20%60GLOBAL_ASYNC_QUERIES_JWT_COOKIE_SECURE%20%3D%20False%60%0A4.%20Make%20sure%20your%20OAuth%20flow%20doesn%27t%20clear/recreate%20the%20Flask%20session%20after%20the%20async-token%20cookie%20is%20already%20set%0A%0AThe%20key%20is%20keeping%20the%20%60async_channel_id%60%20stable%20across%20all%20requests%20during%20a%20session%20-%20otherwise%20events%20get%20written%20to%20one%20channel%20but%20polled%20from%20another.)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share
 on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/38303)

GitHub link: 
https://github.com/apache/superset/discussions/38303#discussioncomment-15954693

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to