Skip to content

feat(notifications): a click on a Juno banner goes where the banner says (LAC-8588) - #1042

Merged
lacymorrow merged 6 commits into
mainfrom
LAC-8588/notification-click-routing
Nov 19, 2026
Merged

lacymorrow merged 6 commits into
mainfrom
LAC-8588/notification-click-routing

Conversation

@lacymorrow

@lacymorrow lacymorrow commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Paperclip: LAC-8588 (child of LAC-8231)

The seam

commands::notifications::presenter implemented exactly one
UNUserNotificationCenterDelegate method, willPresentNotification, which is
what makes a banner appear while Juno is frontmost. There was no
didReceiveNotificationResponse, so macOS had nowhere to deliver a click
and every notification Juno posts was a dead end: a finished timer, a new
automation, the scheduler, a finished turn, and LAC-8231's "Juno has no voice
to speak with", whose entire body is an instruction to open a System Settings
pane.

The shape of the fix

A click hands the delegate the identifier of the notification and nothing
else
. So the action rides on the identifier, appended after a #, and
action_from_identifier is the single place that reads it back. One table, not
a callback per caller.

The table is total. No separator, a slug this build does not know, an empty
session id, or a string Juno never posted all read as "bring Juno forward".
There is no path through it that does nothing, and none that can panic.

juno.1763480000123.4                      -> BringJunoForward
juno.1763480000123.4#read-and-speak       -> OpenReadAndSpeak
juno.1763480000123.4#session=9d3f...90ab  -> ShowSession { .. }

The unique part stays in front of the separator, untouched, so two
notifications carrying the same action still do not replace each other in
Notification Center.

Two actions wired

Caller Click goes to
tts/no_voice.rs (LAC-8231's notice) Accessibility > Read & Speak, through the same READ_AND_SPEAK_URLS the Voice picker's own link uses
anthropic.rs (background turn finished / failed), agent_runner.rs (needs input) that conversation, forward, with the session focused in the registry

Read & Speak deliberately does not also bring Juno forward: the person is
being sent to System Settings, and fighting it for the foreground would land
them back where they started.

The session focus is best effort and in that order. A session that has already
finished is gone from the registry, so focusing it fails for the most ordinary
click there is, the one on "finished". The conversation is still what the
person asked for, so the window comes forward either way. open_main_window
makes that call, since it is the one place that decides which surface holds the
full chat.

Only the default action is routed

macOS calls the same method for a dismissal where a category asks for one. Juno
registers no category today, so only the default action arrives, but a
dismissal that opened System Settings would be a real bug the day one is
registered. A dismissal closes the completion handler and does nothing else.

Six callers untouched

notify(app, title, body) and deliver(app, title, body) keep their
signatures. notify_action / deliver_action are the siblings that carry an
action, and NotificationData gained a #[serde(default)] field, so the
frontend payload (which has never carried one) still deserializes.

Acceptance criteria

  • didReceiveNotificationResponse on the existing presenter delegate; a click reaches Rust
  • One place decides what a click means, keyed off the identifier
  • Two actions wired, from two unrelated callers
  • No action or an unknown one brings Juno forward; never a crash, never silent nothing
  • notify(app, title, body) works untouched for the callers with nowhere to go
  • The identifier-to-action mapping is pure and unit-tested, unknown identifier included

Testing

Six unit tests in commands::notifications::tests:

  • an_identifier_says_where_its_click_goes — the table, all three arms
  • an_unknown_action_brings_juno_forward — 7 inputs: a slug from a later build, a bare separator, an empty session id, session without its =, no unique part, the empty string, a string Juno never posted
  • every_action_survives_the_round_trip — post and click are two halves of one encoding
  • an_action_does_not_make_two_notifications_collide — the action must not cost the identifier its uniqueness
  • a_payload_with_no_action_brings_juno_forward — the serde default
  • plus the four existing notification tests, unchanged

Rust compiles in CI, not locally, per CLAUDE.md.

Two notes for the reviewer

Rebased onto main now that #1041 has merged (61060a59), so this PR's diff
is its own three commits and nothing else.

It was opened against the LAC-8231-tts-no-voice-notice branch first, because
the ticket names LAC-8231's notice as the caller for the Read & Speak action
and that notice existed only there. That does not work in this repo: ci.yml
is pull_request: branches: [main], so against any other base no Rust job
runs at all
. One check reported instead of twelve was the tell. It was
retargeted to main and has carried #1041's commits until now.

#1041 was squash-merged, so its commits were never ancestors of main and a
plain rebase would have replayed content already there. Repaired with
git rebase --onto origin/main 48de4c28, after confirming
git diff 48de4c28 61060a59 was empty, which proves the squash is
byte-identical to what was dropped.

Ignore the earlier failed Rust (fmt + clippy + test) on eba31be8. That
job is a 2-second reporter: the macOS Rust job under it sat in the hosted queue
from 17:20:30Z to 17:43:07Z with steps: [], never got a runner, and was
cancelled, so the gate reported failure. Nothing was compiled and nothing
failed. Rust (x86_64 check) passed on the same head, which is a real
cargo check of the workspace. The rebase above is also the fix for this: a
pull_request re-run replays against its original merge ref, and main had
moved to v0.8.297, so gh run rerun would have reproduced it.

src/types/notifications.ts is deliberately not updated. Its
NotificationData is hand-written, has already drifted from the Rust struct
(it carries actions and icon, which Rust has never had), and nothing in
src/ invokes send_notification. Adding a field to dead code is not a fix;
it is out of scope here.

Feature media

Not attached, and it needs a human: a notification click can only be shot from
an installed build (a dev build posts under Terminal, not Juno) with
notification permission granted, on the recording Mac. What to shoot, per
docs/media/CAPTURE.md:

  1. no-voice-click-opens-read-and-speak.mp4 — the no-voice banner, clicked, System Settings opening on Accessibility > Read & Speak
  2. finished-turn-click-opens-conversation.mp4 — a background session finishing, its banner clicked, that conversation coming forward

Both are under 10 seconds. I can take this on a session with the recording Mac
if that is the right next step.

@claude

claude Bot commented Nov 18, 2026

Copy link
Copy Markdown

Review of #1042: a click on a Juno banner now goes where the banner says.

I read the diff and confirmed the helpers it calls exist (open_read_and_speak, focus_agent_session, open_main_window). I did not build or run anything, so CI is the check for compilation and the new tests.

What works well

  • action_from_identifier is total, so no click is ever answered with nothing and none can panic. Splitting on the first # means a session id that contained # would still parse correctly.
  • The unique prefix of the identifier is left untouched, so two banners with the same action still do not replace each other. A test covers this.
  • #[serde(default)] on action keeps the existing frontend payload working. A test covers that too.
  • The delegate calls the completion handler on every path, dismissals included. Only UNNotificationDefaultActionIdentifier triggers navigation.
  • The work moves to tauri::async_runtime::spawn, so the main thread is not blocked on AppKit. There is no unwrap/expect.
  • The round-trip, unknown-slug and empty-session tests cover the table well.

Suggestions (none blocking)

  1. Frontend-supplied actions. ClickAction derives Deserialize and is now part of the send_notification payload, so the webview can request any action. The actions are harmless today (open a fixed settings pane, focus a session, show the window). Any future variant that carries a path or URL would be a privilege surface. A short comment on the enum saying "never add variants that carry user-controlled targets" would help. Alternatively, mark the field #[serde(skip)] if the frontend should never set it.
  2. Identifier length and charset. The session id is appended verbatim. If a session id is ever not UUID-shaped (for example a user-chosen name containing # or whitespace), it still parses, but the identifier grows. A debug assertion or a test that SessionId is always UUID-shaped would document the invariant the separator comment relies on.
  3. Missing session on click. ShowSession for a finished session logs at info and then falls back to bringing Juno forward, which is the intended behaviour. It would be nicer to also emit an event so the UI can select that conversation, but this is a reasonable first step.
  4. Cold-launch clicks. If a click launches Juno, the response can arrive before install runs. APP.get() then returns None, the click is only logged, and the person gets nothing. This is the one path that still ends in silence, against the stated goal. Consider storing the pending identifier and replaying it once install runs.
  5. Dead-code attributes. The repeated #[cfg_attr(not(target_os = "macos"), allow(dead_code))] could be folded into a #[cfg(target_os = "macos")] module, or into one #![allow] on a small submodule. This is cosmetic.

No bugs found that I would block on. Nice, tightly scoped change.

@lacymorrow
lacymorrow changed the base branch from LAC-8231-tts-no-voice-notice to main November 18, 2026 17:13
@lacymorrow lacymorrow closed this Nov 18, 2026
@lacymorrow lacymorrow reopened this Nov 18, 2026
lacymorrow added a commit that referenced this pull request Nov 18, 2026
…d (LAC-8588)

Review of #1042 found `ClickAction` reachable from the `send_notification`
payload: it derived `Deserialize` and rode on `NotificationData`, so a webview
could name a destination. Every variant is a fixed target compiled into the
app, so nothing was exploitable today, but it is the wrong side of Juno's
boundary and the first variant carrying a path or a URL would make it a real
surface.

The derives are gone and the field is `#[serde(skip)]`. A Rust caller sets it;
a payload asking for one reads as the default, which is also what the frontend
has always sent. A test pins both halves.

Also from the review:

- a test asserts the separator cannot appear in the unique part of an
  identifier, which is the claim the unambiguous split rests on
- the round trip now includes a session id containing the separator, since
  `AgentSessionId` is a `From<String>` newtype and UUID shape is convention
- the delegate's unset-handle arm says why it is unreachable (`install` sets
  the handle before the delegate, and the object takes no message until it is
  the delegate), so it is not later "fixed" with a replay latch no click
  can reach
@lacymorrow

Copy link
Copy Markdown
Owner Author

Thanks. Two taken, three declined with reasons. Fixes are in 86c32110.

1. Frontend-supplied actions. Taken, and further than suggested. You are
right that it was the wrong side of Juno's boundary, and #[serde(skip)] is
the better of your two options, so ClickAction lost its serde derives
entirely and the field is skipped. A Rust caller sets it; a payload that asks
for one reads as the default, same as the payload the frontend has always sent
(nothing). Both halves are pinned by
a_payload_cannot_choose_where_a_click_goes. The enum's doc comment now says
no variant may carry a user-controlled target and why, which is the comment you
asked for, in the place a future variant author will be standing.

2. Identifier charset. Taken as a test, not an assertion. The invariant the
separator comment actually rests on is that the unique part cannot contain
#, and that is guaranteed by format!("juno.{}.{}", millis, sequence). That
is now the_unique_part_of_an_identifier_never_contains_the_separator. The
session-id side needs no invariant: AgentSessionId is a From<String>
newtype, so UUID shape is convention, and the parse is already correct without
it. The round trip now carries not#a#uuid to show that, since the first
separator ends the unique part and every later one belongs to the slug.

3. Emit an event so the UI selects that conversation. Declined: that event
already exists, and there is no second conversation to select.
Juno's
parallel sessions are rows in one chat surface, not windows or panes of their
own. focus_agent_session already emits AGENT_SESSION_FOCUSED and
AGENT_SESSIONS_UPDATED, and useAgentSessions keys the roster and the
switcher off the focused flag those carry, so focusing is the selection
mechanism the app has. A new event would be a second way to say the same thing,
and a per-session conversation view to select does not exist to be selected.

4. Cold-launch clicks. Declined: that arm is unreachable, including for a
click that launches Juno.
install sets APP before setDelegate, and the
presenter cannot be sent a message until it is the delegate, so there is no
window in which a response arrives with APP unset. A pending-identifier latch
would be code no click can reach, which is worse than the log: it reads as a
handled case and is never exercised. I have written that ordering argument into
the None arm so the next reader does not add the latch.

Worth noting the related path that is real and is handled: with no delegate
at all (a dev build, or a binary outside Juno.app) install_presenter
returns early, nothing is posted, and there is no banner to click.

5. Dead-code attributes. Declined, with the tradeoff stated. The file
already carries exactly this attribute on request_identifier and
next_request_identifier for exactly this reason, so following it keeps one
pattern rather than two. Folding the cluster into a #[cfg(target_os = "macos")] module would also move the pure mapping tests off the Linux job,
and a &str -> enum function is the piece most worth running on both.

@claude

claude Bot commented Nov 18, 2026

Copy link
Copy Markdown

Review of #1042: click-to-action for Juno notifications.

Verdict: the design is sound and I found no blocking issues.

What works well

  • action_from_identifier is total. A missing separator, an unknown slug, an empty session id or a foreign string all fall back to BringJunoForward, and nothing panics. That matches the CLAUDE.md rules on no unwrap and no silent dead ends.
  • ClickAction has no serde derives and NotificationData.action is #[serde(skip)], so the webview cannot choose a click destination. This is a good security boundary, and the doc comment explains why it must stay.
  • Only UNNotificationDefaultActionIdentifier triggers navigation. The completion handler is called on every path.
  • Work is moved onto tauri::async_runtime::spawn, so AppKit does not block the delegate callback.
  • APP is set before the delegate is installed, and the unreachable None case is logged rather than latched.
  • The unique part of the identifier stays in front of the #, so notifications do not replace each other in Notification Center.

Minor suggestions (non-blocking)

  1. ShowSession takes everything after session= as the id. If a session id could ever contain #, split_once still splits at the first one, so it is safe. The doc comment says ids are UUIDs, so a debug_assert! or a test in identifier_with_action pinning that assumption would guard against future id formats.
  2. handle_click logs the full identifier, session id included, at info. That is fine for local logs, but it is worth a thought if logs are ever uploaded.
  3. OpenReadAndSpeak does not bring Juno forward, which is a reasonable choice. A short note in the user docs would help if the behaviour is user-visible.
  4. I did not see an end-to-end test of the delegate method. That is understandable, since it needs a real UNUserNotificationCenter. The pure functions (slug, identifier_with_action, action_from_identifier) are the right place for round-trip tests. Make sure they cover a round trip for every variant and malformed inputs such as "x#", "x#session=", "#" and "x#a#b".
  5. Please confirm CI passes fmt, clippy -D warnings and tests. The cfg_attr(not(target_os = "macos"), allow(dead_code)) attributes should keep non-macOS builds clean.
  6. Per CLAUDE.md, a visible behaviour change like this needs PR feature media under docs/changelog/media/1042/.

I only read the diff. I have not run or built anything.

🤖 Generated with Claude Code

@claude

claude Bot commented Nov 18, 2026

Copy link
Copy Markdown

Review of #1042 (click on a Juno banner goes where it says)

Overall: a well-shaped fix. Putting the action on the request identifier after a # is the right call, because a click delivers only the identifier. action_from_identifier is total, so no click does nothing. I read the code and did not run it, since CI compiles Rust here.

What I like

  • The unique part of the identifier is left untouched, so banners still do not replace each other in Notification Center.
  • did_receive_response only acts on UNNotificationDefaultActionIdentifier, and the completion handler is called on every path out. A missing call would stall later responses.
  • install sets APP before setting the delegate, so the None branch cannot be reached by a real click. Logging there rather than latching a replay is reasonable.
  • handle_click hands off to tauri::async_runtime::spawn, so the main-thread delegate callback is not blocked on AppKit. This follows the repo rule.
  • The tests cover the table edge cases: empty slug, empty session id, unknown slug, and a session id that itself contains #. The test that the unique part never contains the separator is a good guard.

Suggestions (non-blocking)

  1. Delegate-method coverage: did_receive_response is not exercised by any test, and it cannot be on Linux CI. The handle_click -> run_action split is testable in principle. A small seam, such as a trait or fn pointer for the three side effects, would let a test assert that ShowSession calls focus and then bring_juno_forward even when focus errors. That ordering is the subtle part of the PR.
  2. ShowSession falling through to bring_juno_forward after a failed focus is the right user-facing behaviour. It is logged at info, though. If a session that is still waiting on the user fails to focus, that is worth a warn. A finished session failing to focus is the expected case. If focus_agent_session returns a structured "not found", you could log only the other errors at warn, which also fits the repo rule against string-based error detection.
  3. Session ids ride in the identifier verbatim. This is fine today, since ids are Juno-generated and the notification is local. If an id format ever allows arbitrary text, percent-encoding the slug would remove any ambiguity. The split_once design already tolerates # inside the id.
  4. std::mem::forget(presenter) works because install runs once. A static holding the Retained would state the intent more clearly, though it needs a Send/Sync wrapper, so I would leave it.
  5. OpenReadAndSpeak deliberately does not bring Juno forward. A one-line note in the banner copy or docs is enough. The behaviour is documented in the code already.

No security concerns: the identifier is only parsed, never executed, and unknown input degrades to bringing Juno forward. No new unwrap/expect, no tokio::spawn, and the Cargo feature addition (UNNotificationResponse) is minimal.

I would merge once CI (fmt, clippy, tests) is green. A manual click test on a built app for the three paths would still be worth doing, since the delegate method only runs on macOS.

@lacymorrow

Copy link
Copy Markdown
Owner Author

#1041 is merged (17:23:01Z, squash 61060a59), so the stack is clear and #1042 is next.

All 12 checks passed on its final head before merge, including both macOS Rust jobs. Three claude-review passes were answered in full; the one substantive fix was a latent bug worth knowing about if you are touching tts/no_voice.rs: report_silence used to spend the one-shot TOLD latch before reading APP, so a silence arriving before remember_app had run would eat the run's only notice and show nothing. It now reads the handle first (let ... else) and spends the latch only when there is something to post through, logging at debug otherwise. If your one-line change at no_voice.rs:118 sits inside report_silence, re-read that order after you rebase.

Rebase on main and the three commits this PR was carrying should drop out of its diff, leaving only the delegate method and the routing table.

Two things from my side that are relevant to your review:

  • The notice's body is "Pick a Siri voice in System Settings > Accessibility > Read & Speak.", and the_notice_agrees_with_the_picker derives the pane name from voices::READ_AND_SPEAK_LINK so the two surfaces cannot drift apart. If your click action opens that pane via READ_AND_SPEAK_URLS, all three now agree by construction, which was the point of filing LAC-8588 rather than hand-wiring one URL into one notice.
  • Thanks for the ci.yml note on stacking. That matches what I measured here from the other side: a base that is not main reports 1 check instead of 12, so targeting main and carrying the diff was the right call.

…ays (LAC-8588)

The presenter delegate implemented one method, `willPresentNotification`,
which is what makes a banner appear while Juno is frontmost. With no
`didReceiveNotificationResponse` macOS had nowhere to deliver a click, so
every notification Juno posts was a dead end: a finished timer, a new
automation, the scheduler, a finished turn, and LAC-8231's "Juno has no
voice to speak with", whose whole body is an instruction to open a System
Settings pane.

One table, not a callback per caller. A click hands the delegate the
identifier of the notification and nothing else, so the action rides on the
identifier after a `#`, and `action_from_identifier` is the single place
that reads it back. It is total: no separator, an unknown slug, an empty
session id, or a string Juno never posted all read as "bring Juno
forward". No click is answered with silence, and none can panic.

Wired:

- the no-voice notice opens Accessibility > Read & Speak, through the same
  `READ_AND_SPEAK_URLS` the Voice picker's own link uses
- a background session that finished, failed, or is waiting on input brings
  its conversation forward and focuses that session in the registry

`notify(app, title, body)` and `deliver` keep their signatures, so the six
callers with nowhere to go are untouched; `notify_action` and
`deliver_action` are the siblings that carry one.

Only the default action is routed. A dismissal closes the handler and does
nothing else, so the day a category asks for dismiss responses one does not
open System Settings.
…d (LAC-8588)

Review of #1042 found `ClickAction` reachable from the `send_notification`
payload: it derived `Deserialize` and rode on `NotificationData`, so a webview
could name a destination. Every variant is a fixed target compiled into the
app, so nothing was exploitable today, but it is the wrong side of Juno's
boundary and the first variant carrying a path or a URL would make it a real
surface.

The derives are gone and the field is `#[serde(skip)]`. A Rust caller sets it;
a payload asking for one reads as the default, which is also what the frontend
has always sent. A test pins both halves.

Also from the review:

- a test asserts the separator cannot appear in the unique part of an
  identifier, which is the claim the unambiguous split rests on
- the round trip now includes a session id containing the separator, since
  `AgentSessionId` is a `From<String>` newtype and UUID shape is convention
- the delegate's unset-handle arm says why it is unreachable (`install` sets
  the handle before the delegate, and the object takes no message until it is
  the delegate), so it is not later "fixed" with a replay latch no click
  can reach
…t the slug (LAC-8588)

The comment claimed neither half of an identifier could contain the
separator. The unique part cannot, by construction, and a test now says so.
A session id can: `AgentSessionId` is a `From<String>` newtype, so UUID
shape is convention. The parse was already right either way, because the
first separator ends the unique part and every later one belongs to the slug,
and a round-trip case covers it. Only the comment was wrong.
@lacymorrow
lacymorrow force-pushed the LAC-8588/notification-click-routing branch from eba31be to 9da447b Compare November 18, 2026 20:14
@claude

claude Bot commented Nov 18, 2026

Copy link
Copy Markdown

Review: notification click routing (LAC-8588)

Overall this is a clean, well-reasoned change. I did not run anything locally (CI owns Rust builds), so this is a read-through of the diff.

What works well

  • Encoding the action in the request identifier is the right fit, since macOS hands the delegate only the identifier on a click. action_from_identifier is total and cannot panic, and the unique prefix stays untouched so notifications still do not replace each other.
  • ClickAction has no serde derives and the field is #[serde(skip)], so the webview cannot pick a destination. a_payload_cannot_choose_where_a_click_goes pins that behaviour.
  • The delegate only acts on UNNotificationDefaultActionIdentifier, and the completion handler is called on every path. APP is set before the delegate is installed, which the comment explains.
  • Test coverage is good: the routing table, unknown or malformed identifiers, a round trip including a session id containing #, uniqueness, and the separator invariant.

Minor points and suggestions

  1. ShowSession calls focus_agent_session and then always calls bring_juno_forward. If focus_agent_session already raises the window and selects the session, the second open_main_window could re-resolve the surface and undo or duplicate that focus. Worth confirming on a real build that the session stays selected. If it does not, bring the window forward first and then focus.
  2. handle_click runs run_action on tauri::async_runtime::spawn, which is correct. deliver_action and notify_action mostly duplicate deliver and notify. That is fine as an additive API, but consider having callers migrate so there is only one path eventually.
  3. The session id is embedded in the notification identifier. That is not sensitive, but identifiers can show up in Notification Center logs, so keep the invariant that only opaque ids go in the slug.
  4. The many #[cfg_attr(not(target_os = "macos"), allow(dead_code))] attributes are noisy. A single #[cfg(target_os = "macos")] gate on a small submodule would be tidier, though the tests then need to run cross-platform, so the current approach is defensible.
  5. The click-handling path itself (delegate to handle_click to run_action) is not unit-tested. That is understandable because it needs AppKit, but the PR media or a manual QA note on clicking a finished-session banner and the no-voice banner would be good evidence.

No blocking issues found. Nice work.

CI's test step failed on one of this PR's own tests:

    assertion `left == right` failed: '#read-and-speak' should bring Juno forward

The test was wrong and the code was right, but the doc comment was wrong too,
which is why the test got written that way. `action_from_identifier` reads
only the slug after the separator; the comment claimed that "a string Juno
never posted" brings Juno forward, and `#read-and-speak` is such a string
while plainly naming a known action.

Keeping the behaviour, because validating the unique part would buy nothing
and cost something:

- there is no channel for a forged identifier. Only Juno's own bundle can have
  a response delivered to Juno's delegate, so everything arriving here was
  written by some build of Juno
- tying routing to `request_identifier`'s format would mean a later change to
  that format silently stopped routing the notifications already sitting in
  Notification Center. The unique part is macOS's dedup key and nothing else

So the comment now states the real rule, `#read-and-speak` moves out of the
unknown-action list (it is a known action with a degenerate prefix), and a new
test pins invariance across the prefix: the same slug behind what Juno posts,
behind nothing, and behind a prefix Juno would never write.

fmt and clippy were clean, and 2237 of 2238 tests passed, so this was the only
disagreement in the change.
@claude

claude Bot commented Nov 18, 2026

Copy link
Copy Markdown

Review: click routing for Juno notifications (LAC-8588)

Overall this is a well-built change. I have no blocking findings. I read the diff and checked that the callees exist with the signatures used (open_read_and_speak, focus_agent_session, open_main_window, and the two NotificationData construction sites). I did not compile or run anything; CI covers that.

What I like

  • The routing table is total, so no click gets silence. It is also pure, so it can be tested without a macOS runtime.
  • #[serde(skip)] on action keeps the webview from choosing a click destination. a_payload_cannot_choose_where_a_click_goes pins that.
  • The delegate filters on UNNotificationDefaultActionIdentifier, so a future dismiss action will not open System Settings.
  • The completion handler is called on every path.
  • APP is set before the delegate is installed, and the doc comment explains why the None branch is unreachable.
  • The round-trip, uniqueness and separator-in-session-id tests cover the real edge cases.

Suggestions (non-blocking)

  1. handle_click logs the full identifier at info. For ShowSession the identifier embeds the session id. That is probably fine for local logs, but if logs are ever attached to bug reports it is worth a thought.
  2. ShowSession always calls bring_juno_forward, even when focus succeeded. That seems intended: focusing only sets registry state and emits an event. Please check that open_main_window does not reset the focused session, because it runs after focus_agent_session. A short test or a manual check on a built app would settle it, and I could not verify it from the diff.
  3. focus_agent_session takes tauri::State. The code gets it from try_state::<AppState>(), which works. If the command has a plain-function core, calling that would avoid the State wrapper dance.
  4. The cfg_attr(not(macos), allow(dead_code)) attributes are repeated on seven items. A single #[cfg(target_os = "macos")] submodule, or one #![allow] on a small click module, would be tidier. This is cosmetic.
  5. Test coverage gap. run_action and the delegate are untested, which is understandable given the AppKit dependency. The PR description should state that a click on a built app was checked manually for the Read & Speak and session cases. Per the project media rules, that capture is also needed for QA.
  6. # is not documented as reserved for notification identifiers in Apple docs. It works, but a one-line note that the identifier is opaque to macOS would help the next reader.

The Cargo feature addition (UNNotificationResponse) and the install_presenter(&app_handle) call-site change both look right. Nice work.

@lacymorrow

Copy link
Copy Markdown
Owner Author

CI's first real verdict on this PR (the earlier red was a starved macOS runner, see the body): fmt clean, clippy clean, 2237 of 2238 tests passed. The one failure was one of this PR's own tests, and it was pointing at something real.

assertion `left == right` failed: '#read-and-speak' should bring Juno forward

an_unknown_action_brings_juno_forward listed #read-and-speak as an unknown action. It is not: it is a known action with a degenerate prefix, and action_from_identifier correctly returned OpenReadAndSpeak because it reads only the slug after the separator.

The reason the test said otherwise is the actual defect: the function's doc comment promised that "a string Juno never posted" reads as BringJunoForward. #read-and-speak is such a string and plainly names a known action, so the code and its own documentation disagreed and the test encoded the documentation.

I kept the behaviour and fixed the documentation, because validating the unique part buys nothing and costs something:

  • No forged identifier can arrive. Only Juno's own bundle can have a response delivered to Juno's delegate, so everything reaching the handler was written by some build of Juno.
  • It would couple routing to a format. The unique part is macOS's dedup key and nothing more. Tying routing to request_identifier's shape means a later change to that shape silently stops routing the notifications already sitting in Notification Center.

0c2ecbc5 therefore: states the real rule in the doc comment, moves #read-and-speak out of the unknown-action list, and adds routing_reads_the_slug_and_never_the_unique_part, which pins invariance across the prefix (the same slug behind what Juno posts, behind nothing, and behind a prefix Juno would never write). Nine tests now.

Two review passes independently asked whether `open_main_window`, which runs
after `focus_agent_session` in the `ShowSession` arm, could reset the session
that was just focused. Neither could tell from the diff. Checked instead of
assumed:

- `AgentSessionRegistry::set_focused` has exactly one caller in the app,
  `focus_agent_session`. Nothing on `open_main_window`'s path (`show_bar`,
  `emit_ladder`, `create_or_show_window`, `announce_main_window`) writes focus
- every frontend `focusSession` call is an `onFocus` prop on a session row, so
  it fires on a click and never on mount. Showing the window mounts nothing
  that re-focuses

The order is therefore correct as written. That reasoning now sits in the arm,
along with what to do if the premise ever stops holding, so the next person to
add a focus writer sees which order depends on them.
@lacymorrow

Copy link
Copy Markdown
Owner Author

Answering the two review passes at 20:15Z and 22:05Z together, since they overlap.

The one point worth real work: does showing the window reset the focus?

Both passes asked this and both said they could not tell from the diff. It is the right question, so I checked rather than asserted. The order is correct, and here is the evidence.

  • AgentSessionRegistry::set_focused has exactly one caller in the app: focus_agent_session, the command this arm calls. Every other hit in the tree is the definition or a test. Nothing on open_main_window's path writes focus: bar_owns_full_chat, show_bar, emit_ladder, create_or_show_window, announce_main_window.
  • Every frontend focusSession call is an onFocus={...} prop on AgentSessionRows (App.tsx, FloatingBar.tsx, IslandBar.tsx, TransparentFloatingPanel.tsx). It fires on a click on a session row, never on mount. So putting the window on screen mounts nothing that re-focuses.

2e8ec0c3 records that in the arm itself, with what to do if the premise ever stops holding, so whoever adds a second focus writer can see which ordering depended on them. I preferred that to the manual check you suggested: a manual check expires, and a note in the PR thread is not where the next person will be looking.

I did not add a source-scanning test pinning "one focus writer". That invariant belongs to the session registry, not to notification routing, and asserting another module's invariant from this PR is the wrong home for it.

One factual correction

deliver_action and notify_action mostly duplicate deliver and notify. [...] consider having callers migrate so there is only one path eventually.

There is already only one path. deliver is a two-line wrapper that calls deliver_action(.., &ClickAction::BringJunoForward), and notify likewise calls notify_action. There is exactly one implementation of each; the short names survive so the six callers with nowhere to go did not have to change, which the ticket asked for. Nothing to migrate.

The rest, declined with reasons

Logging the identifier at info (so the session id). Kept. The id is a random v4 UUID with no personal data in it, and it is the only thing that makes the line diagnostic: "a click arrived and routed to X" without naming the session answers nothing. If Juno ever puts a human-chosen name in a session id, that is the moment to revisit, which is the same invariant your other point asks for (only opaque ids in the slug).

focus_agent_session takes tauri::State. There is no plain-function core to call. set_focused on the registry is the primitive, but the command also emits AGENT_SESSION_FOCUSED and the sessions-updated broadcast, and the UI keys off both. Calling the command reuses that; calling the primitive would mean duplicating the two emits here, which is how they drift.

The seven cfg_attr(not(macos), allow(dead_code)). Declined for the third time, same reason: the file already carries that exact attribute on request_identifier and next_request_identifier, so this follows one pattern instead of adding a second, and a #[cfg(target_os = "macos")] submodule would move the pure mapping tests off the Linux job. Both passes now call it defensible or cosmetic, which I agree with.

# is not documented by Apple as reserved. Correct, and it does not need to be: the identifier is opaque to macOS, which uses it only as a replacement key. The doc comment on ACTION_SEPARATOR already says the separator's guarantee comes from Juno's own format rather than from Apple, and the_unique_part_of_an_identifier_never_contains_the_separator asserts the half that is actually load-bearing.

run_action and the delegate are untested. True, and it stays true: both need AppKit. I am not going to state in the PR body that I clicked a built app, because I have not. A click can only be shot from an installed build with notification permission, and a dev build posts notifications under Terminal rather than Juno, so the delegate is never even installed. That is the same reason the feature media needs the recording Mac, and it is called out in the body rather than papered over.

@claude

claude Bot commented Nov 18, 2026

Copy link
Copy Markdown

Review of #1042 (notification click routing)

I read the diff only. I did not build it or run CI, per the repo rules.

Overall: this looks good to merge once CI is green. The design is small and easy to check. The action is encoded on the request identifier, one total parse function reads it back, and every unknown input falls through to "bring Juno forward".

What I checked

  • Delegate method: completion_handler is called on every path, including dismissal and a missing APP. macOS holds the next response until it is called.
  • Click handling: only UNNotificationDefaultActionIdentifier triggers navigation. The work is moved onto tauri::async_runtime::spawn off the main-thread delegate callback, as CLAUDE.md requires.
  • Frontend boundary: #[serde(skip)] on NotificationData.action keeps the webview from choosing a click destination. a_payload_cannot_choose_where_a_click_goes covers that. ClickAction is Default, which serde(skip) needs.
  • Parsing: split_once on the first # is safe with # inside a session id, and the round-trip test covers it. Nothing byte-slices a string and nothing panics. There is no unwrap or expect outside tests.
  • Uniqueness: the unique prefix is untouched, so two notifications with the same action still do not replace each other. A test asserts this.

Minor suggestions (non-blocking)

  1. ShowSession focuses the session and then brings the window forward. The comment justifies the order by saying set_focused has one caller. That invariant is only in prose. A cheap guard would help: a test, or a // keep in sync note next to set_focused, so a second writer does not silently break the order.
  2. info!("Notification ... was clicked: {:?}", ...) logs the session id. That is probably fine, since it is a local log. Keep it in mind if session ids ever become sensitive.
  3. The repeated #[cfg_attr(not(target_os = "macos"), allow(dead_code))] is noisy. A single #[cfg(target_os = "macos")] section, or a module-level attribute, would be tidier. The parser tests would then need to stay platform-independent, since they currently run on Linux CI.
  4. Everything the delegate does after handle_click (the OpenReadAndSpeak and ShowSession flows) is untested. That is understandable for the AppKit-bound parts. A thin test seam around run_action is optional. The pure routing table is well covered.

Security: no new attack surface. Destinations are fixed and compiled in, and the identifier is only ever written by Juno. The doc comment warning against variants that carry a path, URL or shell word is a useful guardrail.

Nice work.

@lacymorrow

Copy link
Copy Markdown
Owner Author

Closing out the two earlier passes (17:18Z, 17:21Z). Most of their points are covered by the reply above or by the commits since; two are new.

A seam (trait or fn pointer) so a test can assert ShowSession focuses and then brings Juno forward, even when focus errors. Declined. You are right that the ordering is the subtle part of this PR, which is why I verified it directly and wrote the reasoning into the arm in 2e8ec0c3: set_focused has exactly one caller in the app and nothing on open_main_window's path writes focus, so the order cannot be undone by showing the window. An indirection layer over three direct calls, existing only so a test can observe their order, is more machinery than the fact it would protect, and the repo's own rule is not to add an abstraction for a case that is not there. If a second focus writer ever appears, the comment names this ordering as the thing that breaks.

warn rather than info when a session that is still waiting on the user fails to focus. Good distinction, and declined for the reason you spotted yourself: focus_agent_session returns Result<(), String>, so separating "not found" from any other failure would mean matching on the message, and src-tauri/CLAUDE.md bans string-based error detection outright. The honest options are to log every failure at one level or to change set_focused's error type, and the second is a session-registry change that does not belong in a notification-routing PR. info is the level that fits the dominant case: a finished session is expected to be gone, and that is the most ordinary click there is. Making the rare case louder is worth doing the day set_focused has a typed error, not before.

Already handled rather than declined:

  • A debug_assert! or test pinning that session ids are UUID-shaped. Covered better than asserted: every_action_survives_the_round_trip now carries a not#a#uuid id, which shows the parse does not depend on the shape. The first separator ends the unique part and every later one belongs to the slug. Pinning an assumption the code does not rely on would be the wrong guard.
  • Percent-encoding the slug. Same reason: nothing is ambiguous, and the round-trip test is the proof rather than the claim.
  • Confirm fmt, clippy -D warnings and tests. Confirmed on 0c2ecbc5: fmt clean, clippy clean, 2238 tests. The macOS job ran with steps=15. The earlier red was a starved runner, which the body explains.
  • Feature media under docs/changelog/media/1042/. Not attached, and the body says so rather than papering over it: a click can only be shot from an installed build with notification permission, and a dev build posts under Terminal, so the delegate is never installed. It needs the recording Mac.
  • std::mem::forget(presenter) vs a static. Pre-existing, untouched by this PR, and you landed on leaving it. Agreed, and changing it here would be scope I should not take.

No unanswered comments remain on my side.

… on (LAC-8588)

A sixth review pass made the point the previous five had not quite landed:

  The comment justifies the order by saying `set_focused` has one caller.
  That invariant is only in prose.

Correct, and prose is the weakest kind of guard. I had declined the expensive
half of the suggestion (a trait seam so a test could observe call order) and
dropped the cheap half with it, which was the wrong call: the invariant is
checkable without any seam at all.

`ShowSession` focuses the session and then calls `open_main_window`. That
order is safe only while nothing on the window-opening path writes focus.
The new test walks `src-tauri/src` and asserts the set of files containing a
focus write is exactly two: the registry that defines the setter, and the
command module whose job is focusing a session. A write appearing anywhere
else, `window_management.rs` above all, fails with a message naming this
ordering and what to do about it.

Two traps the repo has been bitten by before, both handled:

- it would match its own marker and report this file, so the marker is
  assembled from pieces (`format!("set_{}(", "focused")`) and never appears
  contiguously on a code line here
- a scan that walked the wrong tree, or stopped matching, finds nothing and
  passes while proving nothing. So the allowed files are asserted present
  *before* the unexpected set is checked. Both halves have to hold

Comment lines are skipped in all three forms, following
`agents_holds_no_executor`, which is the house pattern for this.
@lacymorrow

Copy link
Copy Markdown
Owner Author

Sixth review pass, and it landed the point the previous five had circled:

The comment justifies the order by saying set_focused has one caller. That invariant is only in prose.

You are right, and prose is the weakest kind of guard. I had declined the expensive half of this suggestion (a trait seam so a test could observe the call order) and dropped the cheap half along with it. That was the wrong call: the invariant is checkable with no seam at all.

d335fb8b adds nothing_outside_the_session_registry_writes_focus. It walks src-tauri/src and asserts the set of files containing a focus write is exactly two: the registry that defines the setter, and the command module whose job is focusing a session. A write appearing anywhere else, window_management.rs above all, fails with a message that names this ordering and says what to do:

a new focus writer appeared in [...]. ClickAction::ShowSession in this file focuses a session and then calls open_main_window, which is only safe while putting a window on screen cannot change the focused session. Either bring the window forward first and focus second, or add the file here once you have checked it can never run on a window-open path.

That is better than the // keep in sync note you offered as the alternative, because a new caller does not edit the setter, they call it. A failing test reaches them; a comment on the definition might not.

Two traps this kind of test has fallen into in this repo before, both handled:

  • It would match its own marker and report notifications.rs as a focus writer. The marker is assembled from pieces, format!("set_{}(", "focused"), so the literal never appears contiguously on a code line in this file.
  • A scan that found nothing would pass while proving nothing (wrong tree, marker stopped matching). So the two allowed files are asserted present before the unexpected set is checked. Both halves have to hold.

Comment lines are skipped in all three forms, following agents_holds_no_executor, which is the house pattern here. I simulated the scan before pushing: two files found, non-vacuity holds, nothing unexpected.

Points 2, 3 and 4 of your review are answered in the two replies above (the info log of a v4 UUID, the cfg_attr attributes, and the AppKit-bound paths that cannot be unit-tested and whose capture needs the recording Mac). Merging once this head is green.

@claude

claude Bot commented Nov 19, 2026

Copy link
Copy Markdown

Review: notification click routing (LAC-8588)

Overall this is a well-reasoned change. I read the diff but did not build or run it, since CI owns the Rust compile.

What I like

  • Putting the action in the request identifier after # is the right seam, because macOS returns only the identifier on a click. action_from_identifier is total: every unknown input maps to BringJunoForward, with no panic path and no unwrap.
  • #[serde(skip)] on NotificationData.action plus no serde derives on ClickAction means the webview cannot choose a click destination. This is a good security property, and the doc comment says to keep it.
  • Only UNNotificationDefaultActionIdentifier triggers navigation, and completion_handler.call(()) runs on every path.
  • The APP OnceLock is set before the delegate is installed, which avoids a race.
  • The handler spawns via tauri::async_runtime::spawn, as the repo rules require.
  • The tests cover the round trip, the unknown-slug fallback, identifier uniqueness and the # separator invariant.

Suggestions (non-blocking)

  1. nothing_outside_the_session_registry_writes_focus is a source-grep style test. It will pass or fail on formatting and renames rather than behaviour. A comment pointing at the ordering assumption in run_action may be enough, or the test could assert on set_focused call sites in a less brittle way.
  2. In ShowSession, focus runs before the window is shown, and the correctness argument depends on there being a single focus writer. A cheap hardening is to bring the window forward first and then focus, if focus_agent_session emits an event the frontend can handle either way. Otherwise the current comment documenting the constraint is fine.
  3. ShowSession embeds the session id in the identifier. Identifier length is not a concern for UUIDs. It would be worth a debug_assert! or truncation guard if ids ever become free-form, since UserNotifications identifiers feed Notification Center dedup.
  4. APP.set(..) silently ignores a second install. That is fine today, but a debug! log when it is already set would make a double install visible.
  5. On a click that launches a cold Juno, try_state::<AppState> may be None. This is handled gracefully by falling back to showing the window, though the session is not focused in that case. That is an acceptable degradation, but you could note it as a known gap.

Test coverage: good for the pure parsing and routing table. The macOS delegate path cannot run in CI, so a manual click-through on a built branch app is worth recording for the three actions (timer or turn finished, no-voice notice, waiting session). Per CLAUDE.md, a visible behaviour change also needs QA media under docs/changelog/media/1042/.

No blocking issues found.

🤖 Generated with Claude Code

@lacymorrow

Copy link
Copy Markdown
Owner Author

Seventh pass. Nothing blocking, no code changes needed. Two of your points are factually answered by the source, and one contradicts the sixth review, so I am making a call rather than ping-ponging.

Two corrections

5. "On a click that launches a cold Juno, try_state::<AppState> may be None [...] note it as a known gap." Not reachable. .manage(app_state) is at lib.rs:347, on the Builder, and install_presenter is at lib.rs:1155 inside setup. AppState is registered before the delegate exists, so there is no window in which a response arrives without it, the same structural reason the APP branch is unreachable. It is defensive code for an impossible state, not a gap, so I will not write it up as one.

4. "APP.set(..) silently ignores a second install." It cannot happen: the whole body of install is inside ONCE.call_once(...), so it runs exactly once per process. A debug! for the second call would be a log line for an unreachable path.

Your point 2 is right for a better reason than I gave

You suggested bringing the window forward first and focusing second. I checked, and focus-first is actively the better order, not just the safe one:

useAgentSessions loads its initial snapshot at mount via list_agent_sessions, and every AgentSessionInfo in that snapshot carries focused. So when open_main_window has to create the window, React mounts and reads the focused session straight from the registry. Focusing first means the new window renders with the right session already outlined. Showing first would let the mount read the previous focus and then correct itself when the event arrives, which is a visible flicker on exactly the path that matters.

I have added that to the thread rather than to the comment, since the comment already names the invariant and what breaks it, and the test now enforces it.

Point 1 contradicts the sixth review, and I am keeping the test

You call nothing_outside_the_session_registry_writes_focus brittle and suggest a comment may be enough. The sixth pass said the opposite about the same code, in as many words:

The comment justifies the order by saying set_focused has one caller. That invariant is only in prose.

I agree with the sixth, and I am not removing enforcement because a later pass prefers prose. Specifically:

  • The brittleness runs in the right direction. Rename the setter and the non-vacuity assert fires with a message naming this ordering. That is a loud failure at precisely the moment someone is restructuring focus handling, which is when I want them to look. A silent pass is the failure mode I was asked to remove.
  • Formatting is not a real risk. rustfmt never separates a function name from its (, and the scan skips //, /// and //! lines.
  • It is the house pattern, not an invention. agents_holds_no_executor in src/agents/mod.rs is the same source-scan shape, for the same reason: pinning a structural fact that types cannot express.

3. A debug_assert! or truncation guard on identifier length. Declined. UserNotifications documents no length limit a UUID comes near, and every_action_survives_the_round_trip already carries not#a#uuid, which shows the parse does not depend on the id's shape. Asserting a shape the code does not rely on is the wrong guard.

Coverage and media. Unchanged and stated in the body rather than papered over: the delegate path is AppKit-bound and cannot run in CI, and a click can only be shot from an installed build with notification permission, because a dev build posts under Terminal so the delegate is never installed. That needs the recording Mac.

All seven passes are now answered. d335fb8b is 12/12 green with the macOS Rust job genuinely run (steps=15, Clippy and Test each success), main is an ancestor, and no inline comments are outstanding. Merging.

@lacymorrow
lacymorrow merged commit 8e06adb into main Nov 19, 2026
12 checks passed
@lacymorrow
lacymorrow deleted the LAC-8588/notification-click-routing branch November 19, 2026 04:46

This branch was successfully deployed

1 active deployment
ai-review — d335fb8b Deployed Nov 19, 2026 by lacymorrow via claude-review #1374
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant