Skip to content

fix(core): carry filter through pending emit queue - #15779

Closed
tenderdeve wants to merge 1 commit into
tauri-apps:devfrom
tenderdeve:fix/15759-emit-filter-pending
Closed

tenderdeve wants to merge 1 commit into
tauri-apps:devfrom
tenderdeve:fix/15759-emit-filter-pending

Conversation

@tenderdeve

Copy link
Copy Markdown
Contributor

Closes #15759

emit_filter/emit_str_filter broadcast to every target when the emit gets deferred onto the pending queue. That deferral happens whenever an emit runs while the handlers lock is held — most commonly emitting from inside an event handler. The queued Pending::Emit only stored the payload, so on flush it replayed as a plain unfiltered emit().

Fix: store the filter on Pending::Emit and replay it through emit_filter on flush.

Because the queue can be flushed from a different thread than the one that deferred the emit, the stored filter has to be Send, and boxing it into the queue requires 'static. So the filter closure now requires Send + 'static, threaded through Emitter::emit_filter/emit_str_filter and the internal manager/listener paths. This matches the bound Listeners::listen already places on its callback. Internal callers were updated to own their captured labels; if you'd rather keep the public bound unchanged I can rework, but this mirrors the existing listener API.

Added a regression test (pending_emit_keeps_filter) that emits a filtered event from within a handler (forcing the pending path) and asserts only the targeted listener fires.

@tenderdeve
tenderdeve requested a review from a team as a code owner July 26, 2026 04:08
@Legend-Master Legend-Master added the ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy label Jul 26, 2026
When emit_filter runs while the handlers lock is held (e.g. emitting
from inside an event handler) the emit is deferred onto the pending
queue. The queued action dropped the filter and flushed as a plain
emit, broadcasting to every target. Store the boxed filter on
Pending::Emit and replay it via emit_filter. The filter now requires
Send + 'static, consistent with Listeners::listen.

Closes tauri-apps#15759
@tenderdeve
tenderdeve force-pushed the fix/15759-emit-filter-pending branch from 8c59a53 to 14cfefa Compare July 26, 2026 05:17
@tenderdeve

Copy link
Copy Markdown
Contributor Author

Sorry about the noise here — the runtime-wry monitor commits belonged to another branch and got dragged in by accident. Rebased them out, so this is now just the emit-filter change.

On the Send + 'static bound you flagged in the issue: the reason it's hard to avoid is that a deferred emit sits in the shared pending queue, and that queue can be drained by a different thread than the one that queued it — so to replay the filter later it has to be both storable ('static) and sendable (Send). That's the same bound Listeners::listen already puts on its callback, which is why I went this way.

If you'd rather not widen the public emit_filter/emit_str_filter bound, the alternative is to only carry the filter for the same-thread case (emitting from inside a handler, which is the repro) and leave the rare cross-thread defer as the current broadcast. That keeps the public signature untouched but doesn't fully fix the cross-thread path. Happy to switch to that if you prefer — just let me know which direction you want.

@sftse

sftse commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

On the Send + 'static bound you flagged in the issue: the reason it's hard to avoid is that a deferred emit sits in the shared pending queue, and that queue can be drained by a different thread than the one that queued it — so to replay the filter later it has to be both storable ('static) and sendable (Send). That's the same bound Listeners::listen already puts on its callback, which is why I went this way.

@FabianLars @Legend-Master

Posting chatbot responses without verifying them into a comment is to me unacceptable. It's beneath the dignity of people that care for the project to deal with this mercenary behavior.

Vote to close with prejudice.

@Legend-Master

Copy link
Copy Markdown
Contributor

Fully agree here, I'm closing this one.

@tenderdeve Hey, thanks for consider contributing. I merged the last few agent PRs purely because they were better than I expected from current day LLMs and the problems need fixing. But please review all the code yourself and summarize in your own language before submitting to make it a high quality contribution.

Copying something I said some time ago on Discord:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-slop Low effort content, see https://github.com/tauri-apps/tauri?tab=contributing-ov-file#ai-tool-policy

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] emit_filter emits to all targets if inserted to pending

3 participants